[khronos-opencl-clhpp] 01/03: New upstream version 2.0.10
Vincent Danjean
vdanjean at debian.org
Thu Sep 8 23:40:22 UTC 2016
This is an automated email from the git hooks/post-receive script.
vdanjean pushed a commit to branch master
in repository khronos-opencl-clhpp.
commit 561c56710022f3c46194b05235e27a0cae21aaaf
Author: Vincent Danjean <Vincent.Danjean at ens-lyon.org>
Date: Thu Sep 8 21:33:29 2016 +0200
New upstream version 2.0.10
---
CMakeLists.txt | 53 +
README.txt | 46 +
docs/CMakeLists.txt | 15 +
docs/Doxyfile.in | 2362 ++++++++
examples/CMakeLists.txt | 3 +
examples/src/CMakeLists.txt | 61 +
examples/src/headerexampleCL2.cpp | 164 +
examples/src/trivial.cpp | 61 +
examples/src/trivialCL2.cpp | 267 +
examples/src/trivialCL2SizeTCompat.cpp | 130 +
gen_cl_hpp.py | 126 +
include/CMakeLists.txt | 21 +
input_cl.hpp | 8075 +++++++++++++++++++++++++++
input_cl2.hpp | 9570 ++++++++++++++++++++++++++++++++
tests/CMakeLists.txt | 98 +
tests/ToAdd.txt | 8 +
tests/cmock.yml | 9 +
tests/strip_defines.py | 18 +
tests/test_cl2hpp.cpp | 581 ++
tests/test_clhpp.cpp | 1802 ++++++
tests/test_clhpp_cxx11.cpp | 1 +
21 files changed, 23471 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..92e5572
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,53 @@
+cmake_minimum_required(VERSION 2.6)
+project(CLCPP)
+enable_testing()
+
+option(BUILD_DOCS "Build Documentation" ON)
+option(BUILD_EXAMPLES "Build Examples" ON)
+option(BUILD_TESTS "Build Unit Tests" ON)
+
+if(DEFINED ENV{AMDAPPSDKROOT})
+ set(OPENCL_DIST_DIR $ENV{AMDAPPSDKROOT} CACHE PATH "OpenCL source dir")
+ if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+ set(OPENCL_LIB_DIR ${OPENCL_DIST_DIR}/lib/x86_64 )
+ else( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+ set(OPENCL_LIB_DIR ${OPENCL_DIST_DIR}/lib/x86 )
+ endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+elseif(DEFINED ENV{INTELOCLSDKROOT})
+ set(OPENCL_DIST_DIR $ENV{INTELOCLSDKROOT} CACHE PATH "OpenCL source dir")
+ if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+ set(OPENCL_LIB_DIR ${OPENCL_DIST_DIR}/lib/x64 )
+ else( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+ set(OPENCL_LIB_DIR ${OPENCL_DIST_DIR}/lib/x86 )
+ endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+else()
+ set(OPENCL_DIST_DIR "Hello" CACHE PATH "OpenCL source dir")
+ if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+ set(OPENCL_LIB_DIR "" )
+ else( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+ set(OPENCL_LIB_DIR "" )
+ endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+endif()
+
+if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
+endif()
+
+set(OPENCL_INCLUDE_DIR ${OPENCL_DIST_DIR}/include CACHE PATH "OpenCL source dir")
+set(UNITY_DIR $ENV{UNITY_DIR} CACHE PATH "Unity dir")
+set(CMOCK_DIR $ENV{CMOCK_DIR} CACHE PATH "CMock dir")
+
+if(BUILD_DOCS)
+add_subdirectory(docs)
+endif(BUILD_DOCS)
+
+add_subdirectory(include)
+
+if(BUILD_EXAMPLES)
+add_subdirectory(examples)
+endif(BUILD_EXAMPLES)
+
+if(BUILD_TESTS)
+add_subdirectory(tests)
+endif(BUILD_TESTS)
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..382a197
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,46 @@
+Sources for the OpenCL Host API C++ bindings (cl.hpp and cl2.hpp).
+
+Doxgen documentation for the cl2.hpp header is available here:
+
+ http://khronosgroup.github.io/OpenCL-CLHPP/
+
+
+Components:
+ input_cl.hpp:
+ Acts as the master source for the 1.x version of the header.
+ The reason for doing it this way is to generate an appropriate set of functors with varying argument counts without assuming variadic template support in the header.
+
+ input_cl2.hpp:
+ Acts as the master source for the 2.x version of the header.
+ Directly copied as cl2.hpp
+
+ gen_cl_hpp.py:
+ A generator script written in python to convert input_cl.hpp into cl.hpp, generating the functor expansions as necessary.
+ cl2.hpp does not require this as it uses variadic templates expanded in the compiler.
+
+ docs:
+ Doxygen file used to generate HTML documentation for cl2.hpp.
+
+ examples:
+ A simple example application using the very basic features of the header and generating cl.hpp dynamically through the build system.
+
+ tests:
+ A (very small, incomplete) set of regression tests. Building the tests requires Python, Ruby, Unity and CMock. For the last two I've used Unity 2.1.0 [1] and CMock top-of-tree from Github [2] (the version 2.0.204 on Sourceforge does not work). At the moment there is no way to skip building the tests.
+
+ CMake scripts:
+ A build system that both generates the example and drives generation of cl.hpp.
+
+You need to tell cmake where to find external dependencies, using the variables OPENCL_DIST_DIR, UNITY_DIR and CMOCK_DIR. These can be set either as environment variables, or on the cmake command line using the syntax -D<VAR>=<VALUE>. For the lazy, I use the following commands to build and test (you'll need to adapt your paths):
+
+mkdir build
+cd build
+cmake -DUNITY_DIR=$HOME/src/unity -DCMOCK_DIR=$HOME/src/cmock -DOPENCL_DIST_DIR=/opt/AMD-APP-SDK-v2.7-RC-lnx64/ ..
+make
+tests/test_clhpp
+tests/test_clhpp_cxx11
+tests/test_clhpp_deprecated_1_1
+
+After building, the headers appear in build/include/CL/. If Doxygen is available, you can generate HTML documentation by typing `make docs`.
+
+[1] https://github.com/ThrowTheSwitch/Unity/releases/tag/v2.1.0
+[2] https://github.com/ThrowTheSwitch/CMock
diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
new file mode 100644
index 0000000..fee8347
--- /dev/null
+++ b/docs/CMakeLists.txt
@@ -0,0 +1,15 @@
+find_package(Doxygen)
+
+if (DOXYGEN_FOUND)
+
+configure_file(Doxyfile.in Doxyfile COPYONLY)
+add_custom_target(
+ docs
+ COMMAND
+ ${DOXYGEN_EXECUTABLE}
+ WORKING_DIRECTORY
+ ${CMAKE_CURRENT_BINARY_DIR}
+ VERBATIM)
+add_dependencies(docs generate_cl2hpp)
+
+endif (DOXYGEN_FOUND)
diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in
new file mode 100644
index 0000000..d6f7586
--- /dev/null
+++ b/docs/Doxyfile.in
@@ -0,0 +1,2362 @@
+# Doxyfile 1.8.9.1
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project.
+#
+# All text after a double hash (##) is considered a comment and is placed in
+# front of the TAG it is preceding.
+#
+# All text after a single hash (#) is considered a comment and will be ignored.
+# The format is:
+# TAG = value [value, ...]
+# For lists, items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (\" \").
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all text
+# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv
+# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv
+# for the list of possible encodings.
+# The default value is: UTF-8.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
+# double-quotes, unless you are using Doxywizard) that should identify the
+# project for which the documentation is generated. This name is used in the
+# title of most generated pages and in a few other places.
+# The default value is: My Project.
+
+PROJECT_NAME = "OpenCL C++ Bindings"
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
+# could be handy for archiving the generated documentation or if some version
+# control system is used.
+
+PROJECT_NUMBER =
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer a
+# quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF =
+
+# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
+# in the documentation. The maximum height of the logo should not exceed 55
+# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
+# the logo to the output directory.
+
+PROJECT_LOGO =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
+# into which the generated documentation will be written. If a relative path is
+# entered, it will be relative to the location where doxygen was started. If
+# left blank the current directory will be used.
+
+OUTPUT_DIRECTORY =
+
+# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
+# directories (in 2 levels) under the output directory of each output format and
+# will distribute the generated files over these directories. Enabling this
+# option can be useful when feeding doxygen a huge amount of source files, where
+# putting all generated files in the same directory would otherwise causes
+# performance problems for the file system.
+# The default value is: NO.
+
+CREATE_SUBDIRS = NO
+
+# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
+# characters to appear in the names of generated files. If set to NO, non-ASCII
+# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode
+# U+3044.
+# The default value is: NO.
+
+ALLOW_UNICODE_NAMES = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,
+# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),
+# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,
+# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),
+# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,
+# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,
+# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,
+# Ukrainian and Vietnamese.
+# The default value is: English.
+
+OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
+# descriptions after the members that are listed in the file and class
+# documentation (similar to Javadoc). Set to NO to disable this.
+# The default value is: YES.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief
+# description of a member or function before the detailed description
+#
+# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+# The default value is: YES.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator that is
+# used to form the text in various listings. Each string in this list, if found
+# as the leading text of the brief description, will be stripped from the text
+# and the result, after processing the whole list, is used as the annotated
+# text. Otherwise, the brief description is used as-is. If left blank, the
+# following values are used ($name is automatically replaced with the name of
+# the entity):The $name class, The $name widget, The $name file, is, provides,
+# specifies, contains, represents, a, an and the.
+
+ABBREVIATE_BRIEF =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# doxygen will generate a detailed section even if there is only a brief
+# description.
+# The default value is: NO.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+# The default value is: NO.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
+# before files name in the file list and in the header files. If set to NO the
+# shortest path that makes the file name unique will be used
+# The default value is: YES.
+
+FULL_PATH_NAMES = NO
+
+# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
+# Stripping is only done if one of the specified strings matches the left-hand
+# part of the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the path to
+# strip.
+#
+# Note that you can specify absolute paths here, but also relative paths, which
+# will be relative from the directory where doxygen is started.
+# This tag requires that the tag FULL_PATH_NAMES is set to YES.
+
+STRIP_FROM_PATH =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
+# path mentioned in the documentation of a class, which tells the reader which
+# header file to include in order to use a class. If left blank only the name of
+# the header file containing the class definition is used. Otherwise one should
+# specify the list of include paths that are normally passed to the compiler
+# using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
+# less readable) file names. This can be useful is your file systems doesn't
+# support long names like on DOS, Mac, or CD-ROM.
+# The default value is: NO.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the
+# first line (until the first dot) of a Javadoc-style comment as the brief
+# description. If set to NO, the Javadoc-style will behave just like regular Qt-
+# style comments (thus requiring an explicit @brief command for a brief
+# description.)
+# The default value is: NO.
+
+JAVADOC_AUTOBRIEF = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
+# line (until the first dot) of a Qt-style comment as the brief description. If
+# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
+# requiring an explicit \brief command for a brief description.)
+# The default value is: NO.
+
+QT_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
+# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
+# a brief description. This used to be the default behavior. The new default is
+# to treat a multi-line C++ comment block as a detailed description. Set this
+# tag to YES if you prefer the old behavior instead.
+#
+# Note that setting this tag to YES also means that rational rose comments are
+# not recognized any more.
+# The default value is: NO.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
+# documentation from any documented member that it re-implements.
+# The default value is: YES.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new
+# page for each member. If set to NO, the documentation of a member will be part
+# of the file/class/namespace that contains it.
+# The default value is: NO.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen
+# uses this value to replace tabs by spaces in code fragments.
+# Minimum value: 1, maximum value: 16, default value: 4.
+
+TAB_SIZE = 4
+
+# This tag can be used to specify a number of aliases that act as commands in
+# the documentation. An alias has the form:
+# name=value
+# For example adding
+# "sideeffect=@par Side Effects:\n"
+# will allow you to put the command \sideeffect (or @sideeffect) in the
+# documentation, which will result in a user-defined paragraph with heading
+# "Side Effects:". You can put \n's in the value part of an alias to insert
+# newlines.
+
+ALIASES =
+
+# This tag can be used to specify a number of word-keyword mappings (TCL only).
+# A mapping has the form "name=value". For example adding "class=itcl::class"
+# will allow you to use the command class in the itcl::class meaning.
+
+TCL_SUBST =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
+# only. Doxygen will then generate output that is more tailored for C. For
+# instance, some of the names that are used will be different. The list of all
+# members will be omitted, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_FOR_C = NO
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
+# Python sources only. Doxygen will then generate output that is more tailored
+# for that language. For instance, namespaces will be presented as packages,
+# qualified scopes will look different, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources. Doxygen will then generate output that is tailored for Fortran.
+# The default value is: NO.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for VHDL.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given
+# extension. Doxygen has a built-in mapping, but you can override or extend it
+# using this tag. The format is ext=language, where ext is a file extension, and
+# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
+# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran:
+# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran:
+# Fortran. In the later case the parser tries to guess whether the code is fixed
+# or free formatted code, this is the default for Fortran type files), VHDL. For
+# instance to make doxygen treat .inc files as Fortran files (default is PHP),
+# and .f files as C (default is Fortran), use: inc=Fortran f=C.
+#
+# Note: For files without extension you can use no_extension as a placeholder.
+#
+# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
+# the files are not read by doxygen.
+
+EXTENSION_MAPPING =
+
+# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
+# according to the Markdown format, which allows for more readable
+# documentation. See http://daringfireball.net/projects/markdown/ for details.
+# The output of markdown processing is further processed by doxygen, so you can
+# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
+# case of backward compatibilities issues.
+# The default value is: YES.
+
+MARKDOWN_SUPPORT = YES
+
+# When enabled doxygen tries to link words that correspond to documented
+# classes, or namespaces to their corresponding documentation. Such a link can
+# be prevented in individual cases by putting a % sign in front of the word or
+# globally by setting AUTOLINK_SUPPORT to NO.
+# The default value is: YES.
+
+AUTOLINK_SUPPORT = YES
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should set this
+# tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string);
+# versus func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+# The default value is: NO.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+# The default value is: NO.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:
+# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen
+# will parse them like normal C++ but will assume all classes use public instead
+# of private inheritance when no explicit protection keyword is present.
+# The default value is: NO.
+
+SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate
+# getter and setter methods for a property. Setting this option to YES will make
+# doxygen to replace the get and set methods by a property in the documentation.
+# This will only work if the methods are indeed getting or setting a simple
+# type. If this is not the case, or you want to show the methods anyway, you
+# should set this option to NO.
+# The default value is: YES.
+
+IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+# The default value is: NO.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# Set the SUBGROUPING tag to YES to allow class member groups of the same type
+# (for instance a group of public functions) to be put as a subgroup of that
+# type (e.g. under the Public Functions section). Set it to NO to prevent
+# subgrouping. Alternatively, this can be done per class using the
+# \nosubgrouping command.
+# The default value is: YES.
+
+SUBGROUPING = YES
+
+# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions
+# are shown inside the group in which they are included (e.g. using \ingroup)
+# instead of on a separate page (for HTML and Man pages) or section (for LaTeX
+# and RTF).
+#
+# Note that this feature does not work in combination with
+# SEPARATE_MEMBER_PAGES.
+# The default value is: NO.
+
+INLINE_GROUPED_CLASSES = NO
+
+# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
+# with only public data fields or simple typedef fields will be shown inline in
+# the documentation of the scope in which they are defined (i.e. file,
+# namespace, or group documentation), provided this scope is documented. If set
+# to NO, structs, classes, and unions are shown on a separate page (for HTML and
+# Man pages) or section (for LaTeX and RTF).
+# The default value is: NO.
+
+INLINE_SIMPLE_STRUCTS = NO
+
+# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
+# enum is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically be
+# useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+# The default value is: NO.
+
+TYPEDEF_HIDES_STRUCT = NO
+
+# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
+# cache is used to resolve symbols given their name and scope. Since this can be
+# an expensive process and often the same symbol appears multiple times in the
+# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small
+# doxygen will become slower. If the cache is too large, memory is wasted. The
+# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range
+# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536
+# symbols. At the end of a run doxygen will report the cache usage and suggest
+# the optimal cache size from a speed point of view.
+# Minimum value: 0, maximum value: 9, default value: 0.
+
+LOOKUP_CACHE_SIZE = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
+# documentation are documented, even if no documentation was available. Private
+# class members and static file members will be hidden unless the
+# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
+# Note: This will also disable the warnings about undocumented members that are
+# normally produced when WARNINGS is set to YES.
+# The default value is: NO.
+
+EXTRACT_ALL = NO
+
+# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
+# be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
+# scope will be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PACKAGE = NO
+
+# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
+# included in the documentation.
+# The default value is: NO.
+
+EXTRACT_STATIC = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
+# locally in source files will be included in the documentation. If set to NO,
+# only classes defined in header files are included. Does not have any effect
+# for Java sources.
+# The default value is: YES.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. If set to YES, local methods,
+# which are defined in the implementation section but not in the interface are
+# included in the documentation. If set to NO, only methods in the interface are
+# included.
+# The default value is: NO.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base name of
+# the file that contains the anonymous namespace. By default anonymous namespace
+# are hidden.
+# The default value is: NO.
+
+EXTRACT_ANON_NSPACES = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
+# undocumented members inside documented classes or files. If set to NO these
+# members will be included in the various overviews, but no documentation
+# section is generated. This option has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy. If set
+# to NO, these classes will be included in the various overviews. This option
+# has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
+# (class|struct|union) declarations. If set to NO, these declarations will be
+# included in the documentation.
+# The default value is: NO.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
+# documentation blocks found inside the body of a function. If set to NO, these
+# blocks will be appended to the function's detailed documentation block.
+# The default value is: NO.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation that is typed after a
+# \internal command is included. If the tag is set to NO then the documentation
+# will be excluded. Set it to YES to include the internal documentation.
+# The default value is: NO.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
+# names in lower-case letters. If set to YES, upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+# The default value is: system dependent.
+
+CASE_SENSE_NAMES = NO
+
+# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
+# their full class and namespace scopes in the documentation. If set to YES, the
+# scope will be hidden.
+# The default value is: NO.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
+# append additional text to a page's title, such as Class Reference. If set to
+# YES the compound reference will be hidden.
+# The default value is: NO.
+
+HIDE_COMPOUND_REFERENCE= NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
+# the files that are included by a file in the documentation of that file.
+# The default value is: YES.
+
+SHOW_INCLUDE_FILES = NO
+
+# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
+# grouped member an include statement to the documentation, telling the reader
+# which file to include in order to use the member.
+# The default value is: NO.
+
+SHOW_GROUPED_MEMB_INC = NO
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
+# files with double quotes in the documentation rather than with sharp brackets.
+# The default value is: NO.
+
+FORCE_LOCAL_INCLUDES = NO
+
+# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
+# documentation for inline members.
+# The default value is: YES.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
+# (detailed) documentation of file and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order.
+# The default value is: YES.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
+# descriptions of file, namespace and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order. Note that
+# this will also influence the order of the classes in the class list.
+# The default value is: NO.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the
+# (brief and detailed) documentation of class members so that constructors and
+# destructors are listed first. If set to NO the constructors will appear in the
+# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
+# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
+# member documentation.
+# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
+# detailed member documentation.
+# The default value is: NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy
+# of group names into alphabetical order. If set to NO the group names will
+# appear in their defined order.
+# The default value is: NO.
+
+SORT_GROUP_NAMES = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
+# fully-qualified names, including namespaces. If set to NO, the class list will
+# be sorted only by class name, not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the alphabetical
+# list.
+# The default value is: NO.
+
+SORT_BY_SCOPE_NAME = NO
+
+# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
+# type resolution of all parameters of a function it will reject a match between
+# the prototype and the implementation of a member function even if there is
+# only one candidate or it is obvious which candidate to choose by doing a
+# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still
+# accept a match between prototype and implementation in such cases.
+# The default value is: NO.
+
+STRICT_PROTO_MATCHING = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo
+# list. This list is created by putting \todo commands in the documentation.
+# The default value is: YES.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test
+# list. This list is created by putting \test commands in the documentation.
+# The default value is: YES.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug
+# list. This list is created by putting \bug commands in the documentation.
+# The default value is: YES.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)
+# the deprecated list. This list is created by putting \deprecated commands in
+# the documentation.
+# The default value is: YES.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional documentation
+# sections, marked by \if <section_label> ... \endif and \cond <section_label>
+# ... \endcond blocks.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
+# initial value of a variable or macro / define can have for it to appear in the
+# documentation. If the initializer consists of more lines than specified here
+# it will be hidden. Use a value of 0 to hide initializers completely. The
+# appearance of the value of individual variables and macros / defines can be
+# controlled using \showinitializer or \hideinitializer command in the
+# documentation regardless of this setting.
+# Minimum value: 0, maximum value: 10000, default value: 30.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
+# the bottom of the documentation of classes and structs. If set to YES, the
+# list will mention the files that were used to generate the documentation.
+# The default value is: YES.
+
+SHOW_USED_FILES = YES
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
+# will remove the Files entry from the Quick Index and from the Folder Tree View
+# (if specified).
+# The default value is: YES.
+
+SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
+# page. This will remove the Namespaces entry from the Quick Index and from the
+# Folder Tree View (if specified).
+# The default value is: YES.
+
+SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command command input-file, where command is the value of the
+# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
+# by doxygen. Whatever the program writes to standard output is used as the file
+# version. For an example see the documentation.
+
+FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. To create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option. You can
+# optionally specify a file name after the option, if omitted DoxygenLayout.xml
+# will be used as the name of the layout file.
+#
+# Note that if you run doxygen from a directory containing a file called
+# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
+# tag is left empty.
+
+LAYOUT_FILE =
+
+# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
+# the reference definitions. This must be a list of .bib files. The .bib
+# extension is automatically appended if omitted. This requires the bibtex tool
+# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.
+# For LaTeX the style of the bibliography can be controlled using
+# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
+# search path. See also \cite for info how to create references.
+
+CITE_BIB_FILES =
+
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated to
+# standard output by doxygen. If QUIET is set to YES this implies that the
+# messages are off.
+# The default value is: NO.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
+# this implies that the warnings are on.
+#
+# Tip: Turn warnings on while writing the documentation.
+# The default value is: YES.
+
+WARNINGS = YES
+
+# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate
+# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
+# will automatically be disabled.
+# The default value is: YES.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some parameters
+# in a documented function, or documenting parameters that don't exist or using
+# markup commands wrongly.
+# The default value is: YES.
+
+WARN_IF_DOC_ERROR = YES
+
+# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
+# are documented, but have no documentation for their parameters or return
+# value. If set to NO, doxygen will only warn about wrong or incomplete
+# parameter documentation, but not about the absence of documentation.
+# The default value is: NO.
+
+WARN_NO_PARAMDOC = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that doxygen
+# can produce. The string should contain the $file, $line, and $text tags, which
+# will be replaced by the file and line number from which the warning originated
+# and the warning text. Optionally the format may contain $version, which will
+# be replaced by the version of the file (if it could be obtained via
+# FILE_VERSION_FILTER)
+# The default value is: $file:$line: $text.
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning and error
+# messages should be written. If left blank the output is written to standard
+# error (stderr).
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag is used to specify the files and/or directories that contain
+# documented source files. You may enter file names like myfile.cpp or
+# directories like /usr/src/myproject. Separate the files or directories with
+# spaces.
+# Note: If this tag is empty the current directory is searched.
+
+INPUT = ../include/CL/cl2.hpp
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
+# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
+# documentation (see: http://www.gnu.org/software/libiconv) for the list of
+# possible encodings.
+# The default value is: UTF-8.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
+# *.h) to filter out the source-files in the directories. If left blank the
+# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii,
+# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp,
+# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown,
+# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf,
+# *.qsf, *.as and *.js.
+
+FILE_PATTERNS =
+
+# The RECURSIVE tag can be used to specify whether or not subdirectories should
+# be searched for input files as well.
+# The default value is: NO.
+
+RECURSIVE = NO
+
+# The EXCLUDE tag can be used to specify files and/or directories that should be
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+#
+# Note that relative paths are relative to the directory from which doxygen is
+# run.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
+# directories that are symbolic links (a Unix file system feature) are excluded
+# from the input.
+# The default value is: NO.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories.
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories for example use the pattern */test/*
+
+EXCLUDE_PATTERNS =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories use the pattern */test/*
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or directories
+# that contain example code fragments that are included (see the \include
+# command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
+# *.h) to filter out the source-files in the directories. If left blank all
+# files are included.
+
+EXAMPLE_PATTERNS =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude commands
+# irrespective of the value of the RECURSIVE tag.
+# The default value is: NO.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or directories
+# that contain images that are to be included in the documentation (see the
+# \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command:
+#
+# <filter> <input-file>
+#
+# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the
+# name of an input file. Doxygen will then use the output that the filter
+# program writes to standard output. If FILTER_PATTERNS is specified, this tag
+# will be ignored.
+#
+# Note that the filter must not add or remove lines; it is applied before the
+# code is scanned, but not when the output code is generated. If lines are added
+# or removed, the anchors will not be placed correctly.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form: pattern=filter
+# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
+# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
+# patterns match the file name, INPUT_FILTER is applied.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will also be used to filter the input files that are used for
+# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
+# The default value is: NO.
+
+FILTER_SOURCE_FILES = NO
+
+# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
+# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
+# it is also possible to disable source filtering for a specific pattern using
+# *.ext= (so without naming a filter).
+# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.
+
+FILTER_SOURCE_PATTERNS =
+
+# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
+# is part of the input, its contents will be placed on the main page
+# (index.html). This can be useful if you have a project on for instance GitHub
+# and want to reuse the introduction page also for the doxygen output.
+
+USE_MDFILE_AS_MAINPAGE =
+
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will be
+# generated. Documented entities will be cross-referenced with these sources.
+#
+# Note: To get rid of all source code in the generated output, make sure that
+# also VERBATIM_HEADERS is set to NO.
+# The default value is: NO.
+
+SOURCE_BROWSER = YES
+
+# Setting the INLINE_SOURCES tag to YES will include the body of functions,
+# classes and enums directly into the documentation.
+# The default value is: NO.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
+# special comment blocks from generated source code fragments. Normal C, C++ and
+# Fortran comments will always remain visible.
+# The default value is: YES.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
+# function all documented functions referencing it will be listed.
+# The default value is: NO.
+
+REFERENCED_BY_RELATION = NO
+
+# If the REFERENCES_RELATION tag is set to YES then for each documented function
+# all documented entities called/used by that function will be listed.
+# The default value is: NO.
+
+REFERENCES_RELATION = NO
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
+# to YES then the hyperlinks from functions in REFERENCES_RELATION and
+# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
+# link to the documentation.
+# The default value is: YES.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the
+# source code will show a tooltip with additional information such as prototype,
+# brief description and links to the definition and documentation. Since this
+# will make the HTML file larger and loading of large files a bit slower, you
+# can opt to disable this feature.
+# The default value is: YES.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+SOURCE_TOOLTIPS = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code will
+# point to the HTML generated by the htags(1) tool instead of doxygen built-in
+# source browser. The htags tool is part of GNU's global source tagging system
+# (see http://www.gnu.org/software/global/global.html). You will need version
+# 4.8.6 or higher.
+#
+# To use it do the following:
+# - Install the latest version of global
+# - Enable SOURCE_BROWSER and USE_HTAGS in the config file
+# - Make sure the INPUT points to the root of the source tree
+# - Run doxygen as normal
+#
+# Doxygen will invoke htags (and that will in turn invoke gtags), so these
+# tools must be available from the command line (i.e. in the search path).
+#
+# The result: instead of the source browser generated by doxygen, the links to
+# source code will now point to the output of htags.
+# The default value is: NO.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a
+# verbatim copy of the header file for each class for which an include is
+# specified. Set to NO to disable this.
+# See also: Section \class.
+# The default value is: YES.
+
+VERBATIM_HEADERS = YES
+
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all
+# compounds will be generated. Enable this if the project contains a lot of
+# classes, structs, unions or interfaces.
+# The default value is: YES.
+
+ALPHABETICAL_INDEX = YES
+
+# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
+# which the alphabetical index list will be split.
+# Minimum value: 1, maximum value: 20, default value: 5.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all classes will
+# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
+# can be used to specify a prefix (or a list of prefixes) that should be ignored
+# while generating the index headers.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
+# The default value is: YES.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
+# generated HTML page (for example: .htm, .php, .asp).
+# The default value is: .html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a user-defined HTML header file for
+# each generated HTML page. If the tag is left blank doxygen will generate a
+# standard header.
+#
+# To get valid HTML the header file that includes any scripts and style sheets
+# that doxygen needs, which is dependent on the configuration options used (e.g.
+# the setting GENERATE_TREEVIEW). It is highly recommended to start with a
+# default header using
+# doxygen -w html new_header.html new_footer.html new_stylesheet.css
+# YourConfigFile
+# and then modify the file new_header.html. See also section "Doxygen usage"
+# for information on how to generate the default header that doxygen normally
+# uses.
+# Note: The header is subject to change so you typically have to regenerate the
+# default header when upgrading to a newer version of doxygen. For a description
+# of the possible markers and block names see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
+# generated HTML page. If the tag is left blank doxygen will generate a standard
+# footer. See HTML_HEADER for more information on how to generate a default
+# footer and what special commands can be used inside the footer. See also
+# section "Doxygen usage" for information on how to generate the default footer
+# that doxygen normally uses.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
+# sheet that is used by each HTML page. It can be used to fine-tune the look of
+# the HTML output. If left blank doxygen will generate a default style sheet.
+# See also section "Doxygen usage" for information on how to generate the style
+# sheet that doxygen normally uses.
+# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as
+# it is more robust and this tag (HTML_STYLESHEET) will in the future become
+# obsolete.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_STYLESHEET =
+
+# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# cascading style sheets that are included after the standard style sheets
+# created by doxygen. Using this option one can overrule certain style aspects.
+# This is preferred over using HTML_STYLESHEET since it does not replace the
+# standard style sheet and is therefore more robust against future updates.
+# Doxygen will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list). For an example see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_STYLESHEET =
+
+# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the HTML output directory. Note
+# that these files will be copied to the base HTML output directory. Use the
+# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
+# files. In the HTML_STYLESHEET file, use the file name only. Also note that the
+# files will be copied as-is; there are no commands or markers available.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_FILES =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
+# will adjust the colors in the style sheet and background images according to
+# this color. Hue is specified as an angle on a colorwheel, see
+# http://en.wikipedia.org/wiki/Hue for more information. For instance the value
+# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
+# purple, and 360 is red again.
+# Minimum value: 0, maximum value: 359, default value: 220.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_HUE = 220
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
+# in the HTML output. For a value of 0 the output will use grayscales only. A
+# value of 255 will produce the most vivid colors.
+# Minimum value: 0, maximum value: 255, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_SAT = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
+# luminance component of the colors in the HTML output. Values below 100
+# gradually make the output lighter, whereas values above 100 make the output
+# darker. The value divided by 100 is the actual gamma applied, so 80 represents
+# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not
+# change the gamma.
+# Minimum value: 40, maximum value: 240, default value: 80.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_GAMMA = 80
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting this
+# to NO can help when comparing the output of multiple runs.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_TIMESTAMP = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
+# shown in the various tree structured indices initially; the user can expand
+# and collapse entries dynamically later on. Doxygen will expand the tree to
+# such a level that at most the specified number of entries are visible (unless
+# a fully collapsed tree already exceeds this amount). So setting the number of
+# entries 1 will produce a full collapsed tree by default. 0 is a special value
+# representing an infinite number of entries and will result in a full expanded
+# tree by default.
+# Minimum value: 0, maximum value: 9999, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_INDEX_NUM_ENTRIES = 100
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files will be
+# generated that can be used as input for Apple's Xcode 3 integrated development
+# environment (see: http://developer.apple.com/tools/xcode/), introduced with
+# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a
+# Makefile in the HTML output directory. Running make will produce the docset in
+# that directory and running make install will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
+# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
+# for more information.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_DOCSET = NO
+
+# This tag determines the name of the docset feed. A documentation feed provides
+# an umbrella under which multiple documentation sets from a single provider
+# (such as a company or product suite) can be grouped.
+# The default value is: Doxygen generated docs.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# This tag specifies a string that should uniquely identify the documentation
+# set bundle. This should be a reverse domain-name style string, e.g.
+# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify
+# the documentation publisher. This should be a reverse domain-name style
+# string, e.g. com.mycompany.MyDocSet.documentation.
+# The default value is: org.doxygen.Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+
+# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
+# The default value is: Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_NAME = Publisher
+
+# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
+# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
+# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
+# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on
+# Windows.
+#
+# The HTML Help Workshop contains a compiler that can convert all HTML output
+# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
+# files are now used as the Windows 98 help format, and will replace the old
+# Windows help format (.hlp) on all Windows platforms in the future. Compressed
+# HTML files also contain an index, a table of contents, and you can search for
+# words in the documentation. The HTML workshop also contains a viewer for
+# compressed HTML files.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_HTMLHELP = NO
+
+# The CHM_FILE tag can be used to specify the file name of the resulting .chm
+# file. You can add a path in front of the file if the result should not be
+# written to the html output directory.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+CHM_FILE =
+
+# The HHC_LOCATION tag can be used to specify the location (absolute path
+# including file name) of the HTML help compiler (hhc.exe). If non-empty,
+# doxygen will try to run the HTML help compiler on the generated index.hhp.
+# The file has to be specified with full path.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+HHC_LOCATION =
+
+# The GENERATE_CHI flag controls if a separate .chi index file is generated
+# (YES) or that it should be included in the master .chm file (NO).
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+GENERATE_CHI = NO
+
+# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)
+# and project file content.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+CHM_INDEX_ENCODING =
+
+# The BINARY_TOC flag controls whether a binary table of contents is generated
+# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it
+# enables the Previous and Next buttons.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members to
+# the table of contents of the HTML help documentation and to the tree view.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
+# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
+# (.qch) of the generated HTML documentation.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify
+# the file name of the resulting .qch file. The path specified is relative to
+# the HTML output folder.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
+# Project output. For more information please see Qt Help Project / Namespace
+# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_NAMESPACE = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
+# Help Project output. For more information please see Qt Help Project / Virtual
+# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-
+# folders).
+# The default value is: doc.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
+# filter to add. For more information please see Qt Help Project / Custom
+# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
+# filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see Qt Help Project / Custom
+# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
+# filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's filter section matches. Qt Help Project / Filter Attributes (see:
+# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_SECT_FILTER_ATTRS =
+
+# The QHG_LOCATION tag can be used to specify the location of Qt's
+# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
+# generated .qhp file.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHG_LOCATION =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be
+# generated, together with the HTML files, they form an Eclipse help plugin. To
+# install this plugin and make it available under the help contents menu in
+# Eclipse, the contents of the directory containing the HTML and XML files needs
+# to be copied into the plugins directory of eclipse. The name of the directory
+# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.
+# After copying Eclipse needs to be restarted before the help appears.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_ECLIPSEHELP = NO
+
+# A unique identifier for the Eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have this
+# name. Each documentation set should have its own identifier.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
+
+ECLIPSE_DOC_ID = org.doxygen.Project
+
+# If you want full control over the layout of the generated HTML pages it might
+# be necessary to disable the index and replace it with your own. The
+# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
+# of each HTML page. A value of NO enables the index and the value YES disables
+# it. Since the tabs in the index contain the same information as the navigation
+# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+DISABLE_INDEX = NO
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information. If the tag
+# value is set to YES, a side panel will be generated containing a tree-like
+# index structure (just like the one that is generated for HTML Help). For this
+# to work a browser that supports JavaScript, DHTML, CSS and frames is required
+# (i.e. any modern browser). Windows users are probably better off using the
+# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can
+# further fine-tune the look of the index. As an example, the default style
+# sheet generated by doxygen has an example that shows how to put an image at
+# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
+# the same information as the tab index, you could consider setting
+# DISABLE_INDEX to YES when enabling this option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_TREEVIEW = YES
+
+# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
+# doxygen will group on one line in the generated HTML documentation.
+#
+# Note that a value of 0 will completely suppress the enum values from appearing
+# in the overview section.
+# Minimum value: 0, maximum value: 20, default value: 4.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
+# to set the initial width (in pixels) of the frame in which the tree is shown.
+# Minimum value: 0, maximum value: 1500, default value: 250.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+TREEVIEW_WIDTH = 250
+
+# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
+# external symbols imported via tag files in a separate window.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+EXT_LINKS_IN_WINDOW = NO
+
+# Use this tag to change the font size of LaTeX formulas included as images in
+# the HTML documentation. When you change the font size after a successful
+# doxygen run you need to manually remove any form_*.png images from the HTML
+# output directory to force them to be regenerated.
+# Minimum value: 8, maximum value: 50, default value: 10.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_FONTSIZE = 10
+
+# Use the FORMULA_TRANPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are not
+# supported properly for IE 6.0, but are supported on all modern browsers.
+#
+# Note that when changing this option you need to delete any form_*.png files in
+# the HTML output directory before the changes have effect.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_TRANSPARENT = YES
+
+# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
+# http://www.mathjax.org) which uses client side Javascript for the rendering
+# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
+# installed or if you want to formulas look prettier in the HTML output. When
+# enabled you may also need to install MathJax separately and configure the path
+# to it using the MATHJAX_RELPATH option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+USE_MATHJAX = NO
+
+# When MathJax is enabled you can set the default output format to be used for
+# the MathJax output. See the MathJax site (see:
+# http://docs.mathjax.org/en/latest/output.html) for more details.
+# Possible values are: HTML-CSS (which is slower, but has the best
+# compatibility), NativeMML (i.e. MathML) and SVG.
+# The default value is: HTML-CSS.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_FORMAT = HTML-CSS
+
+# When MathJax is enabled you need to specify the location relative to the HTML
+# output directory using the MATHJAX_RELPATH option. The destination directory
+# should contain the MathJax.js script. For instance, if the mathjax directory
+# is located at the same level as the HTML output directory, then
+# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
+# Content Delivery Network so you can quickly see the result without installing
+# MathJax. However, it is strongly recommended to install a local copy of
+# MathJax from http://www.mathjax.org before deployment.
+# The default value is: http://cdn.mathjax.org/mathjax/latest.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+
+# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
+# extension names that should be enabled during MathJax rendering. For example
+# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_EXTENSIONS =
+
+# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
+# of code that will be used on startup of the MathJax code. See the MathJax site
+# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
+# example see the documentation.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_CODEFILE =
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
+# the HTML output. The underlying search engine uses javascript and DHTML and
+# should work on any modern browser. Note that when using HTML help
+# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
+# there is already a search function so this one should typically be disabled.
+# For large projects the javascript based search engine can be slow, then
+# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
+# search using the keyboard; to jump to the search box use <access key> + S
+# (what the <access key> is depends on the OS and browser, but it is typically
+# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down
+# key> to jump into the search results window, the results can be navigated
+# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel
+# the search. The filter options can be selected when the cursor is inside the
+# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>
+# to select a filter and <Enter> or <escape> to activate or cancel the filter
+# option.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+SEARCHENGINE = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a web server instead of a web client using Javascript. There
+# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
+# setting. When disabled, doxygen will generate a PHP script for searching and
+# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
+# and searching needs to be provided by external tools. See the section
+# "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SERVER_BASED_SEARCH = NO
+
+# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
+# script for searching. Instead the search results are written to an XML file
+# which needs to be processed by an external indexer. Doxygen will invoke an
+# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
+# search results.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see: http://xapian.org/).
+#
+# See the section "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH = NO
+
+# The SEARCHENGINE_URL should point to a search engine hosted by a web server
+# which will return the search results when EXTERNAL_SEARCH is enabled.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see: http://xapian.org/). See the section "External Indexing and
+# Searching" for details.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHENGINE_URL =
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
+# search data is written to a file for indexing by an external tool. With the
+# SEARCHDATA_FILE tag the name of this file can be specified.
+# The default file is: searchdata.xml.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHDATA_FILE = searchdata.xml
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the
+# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
+# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
+# projects and redirect the results back to the right project.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH_ID =
+
+# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
+# projects other than the one defined by this configuration file, but that are
+# all added to the same external search index. Each project needs to have a
+# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of
+# to a relative location where the documentation can be found. The format is:
+# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTRA_SEARCH_MAPPINGS =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
+# The default value is: YES.
+
+GENERATE_LATEX = NO
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: latex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked.
+#
+# Note that when enabling USE_PDFLATEX this option is only used for generating
+# bitmaps for formulas in the HTML output, but not in the Makefile that is
+# written to the output directory.
+# The default file is: latex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate
+# index for LaTeX.
+# The default file is: makeindex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used by the
+# printer.
+# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x
+# 14 inches) and executive (7.25 x 10.5 inches).
+# The default value is: a4.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+PAPER_TYPE = a4
+
+# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
+# that should be included in the LaTeX output. To get the times font for
+# instance you can specify
+# EXTRA_PACKAGES=times
+# If left blank no extra packages will be included.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the
+# generated LaTeX document. The header should contain everything until the first
+# chapter. If it is left blank doxygen will generate a standard header. See
+# section "Doxygen usage" for information on how to let doxygen write the
+# default header to a separate file.
+#
+# Note: Only use a user-defined header if you know what you are doing! The
+# following commands have a special meaning inside the header: $title,
+# $datetime, $date, $doxygenversion, $projectname, $projectnumber,
+# $projectbrief, $projectlogo. Doxygen will replace $title with the empty
+# string, for the replacement values of the other commands the user is referred
+# to HTML_HEADER.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_HEADER =
+
+# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the
+# generated LaTeX document. The footer should contain everything after the last
+# chapter. If it is left blank doxygen will generate a standard footer. See
+# LATEX_HEADER for more information on how to generate a default footer and what
+# special commands can be used inside the footer.
+#
+# Note: Only use a user-defined footer if you know what you are doing!
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_FOOTER =
+
+# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# LaTeX style sheets that are included after the standard style sheets created
+# by doxygen. Using this option one can overrule certain style aspects. Doxygen
+# will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list).
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_STYLESHEET =
+
+# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the LATEX_OUTPUT output
+# directory. Note that the files will be copied as-is; there are no commands or
+# markers available.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_FILES =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is
+# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will
+# contain links (just like the HTML output) instead of page references. This
+# makes the output suitable for online browsing using a PDF viewer.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+PDF_HYPERLINKS = YES
+
+# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
+# the PDF file directly from the LaTeX files. Set this option to YES, to get a
+# higher quality PDF documentation.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+USE_PDFLATEX = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
+# command to the generated LaTeX files. This will instruct LaTeX to keep running
+# if errors occur, instead of asking the user for help. This option is also used
+# when generating formulas in HTML.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BATCHMODE = NO
+
+# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the
+# index chapters (such as File Index, Compound Index, etc.) in the output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_HIDE_INDICES = NO
+
+# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source
+# code with syntax highlighting in the LaTeX output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_SOURCE_CODE = NO
+
+# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
+# bibliography, e.g. plainnat, or ieeetr. See
+# http://en.wikipedia.org/wiki/BibTeX and \cite for more info.
+# The default value is: plain.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BIB_STYLE = plain
+
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The
+# RTF output is optimized for Word 97 and may not look too pretty with other RTF
+# readers/editors.
+# The default value is: NO.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: rtf.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will
+# contain hyperlink fields. The RTF file will contain links (just like the HTML
+# output) instead of page references. This makes the output suitable for online
+# browsing using Word or some other Word compatible readers that support those
+# fields.
+#
+# Note: WordPad (write) and others do not support links.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's config
+# file, i.e. a series of assignments. You only have to provide replacements,
+# missing definitions are set to their default value.
+#
+# See also section "Doxygen usage" for information on how to generate the
+# default style sheet that doxygen normally uses.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an RTF document. Syntax is
+# similar to doxygen's config file. A template extensions file can be generated
+# using doxygen -e rtf extensionFile.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_EXTENSIONS_FILE =
+
+# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code
+# with syntax highlighting in the RTF output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_SOURCE_CODE = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for
+# classes and files.
+# The default value is: NO.
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it. A directory man3 will be created inside the directory specified by
+# MAN_OUTPUT.
+# The default directory is: man.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to the generated
+# man pages. In case the manual section does not start with a number, the number
+# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is
+# optional.
+# The default value is: .3.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_EXTENSION = .3
+
+# The MAN_SUBDIR tag determines the name of the directory created within
+# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by
+# MAN_EXTENSION with the initial . removed.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_SUBDIR =
+
+# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
+# will generate one additional man file for each entity documented in the real
+# man page(s). These additional files only source the real man page, but without
+# them the man command would be unable to find the correct page.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
+# captures the structure of the code including all documentation.
+# The default value is: NO.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: xml.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_OUTPUT = xml
+
+# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
+# listings (including syntax highlighting and cross-referencing information) to
+# the XML output. Note that enabling this will significantly increase the size
+# of the XML output.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_PROGRAMLISTING = YES
+
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files
+# that can be used to generate PDF.
+# The default value is: NO.
+
+GENERATE_DOCBOOK = NO
+
+# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in
+# front of it.
+# The default directory is: docbook.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_OUTPUT = docbook
+
+# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the
+# program listings (including syntax highlighting and cross-referencing
+# information) to the DOCBOOK output. Note that enabling this will significantly
+# increase the size of the DOCBOOK output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_PROGRAMLISTING = NO
+
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
+# AutoGen Definitions (see http://autogen.sf.net) file that captures the
+# structure of the code including all documentation. Note that this feature is
+# still experimental and incomplete at the moment.
+# The default value is: NO.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module
+# file that captures the structure of the code including all documentation.
+#
+# Note that this feature is still experimental and incomplete at the moment.
+# The default value is: NO.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary
+# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI
+# output from the Perl module output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely
+# formatted so it can be parsed by a human reader. This is useful if you want to
+# understand what is going on. On the other hand, if this tag is set to NO, the
+# size of the Perl module output will be much smaller and Perl will parse it
+# just the same.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file are
+# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful
+# so different doxyrules.make files included by the same Makefile don't
+# overwrite each other's variables.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
+# C-preprocessor directives found in the sources and include files.
+# The default value is: YES.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
+# in the source code. If set to NO, only conditional compilation will be
+# performed. Macro expansion can be done in a controlled way by setting
+# EXPAND_ONLY_PREDEF to YES.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+MACRO_EXPANSION = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
+# the macro expansion is limited to the macros specified with the PREDEFINED and
+# EXPAND_AS_DEFINED tags.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES, the include files in the
+# INCLUDE_PATH will be searched if a #include is found.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by the
+# preprocessor.
+# This tag requires that the tag SEARCH_INCLUDES is set to YES.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will be
+# used.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that are
+# defined before the preprocessor is started (similar to the -D option of e.g.
+# gcc). The argument of the tag is a list of macros of the form: name or
+# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
+# is assumed. To prevent a macro definition from being undefined via #undef or
+# recursively expanded use the := operator instead of the = operator.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+PREDEFINED = CL_HPP_MINIMUM_OPENCL_VERSION=100
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
+# tag can be used to specify a list of macro names that should be expanded. The
+# macro definition that is found in the sources will be used. Use the PREDEFINED
+# tag if you want to use a different macro definition that overrules the
+# definition found in the source code.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
+# remove all references to function-like macros that are alone on a line, have
+# an all uppercase name, and do not end with a semicolon. Such function macros
+# are typically used for boiler-plate code, and will confuse the parser if not
+# removed.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES tag can be used to specify one or more tag files. For each tag
+# file the location of the external documentation should be added. The format of
+# a tag file without this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where loc1 and loc2 can be relative or absolute paths or URLs. See the
+# section "Linking to external documentation" for more information about the use
+# of tag files.
+# Note: Each tag file must have a unique name (where the name does NOT include
+# the path). If a tag file is not located in the directory in which doxygen is
+# run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
+# tag file that is based on the input files it reads. See section "Linking to
+# external documentation" for more information about the usage of tag files.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
+# the class index. If set to NO, only the inherited external classes will be
+# listed.
+# The default value is: NO.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will be
+# listed.
+# The default value is: YES.
+
+EXTERNAL_GROUPS = YES
+
+# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
+# the related pages index. If set to NO, only the current project's pages will
+# be listed.
+# The default value is: YES.
+
+EXTERNAL_PAGES = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of 'which perl').
+# The default file (with absolute path) is: /usr/bin/perl.
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram
+# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
+# NO turns the diagrams off. Note that this option also works with HAVE_DOT
+# disabled, but it is recommended to install and use dot, since it yields more
+# powerful graphs.
+# The default value is: YES.
+
+CLASS_DIAGRAMS = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see:
+# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
+# You can include diagrams made with dia in doxygen documentation. Doxygen will
+# then run dia to produce the diagram and insert it in the documentation. The
+# DIA_PATH tag allows you to specify the directory where the dia binary resides.
+# If left empty dia is assumed to be found in the default search path.
+
+DIA_PATH =
+
+# If set to YES the inheritance and collaboration graphs will hide inheritance
+# and usage relations if the target is undocumented or is not a class.
+# The default value is: YES.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz (see:
+# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
+# Bell Labs. The other options in this section have no effect if this option is
+# set to NO
+# The default value is: NO.
+
+HAVE_DOT = NO
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
+# to run in parallel. When set to 0 doxygen will base this on the number of
+# processors available in the system. You can set it explicitly to a value
+# larger than 0 to get control over the balance between CPU load and processing
+# speed.
+# Minimum value: 0, maximum value: 32, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_NUM_THREADS = 0
+
+# When you want a differently looking font in the dot files that doxygen
+# generates you can specify the font name using DOT_FONTNAME. You need to make
+# sure dot is able to find the font, which can be done by putting it in a
+# standard location or by setting the DOTFONTPATH environment variable or by
+# setting DOT_FONTPATH to the directory containing the font.
+# The default value is: Helvetica.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTNAME = Helvetica
+
+# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of
+# dot graphs.
+# Minimum value: 4, maximum value: 24, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the default font as specified with
+# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set
+# the path where dot can find it using this tag.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for
+# each documented class showing the direct and indirect inheritance relations.
+# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
+# graph for each documented class showing the direct and indirect implementation
+# dependencies (inheritance, containment, and class references variables) of the
+# class with other documented classes.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
+# groups, showing the direct groups dependencies.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+UML_LOOK = NO
+
+# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
+# class node. If there are many fields or methods and many nodes the graph may
+# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the
+# number of items for each type to make the size more manageable. Set this to 0
+# for no limit. Note that the threshold may be exceeded by 50% before the limit
+# is enforced. So when you set the threshold to 10, up to 15 fields may appear,
+# but if the number exceeds 15, the total amount of fields shown is limited to
+# 10.
+# Minimum value: 0, maximum value: 100, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+UML_LIMIT_NUM_FIELDS = 10
+
+# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
+# collaboration graphs will show the relations between templates and their
+# instances.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+TEMPLATE_RELATIONS = NO
+
+# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
+# YES then doxygen will generate a graph for each documented file showing the
+# direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INCLUDE_GRAPH = YES
+
+# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
+# set to YES then doxygen will generate a graph for each documented file showing
+# the direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable call graphs for selected
+# functions only using the \callgraph command.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable caller graphs for selected
+# functions only using the \callergraph command.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
+# hierarchy of all classes instead of a textual one.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
+# dependencies a directory has on other directories in a graphical way. The
+# dependency relations are determined by the #include relations between the
+# files in the directories.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot.
+# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
+# to make the SVG files visible in IE 9+ (other browsers do not have this
+# requirement).
+# Possible values are: png, jpg, gif and svg.
+# The default value is: png.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_IMAGE_FORMAT = png
+
+# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
+# enable generation of interactive SVG images that allow zooming and panning.
+#
+# Note that this requires a modern browser other than Internet Explorer. Tested
+# and working are Firefox, Chrome, Safari, and Opera.
+# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make
+# the SVG files visible. Older versions of IE do not have SVG support.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INTERACTIVE_SVG = NO
+
+# The DOT_PATH tag can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the \dotfile
+# command).
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOTFILE_DIRS =
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the \mscfile
+# command).
+
+MSCFILE_DIRS =
+
+# The DIAFILE_DIRS tag can be used to specify one or more directories that
+# contain dia files that are included in the documentation (see the \diafile
+# command).
+
+DIAFILE_DIRS =
+
+# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
+# path where java can find the plantuml.jar file. If left blank, it is assumed
+# PlantUML is not used or called during a preprocessing step. Doxygen will
+# generate a warning when it encounters a \startuml command in this case and
+# will not generate output for the diagram.
+
+PLANTUML_JAR_PATH =
+
+# When using plantuml, the specified paths are searched for files specified by
+# the !include statement in a plantuml block.
+
+PLANTUML_INCLUDE_PATH =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
+# that will be shown in the graph. If the number of nodes in a graph becomes
+# larger than this value, doxygen will truncate the graph, which is visualized
+# by representing a node as a red box. Note that doxygen if the number of direct
+# children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that
+# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+# Minimum value: 0, maximum value: 10000, default value: 50.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
+# generated by dot. A depth value of 3 means that only nodes reachable from the
+# root by following a path via at most 3 edges will be shown. Nodes that lay
+# further from the root node will be omitted. Note that setting this option to 1
+# or 2 may greatly reduce the computation time needed for large code bases. Also
+# note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+# Minimum value: 0, maximum value: 1000, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not seem
+# to support this out of the box.
+#
+# Warning: Depending on the platform used, enabling this option may lead to
+# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
+# read).
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10) support
+# this, this feature is disabled by default.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
+# explaining the meaning of the various boxes and arrows in the dot generated
+# graphs.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
+# files that are used to generate the various graphs.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_CLEANUP = YES
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..aeb6a51
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.6)
+
+add_subdirectory(src)
diff --git a/examples/src/CMakeLists.txt b/examples/src/CMakeLists.txt
new file mode 100644
index 0000000..2482ad4
--- /dev/null
+++ b/examples/src/CMakeLists.txt
@@ -0,0 +1,61 @@
+set(TRIVIAL_SOURCES
+ trivial.cpp )
+
+set(TRIVIAL_HEADERS
+ ${CLCPP_BINARY_DIR}/include/CL/cl.hpp)
+set_source_files_properties(${CLCPP_BINARY_DIR}/include/CL/cl.hpp PROPERTIES GENERATED 1)
+
+set(TRIVIALCL2_SOURCES
+ trivialCL2.cpp )
+
+set(TRIVIALCL2_HEADERS
+ ${CLCPP_BINARY_DIR}/include/CL/cl2.hpp)
+set_source_files_properties(${CLCPP_BINARY_DIR}/include/CL/cl2.hpp PROPERTIES GENERATED 1)
+
+set(TRIVIALCL2_SIZET_COMPAT_SOURCES
+ trivialCL2SizeTCompat.cpp )
+
+set(TRIVIALCL2_SIZET_COMPAT_HEADERS
+ ${CLCPP_BINARY_DIR}/include/CL/cl2.hpp)
+set_source_files_properties(${CLCPP_BINARY_DIR}/include/CL/cl2.hpp PROPERTIES GENERATED 1)
+
+set(HEADEREXAMPLECL2_SOURCES
+ headerexampleCL2.cpp )
+
+set(HEADEREXAMPLECL2_HEADERS
+ ${CLCPP_BINARY_DIR}/include/CL/cl2.hpp)
+set_source_files_properties(${CLCPP_BINARY_DIR}/include/CL/cl2.hpp PROPERTIES GENERATED 1)
+
+
+
+
+include_directories(
+ ${CLCPP_BINARY_DIR}/include
+ ${OPENCL_DIST_DIR}/include
+ ${OPENCL_INCLUDE_DIR})
+
+link_directories( ${OPENCL_LIB_DIR} )
+
+if( MSVC )
+ set(CMAKE_CXX_FLAGS " -W3 /EHsc" )
+elseif( CMAKE_COMPILER_IS_GNUCXX )
+ set(CMAKE_CXX_FLAGS "-Wall -std=c++0x" )
+elseif( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
+ set(CMAKE_CXX_FLAGS "-Wall -std=c++11" )
+endif()
+
+add_executable(trivial ${TRIVIAL_SOURCES} ${TRIVIAL_HEADERS})
+add_dependencies(trivial generate_clhpp)
+target_link_libraries( trivial OpenCL )
+
+add_executable(trivialCL2 ${TRIVIALCL2_SOURCES} ${TRIVIALCL2_HEADERS})
+add_dependencies(trivialCL2 generate_cl2hpp)
+target_link_libraries( trivialCL2 OpenCL )
+
+add_executable(trivialCL2SizeTCompat ${TRIVIALCL2_SIZET_COMPAT_SOURCES} ${TRIVIALCL2_SIZET_COMPAT_HEADERS})
+add_dependencies(trivialCL2SizeTCompat generate_cl2hpp)
+target_link_libraries( trivialCL2SizeTCompat OpenCL )
+
+add_executable(headerexampleCL2 ${HEADEREXAMPLECL2_SOURCES} ${HEADEREXAMPLECL2_HEADERS})
+add_dependencies(headerexampleCL2 generate_cl2hpp)
+target_link_libraries( headerexampleCL2 OpenCL )
\ No newline at end of file
diff --git a/examples/src/headerexampleCL2.cpp b/examples/src/headerexampleCL2.cpp
new file mode 100644
index 0000000..a5ee391
--- /dev/null
+++ b/examples/src/headerexampleCL2.cpp
@@ -0,0 +1,164 @@
+#define CL_HPP_ENABLE_EXCEPTIONS
+#define CL_HPP_TARGET_OPENCL_VERSION 200
+
+#include <CL/cl2.hpp>
+#include <iostream>
+#include <vector>
+#include <memory>
+#include <algorithm>
+
+const int numElements = 32;
+
+int main(void)
+{
+ // Filter for a 2.0 platform and set it as the default
+ std::vector<cl::Platform> platforms;
+ cl::Platform::get(&platforms);
+ cl::Platform plat;
+ for (auto &p : platforms) {
+ std::string platver = p.getInfo<CL_PLATFORM_VERSION>();
+ if (platver.find("OpenCL 2.") != std::string::npos) {
+ plat = p;
+ }
+ }
+ if (plat() == 0) {
+ std::cout << "No OpenCL 2.0 platform found.";
+ return -1;
+ }
+
+ cl::Platform newP = cl::Platform::setDefault(plat);
+ if (newP != plat) {
+ std::cout << "Error setting default platform.";
+ return -1;
+ }
+
+ // Use C++11 raw string literals for kernel source code
+ std::string kernel1{R"CLC(
+ global int globalA;
+ kernel void updateGlobal()
+ {
+ globalA = 75;
+ }
+ )CLC"};
+ std::string kernel2{R"CLC(
+ typedef struct { global int *bar; } Foo;
+ kernel void vectorAdd(global const Foo* aNum, global const int *inputA, global const int *inputB,
+ global int *output, int val, write_only pipe int outPipe, queue_t childQueue)
+ {
+ output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar);
+ write_pipe(outPipe, &val);
+ queue_t default_queue = get_default_queue();
+ ndrange_t ndrange = ndrange_1D(get_global_size(0)/2, get_global_size(0)/2);
+
+ // Have a child kernel write into third quarter of output
+ enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
+ ^{
+ output[get_global_size(0)*2 + get_global_id(0)] =
+ inputA[get_global_size(0)*2 + get_global_id(0)] + inputB[get_global_size(0)*2 + get_global_id(0)] + globalA;
+ });
+
+ // Have a child kernel write into last quarter of output
+ enqueue_kernel(childQueue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
+ ^{
+ output[get_global_size(0)*3 + get_global_id(0)] =
+ inputA[get_global_size(0)*3 + get_global_id(0)] + inputB[get_global_size(0)*3 + get_global_id(0)] + globalA + 2;
+ });
+ }
+ )CLC"};
+
+ // New simpler string interface style
+ std::vector<std::string> programStrings;
+ programStrings.push_back(kernel1);
+ programStrings.push_back(kernel2);
+
+ cl::Program vectorAddProgram(programStrings);
+ try {
+ vectorAddProgram.build("-cl-std=CL2.0");
+ }
+ catch (...) {
+ // Print build info for all devices
+ cl_int buildErr = CL_SUCCESS;
+ auto buildInfo = vectorAddProgram.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&buildErr);
+ for (auto &pair : buildInfo) {
+ std::cerr << pair.second << std::endl << std::endl;
+ }
+
+ return 1;
+ }
+
+ typedef struct { int *bar; } Foo;
+
+ // Get and run kernel that initializes the program-scope global
+ // A test for kernels that take no arguments
+ auto program2Kernel =
+ cl::KernelFunctor<>(vectorAddProgram, "updateGlobal");
+ program2Kernel(
+ cl::EnqueueArgs(
+ cl::NDRange(1)));
+
+ //////////////////
+ // SVM allocations
+
+ auto anSVMInt = cl::allocate_svm<int, cl::SVMTraitCoarse<>>();
+ *anSVMInt = 5;
+ cl::SVMAllocator<Foo, cl::SVMTraitCoarse<cl::SVMTraitReadOnly<>>> svmAllocReadOnly;
+ auto fooPointer = cl::allocate_pointer<Foo>(svmAllocReadOnly);
+ fooPointer->bar = anSVMInt.get();
+ cl::SVMAllocator<int, cl::SVMTraitCoarse<>> svmAlloc;
+ std::vector<int, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>> inputA(numElements, 1, svmAlloc);
+ cl::coarse_svm_vector<int> inputB(numElements, 2, svmAlloc);
+
+ //
+ //////////////
+
+ // Traditional cl_mem allocations
+ std::vector<int> output(numElements, 0xdeadbeef);
+ cl::Buffer outputBuffer(begin(output), end(output), false);
+ cl::Pipe aPipe(sizeof(cl_int), numElements / 2);
+
+ // Default command queue, also passed in as a parameter
+ cl::DeviceCommandQueue defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault(
+ cl::Context::getDefault(), cl::Device::getDefault());
+
+ auto vectorAddKernel =
+ cl::KernelFunctor<
+ decltype(fooPointer)&,
+ int*,
+ cl::coarse_svm_vector<int>&,
+ cl::Buffer,
+ int,
+ cl::Pipe&,
+ cl::DeviceCommandQueue
+ >(vectorAddProgram, "vectorAdd");
+
+ // Ensure that the additional SVM pointer is available to the kernel
+ // This one was not passed as a parameter
+ vectorAddKernel.setSVMPointers(anSVMInt);
+
+ cl_int error;
+ vectorAddKernel(
+ cl::EnqueueArgs(
+ cl::NDRange(numElements/2),
+ cl::NDRange(numElements/2)),
+ fooPointer,
+ inputA.data(),
+ inputB,
+ outputBuffer,
+ 3,
+ aPipe,
+ defaultDeviceQueue,
+ error
+ );
+
+ cl::copy(outputBuffer, begin(output), end(output));
+
+ cl::Device d = cl::Device::getDefault();
+
+ std::cout << "Output:\n";
+ for (int i = 1; i < numElements; ++i) {
+ std::cout << "\t" << output[i] << "\n";
+ }
+ std::cout << "\n\n";
+
+ return 0;
+}
diff --git a/examples/src/trivial.cpp b/examples/src/trivial.cpp
new file mode 100644
index 0000000..ceb92a6
--- /dev/null
+++ b/examples/src/trivial.cpp
@@ -0,0 +1,61 @@
+#define __CL_ENABLE_EXCEPTIONS
+#define __NO_STD_STRING
+#define _VARIADIC_MAX 10
+#include <CL/cl.hpp>
+#include <iostream>
+#include <vector>
+
+const int numElements = 32;
+
+int main(void)
+{
+ cl::Program addProgram(
+ cl::STRING_CLASS(
+ "int add(int a, int b) { return a + b; }")
+ , false);
+ cl::Program vectorWrapper(
+ cl::STRING_CLASS(
+ "int add(int a, int b); kernel void vectorAdd(global const int *inputA, global const int *inputB, global int *output){output[get_global_id(0)] = add(inputA[get_global_id(0)], inputB[get_global_id(0)]);}")
+ , false);
+ std::vector<cl::Program> programs;
+ addProgram.compile();
+ vectorWrapper.compile();
+
+ cl::STRING_CLASS s = addProgram.getInfo<CL_PROGRAM_SOURCE>();
+
+ programs.push_back(addProgram);
+ programs.push_back(vectorWrapper);
+ cl::Program vectorAddProgram = cl::linkProgram(programs);
+
+ auto vectorAddKernel =
+ cl::make_kernel<
+ cl::Buffer&,
+ cl::Buffer&,
+ cl::Buffer&
+ >( vectorAddProgram, "vectorAdd" );
+
+
+ std::vector<int> inputA(numElements, 1);
+ std::vector<int> inputB(numElements, 2);
+ std::vector<int> output(numElements, 0xdeadbeef);
+ cl::Buffer inputABuffer(begin(inputA), end(inputA), true);
+ cl::Buffer inputBBuffer(begin(inputB), end(inputB), true);
+ cl::Buffer outputBuffer(begin(output), end(output), false);
+
+ vectorAddKernel(
+ cl::EnqueueArgs(
+ cl::NDRange(numElements),
+ cl::NDRange(numElements)),
+ inputABuffer,
+ inputBBuffer,
+ outputBuffer);
+
+ cl::copy(outputBuffer, begin(output), end(output));
+
+ std::cout << "Output:\n";
+ for( int i = 1; i < numElements; ++i ) {
+ std::cout << "\t" << output[i] << "\n";
+ }
+ std::cout << "\n\n";
+
+}
diff --git a/examples/src/trivialCL2.cpp b/examples/src/trivialCL2.cpp
new file mode 100644
index 0000000..e90b091
--- /dev/null
+++ b/examples/src/trivialCL2.cpp
@@ -0,0 +1,267 @@
+#define CL_HPP_ENABLE_EXCEPTIONS
+#define CL_HPP_TARGET_OPENCL_VERSION 200
+
+//#define CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY
+//#define CL_HPP_CL_1_2_DEFAULT_BUILD
+#include <CL/cl2.hpp>
+#include <iostream>
+#include <vector>
+#include <memory>
+#include <algorithm>
+
+const int numElements = 32;
+
+int main(void)
+{
+ // Filter for a 2.0 platform and set it as the default
+ std::vector<cl::Platform> platforms;
+ cl::Platform::get(&platforms);
+ cl::Platform plat;
+ for (auto &p : platforms) {
+ std::string platver = p.getInfo<CL_PLATFORM_VERSION>();
+ std::cerr << "Plat: " << platver << "\n";
+ if (platver.find("OpenCL 2.") != std::string::npos) {
+ plat = p;
+ }
+ }
+ if (plat() == 0) {
+ std::cout << "No OpenCL 2.0 platform found.\n";
+ return -1;
+ }
+
+ cl::Platform newP = cl::Platform::setDefault(plat);
+ if (newP != plat) {
+ std::cout << "Error setting default platform.";
+ return -1;
+ }
+
+ // Test command queue property construction
+ cl::CommandQueue q5(cl::QueueProperties::Profiling | cl::QueueProperties::OutOfOrder);
+
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ cl::Program errorProgram(
+ std::string(
+ "sakfdjnksajfnksajnfsa")
+ , false);
+ try {
+ errorProgram.build("-cl-std=CL2.0");
+ }
+ catch (...) {
+ // Print build info for all devices
+ cl_int buildErr = CL_SUCCESS;
+ auto buildInfo = errorProgram.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&buildErr);
+ std::cerr << "Errors for failed build for all devices" << std::endl;
+ for (auto &pair : buildInfo) {
+ std::cerr << "Device: " << pair.first.getInfo<CL_DEVICE_NAME>() << std::endl << pair.second << std::endl << std::endl;
+ }
+ }
+
+
+ cl::Program errorProgramException(
+ std::string(
+ "sakfdjnksajfnksajnfsa")
+ , false);
+ try {
+ errorProgramException.build("-cl-std=CL2.0");
+ }
+ catch (const cl::BuildError &err) {
+ // Print build info for all devices
+ auto buildInfo = err.getBuildLog();
+ std::cerr << "Errors for failed build for all devices from thrown exception" << std::endl;
+ for (auto &pair : buildInfo) {
+ std::cerr << "Device: " << pair.first.getInfo<CL_DEVICE_NAME>() << std::endl << pair.second << std::endl << std::endl;
+ }
+ }
+#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
+
+
+ std::string kernel1{"global int globalA;"
+ "kernel void updateGlobal(){"
+ " globalA = 75;"
+ "}"};
+ std::string kernel2{
+ "typedef struct { global int *bar; } Foo; kernel void vectorAdd(global const Foo* aNum, global const int *inputA, global const int *inputB, global int *output, global int *output2, int val, write_only pipe int outPipe, queue_t childQueue){"
+ " output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar);"
+ " output2[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar);"
+ " write_pipe(outPipe, &val);"
+ " queue_t default_queue = get_default_queue(); "
+ " ndrange_t ndrange = ndrange_1D(get_global_size(0)/2, get_global_size(0)/2); "
+ // Have a child kernel write into third quarter of output
+ " enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, "
+ " ^{"
+ " output[get_global_size(0)*2 + get_global_id(0)] = inputA[get_global_size(0)*2+get_global_id(0)] + inputB[get_global_size(0)*2+get_global_id(0)] + globalA;"
+ " });"
+ // Have a child kernel write into last quarter of output
+ " enqueue_kernel(childQueue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, "
+ " ^{"
+ " output[get_global_size(0)*3 + get_global_id(0)] = inputA[get_global_size(0)*3 + get_global_id(0)] + inputB[get_global_size(0)*3 + get_global_id(0)] + globalA + 2;"
+ " });"
+ "}" };
+#if defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ // Old interface style
+ cl::Program::Sources programStrings;
+ programStrings.push_back(std::pair<const char*, size_t>(kernel1.data(), kernel1.length()));
+ programStrings.push_back(std::pair<const char*, size_t>(kernel2.data(), kernel2.length()));
+#else // #if defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ // New simpler string interface style
+ std::vector<std::string> programStrings {
+ kernel1,
+ kernel2 };
+#endif // #if defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ cl::Program vectorAddProgram(
+ programStrings);
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ try {
+ vectorAddProgram.build("-cl-std=CL2.0");
+ }
+ catch (...) {
+ // Print build info for all devices
+ cl_int buildErr = CL_SUCCESS;
+ auto buildInfo = vectorAddProgram.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&buildErr);
+ for (auto &pair : buildInfo) {
+ std::cerr << pair.second << std::endl << std::endl;
+ }
+
+ return 1;
+ }
+#else // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ cl_int buildErr = vectorAddProgram.build("-cl-std=CL2.0");
+ if (buildErr != CL_SUCCESS) {
+ std::cerr << "Build error: " << buildErr << "\n";
+ return -1;
+ }
+#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
+
+ typedef struct { int *bar; } Foo;
+
+ // Get and run kernel that initializes the program-scope global
+ // A test for kernels that take no arguments
+ auto program2Kernel =
+ cl::KernelFunctor<>(vectorAddProgram, "updateGlobal");
+ program2Kernel(
+ cl::EnqueueArgs(
+ cl::NDRange(1)));
+
+
+ //////////////////
+ // SVM allocations
+
+ // Store pointer to pointer here to test clSetKernelExecInfo
+ // Code using cl namespace allocators etc as a test
+ // std::shared_ptr etc should work fine too
+
+ auto anSVMInt = cl::allocate_svm<int, cl::SVMTraitCoarse<>>();
+ *anSVMInt = 5;
+ cl::SVMAllocator<int, cl::SVMTraitCoarse<>> svmAlloc;
+ std::cout << "Max alloc size: " << svmAlloc.max_size() << " bytes\n";
+ cl::SVMAllocator<Foo, cl::SVMTraitCoarse<cl::SVMTraitReadOnly<>>> svmAllocReadOnly;
+ auto fooPointer = cl::allocate_pointer<Foo>(svmAllocReadOnly);
+ fooPointer->bar = anSVMInt.get();
+
+ std::vector<int, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>> inputA(numElements, 1, svmAlloc);
+
+ cl::coarse_svm_vector<int> inputB(numElements, 2, svmAlloc);
+
+ //
+ //////////////
+
+ // Traditional cl_mem allocations
+ std::vector<int> output(numElements, 0xdeadbeef);
+ cl::Buffer outputBuffer(begin(output), end(output), false);
+
+ std::vector<int, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>> output2(numElements / 2, 0xdeadbeef);
+ cl::Pipe aPipe(sizeof(cl_int), numElements / 2);
+ // Unfortunately, there is no way to check for a default or know if a kernel needs one
+ // so the user has to create one
+ // We can't preemptively do so on device creation because they cannot then replace it
+ cl::DeviceCommandQueue defaultDeviceQueue;
+ defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault();
+
+ auto vectorAddKernel =
+ cl::KernelFunctor<
+ decltype(fooPointer)&,
+ int*,
+ cl::coarse_svm_vector<int>&,
+ cl::Buffer,
+ std::vector<int, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>&,
+ int,
+ cl::Pipe&,
+ cl::DeviceCommandQueue
+ >(vectorAddProgram, "vectorAdd");
+
+
+ // Only the last of these will actually be used
+ // but this will check that the API is working for all
+ // of them
+ cl::vector<void*> ptrs{ static_cast<void*>(anSVMInt.get()) };
+ vectorAddKernel.setSVMPointers(ptrs);
+ vectorAddKernel.setSVMPointers(anSVMInt.get());
+ vectorAddKernel.setSVMPointers(anSVMInt);
+
+ // Hand control of coarse allocations to runtime
+ cl::enqueueUnmapSVM(anSVMInt);
+ cl::enqueueUnmapSVM(fooPointer);
+ cl::unmapSVM(inputB);
+ cl::unmapSVM(output2);
+
+
+ cl_int error;
+ vectorAddKernel(
+ cl::EnqueueArgs(
+ cl::NDRange(numElements/2),
+ cl::NDRange(numElements/2)),
+ fooPointer,
+ inputA.data(),
+ inputB,
+ outputBuffer,
+ output2,
+ 3,
+ aPipe,
+ defaultDeviceQueue,
+ error
+ );
+
+ // Copy the cl_mem output back to the vector
+ cl::copy(outputBuffer, begin(output), end(output));
+ // Grab the SVM output vector using a map
+ cl::mapSVM(output2);
+
+ cl::Device d = cl::Device::getDefault();
+ std::cout << "Max pipe args: " << d.getInfo<CL_DEVICE_MAX_PIPE_ARGS>() << "\n";
+ std::cout << "Max pipe active reservations: " << d.getInfo<CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS>() << "\n";
+ std::cout << "Max pipe packet size: " << d.getInfo<CL_DEVICE_PIPE_MAX_PACKET_SIZE>() << "\n";
+ std::cout << "Device SVM capabilities: " << d.getInfo<CL_DEVICE_SVM_CAPABILITIES>() << "\n";
+ std::cout << "\tCL_DEVICE_SVM_COARSE_GRAIN_BUFFER = " << CL_DEVICE_SVM_COARSE_GRAIN_BUFFER << "\n";
+ std::cout << "\tCL_DEVICE_SVM_FINE_GRAIN_BUFFER = " << CL_DEVICE_SVM_FINE_GRAIN_BUFFER << "\n";
+ std::cout << "\tCL_DEVICE_SVM_FINE_GRAIN_SYSTEM = " << CL_DEVICE_SVM_FINE_GRAIN_SYSTEM << "\n";
+ std::cout << "\tCL_DEVICE_SVM_ATOMICS = " << CL_DEVICE_SVM_ATOMICS << "\n";
+
+ cl_device_id clD = d();
+ cl_device_id clD2 = d.get();
+
+ auto v = vectorAddProgram.getInfo<CL_PROGRAM_BINARIES>();
+ auto v2 = vectorAddProgram.getInfo<CL_PROGRAM_BINARY_SIZES>();
+ std::vector<std::vector<unsigned char>> v3;
+ std::vector<size_t> v4;
+ vectorAddProgram.getInfo(CL_PROGRAM_BINARIES, &v3);
+ vectorAddProgram.getInfo(CL_PROGRAM_BINARY_SIZES, &v4);
+
+ std::cout << "Binaries: " << v.size() << "\n";
+ std::cout << "Binary sizes: " << v2.size() << "\n";
+ for (size_t s : v2) {
+ std::cout << "\t" << s << "\n";
+ }
+
+ std::cout << "Output:\n";
+ for (int i = 1; i < numElements; ++i) {
+ std::cout << "\t" << output[i] << "\n";
+ }
+ std::cout << "\n\n";
+ std::cout << "Output2:\n";
+ for (auto &e : output2) {
+ std::cout << "\t" << e << "\n";
+ }
+ std::cout << "\n\n";
+
+ return 0;
+}
diff --git a/examples/src/trivialCL2SizeTCompat.cpp b/examples/src/trivialCL2SizeTCompat.cpp
new file mode 100644
index 0000000..90731fc
--- /dev/null
+++ b/examples/src/trivialCL2SizeTCompat.cpp
@@ -0,0 +1,130 @@
+#define CL_HPP_ENABLE_EXCEPTIONS
+#define CL_HPP_TARGET_OPENCL_VERSION 200
+#define CL_HPP_ENABLE_SIZE_T_COMPATIBILITY
+
+#include <CL/cl2.hpp>
+#include <iostream>
+#include <vector>
+
+const int numElements = 32;
+
+int main(void)
+{
+ // Filter for a 2.0 platform and set it as the default
+ std::vector<cl::Platform> platforms;
+ cl::Platform::get(&platforms);
+ cl::Platform plat;
+ for (auto &p : platforms) {
+ std::string platver = p.getInfo<CL_PLATFORM_VERSION>();
+ if (platver.find("OpenCL 2.") != std::string::npos) {
+ plat = p;
+ }
+ }
+ if (plat() == 0) {
+ std::cout << "No OpenCL 2.0 platform found.\n";
+ return -1;
+ }
+
+ cl::Platform newP = cl::Platform::setDefault(plat);
+ if (newP != plat) {
+ std::cout << "Error setting default platform.";
+ return -1;
+ }
+ cl::Program vectorAddProgram(
+ std::string(
+ "global int globalA;"
+ "kernel void updateGlobal(){"
+ " globalA = 75;"
+ "}"
+ "kernel void vectorAdd(global const int *inputA, global const int *inputB, global int *output, int val, write_only pipe int outPipe){"
+ " output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val;"
+ " write_pipe(outPipe, &val);"
+ " queue_t default_queue = get_default_queue(); "
+ " ndrange_t ndrange = ndrange_1D(get_global_size(0), get_global_size(0)); "
+ " enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange, "
+ " ^{"
+ " output[get_global_size(0)+get_global_id(0)] = inputA[get_global_size(0)+get_global_id(0)] + inputB[get_global_size(0)+get_global_id(0)] + globalA;"
+ " });"
+ "}")
+ , false);
+ try {
+ vectorAddProgram.build("-cl-std=CL2.0");
+ }
+ catch (...) {
+ std::string bl = vectorAddProgram.getBuildInfo<CL_PROGRAM_BUILD_LOG>(cl::Device::getDefault());
+ std::cerr << bl << std::endl;
+ }
+
+ // Get and run kernel that initializes the program-scope global
+ // A test for kernels that take no arguments
+ auto program2Kernel =
+ cl::KernelFunctor<>(vectorAddProgram, "updateGlobal");
+ program2Kernel(
+ cl::EnqueueArgs(
+ cl::NDRange(1)));
+
+ auto vectorAddKernel =
+ cl::KernelFunctor<
+ cl::Buffer&,
+ cl::Buffer&,
+ cl::Buffer&,
+ int,
+ cl::Pipe&
+ >(vectorAddProgram, "vectorAdd");
+
+ std::vector<int> inputA(numElements, 1);
+ std::vector<int> inputB(numElements, 2);
+ std::vector<int> output(numElements, 0xdeadbeef);
+ cl::Buffer inputABuffer(begin(inputA), end(inputA), true);
+ cl::Buffer inputBBuffer(begin(inputB), end(inputB), true);
+ cl::Buffer outputBuffer(begin(output), end(output), false);
+ cl::Pipe aPipe(sizeof(cl_int), numElements / 2);
+ // Unfortunately, there is no way to check for a default or know if a kernel needs one
+ // so the user has to create one
+ // We can't preemptively do so on device creation because they cannot then replace it
+ cl::DeviceCommandQueue deviceQueue = cl::DeviceCommandQueue::makeDefault(
+ cl::Context::getDefault(), cl::Device::getDefault());
+
+ vectorAddKernel(
+ cl::EnqueueArgs(
+ cl::NDRange(numElements/2),
+ cl::NDRange(numElements/2)),
+ inputABuffer,
+ inputBBuffer,
+ outputBuffer,
+ 3,
+ aPipe);
+
+ cl_int error;
+ vectorAddKernel(
+ cl::EnqueueArgs(
+ cl::NDRange(numElements/2),
+ cl::NDRange(numElements/2)),
+ inputABuffer,
+ inputBBuffer,
+ outputBuffer,
+ 3,
+ aPipe,
+ error);
+
+ cl::array<size_t, 3> WGSizeResultArray = vectorAddKernel.getKernel().getWorkGroupInfo<CL_KERNEL_COMPILE_WORK_GROUP_SIZE>(cl::Device::getDefault());
+ std::cout << "Array return: " << WGSizeResultArray[0] << ", " << WGSizeResultArray[1] << ", " << WGSizeResultArray[2] << "\n";
+ cl::size_t<3> WGSizeResult = vectorAddKernel.getKernel().getWorkGroupInfo<CL_KERNEL_COMPILE_WORK_GROUP_SIZE>(cl::Device::getDefault());
+ std::cout << "Size_t return: " << WGSizeResult[0] << ", " << WGSizeResult[1] << ", " << WGSizeResult[2] << "\n";
+
+ cl::copy(outputBuffer, begin(output), end(output));
+
+ cl::Device d = cl::Device::getDefault();
+ std::cout << "Max pipe args: " << d.getInfo<CL_DEVICE_MAX_PIPE_ARGS>() << "\n";
+ std::cout << "Max pipe active reservations: " << d.getInfo<CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS>() << "\n";
+ std::cout << "Max pipe packet size: " << d.getInfo<CL_DEVICE_PIPE_MAX_PACKET_SIZE>() << "\n";
+
+
+
+ std::cout << "Output:\n";
+ for (int i = 1; i < numElements; ++i) {
+ std::cout << "\t" << output[i] << "\n";
+ }
+ std::cout << "\n\n";
+
+}
diff --git a/gen_cl_hpp.py b/gen_cl_hpp.py
new file mode 100755
index 0000000..9056f08
--- /dev/null
+++ b/gen_cl_hpp.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+# Generation for the 1.x version of cl.hpp where expansion of variadic interfaces is required.
+
+import re
+import sys
+from optparse import OptionParser
+
+parser = OptionParser()
+parser.add_option('-i', '--input', dest = 'input_filename', metavar = 'FILE', default = 'input_cl.hpp', help = 'Template file')
+parser.add_option('-o', '--output', dest = 'output_filename', metavar = 'FILE', default = 'cl.hpp', help = 'Output file')
+(options, args) = parser.parse_args()
+if len(args) > 0:
+ parser.error("No arguments expected")
+
+inputCLHPP = open(options.input_filename, 'r')
+contents = inputCLHPP.read()
+inputCLHPP.close()
+
+outputCLHPP = open(options.output_filename, 'w')
+
+numArgs = 32
+
+
+def genTypeNameList(numEntries):
+ typeNameString = ""
+ for i in range(0, numEntries):
+ typeNameString = typeNameString + "\ttypename T" + str(i)
+ if i < (numEntries-1):
+ typeNameString = typeNameString + ",\n"
+ return typeNameString;
+
+def genTemplateParameterList(numArguments, totalArguments, indent):
+ fullArgList = ""
+ for i in range(0, numArguments):
+ fullArgList = fullArgList + indent + "T" + str(i)
+ if i < (totalArguments-1):
+ fullArgList = fullArgList + ",\n"
+ return fullArgList
+
+def genTemplateParameterListCommaFirst(numArguments, totalArguments):
+ fullArgList = ""
+ for i in range(0, numArguments):
+ fullArgList = fullArgList + ",\n\t\tT" + str(i)
+ return fullArgList
+
+def genTemplateArgumentList(numArguments, totalArguments):
+ fullArgList = ""
+ for i in range(0, numArguments):
+ fullArgList = fullArgList + ",\n\t\tT" + str(i) + " arg" + str(i)
+ return fullArgList
+
+def genFunctionArgumentList(numArguments, totalArguments):
+ fullArgList = ""
+ for i in range(0, numArguments):
+ fullArgList = fullArgList + ",\n\t\t\targ" + str(i)
+ return fullArgList
+
+def genFullArgList(numArguments, totalArguments, indent):
+ fullArgList = genTemplateParameterList(numArguments, totalArguments, indent)
+
+ for i in range(0, totalArguments - numArguments):
+ fullArgList = fullArgList + indent + "NullType"
+ if i < (totalArguments - numArguments - 1):
+ fullArgList = fullArgList + ",\n"
+ return fullArgList
+
+def genSpecialization(numArguments, totalArguments):
+ specialization = ""
+ specialization = "template<\n" + genTypeNameList(numArguments) + ">\nstruct functionImplementation_\n"
+
+ if( numArguments < totalArguments ):
+ specialization = specialization + "<" + genFullArgList(numArguments, totalArguments, "\t") + ">\n"
+ specialization = specialization + "{\n\ttypedef detail::KernelFunctorGlobal<\n"
+ specialization = specialization + genFullArgList(numArguments, totalArguments, "\t\t") + "> FunctorType;\n"
+
+ specialization = specialization + """
+ FunctorType functor_;
+
+ functionImplementation_(const FunctorType &functor) :
+ functor_(functor)
+ {
+ """
+
+ # Insert a compile-time check to assert on Visual Studio 2012 if we have more than 10
+ # arguments in the variadic expansion
+ if totalArguments > 5:
+ specialization = specialization + """
+ #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < """ + str(numArguments) + """))
+ // Fail variadic expansion for dev11
+ static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
+ #endif
+ """
+ specialization = specialization + """
+ }
+
+ //! \\brief Return type of the functor
+ typedef Event result_type;
+
+ //! \\brief Function signature of kernel functor with no event dependency.
+ typedef Event type_(
+ const EnqueueArgs&"""
+ specialization = specialization + genTemplateParameterListCommaFirst(numArguments, numArguments) + ");\n\n"
+
+ specialization = specialization + "\tEvent operator()(\n\t\tconst EnqueueArgs& enqueueArgs" + genTemplateArgumentList(numArguments, numArguments) + ")\n"
+ specialization = specialization + "\t{\n\t\treturn functor_(\n\t\t\tenqueueArgs" + genFunctionArgumentList(numArguments, numArguments) + ");\n\t}\n"
+
+ specialization = specialization + """
+
+};
+
+"""
+
+ return specialization
+
+
+
+functionImplementation = ""
+for numParameters in range(numArgs, 0, -1):
+ functionImplementation = functionImplementation + genSpecialization(numParameters, numArgs)
+
+outputContents = contents.replace("%FUNCTION_IMPLEMENTATION_REPLACEMENT_POINT%", functionImplementation)
+
+outputContents = re.sub("//@@@@EXCESSIVE-ARG-START.*?[\n\r](.*?[\n\r])+?//@@@@EXCESSIVE-ARG-END.*?[\n\r]", "", outputContents, 0, re.MULTILINE)
+
+outputCLHPP.write(outputContents)
+outputCLHPP.close()
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
new file mode 100644
index 0000000..256829f
--- /dev/null
+++ b/include/CMakeLists.txt
@@ -0,0 +1,21 @@
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CL/cl.hpp
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/CL
+ COMMAND python ${CLCPP_SOURCE_DIR}/gen_cl_hpp.py -i ${CLCPP_SOURCE_DIR}/input_cl.hpp -o ${CMAKE_CURRENT_BINARY_DIR}/CL/cl.hpp
+ DEPENDS ${CLCPP_SOURCE_DIR}/input_cl.hpp ${CLCPP_SOURCE_DIR}/gen_cl_hpp.py
+ COMMENT "Rebuilding cl.hpp ...")
+add_custom_target(generate_clhpp ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/CL/cl.hpp SOURCES ${CLCPP_SOURCE_DIR}/input_cl.hpp)
+
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/CL/cl2.hpp
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/CL
+ COMMAND ${CMAKE_COMMAND} -E copy ${CLCPP_SOURCE_DIR}/input_cl2.hpp ${CMAKE_CURRENT_BINARY_DIR}/CL/cl2.hpp
+ DEPENDS ${CLCPP_SOURCE_DIR}/input_cl2.hpp
+ COMMENT "Rebuilding cl2.hpp ...")
+add_custom_target(generate_cl2hpp ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/CL/cl2.hpp SOURCES ${CLCPP_SOURCE_DIR}/input_cl2.hpp)
+
+install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CL
+ DESTINATION .
+ FILES_MATCHING
+ PATTERN "*.hpp"
+ )
diff --git a/input_cl.hpp b/input_cl.hpp
new file mode 100644
index 0000000..ad62b0f
--- /dev/null
+++ b/input_cl.hpp
@@ -0,0 +1,8075 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2015 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and/or associated documentation files (the
+ * "Materials"), to deal in the Materials without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Materials, and to
+ * permit persons to whom the Materials are furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
+ * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
+ * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
+ * https://www.khronos.org/registry/
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ ******************************************************************************/
+
+/*! \file
+ *
+ * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and
+ * OpenCL 1.2 (rev 15)
+ * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes
+ *
+ * Additions and fixes from:
+ * Brian Cole, March 3rd 2010 and April 2012
+ * Matt Gruenke, April 2012.
+ * Bruce Merry, February 2013.
+ * Tom Deakin and Simon McIntosh-Smith, July 2013
+ *
+ * \version 1.2.9
+ * \date December 2015
+ *
+ * Optional extension support
+ *
+ * cl
+ * cl_ext_device_fission
+ * #define USE_CL_DEVICE_FISSION
+ */
+
+/*! \mainpage
+ * \section intro Introduction
+ * For many large applications C++ is the language of choice and so it seems
+ * reasonable to define C++ bindings for OpenCL.
+ *
+ *
+ * The interface is contained with a single C++ header file \em cl.hpp and all
+ * definitions are contained within the namespace \em cl. There is no additional
+ * requirement to include \em cl.h and to use either the C++ or original C
+ * bindings it is enough to simply include \em cl.hpp.
+ *
+ * The bindings themselves are lightweight and correspond closely to the
+ * underlying C API. Using the C++ bindings introduces no additional execution
+ * overhead.
+ *
+ * For detail documentation on the bindings see:
+ *
+ * The OpenCL C++ Wrapper API 1.2 (revision 09)
+ * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf
+ *
+ * \section example Example
+ *
+ * The following example shows a general use case for the C++
+ * bindings, including support for the optional exception feature and
+ * also the supplied vector and string classes, see following sections for
+ * decriptions of these features.
+ *
+ * \code
+ * #define __CL_ENABLE_EXCEPTIONS
+ *
+ * #if defined(__APPLE__) || defined(__MACOSX)
+ * #include <OpenCL/cl.hpp>
+ * #else
+ * #include <CL/cl.hpp>
+ * #endif
+ * #include <cstdio>
+ * #include <cstdlib>
+ * #include <iostream>
+ *
+ * const char * helloStr = "__kernel void "
+ * "hello(void) "
+ * "{ "
+ * " "
+ * "} ";
+ *
+ * int
+ * main(void)
+ * {
+ * cl_int err = CL_SUCCESS;
+ * try {
+ *
+ * std::vector<cl::Platform> platforms;
+ * cl::Platform::get(&platforms);
+ * if (platforms.size() == 0) {
+ * std::cout << "Platform size 0\n";
+ * return -1;
+ * }
+ *
+ * cl_context_properties properties[] =
+ * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
+ * cl::Context context(CL_DEVICE_TYPE_CPU, properties);
+ *
+ * std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
+ *
+ * cl::Program::Sources source(1,
+ * std::make_pair(helloStr,strlen(helloStr)));
+ * cl::Program program_ = cl::Program(context, source);
+ * program_.build(devices);
+ *
+ * cl::Kernel kernel(program_, "hello", &err);
+ *
+ * cl::Event event;
+ * cl::CommandQueue queue(context, devices[0], 0, &err);
+ * queue.enqueueNDRangeKernel(
+ * kernel,
+ * cl::NullRange,
+ * cl::NDRange(4,4),
+ * cl::NullRange,
+ * NULL,
+ * &event);
+ *
+ * event.wait();
+ * }
+ * catch (cl::Error err) {
+ * std::cerr
+ * << "ERROR: "
+ * << err.what()
+ * << "("
+ * << err.err()
+ * << ")"
+ * << std::endl;
+ * }
+ *
+ * return EXIT_SUCCESS;
+ * }
+ *
+ * \endcode
+ *
+ */
+#ifndef CL_HPP_
+#define CL_HPP_
+
+#ifdef _WIN32
+
+#include <malloc.h>
+
+#if defined(USE_DX_INTEROP)
+#include <CL/cl_d3d10.h>
+#include <CL/cl_dx9_media_sharing.h>
+#endif
+#endif // _WIN32
+
+#if defined(_MSC_VER)
+#include <intrin.h>
+#endif // _MSC_VER
+
+//
+#if defined(USE_CL_DEVICE_FISSION)
+#include <CL/cl_ext.h>
+#endif
+
+#if defined(__APPLE__) || defined(__MACOSX)
+#include <OpenCL/opencl.h>
+#else
+#include <CL/opencl.h>
+#endif // !__APPLE__
+
+#if (_MSC_VER >= 1700) || (__cplusplus >= 201103L)
+#define CL_HPP_RVALUE_REFERENCES_SUPPORTED
+#define CL_HPP_CPP11_ATOMICS_SUPPORTED
+#include <atomic>
+#endif
+
+#if (__cplusplus >= 201103L)
+#define CL_HPP_NOEXCEPT noexcept
+#else
+#define CL_HPP_NOEXCEPT
+#endif
+
+
+// To avoid accidentally taking ownership of core OpenCL types
+// such as cl_kernel constructors are made explicit
+// under OpenCL 1.2
+#if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+#define __CL_EXPLICIT_CONSTRUCTORS explicit
+#else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+#define __CL_EXPLICIT_CONSTRUCTORS
+#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+
+// Define deprecated prefixes and suffixes to ensure compilation
+// in case they are not pre-defined
+#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
+#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
+#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
+#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
+
+#if !defined(CL_CALLBACK)
+#define CL_CALLBACK
+#endif //CL_CALLBACK
+
+#include <utility>
+#include <limits>
+#include <iterator>
+
+#if defined(__CL_ENABLE_EXCEPTIONS)
+#include <exception>
+#endif // #if defined(__CL_ENABLE_EXCEPTIONS)
+
+#if !defined(__NO_STD_VECTOR)
+#include <vector>
+#endif
+
+#if !defined(__NO_STD_STRING)
+#include <string>
+#endif
+
+#if defined(__ANDROID__) || defined(linux) || defined(__APPLE__) || defined(__MACOSX)
+#include <alloca.h>
+#endif // linux
+
+#include <cstring>
+
+
+/*! \namespace cl
+ *
+ * \brief The OpenCL C++ bindings are defined within this namespace.
+ *
+ */
+namespace cl {
+
+class Memory;
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
+#define __INIT_CL_EXT_FCN_PTR(name) \
+ if(!pfn_##name) { \
+ pfn_##name = (PFN_##name) \
+ clGetExtensionFunctionAddress(#name); \
+ if(!pfn_##name) { \
+ } \
+ }
+#endif // #if defined(CL_VERSION_1_1)
+
+#if defined(CL_VERSION_1_2)
+#define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \
+ if(!pfn_##name) { \
+ pfn_##name = (PFN_##name) \
+ clGetExtensionFunctionAddressForPlatform(platform, #name); \
+ if(!pfn_##name) { \
+ } \
+ }
+#endif // #if defined(CL_VERSION_1_1)
+
+class Program;
+class Device;
+class Context;
+class CommandQueue;
+class Memory;
+class Buffer;
+
+#if defined(__CL_ENABLE_EXCEPTIONS)
+/*! \brief Exception class
+ *
+ * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined.
+ */
+class Error : public std::exception
+{
+private:
+ cl_int err_;
+ const char * errStr_;
+public:
+ /*! \brief Create a new CL error exception for a given error code
+ * and corresponding message.
+ *
+ * \param err error code value.
+ *
+ * \param errStr a descriptive string that must remain in scope until
+ * handling of the exception has concluded. If set, it
+ * will be returned by what().
+ */
+ Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
+ {}
+
+ ~Error() throw() {}
+
+ /*! \brief Get error string associated with exception
+ *
+ * \return A memory pointer to the error message string.
+ */
+ virtual const char * what() const throw ()
+ {
+ if (errStr_ == NULL) {
+ return "empty";
+ }
+ else {
+ return errStr_;
+ }
+ }
+
+ /*! \brief Get error code associated with exception
+ *
+ * \return The error code.
+ */
+ cl_int err(void) const { return err_; }
+};
+
+#define __ERR_STR(x) #x
+#else
+#define __ERR_STR(x) NULL
+#endif // __CL_ENABLE_EXCEPTIONS
+
+
+namespace detail
+{
+#if defined(__CL_ENABLE_EXCEPTIONS)
+static inline cl_int errHandler (
+ cl_int err,
+ const char * errStr = NULL)
+{
+ if (err != CL_SUCCESS) {
+ throw Error(err, errStr);
+ }
+ return err;
+}
+#else
+static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
+{
+ (void) errStr; // suppress unused variable warning
+ return err;
+}
+#endif // __CL_ENABLE_EXCEPTIONS
+}
+
+
+
+//! \cond DOXYGEN_DETAIL
+#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
+#define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo)
+#define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
+#define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
+#define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
+#define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
+#define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
+#define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
+#define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
+#define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
+#define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
+#define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
+#if defined(CL_VERSION_1_2)
+#define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo)
+#endif // #if defined(CL_VERSION_1_2)
+#define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
+#define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
+#define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
+#define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
+
+#define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext)
+#define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
+#define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
+
+#define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
+#define __COPY_ERR __ERR_STR(cl::copy)
+#define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
+#define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
+#define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
+#define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
+#if defined(CL_VERSION_1_2)
+#define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage)
+#define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture)
+#define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions)
+#endif // #if defined(CL_VERSION_1_2)
+#define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
+#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
+
+#define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
+#define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
+#define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
+#define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
+
+#define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
+#define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
+#define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
+#define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
+#if defined(CL_VERSION_1_2)
+#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels)
+#endif // #if defined(CL_VERSION_1_2)
+#define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
+#if defined(CL_VERSION_1_2)
+#define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram)
+#define __LINK_PROGRAM_ERR __ERR_STR(clLinkProgram)
+#endif // #if defined(CL_VERSION_1_2)
+#define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
+
+#define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
+#define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
+#define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
+#define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
+#define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
+#define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
+#define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
+#define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
+#define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer)
+#define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
+#define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
+#define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
+#define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage)
+#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
+#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
+#define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
+#define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
+#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
+#define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
+#define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
+#define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
+#if defined(CL_VERSION_1_2)
+#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects)
+#endif // #if defined(CL_VERSION_1_2)
+
+#define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
+#define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
+
+
+#define __RETAIN_ERR __ERR_STR(Retain Object)
+#define __RELEASE_ERR __ERR_STR(Release Object)
+#define __FLUSH_ERR __ERR_STR(clFlush)
+#define __FINISH_ERR __ERR_STR(clFinish)
+#define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error)
+
+/**
+ * CL 1.2 version that uses device fission.
+ */
+#if defined(CL_VERSION_1_2)
+#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices)
+#else
+#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT)
+#endif // #if defined(CL_VERSION_1_2)
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
+#define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
+#define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
+#define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
+#define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
+#define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D)
+#define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D)
+#define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
+#define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
+#endif // #if defined(CL_VERSION_1_1)
+
+#endif // __CL_USER_OVERRIDE_ERROR_STRINGS
+//! \endcond
+
+/**
+ * CL 1.2 marker and barrier commands
+ */
+#if defined(CL_VERSION_1_2)
+#define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList)
+#define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList)
+#endif // #if defined(CL_VERSION_1_2)
+
+#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
+typedef std::string STRING_CLASS;
+#elif !defined(__USE_DEV_STRING)
+
+/*! \class string
+ * \brief Simple string class, that provides a limited subset of std::string
+ * functionality but avoids many of the issues that come with that class.
+
+ * \note Deprecated. Please use std::string as default or
+ * re-define the string class to match the std::string
+ * interface by defining STRING_CLASS
+ */
+class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string
+{
+private:
+ ::size_t size_;
+ char * str_;
+public:
+ //! \brief Constructs an empty string, allocating no memory.
+ string(void) : size_(0), str_(NULL)
+ {
+ }
+
+ /*! \brief Constructs a string populated from an arbitrary value of
+ * specified size.
+ *
+ * An extra '\0' is added, in case none was contained in str.
+ *
+ * \param str the initial value of the string instance. Note that '\0'
+ * characters receive no special treatment. If NULL,
+ * the string is left empty, with a size of 0.
+ *
+ * \param size the number of characters to copy from str.
+ */
+ string(const char * str, ::size_t size) :
+ size_(size),
+ str_(NULL)
+ {
+ if( size > 0 ) {
+ str_ = new char[size_+1];
+ if (str_ != NULL) {
+ memcpy(str_, str, size_ * sizeof(char));
+ str_[size_] = '\0';
+ }
+ else {
+ size_ = 0;
+ }
+ }
+ }
+
+ /*! \brief Constructs a string populated from a null-terminated value.
+ *
+ * \param str the null-terminated initial value of the string instance.
+ * If NULL, the string is left empty, with a size of 0.
+ */
+ string(const char * str) :
+ size_(0),
+ str_(NULL)
+ {
+ if( str ) {
+ size_= ::strlen(str);
+ }
+ if( size_ > 0 ) {
+ str_ = new char[size_ + 1];
+ if (str_ != NULL) {
+ memcpy(str_, str, (size_ + 1) * sizeof(char));
+ }
+ }
+ }
+
+ void resize( ::size_t n )
+ {
+ if( size_ == n ) {
+ return;
+ }
+ if (n == 0) {
+ if( str_ ) {
+ delete [] str_;
+ }
+ str_ = NULL;
+ size_ = 0;
+ }
+ else {
+ char *newString = new char[n + 1];
+ ::size_t copySize = n;
+ if( size_ < n ) {
+ copySize = size_;
+ }
+ size_ = n;
+
+ if(str_) {
+ memcpy(newString, str_, (copySize + 1) * sizeof(char));
+ }
+ if( copySize < size_ ) {
+ memset(newString + copySize, 0, size_ - copySize);
+ }
+ newString[size_] = '\0';
+
+ delete [] str_;
+ str_ = newString;
+ }
+ }
+
+ const char& operator[] ( ::size_t pos ) const
+ {
+ return str_[pos];
+ }
+
+ char& operator[] ( ::size_t pos )
+ {
+ return str_[pos];
+ }
+
+ /*! \brief Copies the value of another string to this one.
+ *
+ * \param rhs the string to copy.
+ *
+ * \returns a reference to the modified instance.
+ */
+ string& operator=(const string& rhs)
+ {
+ if (this == &rhs) {
+ return *this;
+ }
+
+ if( str_ != NULL ) {
+ delete [] str_;
+ str_ = NULL;
+ size_ = 0;
+ }
+
+ if (rhs.size_ == 0 || rhs.str_ == NULL) {
+ str_ = NULL;
+ size_ = 0;
+ }
+ else {
+ str_ = new char[rhs.size_ + 1];
+ size_ = rhs.size_;
+
+ if (str_ != NULL) {
+ memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
+ }
+ else {
+ size_ = 0;
+ }
+ }
+
+ return *this;
+ }
+
+ /*! \brief Constructs a string by copying the value of another instance.
+ *
+ * \param rhs the string to copy.
+ */
+ string(const string& rhs) :
+ size_(0),
+ str_(NULL)
+ {
+ *this = rhs;
+ }
+
+ //! \brief Destructor - frees memory used to hold the current value.
+ ~string()
+ {
+ delete[] str_;
+ str_ = NULL;
+ }
+
+ //! \brief Queries the length of the string, excluding any added '\0's.
+ ::size_t size(void) const { return size_; }
+
+ //! \brief Queries the length of the string, excluding any added '\0's.
+ ::size_t length(void) const { return size(); }
+
+ /*! \brief Returns a pointer to the private copy held by this instance,
+ * or "" if empty/unset.
+ */
+ const char * c_str(void) const { return (str_) ? str_ : "";}
+} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+typedef cl::string STRING_CLASS;
+#endif // #elif !defined(__USE_DEV_STRING)
+
+#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
+#define VECTOR_CLASS std::vector
+#elif !defined(__USE_DEV_VECTOR)
+#define VECTOR_CLASS cl::vector
+
+#if !defined(__MAX_DEFAULT_VECTOR_SIZE)
+#define __MAX_DEFAULT_VECTOR_SIZE 10
+#endif
+
+/*! \class vector
+ * \brief Fixed sized vector implementation that mirroring
+ *
+ * \note Deprecated. Please use std::vector as default or
+ * re-define the vector class to match the std::vector
+ * interface by defining VECTOR_CLASS
+
+ * \note Not recommended for use with custom objects as
+ * current implementation will construct N elements
+ *
+ * std::vector functionality.
+ * \brief Fixed sized vector compatible with std::vector.
+ *
+ * \note
+ * This differs from std::vector<> not just in memory allocation,
+ * but also in terms of when members are constructed, destroyed,
+ * and assigned instead of being copy constructed.
+ *
+ * \param T type of element contained in the vector.
+ *
+ * \param N maximum size of the vector.
+ */
+template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
+class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector
+{
+private:
+ T data_[N];
+ unsigned int size_;
+
+public:
+ //! \brief Constructs an empty vector with no memory allocated.
+ vector() :
+ size_(static_cast<unsigned int>(0))
+ {}
+
+ //! \brief Deallocates the vector's memory and destroys all of its elements.
+ ~vector()
+ {
+ clear();
+ }
+
+ //! \brief Returns the number of elements currently contained.
+ unsigned int size(void) const
+ {
+ return size_;
+ }
+
+ /*! \brief Empties the vector of all elements.
+ * \note
+ * This does not deallocate memory but will invoke destructors
+ * on contained elements.
+ */
+ void clear()
+ {
+ while(!empty()) {
+ pop_back();
+ }
+ }
+
+ /*! \brief Appends an element after the last valid element.
+ * Calling this on a vector that has reached capacity will throw an
+ * exception if exceptions are enabled.
+ */
+ void push_back (const T& x)
+ {
+ if (size() < N) {
+ new (&data_[size_]) T(x);
+ size_++;
+ } else {
+ detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
+ }
+ }
+
+ /*! \brief Removes the last valid element from the vector.
+ * Calling this on an empty vector will throw an exception
+ * if exceptions are enabled.
+ */
+ void pop_back(void)
+ {
+ if (size_ != 0) {
+ --size_;
+ data_[size_].~T();
+ } else {
+ detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
+ }
+ }
+
+ /*! \brief Constructs with a value copied from another.
+ *
+ * \param vec the vector to copy.
+ */
+ vector(const vector<T, N>& vec) :
+ size_(vec.size_)
+ {
+ if (size_ != 0) {
+ assign(vec.begin(), vec.end());
+ }
+ }
+
+ /*! \brief Constructs with a specified number of initial elements.
+ *
+ * \param size number of initial elements.
+ *
+ * \param val value of initial elements.
+ */
+ vector(unsigned int size, const T& val = T()) :
+ size_(0)
+ {
+ for (unsigned int i = 0; i < size; i++) {
+ push_back(val);
+ }
+ }
+
+ /*! \brief Overwrites the current content with that copied from another
+ * instance.
+ *
+ * \param rhs vector to copy.
+ *
+ * \returns a reference to this.
+ */
+ vector<T, N>& operator=(const vector<T, N>& rhs)
+ {
+ if (this == &rhs) {
+ return *this;
+ }
+
+ if (rhs.size_ != 0) {
+ assign(rhs.begin(), rhs.end());
+ } else {
+ clear();
+ }
+
+ return *this;
+ }
+
+ /*! \brief Tests equality against another instance.
+ *
+ * \param vec the vector against which to compare.
+ */
+ bool operator==(vector<T,N> &vec)
+ {
+ if (size() != vec.size()) {
+ return false;
+ }
+
+ for( unsigned int i = 0; i < size(); ++i ) {
+ if( operator[](i) != vec[i] ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ //! \brief Conversion operator to T*.
+ operator T* () { return data_; }
+
+ //! \brief Conversion operator to const T*.
+ operator const T* () const { return data_; }
+
+ //! \brief Tests whether this instance has any elements.
+ bool empty (void) const
+ {
+ return size_==0;
+ }
+
+ //! \brief Returns the maximum number of elements this instance can hold.
+ unsigned int max_size (void) const
+ {
+ return N;
+ }
+
+ //! \brief Returns the maximum number of elements this instance can hold.
+ unsigned int capacity () const
+ {
+ return N;
+ }
+
+ //! \brief Resizes the vector to the given size
+ void resize(unsigned int newSize, T fill = T())
+ {
+ if (newSize > N)
+ {
+ detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
+ }
+ else
+ {
+ while (size_ < newSize)
+ {
+ new (&data_[size_]) T(fill);
+ size_++;
+ }
+ while (size_ > newSize)
+ {
+ --size_;
+ data_[size_].~T();
+ }
+ }
+ }
+
+ /*! \brief Returns a reference to a given element.
+ *
+ * \param index which element to access. *
+ * \note
+ * The caller is responsible for ensuring index is >= 0 and < size().
+ */
+ T& operator[](int index)
+ {
+ return data_[index];
+ }
+
+ /*! \brief Returns a const reference to a given element.
+ *
+ * \param index which element to access.
+ *
+ * \note
+ * The caller is responsible for ensuring index is >= 0 and < size().
+ */
+ const T& operator[](int index) const
+ {
+ return data_[index];
+ }
+
+ /*! \brief Assigns elements of the vector based on a source iterator range.
+ *
+ * \param start Beginning iterator of source range
+ * \param end Enditerator of source range
+ *
+ * \note
+ * Will throw an exception if exceptions are enabled and size exceeded.
+ */
+ template<class I>
+ void assign(I start, I end)
+ {
+ clear();
+ while(start != end) {
+ push_back(*start);
+ start++;
+ }
+ }
+
+ /*! \class iterator
+ * \brief Const iterator class for vectors
+ */
+ class iterator
+ {
+ private:
+ const vector<T,N> *vec_;
+ int index_;
+
+ /**
+ * Internal iterator constructor to capture reference
+ * to the vector it iterates over rather than taking
+ * the vector by copy.
+ */
+ iterator (const vector<T,N> &vec, int index) :
+ vec_(&vec)
+ {
+ if( !vec.empty() ) {
+ index_ = index;
+ } else {
+ index_ = -1;
+ }
+ }
+
+ public:
+ iterator(void) :
+ index_(-1),
+ vec_(NULL)
+ {
+ }
+
+ iterator(const iterator& rhs) :
+ vec_(rhs.vec_),
+ index_(rhs.index_)
+ {
+ }
+
+ ~iterator(void) {}
+
+ static iterator begin(const cl::vector<T,N> &vec)
+ {
+ iterator i(vec, 0);
+
+ return i;
+ }
+
+ static iterator end(const cl::vector<T,N> &vec)
+ {
+ iterator i(vec, vec.size());
+
+ return i;
+ }
+
+ bool operator==(iterator i)
+ {
+ return ((vec_ == i.vec_) &&
+ (index_ == i.index_));
+ }
+
+ bool operator!=(iterator i)
+ {
+ return (!(*this==i));
+ }
+
+ iterator& operator++()
+ {
+ ++index_;
+ return *this;
+ }
+
+ iterator operator++(int)
+ {
+ iterator retVal(*this);
+ ++index_;
+ return retVal;
+ }
+
+ iterator& operator--()
+ {
+ --index_;
+ return *this;
+ }
+
+ iterator operator--(int)
+ {
+ iterator retVal(*this);
+ --index_;
+ return retVal;
+ }
+
+ const T& operator *() const
+ {
+ return (*vec_)[index_];
+ }
+ };
+
+ iterator begin(void)
+ {
+ return iterator::begin(*this);
+ }
+
+ iterator begin(void) const
+ {
+ return iterator::begin(*this);
+ }
+
+ iterator end(void)
+ {
+ return iterator::end(*this);
+ }
+
+ iterator end(void) const
+ {
+ return iterator::end(*this);
+ }
+
+ T& front(void)
+ {
+ return data_[0];
+ }
+
+ T& back(void)
+ {
+ return data_[size_];
+ }
+
+ const T& front(void) const
+ {
+ return data_[0];
+ }
+
+ const T& back(void) const
+ {
+ return data_[size_-1];
+ }
+} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+#endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
+
+
+
+
+
+namespace detail {
+#define __DEFAULT_NOT_INITIALIZED 1
+#define __DEFAULT_BEING_INITIALIZED 2
+#define __DEFAULT_INITIALIZED 4
+
+ /*
+ * Compare and exchange primitives are needed for handling of defaults
+ */
+
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+ inline int compare_exchange(std::atomic<int> * dest, int exchange, int comparand)
+#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ inline int compare_exchange(volatile int * dest, int exchange, int comparand)
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ {
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+ std::atomic_compare_exchange_strong(dest, &comparand, exchange);
+ return comparand;
+#elif _MSC_VER
+ return (int)(_InterlockedCompareExchange(
+ (volatile long*)dest,
+ (long)exchange,
+ (long)comparand));
+#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ return (__sync_val_compare_and_swap(
+ dest,
+ comparand,
+ exchange));
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ }
+
+ inline void fence() {
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+ std::atomic_thread_fence(std::memory_order_seq_cst);
+#elif _MSC_VER // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ _ReadWriteBarrier();
+#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ __sync_synchronize();
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ }
+} // namespace detail
+
+
+/*! \brief class used to interface between C++ and
+ * OpenCL C calls that require arrays of size_t values, whose
+ * size is known statically.
+ */
+template <int N>
+class size_t
+{
+private:
+ ::size_t data_[N];
+
+public:
+ //! \brief Initialize size_t to all 0s
+ size_t()
+ {
+ for( int i = 0; i < N; ++i ) {
+ data_[i] = 0;
+ }
+ }
+
+ ::size_t& operator[](int index)
+ {
+ return data_[index];
+ }
+
+ const ::size_t& operator[](int index) const
+ {
+ return data_[index];
+ }
+
+ //! \brief Conversion operator to T*.
+ operator ::size_t* () { return data_; }
+
+ //! \brief Conversion operator to const T*.
+ operator const ::size_t* () const { return data_; }
+};
+
+namespace detail {
+
+// Generic getInfoHelper. The final parameter is used to guide overload
+// resolution: the actual parameter passed is an int, which makes this
+// a worse conversion sequence than a specialization that declares the
+// parameter as an int.
+template<typename Functor, typename T>
+inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
+{
+ return f(name, sizeof(T), param, NULL);
+}
+
+// Specialized getInfoHelper for VECTOR_CLASS params
+template <typename Func, typename T>
+inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, long)
+{
+ ::size_t required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ T* value = (T*) alloca(required);
+ err = f(name, required, value, NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ param->assign(&value[0], &value[required/sizeof(T)]);
+ return CL_SUCCESS;
+}
+
+/* Specialization for reference-counted types. This depends on the
+ * existence of Wrapper<T>::cl_type, and none of the other types having the
+ * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
+ * does not work, because when using a derived type (e.g. Context) the generic
+ * template will provide a better match.
+ */
+template <typename Func, typename T>
+inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, int, typename T::cl_type = 0)
+{
+ ::size_t required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ typename T::cl_type * value = (typename T::cl_type *) alloca(required);
+ err = f(name, required, value, NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ ::size_t elements = required / sizeof(typename T::cl_type);
+ param->assign(&value[0], &value[elements]);
+ for (::size_t i = 0; i < elements; i++)
+ {
+ if (value[i] != NULL)
+ {
+ err = (*param)[i].retain();
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ }
+ }
+ return CL_SUCCESS;
+}
+
+// Specialized for getInfo<CL_PROGRAM_BINARIES>
+template <typename Func>
+inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<char *>* param, int)
+{
+ cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
+
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ return CL_SUCCESS;
+}
+
+// Specialized GetInfoHelper for STRING_CLASS params
+template <typename Func>
+inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long)
+{
+#if defined(__NO_STD_VECTOR) || defined(__NO_STD_STRING)
+ ::size_t required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ char* value = (char*)alloca(required);
+ err = f(name, required, value, NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ *param = value;
+ return CL_SUCCESS;
+#else
+ ::size_t required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ // std::string has a constant data member
+ // a char vector does not
+ VECTOR_CLASS<char> value(required);
+ err = f(name, required, value.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ if (param) {
+ param->assign(value.begin(), value.end());
+ }
+#endif
+ return CL_SUCCESS;
+}
+
+// Specialized GetInfoHelper for cl::size_t params
+template <typename Func, ::size_t N>
+inline cl_int getInfoHelper(Func f, cl_uint name, size_t<N>* param, long)
+{
+ ::size_t required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ ::size_t* value = (::size_t*) alloca(required);
+ err = f(name, required, value, NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ for(int i = 0; i < N; ++i) {
+ (*param)[i] = value[i];
+ }
+
+ return CL_SUCCESS;
+}
+
+template<typename T> struct ReferenceHandler;
+
+/* Specialization for reference-counted types. This depends on the
+ * existence of Wrapper<T>::cl_type, and none of the other types having the
+ * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
+ * does not work, because when using a derived type (e.g. Context) the generic
+ * template will provide a better match.
+ */
+template<typename Func, typename T>
+inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
+{
+ typename T::cl_type value;
+ cl_int err = f(name, sizeof(value), &value, NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ *param = value;
+ if (value != NULL)
+ {
+ err = param->retain();
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ }
+ return CL_SUCCESS;
+}
+
+#define __PARAM_NAME_INFO_1_0(F) \
+ F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
+ F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
+ F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
+ F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
+ F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
+ \
+ F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
+ F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
+ F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
+ F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
+ F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
+ F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
+ F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
+ F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
+ F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
+ F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
+ F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
+ F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
+ F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
+ F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
+ F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
+ F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
+ F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
+ F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
+ F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
+ F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
+ F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
+ F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
+ F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
+ F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
+ F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
+ F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
+ F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
+ F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
+ \
+ F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
+ F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
+ F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
+ \
+ F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
+ F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
+ F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
+ F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
+ \
+ F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
+ F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
+ F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
+ F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
+ \
+ F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
+ F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
+ F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
+ F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
+ F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
+ F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
+ F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
+ \
+ F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
+ F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
+ F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
+ F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
+ F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
+ F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
+ F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
+ \
+ F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
+ F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
+ F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
+ F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
+ F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
+ \
+ F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
+ F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
+ F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
+ F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<Device>) \
+ F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
+ F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
+ F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
+ \
+ F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
+ F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
+ F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
+ \
+ F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
+ F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
+ F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
+ F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
+ F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
+ \
+ F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
+ F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
+ F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
+ \
+ F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
+ F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
+ F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
+ F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
+
+#if defined(CL_VERSION_1_1)
+#define __PARAM_NAME_INFO_1_1(F) \
+ F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
+ F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
+ F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
+ F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
+ F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \
+ \
+ F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
+ F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
+ \
+ F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
+ F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
+ \
+ F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
+#endif // CL_VERSION_1_1
+
+
+#if defined(CL_VERSION_1_2)
+#define __PARAM_NAME_INFO_1_2(F) \
+ F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \
+ \
+ F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \
+ F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \
+ \
+ F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
+ \
+ F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \
+ \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
+ \
+ F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \
+ F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS<cl_device_partition_property>) \
+ F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS<cl_device_partition_property>) \
+ F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \
+ F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
+ F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS)
+#endif // #if defined(CL_VERSION_1_2)
+
+#if defined(USE_CL_DEVICE_FISSION)
+#define __PARAM_NAME_DEVICE_FISSION(F) \
+ F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
+ F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
+ F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
+ F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
+ F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
+#endif // USE_CL_DEVICE_FISSION
+
+template <typename enum_type, cl_int Name>
+struct param_traits {};
+
+#define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \
+struct token; \
+template<> \
+struct param_traits<detail:: token,param_name> \
+{ \
+ enum { value = param_name }; \
+ typedef T param_type; \
+};
+
+__PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS)
+#if defined(CL_VERSION_1_1)
+__PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS)
+#endif // CL_VERSION_1_1
+#if defined(CL_VERSION_1_2)
+__PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS)
+#endif // CL_VERSION_1_1
+
+#if defined(USE_CL_DEVICE_FISSION)
+__PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS);
+#endif // USE_CL_DEVICE_FISSION
+
+#ifdef CL_PLATFORM_ICD_SUFFIX_KHR
+__CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS)
+#endif
+
+#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
+#endif
+
+#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>)
+#endif
+#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_SIMD_WIDTH_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
+#endif
+
+#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
+#endif
+#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
+#endif
+#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
+#endif
+#ifdef CL_DEVICE_WARP_SIZE_NV
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
+#endif
+#ifdef CL_DEVICE_GPU_OVERLAP_NV
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
+#endif
+#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
+#endif
+#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
+__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
+#endif
+
+// Convenience functions
+
+template <typename Func, typename T>
+inline cl_int
+getInfo(Func f, cl_uint name, T* param)
+{
+ return getInfoHelper(f, name, param, 0);
+}
+
+template <typename Func, typename Arg0>
+struct GetInfoFunctor0
+{
+ Func f_; const Arg0& arg0_;
+ cl_int operator ()(
+ cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
+ { return f_(arg0_, param, size, value, size_ret); }
+};
+
+template <typename Func, typename Arg0, typename Arg1>
+struct GetInfoFunctor1
+{
+ Func f_; const Arg0& arg0_; const Arg1& arg1_;
+ cl_int operator ()(
+ cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
+ { return f_(arg0_, arg1_, param, size, value, size_ret); }
+};
+
+template <typename Func, typename Arg0, typename T>
+inline cl_int
+getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
+{
+ GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
+ return getInfoHelper(f0, name, param, 0);
+}
+
+template <typename Func, typename Arg0, typename Arg1, typename T>
+inline cl_int
+getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
+{
+ GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
+ return getInfoHelper(f0, name, param, 0);
+}
+
+template<typename T>
+struct ReferenceHandler
+{ };
+
+#if defined(CL_VERSION_1_2)
+/**
+ * OpenCL 1.2 devices do have retain/release.
+ */
+template <>
+struct ReferenceHandler<cl_device_id>
+{
+ /**
+ * Retain the device.
+ * \param device A valid device created using createSubDevices
+ * \return
+ * CL_SUCCESS if the function executed successfully.
+ * CL_INVALID_DEVICE if device was not a valid subdevice
+ * CL_OUT_OF_RESOURCES
+ * CL_OUT_OF_HOST_MEMORY
+ */
+ static cl_int retain(cl_device_id device)
+ { return ::clRetainDevice(device); }
+ /**
+ * Retain the device.
+ * \param device A valid device created using createSubDevices
+ * \return
+ * CL_SUCCESS if the function executed successfully.
+ * CL_INVALID_DEVICE if device was not a valid subdevice
+ * CL_OUT_OF_RESOURCES
+ * CL_OUT_OF_HOST_MEMORY
+ */
+ static cl_int release(cl_device_id device)
+ { return ::clReleaseDevice(device); }
+};
+#else // #if defined(CL_VERSION_1_2)
+/**
+ * OpenCL 1.1 devices do not have retain/release.
+ */
+template <>
+struct ReferenceHandler<cl_device_id>
+{
+ // cl_device_id does not have retain().
+ static cl_int retain(cl_device_id)
+ { return CL_SUCCESS; }
+ // cl_device_id does not have release().
+ static cl_int release(cl_device_id)
+ { return CL_SUCCESS; }
+};
+#endif // #if defined(CL_VERSION_1_2)
+
+template <>
+struct ReferenceHandler<cl_platform_id>
+{
+ // cl_platform_id does not have retain().
+ static cl_int retain(cl_platform_id)
+ { return CL_SUCCESS; }
+ // cl_platform_id does not have release().
+ static cl_int release(cl_platform_id)
+ { return CL_SUCCESS; }
+};
+
+template <>
+struct ReferenceHandler<cl_context>
+{
+ static cl_int retain(cl_context context)
+ { return ::clRetainContext(context); }
+ static cl_int release(cl_context context)
+ { return ::clReleaseContext(context); }
+};
+
+template <>
+struct ReferenceHandler<cl_command_queue>
+{
+ static cl_int retain(cl_command_queue queue)
+ { return ::clRetainCommandQueue(queue); }
+ static cl_int release(cl_command_queue queue)
+ { return ::clReleaseCommandQueue(queue); }
+};
+
+template <>
+struct ReferenceHandler<cl_mem>
+{
+ static cl_int retain(cl_mem memory)
+ { return ::clRetainMemObject(memory); }
+ static cl_int release(cl_mem memory)
+ { return ::clReleaseMemObject(memory); }
+};
+
+template <>
+struct ReferenceHandler<cl_sampler>
+{
+ static cl_int retain(cl_sampler sampler)
+ { return ::clRetainSampler(sampler); }
+ static cl_int release(cl_sampler sampler)
+ { return ::clReleaseSampler(sampler); }
+};
+
+template <>
+struct ReferenceHandler<cl_program>
+{
+ static cl_int retain(cl_program program)
+ { return ::clRetainProgram(program); }
+ static cl_int release(cl_program program)
+ { return ::clReleaseProgram(program); }
+};
+
+template <>
+struct ReferenceHandler<cl_kernel>
+{
+ static cl_int retain(cl_kernel kernel)
+ { return ::clRetainKernel(kernel); }
+ static cl_int release(cl_kernel kernel)
+ { return ::clReleaseKernel(kernel); }
+};
+
+template <>
+struct ReferenceHandler<cl_event>
+{
+ static cl_int retain(cl_event event)
+ { return ::clRetainEvent(event); }
+ static cl_int release(cl_event event)
+ { return ::clReleaseEvent(event); }
+};
+
+
+// Extracts version number with major in the upper 16 bits, minor in the lower 16
+static cl_uint getVersion(const char *versionInfo)
+{
+ int highVersion = 0;
+ int lowVersion = 0;
+ int index = 7;
+ while(versionInfo[index] != '.' ) {
+ highVersion *= 10;
+ highVersion += versionInfo[index]-'0';
+ ++index;
+ }
+ ++index;
+ while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
+ lowVersion *= 10;
+ lowVersion += versionInfo[index]-'0';
+ ++index;
+ }
+ return (highVersion << 16) | lowVersion;
+}
+
+static cl_uint getPlatformVersion(cl_platform_id platform)
+{
+ ::size_t size = 0;
+ clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
+ char *versionInfo = (char *) alloca(size);
+ clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size);
+ return getVersion(versionInfo);
+}
+
+static cl_uint getDevicePlatformVersion(cl_device_id device)
+{
+ cl_platform_id platform;
+ clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
+ return getPlatformVersion(platform);
+}
+
+#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+static cl_uint getContextPlatformVersion(cl_context context)
+{
+ // The platform cannot be queried directly, so we first have to grab a
+ // device and obtain its context
+ ::size_t size = 0;
+ clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
+ if (size == 0)
+ return 0;
+ cl_device_id *devices = (cl_device_id *) alloca(size);
+ clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL);
+ return getDevicePlatformVersion(devices[0]);
+}
+#endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+
+template <typename T>
+class Wrapper
+{
+public:
+ typedef T cl_type;
+
+protected:
+ cl_type object_;
+
+public:
+ Wrapper() : object_(NULL) { }
+
+ Wrapper(const cl_type &obj) : object_(obj) { }
+
+ ~Wrapper()
+ {
+ if (object_ != NULL) { release(); }
+ }
+
+ Wrapper(const Wrapper<cl_type>& rhs)
+ {
+ object_ = rhs.object_;
+ if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT
+ {
+ object_ = rhs.object_;
+ rhs.object_ = NULL;
+ }
+#endif
+
+ Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
+ {
+ if (this != &rhs) {
+ if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
+ object_ = rhs.object_;
+ if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
+ }
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
+ {
+ if (this != &rhs) {
+ if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
+ object_ = rhs.object_;
+ rhs.object_ = NULL;
+ }
+ return *this;
+ }
+#endif
+
+ Wrapper<cl_type>& operator = (const cl_type &rhs)
+ {
+ if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
+ object_ = rhs;
+ return *this;
+ }
+
+ cl_type operator ()() const { return object_; }
+
+ cl_type& operator ()() { return object_; }
+
+protected:
+ template<typename Func, typename U>
+ friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
+
+ cl_int retain() const
+ {
+ return ReferenceHandler<cl_type>::retain(object_);
+ }
+
+ cl_int release() const
+ {
+ return ReferenceHandler<cl_type>::release(object_);
+ }
+};
+
+template <>
+class Wrapper<cl_device_id>
+{
+public:
+ typedef cl_device_id cl_type;
+
+protected:
+ cl_type object_;
+ bool referenceCountable_;
+
+ static bool isReferenceCountable(cl_device_id device)
+ {
+ bool retVal = false;
+ if (device != NULL) {
+ int version = getDevicePlatformVersion(device);
+ if(version > ((1 << 16) + 1)) {
+ retVal = true;
+ }
+ }
+ return retVal;
+ }
+
+public:
+ Wrapper() : object_(NULL), referenceCountable_(false)
+ {
+ }
+
+ Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false)
+ {
+ referenceCountable_ = isReferenceCountable(obj);
+ }
+
+ ~Wrapper()
+ {
+ if (object_ != NULL) { release(); }
+ }
+
+ Wrapper(const Wrapper<cl_type>& rhs)
+ {
+ object_ = rhs.object_;
+ referenceCountable_ = isReferenceCountable(object_);
+ if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT
+ {
+ object_ = rhs.object_;
+ referenceCountable_ = rhs.referenceCountable_;
+ rhs.object_ = NULL;
+ rhs.referenceCountable_ = false;
+ }
+#endif
+
+ Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
+ {
+ if (this != &rhs) {
+ if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
+ object_ = rhs.object_;
+ referenceCountable_ = rhs.referenceCountable_;
+ if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
+ }
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
+ {
+ if (this != &rhs) {
+ if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
+ object_ = rhs.object_;
+ referenceCountable_ = rhs.referenceCountable_;
+ rhs.object_ = NULL;
+ rhs.referenceCountable_ = false;
+ }
+ return *this;
+ }
+#endif
+
+ Wrapper<cl_type>& operator = (const cl_type &rhs)
+ {
+ if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
+ object_ = rhs;
+ referenceCountable_ = isReferenceCountable(object_);
+ return *this;
+ }
+
+ cl_type operator ()() const { return object_; }
+
+ cl_type& operator ()() { return object_; }
+
+protected:
+ template<typename Func, typename U>
+ friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
+
+ template<typename Func, typename U>
+ friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS<U>*, int, typename U::cl_type);
+
+ cl_int retain() const
+ {
+ if( referenceCountable_ ) {
+ return ReferenceHandler<cl_type>::retain(object_);
+ }
+ else {
+ return CL_SUCCESS;
+ }
+ }
+
+ cl_int release() const
+ {
+ if( referenceCountable_ ) {
+ return ReferenceHandler<cl_type>::release(object_);
+ }
+ else {
+ return CL_SUCCESS;
+ }
+ }
+};
+
+} // namespace detail
+//! \endcond
+
+/*! \stuct ImageFormat
+ * \brief Adds constructors and member functions for cl_image_format.
+ *
+ * \see cl_image_format
+ */
+struct ImageFormat : public cl_image_format
+{
+ //! \brief Default constructor - performs no initialization.
+ ImageFormat(){}
+
+ //! \brief Initializing constructor.
+ ImageFormat(cl_channel_order order, cl_channel_type type)
+ {
+ image_channel_order = order;
+ image_channel_data_type = type;
+ }
+
+ //! \brief Assignment operator.
+ ImageFormat& operator = (const ImageFormat& rhs)
+ {
+ if (this != &rhs) {
+ this->image_channel_data_type = rhs.image_channel_data_type;
+ this->image_channel_order = rhs.image_channel_order;
+ }
+ return *this;
+ }
+};
+
+/*! \brief Class interface for cl_device_id.
+ *
+ * \note Copies of these objects are inexpensive, since they don't 'own'
+ * any underlying resources or data structures.
+ *
+ * \see cl_device_id
+ */
+class Device : public detail::Wrapper<cl_device_id>
+{
+public:
+ //! \brief Default constructor - initializes to NULL.
+ Device() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_device_id.
+ *
+ * This simply copies the device ID value, which is an inexpensive operation.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Device(const cl_device_id &device) : detail::Wrapper<cl_type>(device) { }
+
+ /*! \brief Returns the first device on the default context.
+ *
+ * \see Context::getDefault()
+ */
+ static Device getDefault(cl_int * err = NULL);
+
+ /*! \brief Assignment operator from cl_device_id.
+ *
+ * This simply copies the device ID value, which is an inexpensive operation.
+ */
+ Device& operator = (const cl_device_id& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Device& operator = (const Device &dev)
+ {
+ detail::Wrapper<cl_type>::operator=(dev);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Device(Device&& dev) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(dev)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Device& operator = (Device &&dev)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(dev));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ //! \brief Wrapper for clGetDeviceInfo().
+ template <typename T>
+ cl_int getInfo(cl_device_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetDeviceInfo, object_, name, param),
+ __GET_DEVICE_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetDeviceInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_device_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_device_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /**
+ * CL 1.2 version
+ */
+#if defined(CL_VERSION_1_2)
+ //! \brief Wrapper for clCreateSubDevicesEXT().
+ cl_int createSubDevices(
+ const cl_device_partition_property * properties,
+ VECTOR_CLASS<Device>* devices)
+ {
+ cl_uint n = 0;
+ cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_SUB_DEVICES);
+ }
+
+ cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
+ err = clCreateSubDevices(object_, properties, n, ids, NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_SUB_DEVICES);
+ }
+
+ devices->assign(&ids[0], &ids[n]);
+ return CL_SUCCESS;
+ }
+#endif // #if defined(CL_VERSION_1_2)
+
+/**
+ * CL 1.1 version that uses device fission.
+ */
+#if defined(CL_VERSION_1_1)
+#if defined(USE_CL_DEVICE_FISSION)
+ cl_int createSubDevices(
+ const cl_device_partition_property_ext * properties,
+ VECTOR_CLASS<Device>* devices)
+ {
+ typedef CL_API_ENTRY cl_int
+ ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
+ cl_device_id /*in_device*/,
+ const cl_device_partition_property_ext * /* properties */,
+ cl_uint /*num_entries*/,
+ cl_device_id * /*out_devices*/,
+ cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
+
+ static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
+ __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
+
+ cl_uint n = 0;
+ cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_SUB_DEVICES);
+ }
+
+ cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
+ err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_SUB_DEVICES);
+ }
+
+ devices->assign(&ids[0], &ids[n]);
+ return CL_SUCCESS;
+ }
+#endif // #if defined(USE_CL_DEVICE_FISSION)
+#endif // #if defined(CL_VERSION_1_1)
+};
+
+/*! \brief Class interface for cl_platform_id.
+ *
+ * \note Copies of these objects are inexpensive, since they don't 'own'
+ * any underlying resources or data structures.
+ *
+ * \see cl_platform_id
+ */
+class Platform : public detail::Wrapper<cl_platform_id>
+{
+public:
+ //! \brief Default constructor - initializes to NULL.
+ Platform() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_platform_id.
+ *
+ * This simply copies the platform ID value, which is an inexpensive operation.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Platform(const cl_platform_id &platform) : detail::Wrapper<cl_type>(platform) { }
+
+ /*! \brief Assignment operator from cl_platform_id.
+ *
+ * This simply copies the platform ID value, which is an inexpensive operation.
+ */
+ Platform& operator = (const cl_platform_id& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetPlatformInfo().
+ cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetPlatformInfo, object_, name, param),
+ __GET_PLATFORM_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetPlatformInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_platform_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_platform_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /*! \brief Gets a list of devices for this platform.
+ *
+ * Wraps clGetDeviceIDs().
+ */
+ cl_int getDevices(
+ cl_device_type type,
+ VECTOR_CLASS<Device>* devices) const
+ {
+ cl_uint n = 0;
+ if( devices == NULL ) {
+ return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
+ }
+ cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
+ }
+
+ cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
+ err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
+ }
+
+ devices->assign(&ids[0], &ids[n]);
+ return CL_SUCCESS;
+ }
+
+#if defined(USE_DX_INTEROP)
+ /*! \brief Get the list of available D3D10 devices.
+ *
+ * \param d3d_device_source.
+ *
+ * \param d3d_object.
+ *
+ * \param d3d_device_set.
+ *
+ * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
+ * values returned in devices can be used to identify a specific OpenCL
+ * device. If \a devices argument is NULL, this argument is ignored.
+ *
+ * \return One of the following values:
+ * - CL_SUCCESS if the function is executed successfully.
+ *
+ * The application can query specific capabilities of the OpenCL device(s)
+ * returned by cl::getDevices. This can be used by the application to
+ * determine which device(s) to use.
+ *
+ * \note In the case that exceptions are enabled and a return value
+ * other than CL_SUCCESS is generated, then cl::Error exception is
+ * generated.
+ */
+ cl_int getDevices(
+ cl_d3d10_device_source_khr d3d_device_source,
+ void * d3d_object,
+ cl_d3d10_device_set_khr d3d_device_set,
+ VECTOR_CLASS<Device>* devices) const
+ {
+ typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
+ cl_platform_id platform,
+ cl_d3d10_device_source_khr d3d_device_source,
+ void * d3d_object,
+ cl_d3d10_device_set_khr d3d_device_set,
+ cl_uint num_entries,
+ cl_device_id * devices,
+ cl_uint* num_devices);
+
+ if( devices == NULL ) {
+ return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
+ }
+
+ static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
+ __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR);
+
+ cl_uint n = 0;
+ cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
+ object_,
+ d3d_device_source,
+ d3d_object,
+ d3d_device_set,
+ 0,
+ NULL,
+ &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
+ }
+
+ cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
+ err = pfn_clGetDeviceIDsFromD3D10KHR(
+ object_,
+ d3d_device_source,
+ d3d_object,
+ d3d_device_set,
+ n,
+ ids,
+ NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
+ }
+
+ devices->assign(&ids[0], &ids[n]);
+ return CL_SUCCESS;
+ }
+#endif
+
+ /*! \brief Gets a list of available platforms.
+ *
+ * Wraps clGetPlatformIDs().
+ */
+ static cl_int get(
+ VECTOR_CLASS<Platform>* platforms)
+ {
+ cl_uint n = 0;
+
+ if( platforms == NULL ) {
+ return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
+ }
+
+ cl_int err = ::clGetPlatformIDs(0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
+ }
+
+ cl_platform_id* ids = (cl_platform_id*) alloca(
+ n * sizeof(cl_platform_id));
+ err = ::clGetPlatformIDs(n, ids, NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
+ }
+
+ platforms->assign(&ids[0], &ids[n]);
+ return CL_SUCCESS;
+ }
+
+ /*! \brief Gets the first available platform.
+ *
+ * Wraps clGetPlatformIDs(), returning the first result.
+ */
+ static cl_int get(
+ Platform * platform)
+ {
+ cl_uint n = 0;
+
+ if( platform == NULL ) {
+ return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
+ }
+
+ cl_int err = ::clGetPlatformIDs(0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
+ }
+
+ cl_platform_id* ids = (cl_platform_id*) alloca(
+ n * sizeof(cl_platform_id));
+ err = ::clGetPlatformIDs(n, ids, NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
+ }
+
+ *platform = ids[0];
+ return CL_SUCCESS;
+ }
+
+ /*! \brief Gets the first available platform, returning it by value.
+ *
+ * Wraps clGetPlatformIDs(), returning the first result.
+ */
+ static Platform get(
+ cl_int * errResult = NULL)
+ {
+ Platform platform;
+ cl_uint n = 0;
+ cl_int err = ::clGetPlatformIDs(0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
+ if (errResult != NULL) {
+ *errResult = err;
+ }
+ return Platform();
+ }
+
+ cl_platform_id* ids = (cl_platform_id*) alloca(
+ n * sizeof(cl_platform_id));
+ err = ::clGetPlatformIDs(n, ids, NULL);
+
+ if (err != CL_SUCCESS) {
+ detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
+ if (errResult != NULL) {
+ *errResult = err;
+ }
+ return Platform();
+ }
+
+
+ return Platform(ids[0]);
+ }
+
+ static Platform getDefault(
+ cl_int *errResult = NULL )
+ {
+ return get(errResult);
+ }
+
+
+#if defined(CL_VERSION_1_2)
+ //! \brief Wrapper for clUnloadCompiler().
+ cl_int
+ unloadCompiler()
+ {
+ return ::clUnloadPlatformCompiler(object_);
+ }
+#endif // #if defined(CL_VERSION_1_2)
+}; // class Platform
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
+/**
+ * Unload the OpenCL compiler.
+ * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead.
+ */
+inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
+UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+inline cl_int
+UnloadCompiler()
+{
+ return ::clUnloadCompiler();
+}
+#endif // #if defined(CL_VERSION_1_1)
+
+/*! \brief Class interface for cl_context.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_context as the original. For details, see
+ * clRetainContext() and clReleaseContext().
+ *
+ * \see cl_context
+ */
+class Context
+ : public detail::Wrapper<cl_context>
+{
+private:
+
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+ static std::atomic<int> default_initialized_;
+#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ static volatile int default_initialized_;
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ static Context default_;
+ static volatile cl_int default_error_;
+public:
+ /*! \brief Constructs a context including a list of specified devices.
+ *
+ * Wraps clCreateContext().
+ */
+ Context(
+ const VECTOR_CLASS<Device>& devices,
+ cl_context_properties* properties = NULL,
+ void (CL_CALLBACK * notifyFptr)(
+ const char *,
+ const void *,
+ ::size_t,
+ void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ ::size_t numDevices = devices.size();
+ cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
+ for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
+ deviceIDs[deviceIndex] = (devices[deviceIndex])();
+ }
+
+ object_ = ::clCreateContext(
+ properties, (cl_uint) numDevices,
+ deviceIDs,
+ notifyFptr, data, &error);
+
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Context(
+ const Device& device,
+ cl_context_properties* properties = NULL,
+ void (CL_CALLBACK * notifyFptr)(
+ const char *,
+ const void *,
+ ::size_t,
+ void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ cl_device_id deviceID = device();
+
+ object_ = ::clCreateContext(
+ properties, 1,
+ &deviceID,
+ notifyFptr, data, &error);
+
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Constructs a context including all or a subset of devices of a specified type.
+ *
+ * Wraps clCreateContextFromType().
+ */
+ Context(
+ cl_device_type type,
+ cl_context_properties* properties = NULL,
+ void (CL_CALLBACK * notifyFptr)(
+ const char *,
+ const void *,
+ ::size_t,
+ void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+#if !defined(__APPLE__) && !defined(__MACOS)
+ cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
+
+ if (properties == NULL) {
+ // Get a valid platform ID as we cannot send in a blank one
+ VECTOR_CLASS<Platform> platforms;
+ error = Platform::get(&platforms);
+ if (error != CL_SUCCESS) {
+ detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ return;
+ }
+
+ // Check the platforms we found for a device of our specified type
+ cl_context_properties platform_id = 0;
+ for (unsigned int i = 0; i < platforms.size(); i++) {
+
+ VECTOR_CLASS<Device> devices;
+
+#if defined(__CL_ENABLE_EXCEPTIONS)
+ try {
+#endif
+
+ error = platforms[i].getDevices(type, &devices);
+
+#if defined(__CL_ENABLE_EXCEPTIONS)
+ } catch (Error) {}
+ // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
+ // We do error checking next anyway, and can throw there if needed
+#endif
+
+ // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
+ if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
+ detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ if (devices.size() > 0) {
+ platform_id = (cl_context_properties)platforms[i]();
+ break;
+ }
+ }
+
+ if (platform_id == 0) {
+ detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
+ if (err != NULL) {
+ *err = CL_DEVICE_NOT_FOUND;
+ }
+ return;
+ }
+
+ prop[1] = platform_id;
+ properties = &prop[0];
+ }
+#endif
+ object_ = ::clCreateContextFromType(
+ properties, type, notifyFptr, data, &error);
+
+ detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Context& operator = (const Context &ctx)
+ {
+ detail::Wrapper<cl_type>::operator=(ctx);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Context(Context&& ctx) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(ctx)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Context& operator = (Context &&ctx)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(ctx));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
+ *
+ * \note All calls to this function return the same cl_context as the first.
+ */
+ static Context getDefault(cl_int * err = NULL)
+ {
+ int state = detail::compare_exchange(
+ &default_initialized_,
+ __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED);
+
+ if (state & __DEFAULT_INITIALIZED) {
+ if (err != NULL) {
+ *err = default_error_;
+ }
+ return default_;
+ }
+
+ if (state & __DEFAULT_BEING_INITIALIZED) {
+ // Assume writes will propagate eventually...
+ while(default_initialized_ != __DEFAULT_INITIALIZED) {
+ detail::fence();
+ }
+
+ if (err != NULL) {
+ *err = default_error_;
+ }
+ return default_;
+ }
+
+ cl_int error;
+ default_ = Context(
+ CL_DEVICE_TYPE_DEFAULT,
+ NULL,
+ NULL,
+ NULL,
+ &error);
+
+ detail::fence();
+
+ default_error_ = error;
+ // Assume writes will propagate eventually...
+ default_initialized_ = __DEFAULT_INITIALIZED;
+
+ detail::fence();
+
+ if (err != NULL) {
+ *err = default_error_;
+ }
+ return default_;
+
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Context() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_context - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the cl_context
+ * into the new Context object.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper<cl_type>(context) { }
+
+ /*! \brief Assignment operator from cl_context - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseContext() on the value previously held by this instance.
+ */
+ Context& operator = (const cl_context& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetContextInfo().
+ template <typename T>
+ cl_int getInfo(cl_context_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetContextInfo, object_, name, param),
+ __GET_CONTEXT_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetContextInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_context_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_context_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /*! \brief Gets a list of supported image formats.
+ *
+ * Wraps clGetSupportedImageFormats().
+ */
+ cl_int getSupportedImageFormats(
+ cl_mem_flags flags,
+ cl_mem_object_type type,
+ VECTOR_CLASS<ImageFormat>* formats) const
+ {
+ cl_uint numEntries;
+
+ if (!formats) {
+ return CL_SUCCESS;
+ }
+
+ cl_int err = ::clGetSupportedImageFormats(
+ object_,
+ flags,
+ type,
+ 0,
+ NULL,
+ &numEntries);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
+ }
+
+ if (numEntries > 0) {
+ ImageFormat* value = (ImageFormat*)
+ alloca(numEntries * sizeof(ImageFormat));
+ err = ::clGetSupportedImageFormats(
+ object_,
+ flags,
+ type,
+ numEntries,
+ (cl_image_format*)value,
+ NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
+ }
+
+ formats->assign(&value[0], &value[numEntries]);
+ }
+ else {
+ formats->clear();
+ }
+ return CL_SUCCESS;
+ }
+};
+
+inline Device Device::getDefault(cl_int * err)
+{
+ cl_int error;
+ Device device;
+
+ Context context = Context::getDefault(&error);
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+
+ if (error != CL_SUCCESS) {
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+ else {
+ device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
+ if (err != NULL) {
+ *err = CL_SUCCESS;
+ }
+ }
+
+ return device;
+}
+
+
+#ifdef _WIN32
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+__declspec(selectany) std::atomic<int> Context::default_initialized_;
+#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+__declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+__declspec(selectany) Context Context::default_;
+__declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS;
+#else // !_WIN32
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+__attribute__((weak)) std::atomic<int> Context::default_initialized_;
+#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+__attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+__attribute__((weak)) Context Context::default_;
+__attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS;
+#endif // !_WIN32
+
+/*! \brief Class interface for cl_event.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_event as the original. For details, see
+ * clRetainEvent() and clReleaseEvent().
+ *
+ * \see cl_event
+ */
+class Event : public detail::Wrapper<cl_event>
+{
+public:
+ //! \brief Default constructor - initializes to NULL.
+ Event() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_event - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the cl_event
+ * into the new Event object.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Event(const cl_event& event) : detail::Wrapper<cl_type>(event) { }
+
+ /*! \brief Assignment operator from cl_event - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseEvent() on the value previously held by this instance.
+ */
+ Event& operator = (const cl_event& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetEventInfo().
+ template <typename T>
+ cl_int getInfo(cl_event_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetEventInfo, object_, name, param),
+ __GET_EVENT_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetEventInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_event_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_event_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ //! \brief Wrapper for clGetEventProfilingInfo().
+ template <typename T>
+ cl_int getProfilingInfo(cl_profiling_info name, T* param) const
+ {
+ return detail::errHandler(detail::getInfo(
+ &::clGetEventProfilingInfo, object_, name, param),
+ __GET_EVENT_PROFILE_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetEventProfilingInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_profiling_info, name>::param_type
+ getProfilingInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_profiling_info, name>::param_type param;
+ cl_int result = getProfilingInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /*! \brief Blocks the calling thread until this event completes.
+ *
+ * Wraps clWaitForEvents().
+ */
+ cl_int wait() const
+ {
+ return detail::errHandler(
+ ::clWaitForEvents(1, &object_),
+ __WAIT_FOR_EVENTS_ERR);
+ }
+
+#if defined(CL_VERSION_1_1)
+ /*! \brief Registers a user callback function for a specific command execution status.
+ *
+ * Wraps clSetEventCallback().
+ */
+ cl_int setCallback(
+ cl_int type,
+ void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
+ void * user_data = NULL)
+ {
+ return detail::errHandler(
+ ::clSetEventCallback(
+ object_,
+ type,
+ pfn_notify,
+ user_data),
+ __SET_EVENT_CALLBACK_ERR);
+ }
+#endif
+
+ /*! \brief Blocks the calling thread until every event specified is complete.
+ *
+ * Wraps clWaitForEvents().
+ */
+ static cl_int
+ waitForEvents(const VECTOR_CLASS<Event>& events)
+ {
+ return detail::errHandler(
+ ::clWaitForEvents(
+ (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
+ __WAIT_FOR_EVENTS_ERR);
+ }
+};
+
+#if defined(CL_VERSION_1_1)
+/*! \brief Class interface for user events (a subset of cl_event's).
+ *
+ * See Event for details about copy semantics, etc.
+ */
+class UserEvent : public Event
+{
+public:
+ /*! \brief Constructs a user event on a given context.
+ *
+ * Wraps clCreateUserEvent().
+ */
+ UserEvent(
+ const Context& context,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateUserEvent(
+ context(),
+ &error);
+
+ detail::errHandler(error, __CREATE_USER_EVENT_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ UserEvent() : Event() { }
+
+ /*! \brief Sets the execution status of a user event object.
+ *
+ * Wraps clSetUserEventStatus().
+ */
+ cl_int setStatus(cl_int status)
+ {
+ return detail::errHandler(
+ ::clSetUserEventStatus(object_,status),
+ __SET_USER_EVENT_STATUS_ERR);
+ }
+};
+#endif
+
+/*! \brief Blocks the calling thread until every event specified is complete.
+ *
+ * Wraps clWaitForEvents().
+ */
+inline static cl_int
+WaitForEvents(const VECTOR_CLASS<Event>& events)
+{
+ return detail::errHandler(
+ ::clWaitForEvents(
+ (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
+ __WAIT_FOR_EVENTS_ERR);
+}
+
+/*! \brief Class interface for cl_mem.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_mem as the original. For details, see
+ * clRetainMemObject() and clReleaseMemObject().
+ *
+ * \see cl_mem
+ */
+class Memory : public detail::Wrapper<cl_mem>
+{
+public:
+ //! \brief Default constructor - initializes to NULL.
+ Memory() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the cl_mem
+ * into the new Memory object.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper<cl_type>(memory) { }
+
+ /*! \brief Assignment operator from cl_mem - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseMemObject() on the value previously held by this instance.
+ */
+ Memory& operator = (const cl_mem& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Memory& operator = (const Memory &mem)
+ {
+ detail::Wrapper<cl_type>::operator=(mem);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Memory(Memory&& mem) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(mem)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Memory& operator = (Memory &&mem)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(mem));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ //! \brief Wrapper for clGetMemObjectInfo().
+ template <typename T>
+ cl_int getInfo(cl_mem_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
+ __GET_MEM_OBJECT_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_mem_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_mem_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+#if defined(CL_VERSION_1_1)
+ /*! \brief Registers a callback function to be called when the memory object
+ * is no longer needed.
+ *
+ * Wraps clSetMemObjectDestructorCallback().
+ *
+ * Repeated calls to this function, for a given cl_mem value, will append
+ * to the list of functions called (in reverse order) when memory object's
+ * resources are freed and the memory object is deleted.
+ *
+ * \note
+ * The registered callbacks are associated with the underlying cl_mem
+ * value - not the Memory class instance.
+ */
+ cl_int setDestructorCallback(
+ void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
+ void * user_data = NULL)
+ {
+ return detail::errHandler(
+ ::clSetMemObjectDestructorCallback(
+ object_,
+ pfn_notify,
+ user_data),
+ __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
+ }
+#endif
+
+};
+
+// Pre-declare copy functions
+class Buffer;
+template< typename IteratorType >
+cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
+template< typename IteratorType >
+cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
+template< typename IteratorType >
+cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
+template< typename IteratorType >
+cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
+
+
+/*! \brief Class interface for Buffer Memory Objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Buffer : public Memory
+{
+public:
+
+ /*! \brief Constructs a Buffer in a specified context.
+ *
+ * Wraps clCreateBuffer().
+ *
+ * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
+ * specified. Note alignment & exclusivity requirements.
+ */
+ Buffer(
+ const Context& context,
+ cl_mem_flags flags,
+ ::size_t size,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Constructs a Buffer in the default context.
+ *
+ * Wraps clCreateBuffer().
+ *
+ * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
+ * specified. Note alignment & exclusivity requirements.
+ *
+ * \see Context::getDefault()
+ */
+ Buffer(
+ cl_mem_flags flags,
+ ::size_t size,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ Context context = Context::getDefault(err);
+
+ object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*!
+ * \brief Construct a Buffer from a host container via iterators.
+ * IteratorType must be random access.
+ * If useHostPtr is specified iterators must represent contiguous data.
+ */
+ template< typename IteratorType >
+ Buffer(
+ IteratorType startIterator,
+ IteratorType endIterator,
+ bool readOnly,
+ bool useHostPtr = false,
+ cl_int* err = NULL)
+ {
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ cl_mem_flags flags = 0;
+ if( readOnly ) {
+ flags |= CL_MEM_READ_ONLY;
+ }
+ else {
+ flags |= CL_MEM_READ_WRITE;
+ }
+ if( useHostPtr ) {
+ flags |= CL_MEM_USE_HOST_PTR;
+ }
+
+ ::size_t size = sizeof(DataType)*(endIterator - startIterator);
+
+ Context context = Context::getDefault(err);
+
+ if( useHostPtr ) {
+ object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
+ } else {
+ object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
+ }
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ if( !useHostPtr ) {
+ error = cl::copy(startIterator, endIterator, *this);
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+ }
+
+ /*!
+ * \brief Construct a Buffer from a host container via iterators using a specified context.
+ * IteratorType must be random access.
+ * If useHostPtr is specified iterators must represent contiguous data.
+ */
+ template< typename IteratorType >
+ Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
+ bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
+
+ /*!
+ * \brief Construct a Buffer from a host container via iterators using a specified queue.
+ * If useHostPtr is specified iterators must represent contiguous data.
+ */
+ template< typename IteratorType >
+ Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
+ bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
+
+ //! \brief Default constructor - initializes to NULL.
+ Buffer() : Memory() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Buffer& operator = (const cl_mem& rhs)
+ {
+ Memory::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Buffer(const Buffer& buf) : Memory(buf) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Buffer& operator = (const Buffer &buf)
+ {
+ Memory::operator=(buf);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Buffer(Buffer&& buf) CL_HPP_NOEXCEPT : Memory(std::move(buf)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Buffer& operator = (Buffer &&buf)
+ {
+ Memory::operator=(std::move(buf));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+#if defined(CL_VERSION_1_1)
+ /*! \brief Creates a new buffer object from this.
+ *
+ * Wraps clCreateSubBuffer().
+ */
+ Buffer createSubBuffer(
+ cl_mem_flags flags,
+ cl_buffer_create_type buffer_create_type,
+ const void * buffer_create_info,
+ cl_int * err = NULL)
+ {
+ Buffer result;
+ cl_int error;
+ result.object_ = ::clCreateSubBuffer(
+ object_,
+ flags,
+ buffer_create_type,
+ buffer_create_info,
+ &error);
+
+ detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ return result;
+ }
+#endif
+};
+
+#if defined (USE_DX_INTEROP)
+/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's.
+ *
+ * This is provided to facilitate interoperability with Direct3D.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class BufferD3D10 : public Buffer
+{
+public:
+ typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
+ cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
+ cl_int* errcode_ret);
+
+ /*! \brief Constructs a BufferD3D10, in a specified context, from a
+ * given ID3D10Buffer.
+ *
+ * Wraps clCreateFromD3D10BufferKHR().
+ */
+ BufferD3D10(
+ const Context& context,
+ cl_mem_flags flags,
+ ID3D10Buffer* bufobj,
+ cl_int * err = NULL)
+ {
+ static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
+
+#if defined(CL_VERSION_1_2)
+ vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
+ cl_platform platform = -1;
+ for( int i = 0; i < props.size(); ++i ) {
+ if( props[i] == CL_CONTEXT_PLATFORM ) {
+ platform = props[i+1];
+ }
+ }
+ __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR);
+#endif
+#if defined(CL_VERSION_1_1)
+ __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
+#endif
+
+ cl_int error;
+ object_ = pfn_clCreateFromD3D10BufferKHR(
+ context(),
+ flags,
+ bufobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ BufferD3D10() : Buffer() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ BufferD3D10& operator = (const cl_mem& rhs)
+ {
+ Buffer::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferD3D10(const BufferD3D10& buf) : Buffer(buf) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferD3D10& operator = (const BufferD3D10 &buf)
+ {
+ Buffer::operator=(buf);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferD3D10& operator = (BufferD3D10 &&buf)
+ {
+ Buffer::operator=(std::move(buf));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+#endif
+
+/*! \brief Class interface for GL Buffer Memory Objects.
+ *
+ * This is provided to facilitate interoperability with OpenGL.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class BufferGL : public Buffer
+{
+public:
+ /*! \brief Constructs a BufferGL in a specified context, from a given
+ * GL buffer.
+ *
+ * Wraps clCreateFromGLBuffer().
+ */
+ BufferGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLuint bufobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLBuffer(
+ context(),
+ flags,
+ bufobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ BufferGL() : Buffer() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ BufferGL& operator = (const cl_mem& rhs)
+ {
+ Buffer::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferGL(const BufferGL& buf) : Buffer(buf) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferGL& operator = (const BufferGL &buf)
+ {
+ Buffer::operator=(buf);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferGL& operator = (BufferGL &&buf)
+ {
+ Buffer::operator=(std::move(buf));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ //! \brief Wrapper for clGetGLObjectInfo().
+ cl_int getObjectInfo(
+ cl_gl_object_type *type,
+ cl_GLuint * gl_object_name)
+ {
+ return detail::errHandler(
+ ::clGetGLObjectInfo(object_,type,gl_object_name),
+ __GET_GL_OBJECT_INFO_ERR);
+ }
+};
+
+/*! \brief C++ base class for Image Memory objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image : public Memory
+{
+protected:
+ //! \brief Default constructor - initializes to NULL.
+ Image() : Memory() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image& operator = (const cl_mem& rhs)
+ {
+ Memory::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image(const Image& img) : Memory(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image& operator = (const Image &img)
+ {
+ Memory::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image(Image&& img) CL_HPP_NOEXCEPT : Memory(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image& operator = (Image &&img)
+ {
+ Memory::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+public:
+ //! \brief Wrapper for clGetImageInfo().
+ template <typename T>
+ cl_int getImageInfo(cl_image_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetImageInfo, object_, name, param),
+ __GET_IMAGE_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetImageInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_image_info, name>::param_type
+ getImageInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_image_info, name>::param_type param;
+ cl_int result = getImageInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+};
+
+#if defined(CL_VERSION_1_2)
+/*! \brief Class interface for 1D Image Memory objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image1D : public Image
+{
+public:
+ /*! \brief Constructs a 1D Image in a specified context.
+ *
+ * Wraps clCreateImage().
+ */
+ Image1D(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ ::size_t width,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE1D,
+ width,
+ 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image1D() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image1D& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1D(const Image1D& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1D& operator = (const Image1D &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1D(Image1D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1D& operator = (Image1D &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+
+/*! \class Image1DBuffer
+ * \brief Image interface for 1D buffer images.
+ */
+class Image1DBuffer : public Image
+{
+public:
+ Image1DBuffer(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ ::size_t width,
+ const Buffer &buffer,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE1D_BUFFER,
+ width,
+ 0, 0, 0, 0, 0, 0, 0,
+ buffer()
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ NULL,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Image1DBuffer() { }
+
+ __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { }
+
+ Image1DBuffer& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DBuffer& operator = (const Image1DBuffer &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DBuffer& operator = (Image1DBuffer &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+
+/*! \class Image1DArray
+ * \brief Image interface for arrays of 1D images.
+ */
+class Image1DArray : public Image
+{
+public:
+ Image1DArray(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ ::size_t arraySize,
+ ::size_t width,
+ ::size_t rowPitch,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE1D_ARRAY,
+ width,
+ 0, 0, // height, depth (unused)
+ arraySize,
+ rowPitch,
+ 0, 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Image1DArray() { }
+
+ __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { }
+
+ Image1DArray& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DArray(const Image1DArray& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DArray& operator = (const Image1DArray &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DArray& operator = (Image1DArray &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+#endif // #if defined(CL_VERSION_1_2)
+
+
+/*! \brief Class interface for 2D Image Memory objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image2D : public Image
+{
+public:
+ /*! \brief Constructs a 1D Image in a specified context.
+ *
+ * Wraps clCreateImage().
+ */
+ Image2D(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ ::size_t width,
+ ::size_t height,
+ ::size_t row_pitch = 0,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ bool useCreateImage;
+
+#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+ // Run-time decision based on the actual platform
+ {
+ cl_uint version = detail::getContextPlatformVersion(context());
+ useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
+ }
+#elif defined(CL_VERSION_1_2)
+ useCreateImage = true;
+#else
+ useCreateImage = false;
+#endif
+
+#if defined(CL_VERSION_1_2)
+ if (useCreateImage)
+ {
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE2D,
+ width,
+ height,
+ 0, 0, // depth, array size (unused)
+ row_pitch,
+ 0, 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // #if defined(CL_VERSION_1_2)
+#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+ if (!useCreateImage)
+ {
+ object_ = ::clCreateImage2D(
+ context(), flags,&format, width, height, row_pitch, host_ptr, &error);
+
+ detail::errHandler(error, __CREATE_IMAGE2D_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image2D() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image2D& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2D(const Image2D& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2D& operator = (const Image2D &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2D(Image2D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2D& operator = (Image2D &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+
+
+#if !defined(CL_VERSION_1_2)
+/*! \brief Class interface for GL 2D Image Memory objects.
+ *
+ * This is provided to facilitate interoperability with OpenGL.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ * \note Deprecated for OpenCL 1.2. Please use ImageGL instead.
+ */
+class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D
+{
+public:
+ /*! \brief Constructs an Image2DGL in a specified context, from a given
+ * GL Texture.
+ *
+ * Wraps clCreateFromGLTexture2D().
+ */
+ Image2DGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLenum target,
+ cl_GLint miplevel,
+ cl_GLuint texobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLTexture2D(
+ context(),
+ flags,
+ target,
+ miplevel,
+ texobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image2DGL() : Image2D() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image2DGL& operator = (const cl_mem& rhs)
+ {
+ Image2D::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DGL(const Image2DGL& img) : Image2D(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DGL& operator = (const Image2DGL &img)
+ {
+ Image2D::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT : Image2D(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DGL& operator = (Image2DGL &&img)
+ {
+ Image2D::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+#endif // #if !defined(CL_VERSION_1_2)
+
+#if defined(CL_VERSION_1_2)
+/*! \class Image2DArray
+ * \brief Image interface for arrays of 2D images.
+ */
+class Image2DArray : public Image
+{
+public:
+ Image2DArray(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ ::size_t arraySize,
+ ::size_t width,
+ ::size_t height,
+ ::size_t rowPitch,
+ ::size_t slicePitch,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE2D_ARRAY,
+ width,
+ height,
+ 0, // depth (unused)
+ arraySize,
+ rowPitch,
+ slicePitch,
+ 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Image2DArray() { }
+
+ __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { }
+
+ Image2DArray& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DArray(const Image2DArray& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DArray& operator = (const Image2DArray &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DArray& operator = (Image2DArray &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+#endif // #if defined(CL_VERSION_1_2)
+
+/*! \brief Class interface for 3D Image Memory objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image3D : public Image
+{
+public:
+ /*! \brief Constructs a 3D Image in a specified context.
+ *
+ * Wraps clCreateImage().
+ */
+ Image3D(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ ::size_t width,
+ ::size_t height,
+ ::size_t depth,
+ ::size_t row_pitch = 0,
+ ::size_t slice_pitch = 0,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ bool useCreateImage;
+
+#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+ // Run-time decision based on the actual platform
+ {
+ cl_uint version = detail::getContextPlatformVersion(context());
+ useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
+ }
+#elif defined(CL_VERSION_1_2)
+ useCreateImage = true;
+#else
+ useCreateImage = false;
+#endif
+
+#if defined(CL_VERSION_1_2)
+ if (useCreateImage)
+ {
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE3D,
+ width,
+ height,
+ depth,
+ 0, // array size (unused)
+ row_pitch,
+ slice_pitch,
+ 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // #if defined(CL_VERSION_1_2)
+#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+ if (!useCreateImage)
+ {
+ object_ = ::clCreateImage3D(
+ context(), flags, &format, width, height, depth, row_pitch,
+ slice_pitch, host_ptr, &error);
+
+ detail::errHandler(error, __CREATE_IMAGE3D_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image3D() : Image() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image3D& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3D(const Image3D& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3D& operator = (const Image3D &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3D(Image3D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3D& operator = (Image3D &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+
+#if !defined(CL_VERSION_1_2)
+/*! \brief Class interface for GL 3D Image Memory objects.
+ *
+ * This is provided to facilitate interoperability with OpenGL.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image3DGL : public Image3D
+{
+public:
+ /*! \brief Constructs an Image3DGL in a specified context, from a given
+ * GL Texture.
+ *
+ * Wraps clCreateFromGLTexture3D().
+ */
+ Image3DGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLenum target,
+ cl_GLint miplevel,
+ cl_GLuint texobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLTexture3D(
+ context(),
+ flags,
+ target,
+ miplevel,
+ texobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image3DGL() : Image3D() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image3DGL& operator = (const cl_mem& rhs)
+ {
+ Image3D::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3DGL(const Image3DGL& img) : Image3D(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3DGL& operator = (const Image3DGL &img)
+ {
+ Image3D::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT : Image3D(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3DGL& operator = (Image3DGL &&img)
+ {
+ Image3D::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+#endif // #if !defined(CL_VERSION_1_2)
+
+#if defined(CL_VERSION_1_2)
+/*! \class ImageGL
+ * \brief general image interface for GL interop.
+ * We abstract the 2D and 3D GL images into a single instance here
+ * that wraps all GL sourced images on the grounds that setup information
+ * was performed by OpenCL anyway.
+ */
+class ImageGL : public Image
+{
+public:
+ ImageGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLenum target,
+ cl_GLint miplevel,
+ cl_GLuint texobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLTexture(
+ context(),
+ flags,
+ target,
+ miplevel,
+ texobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ ImageGL() : Image() { }
+
+ __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { }
+
+ ImageGL& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ ImageGL(const ImageGL& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ ImageGL& operator = (const ImageGL &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ ImageGL& operator = (ImageGL &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+};
+#endif // #if defined(CL_VERSION_1_2)
+
+/*! \brief Class interface for GL Render Buffer Memory Objects.
+*
+* This is provided to facilitate interoperability with OpenGL.
+*
+* See Memory for details about copy semantics, etc.
+*
+* \see Memory
+*/
+class BufferRenderGL :
+#if defined(CL_VERSION_1_2)
+ public ImageGL
+#else // #if defined(CL_VERSION_1_2)
+ public Image2DGL
+#endif //#if defined(CL_VERSION_1_2)
+{
+public:
+ /*! \brief Constructs a BufferRenderGL in a specified context, from a given
+ * GL Renderbuffer.
+ *
+ * Wraps clCreateFromGLRenderbuffer().
+ */
+ BufferRenderGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLuint bufobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLRenderbuffer(
+ context(),
+ flags,
+ bufobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+#if defined(CL_VERSION_1_2)
+ BufferRenderGL() : ImageGL() {};
+#else // #if defined(CL_VERSION_1_2)
+ BufferRenderGL() : Image2DGL() {};
+#endif //#if defined(CL_VERSION_1_2)
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * See Memory for further details.
+ */
+#if defined(CL_VERSION_1_2)
+ __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : ImageGL(buffer) { }
+#else // #if defined(CL_VERSION_1_2)
+ __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Image2DGL(buffer) { }
+#endif //#if defined(CL_VERSION_1_2)
+
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ BufferRenderGL& operator = (const cl_mem& rhs)
+ {
+#if defined(CL_VERSION_1_2)
+ ImageGL::operator=(rhs);
+#else // #if defined(CL_VERSION_1_2)
+ Image2DGL::operator=(rhs);
+#endif //#if defined(CL_VERSION_1_2)
+
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+#if defined(CL_VERSION_1_2)
+ BufferRenderGL(const BufferRenderGL& buf) : ImageGL(buf) {}
+#else // #if defined(CL_VERSION_1_2)
+ BufferRenderGL(const BufferRenderGL& buf) : Image2DGL(buf) {}
+#endif //#if defined(CL_VERSION_1_2)
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferRenderGL& operator = (const BufferRenderGL &rhs)
+ {
+#if defined(CL_VERSION_1_2)
+ ImageGL::operator=(rhs);
+#else // #if defined(CL_VERSION_1_2)
+ Image2DGL::operator=(rhs);
+#endif //#if defined(CL_VERSION_1_2)
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+#if defined(CL_VERSION_1_2)
+ BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : ImageGL(std::move(buf)) {}
+#else // #if defined(CL_VERSION_1_2)
+ BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : Image2DGL(std::move(buf)) {}
+#endif //#if defined(CL_VERSION_1_2)
+
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferRenderGL& operator = (BufferRenderGL &&buf)
+ {
+#if defined(CL_VERSION_1_2)
+ ImageGL::operator=(std::move(buf));
+#else // #if defined(CL_VERSION_1_2)
+ Image2DGL::operator=(std::move(buf));
+#endif //#if defined(CL_VERSION_1_2)
+
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ //! \brief Wrapper for clGetGLObjectInfo().
+ cl_int getObjectInfo(
+ cl_gl_object_type *type,
+ cl_GLuint * gl_object_name)
+ {
+ return detail::errHandler(
+ ::clGetGLObjectInfo(object_, type, gl_object_name),
+ __GET_GL_OBJECT_INFO_ERR);
+ }
+};
+
+/*! \brief Class interface for cl_sampler.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_sampler as the original. For details, see
+ * clRetainSampler() and clReleaseSampler().
+ *
+ * \see cl_sampler
+ */
+class Sampler : public detail::Wrapper<cl_sampler>
+{
+public:
+ //! \brief Default constructor - initializes to NULL.
+ Sampler() { }
+
+ /*! \brief Constructs a Sampler in a specified context.
+ *
+ * Wraps clCreateSampler().
+ */
+ Sampler(
+ const Context& context,
+ cl_bool normalized_coords,
+ cl_addressing_mode addressing_mode,
+ cl_filter_mode filter_mode,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateSampler(
+ context(),
+ normalized_coords,
+ addressing_mode,
+ filter_mode,
+ &error);
+
+ detail::errHandler(error, __CREATE_SAMPLER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Constructor from cl_sampler - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the cl_sampler
+ * into the new Sampler object.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Sampler(const cl_sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
+
+ /*! \brief Assignment operator from cl_sampler - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseSampler() on the value previously held by this instance.
+ */
+ Sampler& operator = (const cl_sampler& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Sampler& operator = (const Sampler &sam)
+ {
+ detail::Wrapper<cl_type>::operator=(sam);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Sampler(Sampler&& sam) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(sam)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Sampler& operator = (Sampler &&sam)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(sam));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ //! \brief Wrapper for clGetSamplerInfo().
+ template <typename T>
+ cl_int getInfo(cl_sampler_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetSamplerInfo, object_, name, param),
+ __GET_SAMPLER_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetSamplerInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_sampler_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_sampler_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+};
+
+class Program;
+class CommandQueue;
+class Kernel;
+
+//! \brief Class interface for specifying NDRange values.
+class NDRange
+{
+private:
+ size_t<3> sizes_;
+ cl_uint dimensions_;
+
+public:
+ //! \brief Default constructor - resulting range has zero dimensions.
+ NDRange()
+ : dimensions_(0)
+ { }
+
+ //! \brief Constructs one-dimensional range.
+ NDRange(::size_t size0)
+ : dimensions_(1)
+ {
+ sizes_[0] = size0;
+ }
+
+ //! \brief Constructs two-dimensional range.
+ NDRange(::size_t size0, ::size_t size1)
+ : dimensions_(2)
+ {
+ sizes_[0] = size0;
+ sizes_[1] = size1;
+ }
+
+ //! \brief Constructs three-dimensional range.
+ NDRange(::size_t size0, ::size_t size1, ::size_t size2)
+ : dimensions_(3)
+ {
+ sizes_[0] = size0;
+ sizes_[1] = size1;
+ sizes_[2] = size2;
+ }
+
+ /*! \brief Conversion operator to const ::size_t *.
+ *
+ * \returns a pointer to the size of the first dimension.
+ */
+ operator const ::size_t*() const {
+ return (const ::size_t*) sizes_;
+ }
+
+ //! \brief Queries the number of dimensions in the range.
+ ::size_t dimensions() const { return dimensions_; }
+};
+
+//! \brief A zero-dimensional range.
+static const NDRange NullRange;
+
+//! \brief Local address wrapper for use with Kernel::setArg
+struct LocalSpaceArg
+{
+ ::size_t size_;
+};
+
+namespace detail {
+
+template <typename T>
+struct KernelArgumentHandler
+{
+ static ::size_t size(const T&) { return sizeof(T); }
+ static const T* ptr(const T& value) { return &value; }
+};
+
+template <>
+struct KernelArgumentHandler<LocalSpaceArg>
+{
+ static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
+ static const void* ptr(const LocalSpaceArg&) { return NULL; }
+};
+
+}
+//! \endcond
+
+/*! __local
+ * \brief Helper function for generating LocalSpaceArg objects.
+ * Deprecated. Replaced with Local.
+ */
+inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg
+__local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+inline LocalSpaceArg
+__local(::size_t size)
+{
+ LocalSpaceArg ret = { size };
+ return ret;
+}
+
+/*! Local
+ * \brief Helper function for generating LocalSpaceArg objects.
+ */
+inline LocalSpaceArg
+Local(::size_t size)
+{
+ LocalSpaceArg ret = { size };
+ return ret;
+}
+
+//class KernelFunctor;
+
+/*! \brief Class interface for cl_kernel.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_kernel as the original. For details, see
+ * clRetainKernel() and clReleaseKernel().
+ *
+ * \see cl_kernel
+ */
+class Kernel : public detail::Wrapper<cl_kernel>
+{
+public:
+ inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
+
+ //! \brief Default constructor - initializes to NULL.
+ Kernel() { }
+
+ /*! \brief Constructor from cl_kernel - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the cl_kernel
+ * into the new Kernel object.
+ */
+ __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
+
+ /*! \brief Assignment operator from cl_kernel - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseKernel() on the value previously held by this instance.
+ */
+ Kernel& operator = (const cl_kernel& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Kernel& operator = (const Kernel &kernel)
+ {
+ detail::Wrapper<cl_type>::operator=(kernel);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(kernel)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Kernel& operator = (Kernel &&kernel)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(kernel));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ template <typename T>
+ cl_int getInfo(cl_kernel_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetKernelInfo, object_, name, param),
+ __GET_KERNEL_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_kernel_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_kernel_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+#if defined(CL_VERSION_1_2)
+ template <typename T>
+ cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
+ __GET_KERNEL_ARG_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
+ getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_kernel_arg_info, name>::param_type param;
+ cl_int result = getArgInfo(argIndex, name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+#endif // #if defined(CL_VERSION_1_2)
+
+ template <typename T>
+ cl_int getWorkGroupInfo(
+ const Device& device, cl_kernel_work_group_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(
+ &::clGetKernelWorkGroupInfo, object_, device(), name, param),
+ __GET_KERNEL_WORK_GROUP_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
+ getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_kernel_work_group_info, name>::param_type param;
+ cl_int result = getWorkGroupInfo(device, name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ template <typename T>
+ cl_int setArg(cl_uint index, const T &value)
+ {
+ return detail::errHandler(
+ ::clSetKernelArg(
+ object_,
+ index,
+ detail::KernelArgumentHandler<T>::size(value),
+ detail::KernelArgumentHandler<T>::ptr(value)),
+ __SET_KERNEL_ARGS_ERR);
+ }
+
+ cl_int setArg(cl_uint index, ::size_t size, const void* argPtr)
+ {
+ return detail::errHandler(
+ ::clSetKernelArg(object_, index, size, argPtr),
+ __SET_KERNEL_ARGS_ERR);
+ }
+};
+
+/*! \class Program
+ * \brief Program interface that implements cl_program.
+ */
+class Program : public detail::Wrapper<cl_program>
+{
+public:
+ typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
+ typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
+
+ Program(
+ const STRING_CLASS& source,
+ bool build = false,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ const char * strings = source.c_str();
+ const ::size_t length = source.size();
+
+ Context context = Context::getDefault(err);
+
+ object_ = ::clCreateProgramWithSource(
+ context(), (cl_uint)1, &strings, &length, &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
+
+ if (error == CL_SUCCESS && build) {
+
+ error = ::clBuildProgram(
+ object_,
+ 0,
+ NULL,
+ "",
+ NULL,
+ NULL);
+
+ detail::errHandler(error, __BUILD_PROGRAM_ERR);
+ }
+
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Program(
+ const Context& context,
+ const STRING_CLASS& source,
+ bool build = false,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ const char * strings = source.c_str();
+ const ::size_t length = source.size();
+
+ object_ = ::clCreateProgramWithSource(
+ context(), (cl_uint)1, &strings, &length, &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
+
+ if (error == CL_SUCCESS && build) {
+
+ error = ::clBuildProgram(
+ object_,
+ 0,
+ NULL,
+ "",
+ NULL,
+ NULL);
+
+ detail::errHandler(error, __BUILD_PROGRAM_ERR);
+ }
+
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Program(
+ const Context& context,
+ const Sources& sources,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ const ::size_t n = (::size_t)sources.size();
+ ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
+ const char** strings = (const char**) alloca(n * sizeof(const char*));
+
+ for (::size_t i = 0; i < n; ++i) {
+ strings[i] = sources[(int)i].first;
+ lengths[i] = sources[(int)i].second;
+ }
+
+ object_ = ::clCreateProgramWithSource(
+ context(), (cl_uint)n, strings, lengths, &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /**
+ * Construct a program object from a list of devices and a per-device list of binaries.
+ * \param context A valid OpenCL context in which to construct the program.
+ * \param devices A vector of OpenCL device objects for which the program will be created.
+ * \param binaries A vector of pairs of a pointer to a binary object and its length.
+ * \param binaryStatus An optional vector that on completion will be resized to
+ * match the size of binaries and filled with values to specify if each binary
+ * was successfully loaded.
+ * Set to CL_SUCCESS if the binary was successfully loaded.
+ * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL.
+ * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device.
+ * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors:
+ * CL_INVALID_CONTEXT if context is not a valid context.
+ * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices;
+ * or if any entry in binaries is NULL or has length 0.
+ * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context.
+ * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device.
+ * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
+ */
+ Program(
+ const Context& context,
+ const VECTOR_CLASS<Device>& devices,
+ const Binaries& binaries,
+ VECTOR_CLASS<cl_int>* binaryStatus = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ const ::size_t numDevices = devices.size();
+
+ // Catch size mismatch early and return
+ if(binaries.size() != numDevices) {
+ error = CL_INVALID_VALUE;
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ return;
+ }
+
+ ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t));
+ const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**));
+
+ for (::size_t i = 0; i < numDevices; ++i) {
+ images[i] = (const unsigned char*)binaries[i].first;
+ lengths[i] = binaries[(int)i].second;
+ }
+
+ cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
+ for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
+ deviceIDs[deviceIndex] = (devices[deviceIndex])();
+ }
+
+ if(binaryStatus) {
+ binaryStatus->resize(numDevices);
+ }
+
+ object_ = ::clCreateProgramWithBinary(
+ context(), (cl_uint) devices.size(),
+ deviceIDs,
+ lengths, images, (binaryStatus != NULL && numDevices > 0)
+ ? &binaryStatus->front()
+ : NULL, &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+
+#if defined(CL_VERSION_1_2)
+ /**
+ * Create program using builtin kernels.
+ * \param kernelNames Semi-colon separated list of builtin kernel names
+ */
+ Program(
+ const Context& context,
+ const VECTOR_CLASS<Device>& devices,
+ const STRING_CLASS& kernelNames,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+
+ ::size_t numDevices = devices.size();
+ cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
+ for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
+ deviceIDs[deviceIndex] = (devices[deviceIndex])();
+ }
+
+ object_ = ::clCreateProgramWithBuiltInKernels(
+ context(),
+ (cl_uint) devices.size(),
+ deviceIDs,
+ kernelNames.c_str(),
+ &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // #if defined(CL_VERSION_1_2)
+
+ Program() { }
+
+ __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper<cl_type>(program) { }
+
+ Program& operator = (const cl_program& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Program& operator = (const Program &program)
+ {
+ detail::Wrapper<cl_type>::operator=(program);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Program(Program&& program) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(program)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Program& operator = (Program &&program)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(program));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ cl_int build(
+ const VECTOR_CLASS<Device>& devices,
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL) const
+ {
+ ::size_t numDevices = devices.size();
+ cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
+ for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
+ deviceIDs[deviceIndex] = (devices[deviceIndex])();
+ }
+
+ return detail::errHandler(
+ ::clBuildProgram(
+ object_,
+ (cl_uint)
+ devices.size(),
+ deviceIDs,
+ options,
+ notifyFptr,
+ data),
+ __BUILD_PROGRAM_ERR);
+ }
+
+ cl_int build(
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL) const
+ {
+ return detail::errHandler(
+ ::clBuildProgram(
+ object_,
+ 0,
+ NULL,
+ options,
+ notifyFptr,
+ data),
+ __BUILD_PROGRAM_ERR);
+ }
+
+#if defined(CL_VERSION_1_2)
+ cl_int compile(
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL) const
+ {
+ return detail::errHandler(
+ ::clCompileProgram(
+ object_,
+ 0,
+ NULL,
+ options,
+ 0,
+ NULL,
+ NULL,
+ notifyFptr,
+ data),
+ __COMPILE_PROGRAM_ERR);
+ }
+#endif
+
+ template <typename T>
+ cl_int getInfo(cl_program_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetProgramInfo, object_, name, param),
+ __GET_PROGRAM_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_program_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_program_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ template <typename T>
+ cl_int getBuildInfo(
+ const Device& device, cl_program_build_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(
+ &::clGetProgramBuildInfo, object_, device(), name, param),
+ __GET_PROGRAM_BUILD_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_program_build_info, name>::param_type
+ getBuildInfo(const Device& device, cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_program_build_info, name>::param_type param;
+ cl_int result = getBuildInfo(device, name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
+ {
+ cl_uint numKernels;
+ cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
+ }
+
+ Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
+ err = ::clCreateKernelsInProgram(
+ object_, numKernels, (cl_kernel*) value, NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
+ }
+
+ kernels->assign(&value[0], &value[numKernels]);
+ return CL_SUCCESS;
+ }
+};
+
+#if defined(CL_VERSION_1_2)
+inline Program linkProgram(
+ Program input1,
+ Program input2,
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+{
+ cl_int error_local = CL_SUCCESS;
+
+ cl_program programs[2] = { input1(), input2() };
+
+ Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
+ if(error_local!=CL_SUCCESS) {
+ detail::errHandler(error_local, __LINK_PROGRAM_ERR);
+ }
+
+ cl_program prog = ::clLinkProgram(
+ ctx(),
+ 0,
+ NULL,
+ options,
+ 2,
+ programs,
+ notifyFptr,
+ data,
+ &error_local);
+
+ detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
+ if (err != NULL) {
+ *err = error_local;
+ }
+
+ return Program(prog);
+}
+
+inline Program linkProgram(
+ VECTOR_CLASS<Program> inputPrograms,
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+{
+ cl_int error_local = CL_SUCCESS;
+
+ cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program));
+
+ if (programs != NULL) {
+ for (unsigned int i = 0; i < inputPrograms.size(); i++) {
+ programs[i] = inputPrograms[i]();
+ }
+ }
+
+ Context ctx;
+ if(inputPrograms.size() > 0) {
+ ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
+ if(error_local!=CL_SUCCESS) {
+ detail::errHandler(error_local, __LINK_PROGRAM_ERR);
+ }
+ }
+ cl_program prog = ::clLinkProgram(
+ ctx(),
+ 0,
+ NULL,
+ options,
+ (cl_uint)inputPrograms.size(),
+ programs,
+ notifyFptr,
+ data,
+ &error_local);
+
+ detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
+ if (err != NULL) {
+ *err = error_local;
+ }
+
+ return Program(prog);
+}
+#endif
+
+template<>
+inline VECTOR_CLASS<char *> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
+{
+ VECTOR_CLASS< ::size_t> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
+ VECTOR_CLASS<char *> binaries;
+ for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s)
+ {
+ char *ptr = NULL;
+ if (*s != 0)
+ ptr = new char[*s];
+ binaries.push_back(ptr);
+ }
+
+ cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries);
+ if (err != NULL) {
+ *err = result;
+ }
+ return binaries;
+}
+
+inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
+{
+ cl_int error;
+
+ object_ = ::clCreateKernel(program(), name, &error);
+ detail::errHandler(error, __CREATE_KERNEL_ERR);
+
+ if (err != NULL) {
+ *err = error;
+ }
+
+}
+
+/*! \class CommandQueue
+ * \brief CommandQueue interface for cl_command_queue.
+ */
+class CommandQueue : public detail::Wrapper<cl_command_queue>
+{
+private:
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+ static std::atomic<int> default_initialized_;
+#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ static volatile int default_initialized_;
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+ static CommandQueue default_;
+ static volatile cl_int default_error_;
+public:
+ CommandQueue(
+ cl_command_queue_properties properties,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ Context context = Context::getDefault(&error);
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+
+ if (error != CL_SUCCESS) {
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+ else {
+ Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
+
+ object_ = ::clCreateCommandQueue(
+ context(), device(), properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+ }
+ /*!
+ * \brief Constructs a CommandQueue for an implementation defined device in the given context
+ */
+ explicit CommandQueue(
+ const Context& context,
+ cl_command_queue_properties properties = 0,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ VECTOR_CLASS<cl::Device> devices;
+ error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
+
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+
+ if (error != CL_SUCCESS)
+ {
+ if (err != NULL) {
+ *err = error;
+ }
+ return;
+ }
+
+ object_ = ::clCreateCommandQueue(context(), devices[0](), properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+
+ if (err != NULL) {
+ *err = error;
+ }
+
+ }
+
+ CommandQueue(
+ const Context& context,
+ const Device& device,
+ cl_command_queue_properties properties = 0,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateCommandQueue(
+ context(), device(), properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ CommandQueue& operator = (const CommandQueue &queue)
+ {
+ detail::Wrapper<cl_type>::operator=(queue);
+ return *this;
+ }
+
+#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(queue)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ CommandQueue& operator = (CommandQueue &&queue)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(queue));
+ return *this;
+ }
+#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
+
+ static CommandQueue getDefault(cl_int * err = NULL)
+ {
+ int state = detail::compare_exchange(
+ &default_initialized_,
+ __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED);
+
+ if (state & __DEFAULT_INITIALIZED) {
+ if (err != NULL) {
+ *err = default_error_;
+ }
+ return default_;
+ }
+
+ if (state & __DEFAULT_BEING_INITIALIZED) {
+ // Assume writes will propagate eventually...
+ while(default_initialized_ != __DEFAULT_INITIALIZED) {
+ detail::fence();
+ }
+
+ if (err != NULL) {
+ *err = default_error_;
+ }
+ return default_;
+ }
+
+ cl_int error;
+
+ Context context = Context::getDefault(&error);
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+
+ if (error != CL_SUCCESS) {
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+ else {
+ Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
+
+ default_ = CommandQueue(context, device, 0, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ detail::fence();
+
+ default_error_ = error;
+ // Assume writes will propagate eventually...
+ default_initialized_ = __DEFAULT_INITIALIZED;
+
+ detail::fence();
+
+ if (err != NULL) {
+ *err = default_error_;
+ }
+ return default_;
+
+ }
+
+ CommandQueue() { }
+
+ __CL_EXPLICIT_CONSTRUCTORS CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
+
+ CommandQueue& operator = (const cl_command_queue& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ template <typename T>
+ cl_int getInfo(cl_command_queue_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(
+ &::clGetCommandQueueInfo, object_, name, param),
+ __GET_COMMAND_QUEUE_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_command_queue_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_command_queue_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ cl_int enqueueReadBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ ::size_t offset,
+ ::size_t size,
+ void* ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueReadBuffer(
+ object_, buffer(), blocking, offset, size,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_READ_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueWriteBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ ::size_t offset,
+ ::size_t size,
+ const void* ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueWriteBuffer(
+ object_, buffer(), blocking, offset, size,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_WRITE_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueCopyBuffer(
+ const Buffer& src,
+ const Buffer& dst,
+ ::size_t src_offset,
+ ::size_t dst_offset,
+ ::size_t size,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyBuffer(
+ object_, src(), dst(), src_offset, dst_offset, size,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQEUE_COPY_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueReadBufferRect(
+ const Buffer& buffer,
+ cl_bool blocking,
+ const size_t<3>& buffer_offset,
+ const size_t<3>& host_offset,
+ const size_t<3>& region,
+ ::size_t buffer_row_pitch,
+ ::size_t buffer_slice_pitch,
+ ::size_t host_row_pitch,
+ ::size_t host_slice_pitch,
+ void *ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueReadBufferRect(
+ object_,
+ buffer(),
+ blocking,
+ (const ::size_t *)buffer_offset,
+ (const ::size_t *)host_offset,
+ (const ::size_t *)region,
+ buffer_row_pitch,
+ buffer_slice_pitch,
+ host_row_pitch,
+ host_slice_pitch,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_READ_BUFFER_RECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueWriteBufferRect(
+ const Buffer& buffer,
+ cl_bool blocking,
+ const size_t<3>& buffer_offset,
+ const size_t<3>& host_offset,
+ const size_t<3>& region,
+ ::size_t buffer_row_pitch,
+ ::size_t buffer_slice_pitch,
+ ::size_t host_row_pitch,
+ ::size_t host_slice_pitch,
+ const void *ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueWriteBufferRect(
+ object_,
+ buffer(),
+ blocking,
+ (const ::size_t *)buffer_offset,
+ (const ::size_t *)host_offset,
+ (const ::size_t *)region,
+ buffer_row_pitch,
+ buffer_slice_pitch,
+ host_row_pitch,
+ host_slice_pitch,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_WRITE_BUFFER_RECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueCopyBufferRect(
+ const Buffer& src,
+ const Buffer& dst,
+ const size_t<3>& src_origin,
+ const size_t<3>& dst_origin,
+ const size_t<3>& region,
+ ::size_t src_row_pitch,
+ ::size_t src_slice_pitch,
+ ::size_t dst_row_pitch,
+ ::size_t dst_slice_pitch,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyBufferRect(
+ object_,
+ src(),
+ dst(),
+ (const ::size_t *)src_origin,
+ (const ::size_t *)dst_origin,
+ (const ::size_t *)region,
+ src_row_pitch,
+ src_slice_pitch,
+ dst_row_pitch,
+ dst_slice_pitch,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQEUE_COPY_BUFFER_RECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+#if defined(CL_VERSION_1_2)
+ /**
+ * Enqueue a command to fill a buffer object with a pattern
+ * of a given size. The pattern is specified a as vector.
+ * \tparam PatternType The datatype of the pattern field.
+ * The pattern type must be an accepted OpenCL data type.
+ */
+ template<typename PatternType>
+ cl_int enqueueFillBuffer(
+ const Buffer& buffer,
+ PatternType pattern,
+ ::size_t offset,
+ ::size_t size,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueFillBuffer(
+ object_,
+ buffer(),
+ static_cast<void*>(&pattern),
+ sizeof(PatternType),
+ offset,
+ size,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_FILL_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // #if defined(CL_VERSION_1_2)
+
+ cl_int enqueueReadImage(
+ const Image& image,
+ cl_bool blocking,
+ const size_t<3>& origin,
+ const size_t<3>& region,
+ ::size_t row_pitch,
+ ::size_t slice_pitch,
+ void* ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueReadImage(
+ object_, image(), blocking, (const ::size_t *) origin,
+ (const ::size_t *) region, row_pitch, slice_pitch, ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_READ_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueWriteImage(
+ const Image& image,
+ cl_bool blocking,
+ const size_t<3>& origin,
+ const size_t<3>& region,
+ ::size_t row_pitch,
+ ::size_t slice_pitch,
+ const void* ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueWriteImage(
+ object_, image(), blocking, (const ::size_t *) origin,
+ (const ::size_t *) region, row_pitch, slice_pitch, ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_WRITE_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueCopyImage(
+ const Image& src,
+ const Image& dst,
+ const size_t<3>& src_origin,
+ const size_t<3>& dst_origin,
+ const size_t<3>& region,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyImage(
+ object_, src(), dst(), (const ::size_t *) src_origin,
+ (const ::size_t *)dst_origin, (const ::size_t *) region,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_COPY_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+#if defined(CL_VERSION_1_2)
+ /**
+ * Enqueue a command to fill an image object with a specified color.
+ * \param fillColor is the color to use to fill the image.
+ * This is a four component RGBA floating-point color value if
+ * the image channel data type is not an unnormalized signed or
+ * unsigned data type.
+ */
+ cl_int enqueueFillImage(
+ const Image& image,
+ cl_float4 fillColor,
+ const size_t<3>& origin,
+ const size_t<3>& region,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueFillImage(
+ object_,
+ image(),
+ static_cast<void*>(&fillColor),
+ (const ::size_t *) origin,
+ (const ::size_t *) region,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_FILL_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueue a command to fill an image object with a specified color.
+ * \param fillColor is the color to use to fill the image.
+ * This is a four component RGBA signed integer color value if
+ * the image channel data type is an unnormalized signed integer
+ * type.
+ */
+ cl_int enqueueFillImage(
+ const Image& image,
+ cl_int4 fillColor,
+ const size_t<3>& origin,
+ const size_t<3>& region,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueFillImage(
+ object_,
+ image(),
+ static_cast<void*>(&fillColor),
+ (const ::size_t *) origin,
+ (const ::size_t *) region,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_FILL_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueue a command to fill an image object with a specified color.
+ * \param fillColor is the color to use to fill the image.
+ * This is a four component RGBA unsigned integer color value if
+ * the image channel data type is an unnormalized unsigned integer
+ * type.
+ */
+ cl_int enqueueFillImage(
+ const Image& image,
+ cl_uint4 fillColor,
+ const size_t<3>& origin,
+ const size_t<3>& region,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueFillImage(
+ object_,
+ image(),
+ static_cast<void*>(&fillColor),
+ (const ::size_t *) origin,
+ (const ::size_t *) region,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_FILL_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // #if defined(CL_VERSION_1_2)
+
+ cl_int enqueueCopyImageToBuffer(
+ const Image& src,
+ const Buffer& dst,
+ const size_t<3>& src_origin,
+ const size_t<3>& region,
+ ::size_t dst_offset,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyImageToBuffer(
+ object_, src(), dst(), (const ::size_t *) src_origin,
+ (const ::size_t *) region, dst_offset,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueCopyBufferToImage(
+ const Buffer& src,
+ const Image& dst,
+ ::size_t src_offset,
+ const size_t<3>& dst_origin,
+ const size_t<3>& region,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyBufferToImage(
+ object_, src(), dst(), src_offset,
+ (const ::size_t *) dst_origin, (const ::size_t *) region,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ void* enqueueMapBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ cl_map_flags flags,
+ ::size_t offset,
+ ::size_t size,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL,
+ cl_int* err = NULL) const
+ {
+ cl_event tmp;
+ cl_int error;
+ void * result = ::clEnqueueMapBuffer(
+ object_, buffer(), blocking, flags, offset, size,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL,
+ &error);
+
+ detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ if (event != NULL && error == CL_SUCCESS)
+ *event = tmp;
+
+ return result;
+ }
+
+ void* enqueueMapImage(
+ const Image& buffer,
+ cl_bool blocking,
+ cl_map_flags flags,
+ const size_t<3>& origin,
+ const size_t<3>& region,
+ ::size_t * row_pitch,
+ ::size_t * slice_pitch,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL,
+ cl_int* err = NULL) const
+ {
+ cl_event tmp;
+ cl_int error;
+ void * result = ::clEnqueueMapImage(
+ object_, buffer(), blocking, flags,
+ (const ::size_t *) origin, (const ::size_t *) region,
+ row_pitch, slice_pitch,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL,
+ &error);
+
+ detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ if (event != NULL && error == CL_SUCCESS)
+ *event = tmp;
+ return result;
+ }
+
+ cl_int enqueueUnmapMemObject(
+ const Memory& memory,
+ void* mapped_ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueUnmapMemObject(
+ object_, memory(), mapped_ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+#if defined(CL_VERSION_1_2)
+ /**
+ * Enqueues a marker command which waits for either a list of events to complete,
+ * or all previously enqueued commands to complete.
+ *
+ * Enqueues a marker command which waits for either a list of events to complete,
+ * or if the list is empty it waits for all commands previously enqueued in command_queue
+ * to complete before it completes. This command returns an event which can be waited on,
+ * i.e. this event can be waited on to insure that all events either in the event_wait_list
+ * or all previously enqueued commands, queued before this command to command_queue,
+ * have completed.
+ */
+ cl_int enqueueMarkerWithWaitList(
+ const VECTOR_CLASS<Event> *events = 0,
+ Event *event = 0)
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueMarkerWithWaitList(
+ object_,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_MARKER_WAIT_LIST_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * A synchronization point that enqueues a barrier operation.
+ *
+ * Enqueues a barrier command which waits for either a list of events to complete,
+ * or if the list is empty it waits for all commands previously enqueued in command_queue
+ * to complete before it completes. This command blocks command execution, that is, any
+ * following commands enqueued after it do not execute until it completes. This command
+ * returns an event which can be waited on, i.e. this event can be waited on to insure that
+ * all events either in the event_wait_list or all previously enqueued commands, queued
+ * before this command to command_queue, have completed.
+ */
+ cl_int enqueueBarrierWithWaitList(
+ const VECTOR_CLASS<Event> *events = 0,
+ Event *event = 0)
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueBarrierWithWaitList(
+ object_,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_BARRIER_WAIT_LIST_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueues a command to indicate with which device a set of memory objects
+ * should be associated.
+ */
+ cl_int enqueueMigrateMemObjects(
+ const VECTOR_CLASS<Memory> &memObjects,
+ cl_mem_migration_flags flags,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL
+ )
+ {
+ cl_event tmp;
+
+ cl_mem* localMemObjects = static_cast<cl_mem*>(alloca(memObjects.size() * sizeof(cl_mem)));
+ for( int i = 0; i < (int)memObjects.size(); ++i ) {
+ localMemObjects[i] = memObjects[i]();
+ }
+
+
+ cl_int err = detail::errHandler(
+ ::clEnqueueMigrateMemObjects(
+ object_,
+ (cl_uint)memObjects.size(),
+ static_cast<const cl_mem*>(localMemObjects),
+ flags,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // #if defined(CL_VERSION_1_2)
+
+ cl_int enqueueNDRangeKernel(
+ const Kernel& kernel,
+ const NDRange& offset,
+ const NDRange& global,
+ const NDRange& local = NullRange,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueNDRangeKernel(
+ object_, kernel(), (cl_uint) global.dimensions(),
+ offset.dimensions() != 0 ? (const ::size_t*) offset : NULL,
+ (const ::size_t*) global,
+ local.dimensions() != 0 ? (const ::size_t*) local : NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_NDRANGE_KERNEL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueTask(
+ const Kernel& kernel,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueTask(
+ object_, kernel(),
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_TASK_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueNativeKernel(
+ void (CL_CALLBACK *userFptr)(void *),
+ std::pair<void*, ::size_t> args,
+ const VECTOR_CLASS<Memory>* mem_objects = NULL,
+ const VECTOR_CLASS<const void*>* mem_locs = NULL,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0)
+ ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem))
+ : NULL;
+
+ if (mems != NULL) {
+ for (unsigned int i = 0; i < mem_objects->size(); i++) {
+ mems[i] = ((*mem_objects)[i])();
+ }
+ }
+
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueNativeKernel(
+ object_, userFptr, args.first, args.second,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ mems,
+ (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_NATIVE_KERNEL);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
+ CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+ cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueMarker(
+ object_,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_MARKER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+ cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+ {
+ return detail::errHandler(
+ ::clEnqueueWaitForEvents(
+ object_,
+ (cl_uint) events.size(),
+ events.size() > 0 ? (const cl_event*) &events.front() : NULL),
+ __ENQUEUE_WAIT_FOR_EVENTS_ERR);
+ }
+#endif // #if defined(CL_VERSION_1_1)
+
+ cl_int enqueueAcquireGLObjects(
+ const VECTOR_CLASS<Memory>* mem_objects = NULL,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueAcquireGLObjects(
+ object_,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_ACQUIRE_GL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueReleaseGLObjects(
+ const VECTOR_CLASS<Memory>* mem_objects = NULL,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueReleaseGLObjects(
+ object_,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_RELEASE_GL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+#if defined (USE_DX_INTEROP)
+typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
+ cl_command_queue command_queue, cl_uint num_objects,
+ const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
+ const cl_event* event_wait_list, cl_event* event);
+typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
+ cl_command_queue command_queue, cl_uint num_objects,
+ const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
+ const cl_event* event_wait_list, cl_event* event);
+
+ cl_int enqueueAcquireD3D10Objects(
+ const VECTOR_CLASS<Memory>* mem_objects = NULL,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
+#if defined(CL_VERSION_1_2)
+ cl_context context = getInfo<CL_QUEUE_CONTEXT>();
+ cl::Device device(getInfo<CL_QUEUE_DEVICE>());
+ cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
+ __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR);
+#endif
+#if defined(CL_VERSION_1_1)
+ __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR);
+#endif
+
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ pfn_clEnqueueAcquireD3D10ObjectsKHR(
+ object_,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_ACQUIRE_GL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueReleaseD3D10Objects(
+ const VECTOR_CLASS<Memory>* mem_objects = NULL,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
+#if defined(CL_VERSION_1_2)
+ cl_context context = getInfo<CL_QUEUE_CONTEXT>();
+ cl::Device device(getInfo<CL_QUEUE_DEVICE>());
+ cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
+ __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR);
+#endif // #if defined(CL_VERSION_1_2)
+#if defined(CL_VERSION_1_1)
+ __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR);
+#endif // #if defined(CL_VERSION_1_1)
+
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ pfn_clEnqueueReleaseD3D10ObjectsKHR(
+ object_,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_RELEASE_GL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
+ CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+ cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+ {
+ return detail::errHandler(
+ ::clEnqueueBarrier(object_),
+ __ENQUEUE_BARRIER_ERR);
+ }
+#endif // #if defined(CL_VERSION_1_1)
+
+ cl_int flush() const
+ {
+ return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
+ }
+
+ cl_int finish() const
+ {
+ return detail::errHandler(::clFinish(object_), __FINISH_ERR);
+ }
+};
+
+#ifdef _WIN32
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+__declspec(selectany) std::atomic<int> CommandQueue::default_initialized_;
+#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+__declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+__declspec(selectany) CommandQueue CommandQueue::default_;
+__declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS;
+#else // !_WIN32
+#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
+__attribute__((weak)) std::atomic<int> CommandQueue::default_initialized_;
+#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+__attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
+#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
+__attribute__((weak)) CommandQueue CommandQueue::default_;
+__attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS;
+#endif // !_WIN32
+
+template< typename IteratorType >
+Buffer::Buffer(
+ const Context &context,
+ IteratorType startIterator,
+ IteratorType endIterator,
+ bool readOnly,
+ bool useHostPtr,
+ cl_int* err)
+{
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ cl_mem_flags flags = 0;
+ if( readOnly ) {
+ flags |= CL_MEM_READ_ONLY;
+ }
+ else {
+ flags |= CL_MEM_READ_WRITE;
+ }
+ if( useHostPtr ) {
+ flags |= CL_MEM_USE_HOST_PTR;
+ }
+
+ ::size_t size = sizeof(DataType)*(endIterator - startIterator);
+
+ if( useHostPtr ) {
+ object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
+ } else {
+ object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
+ }
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ if( !useHostPtr ) {
+ CommandQueue queue(context, 0, &error);
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ error = cl::copy(queue, startIterator, endIterator, *this);
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+}
+
+template< typename IteratorType >
+Buffer::Buffer(
+ const CommandQueue &queue,
+ IteratorType startIterator,
+ IteratorType endIterator,
+ bool readOnly,
+ bool useHostPtr,
+ cl_int* err)
+{
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ cl_mem_flags flags = 0;
+ if (readOnly) {
+ flags |= CL_MEM_READ_ONLY;
+ }
+ else {
+ flags |= CL_MEM_READ_WRITE;
+ }
+ if (useHostPtr) {
+ flags |= CL_MEM_USE_HOST_PTR;
+ }
+
+ ::size_t size = sizeof(DataType)*(endIterator - startIterator);
+
+ Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
+
+ if (useHostPtr) {
+ object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
+ }
+ else {
+ object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
+ }
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ if (!useHostPtr) {
+ error = cl::copy(queue, startIterator, endIterator, *this);
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+}
+
+inline cl_int enqueueReadBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ ::size_t offset,
+ ::size_t size,
+ void* ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
+}
+
+inline cl_int enqueueWriteBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ ::size_t offset,
+ ::size_t size,
+ const void* ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
+}
+
+inline void* enqueueMapBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ cl_map_flags flags,
+ ::size_t offset,
+ ::size_t size,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL,
+ cl_int* err = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ void * result = ::clEnqueueMapBuffer(
+ queue(), buffer(), blocking, flags, offset, size,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (cl_event*) event,
+ &error);
+
+ detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ return result;
+}
+
+inline cl_int enqueueUnmapMemObject(
+ const Memory& memory,
+ void* mapped_ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueUnmapMemObject(
+ queue(), memory(), mapped_ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+}
+
+inline cl_int enqueueCopyBuffer(
+ const Buffer& src,
+ const Buffer& dst,
+ ::size_t src_offset,
+ ::size_t dst_offset,
+ ::size_t size,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
+}
+
+/**
+ * Blocking copy operation between iterators and a buffer.
+ * Host to Device.
+ * Uses default command queue.
+ */
+template< typename IteratorType >
+inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS)
+ return error;
+
+ return cl::copy(queue, startIterator, endIterator, buffer);
+}
+
+/**
+ * Blocking copy operation between iterators and a buffer.
+ * Device to Host.
+ * Uses default command queue.
+ */
+template< typename IteratorType >
+inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS)
+ return error;
+
+ return cl::copy(queue, buffer, startIterator, endIterator);
+}
+
+/**
+ * Blocking copy operation between iterators and a buffer.
+ * Host to Device.
+ * Uses specified queue.
+ */
+template< typename IteratorType >
+inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
+{
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ ::size_t length = endIterator-startIterator;
+ ::size_t byteLength = length*sizeof(DataType);
+
+ DataType *pointer =
+ static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
+ // if exceptions enabled, enqueueMapBuffer will throw
+ if( error != CL_SUCCESS ) {
+ return error;
+ }
+#if defined(_MSC_VER)
+ std::copy(
+ startIterator,
+ endIterator,
+ stdext::checked_array_iterator<DataType*>(
+ pointer, length));
+#else
+ std::copy(startIterator, endIterator, pointer);
+#endif
+ Event endEvent;
+ error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
+ // if exceptions enabled, enqueueUnmapMemObject will throw
+ if( error != CL_SUCCESS ) {
+ return error;
+ }
+ endEvent.wait();
+ return CL_SUCCESS;
+}
+
+/**
+ * Blocking copy operation between iterators and a buffer.
+ * Device to Host.
+ * Uses specified queue.
+ */
+template< typename IteratorType >
+inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
+{
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ ::size_t length = endIterator-startIterator;
+ ::size_t byteLength = length*sizeof(DataType);
+
+ DataType *pointer =
+ static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
+ // if exceptions enabled, enqueueMapBuffer will throw
+ if( error != CL_SUCCESS ) {
+ return error;
+ }
+ std::copy(pointer, pointer + length, startIterator);
+ Event endEvent;
+ error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
+ // if exceptions enabled, enqueueUnmapMemObject will throw
+ if( error != CL_SUCCESS ) {
+ return error;
+ }
+ endEvent.wait();
+ return CL_SUCCESS;
+}
+
+#if defined(CL_VERSION_1_1)
+inline cl_int enqueueReadBufferRect(
+ const Buffer& buffer,
+ cl_bool blocking,
+ const size_t<3>& buffer_offset,
+ const size_t<3>& host_offset,
+ const size_t<3>& region,
+ ::size_t buffer_row_pitch,
+ ::size_t buffer_slice_pitch,
+ ::size_t host_row_pitch,
+ ::size_t host_slice_pitch,
+ void *ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueReadBufferRect(
+ buffer,
+ blocking,
+ buffer_offset,
+ host_offset,
+ region,
+ buffer_row_pitch,
+ buffer_slice_pitch,
+ host_row_pitch,
+ host_slice_pitch,
+ ptr,
+ events,
+ event);
+}
+
+inline cl_int enqueueWriteBufferRect(
+ const Buffer& buffer,
+ cl_bool blocking,
+ const size_t<3>& buffer_offset,
+ const size_t<3>& host_offset,
+ const size_t<3>& region,
+ ::size_t buffer_row_pitch,
+ ::size_t buffer_slice_pitch,
+ ::size_t host_row_pitch,
+ ::size_t host_slice_pitch,
+ const void *ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueWriteBufferRect(
+ buffer,
+ blocking,
+ buffer_offset,
+ host_offset,
+ region,
+ buffer_row_pitch,
+ buffer_slice_pitch,
+ host_row_pitch,
+ host_slice_pitch,
+ ptr,
+ events,
+ event);
+}
+
+inline cl_int enqueueCopyBufferRect(
+ const Buffer& src,
+ const Buffer& dst,
+ const size_t<3>& src_origin,
+ const size_t<3>& dst_origin,
+ const size_t<3>& region,
+ ::size_t src_row_pitch,
+ ::size_t src_slice_pitch,
+ ::size_t dst_row_pitch,
+ ::size_t dst_slice_pitch,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyBufferRect(
+ src,
+ dst,
+ src_origin,
+ dst_origin,
+ region,
+ src_row_pitch,
+ src_slice_pitch,
+ dst_row_pitch,
+ dst_slice_pitch,
+ events,
+ event);
+}
+#endif
+
+inline cl_int enqueueReadImage(
+ const Image& image,
+ cl_bool blocking,
+ const size_t<3>& origin,
+ const size_t<3>& region,
+ ::size_t row_pitch,
+ ::size_t slice_pitch,
+ void* ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueReadImage(
+ image,
+ blocking,
+ origin,
+ region,
+ row_pitch,
+ slice_pitch,
+ ptr,
+ events,
+ event);
+}
+
+inline cl_int enqueueWriteImage(
+ const Image& image,
+ cl_bool blocking,
+ const size_t<3>& origin,
+ const size_t<3>& region,
+ ::size_t row_pitch,
+ ::size_t slice_pitch,
+ const void* ptr,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueWriteImage(
+ image,
+ blocking,
+ origin,
+ region,
+ row_pitch,
+ slice_pitch,
+ ptr,
+ events,
+ event);
+}
+
+inline cl_int enqueueCopyImage(
+ const Image& src,
+ const Image& dst,
+ const size_t<3>& src_origin,
+ const size_t<3>& dst_origin,
+ const size_t<3>& region,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyImage(
+ src,
+ dst,
+ src_origin,
+ dst_origin,
+ region,
+ events,
+ event);
+}
+
+inline cl_int enqueueCopyImageToBuffer(
+ const Image& src,
+ const Buffer& dst,
+ const size_t<3>& src_origin,
+ const size_t<3>& region,
+ ::size_t dst_offset,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyImageToBuffer(
+ src,
+ dst,
+ src_origin,
+ region,
+ dst_offset,
+ events,
+ event);
+}
+
+inline cl_int enqueueCopyBufferToImage(
+ const Buffer& src,
+ const Image& dst,
+ ::size_t src_offset,
+ const size_t<3>& dst_origin,
+ const size_t<3>& region,
+ const VECTOR_CLASS<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyBufferToImage(
+ src,
+ dst,
+ src_offset,
+ dst_origin,
+ region,
+ events,
+ event);
+}
+
+
+inline cl_int flush(void)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.flush();
+}
+
+inline cl_int finish(void)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+
+ return queue.finish();
+}
+
+// Kernel Functor support
+// New interface as of September 2011
+// Requires the C++11 std::tr1::function (note do not support TR1)
+// Visual Studio 2010 and GCC 4.2
+
+struct EnqueueArgs
+{
+ CommandQueue queue_;
+ const NDRange offset_;
+ const NDRange global_;
+ const NDRange local_;
+ VECTOR_CLASS<Event> events_;
+
+ EnqueueArgs(NDRange global) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange)
+ {
+
+ }
+
+ EnqueueArgs(NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(local)
+ {
+
+ }
+
+ EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(offset),
+ global_(global),
+ local_(local)
+ {
+
+ }
+
+ EnqueueArgs(Event e, NDRange global) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(Event e, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(local)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(offset),
+ global_(global),
+ local_(local)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(local),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(offset),
+ global_(global),
+ local_(local),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, NDRange global) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(local)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(offset),
+ global_(global),
+ local_(local)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(local)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(offset),
+ global_(global),
+ local_(local)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(local),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(offset),
+ global_(global),
+ local_(local),
+ events_(events)
+ {
+
+ }
+};
+
+namespace detail {
+
+class NullType {};
+
+template<int index, typename T0>
+struct SetArg
+{
+ static void set (Kernel kernel, T0 arg)
+ {
+ kernel.setArg(index, arg);
+ }
+};
+
+template<int index>
+struct SetArg<index, NullType>
+{
+ static void set (Kernel, NullType)
+ {
+ }
+};
+
+template <
+ typename T0, typename T1, typename T2, typename T3,
+ typename T4, typename T5, typename T6, typename T7,
+ typename T8, typename T9, typename T10, typename T11,
+ typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename T17, typename T18, typename T19,
+ typename T20, typename T21, typename T22, typename T23,
+ typename T24, typename T25, typename T26, typename T27,
+ typename T28, typename T29, typename T30, typename T31
+//@@@@EXCESSIVE-ARG-START
+ ,
+ typename T32, typename T33, typename T34, typename T35,
+ typename T36, typename T37, typename T38, typename T39,
+ typename T40, typename T41, typename T42, typename T43,
+ typename T44, typename T45, typename T46, typename T47,
+ typename T48, typename T49, typename T50, typename T51,
+ typename T52, typename T53, typename T54, typename T55,
+ typename T56, typename T57, typename T58, typename T59,
+ typename T60, typename T61, typename T62, typename T63,
+ typename T64, typename T65, typename T66, typename T67,
+ typename T68, typename T69, typename T70, typename T71,
+ typename T72, typename T73, typename T74, typename T75,
+ typename T76, typename T77, typename T78, typename T79,
+ typename T80, typename T81, typename T82, typename T83,
+ typename T84, typename T85, typename T86, typename T87,
+ typename T88, typename T89, typename T90, typename T91,
+ typename T92, typename T93, typename T94, typename T95,
+ typename T96, typename T97, typename T98, typename T99,
+ typename T100, typename T101, typename T102, typename T103,
+ typename T104, typename T105, typename T106, typename T107,
+ typename T108, typename T109, typename T110, typename T111,
+ typename T112, typename T113, typename T114, typename T115,
+ typename T116, typename T117, typename T118, typename T119,
+ typename T120, typename T121, typename T122, typename T123,
+ typename T124, typename T125, typename T126, typename T127
+//@@@@EXCESSIVE-ARG-END
+>
+class KernelFunctorGlobal
+{
+private:
+ Kernel kernel_;
+
+public:
+ KernelFunctorGlobal(
+ Kernel kernel) :
+ kernel_(kernel)
+ {}
+
+ KernelFunctorGlobal(
+ const Program& program,
+ const STRING_CLASS name,
+ cl_int * err = NULL) :
+ kernel_(program, name.c_str(), err)
+ {}
+
+ Event operator() (
+ const EnqueueArgs& args,
+ T0 t0,
+ T1 t1 = NullType(),
+ T2 t2 = NullType(),
+ T3 t3 = NullType(),
+ T4 t4 = NullType(),
+ T5 t5 = NullType(),
+ T6 t6 = NullType(),
+ T7 t7 = NullType(),
+ T8 t8 = NullType(),
+ T9 t9 = NullType(),
+ T10 t10 = NullType(),
+ T11 t11 = NullType(),
+ T12 t12 = NullType(),
+ T13 t13 = NullType(),
+ T14 t14 = NullType(),
+ T15 t15 = NullType(),
+ T16 t16 = NullType(),
+ T17 t17 = NullType(),
+ T18 t18 = NullType(),
+ T19 t19 = NullType(),
+ T20 t20 = NullType(),
+ T21 t21 = NullType(),
+ T22 t22 = NullType(),
+ T23 t23 = NullType(),
+ T24 t24 = NullType(),
+ T25 t25 = NullType(),
+ T26 t26 = NullType(),
+ T27 t27 = NullType(),
+ T28 t28 = NullType(),
+ T29 t29 = NullType(),
+ T30 t30 = NullType(),
+ T31 t31 = NullType()
+//@@@@EXCESSIVE-ARG-START
+,
+ T32 t32 = NullType(),
+ T33 t33 = NullType(),
+ T34 t34 = NullType(),
+ T35 t35 = NullType(),
+ T36 t36 = NullType(),
+ T37 t37 = NullType(),
+ T38 t38 = NullType(),
+ T39 t39 = NullType(),
+ T40 t40 = NullType(),
+ T41 t41 = NullType(),
+ T42 t42 = NullType(),
+ T43 t43 = NullType(),
+ T44 t44 = NullType(),
+ T45 t45 = NullType(),
+ T46 t46 = NullType(),
+ T47 t47 = NullType(),
+ T48 t48 = NullType(),
+ T49 t49 = NullType(),
+ T50 t50 = NullType(),
+ T51 t51 = NullType(),
+ T52 t52 = NullType(),
+ T53 t53 = NullType(),
+ T54 t54 = NullType(),
+ T55 t55 = NullType(),
+ T56 t56 = NullType(),
+ T57 t57 = NullType(),
+ T58 t58 = NullType(),
+ T59 t59 = NullType(),
+ T60 t60 = NullType(),
+ T61 t61 = NullType(),
+ T62 t62 = NullType(),
+ T63 t63 = NullType(),
+ T64 t64 = NullType(),
+ T65 t65 = NullType(),
+ T66 t66 = NullType(),
+ T67 t67 = NullType(),
+ T68 t68 = NullType(),
+ T69 t69 = NullType(),
+ T70 t70 = NullType(),
+ T71 t71 = NullType(),
+ T72 t72 = NullType(),
+ T73 t73 = NullType(),
+ T74 t74 = NullType(),
+ T75 t75 = NullType(),
+ T76 t76 = NullType(),
+ T77 t77 = NullType(),
+ T78 t78 = NullType(),
+ T79 t79 = NullType(),
+ T80 t80 = NullType(),
+ T81 t81 = NullType(),
+ T82 t82 = NullType(),
+ T83 t83 = NullType(),
+ T84 t84 = NullType(),
+ T85 t85 = NullType(),
+ T86 t86 = NullType(),
+ T87 t87 = NullType(),
+ T88 t88 = NullType(),
+ T89 t89 = NullType(),
+ T90 t90 = NullType(),
+ T91 t91 = NullType(),
+ T92 t92 = NullType(),
+ T93 t93 = NullType(),
+ T94 t94 = NullType(),
+ T95 t95 = NullType(),
+ T96 t96 = NullType(),
+ T97 t97 = NullType(),
+ T98 t98 = NullType(),
+ T99 t99 = NullType(),
+ T100 t100 = NullType(),
+ T101 t101 = NullType(),
+ T102 t102 = NullType(),
+ T103 t103 = NullType(),
+ T104 t104 = NullType(),
+ T105 t105 = NullType(),
+ T106 t106 = NullType(),
+ T107 t107 = NullType(),
+ T108 t108 = NullType(),
+ T109 t109 = NullType(),
+ T110 t110 = NullType(),
+ T111 t111 = NullType(),
+ T112 t112 = NullType(),
+ T113 t113 = NullType(),
+ T114 t114 = NullType(),
+ T115 t115 = NullType(),
+ T116 t116 = NullType(),
+ T117 t117 = NullType(),
+ T118 t118 = NullType(),
+ T119 t119 = NullType(),
+ T120 t120 = NullType(),
+ T121 t121 = NullType(),
+ T122 t122 = NullType(),
+ T123 t123 = NullType(),
+ T124 t124 = NullType(),
+ T125 t125 = NullType(),
+ T126 t126 = NullType(),
+ T127 t127 = NullType()
+//@@@@EXCESSIVE-ARG-END
+ )
+ {
+ Event event;
+ SetArg<0, T0>::set(kernel_, t0);
+ SetArg<1, T1>::set(kernel_, t1);
+ SetArg<2, T2>::set(kernel_, t2);
+ SetArg<3, T3>::set(kernel_, t3);
+ SetArg<4, T4>::set(kernel_, t4);
+ SetArg<5, T5>::set(kernel_, t5);
+ SetArg<6, T6>::set(kernel_, t6);
+ SetArg<7, T7>::set(kernel_, t7);
+ SetArg<8, T8>::set(kernel_, t8);
+ SetArg<9, T9>::set(kernel_, t9);
+ SetArg<10, T10>::set(kernel_, t10);
+ SetArg<11, T11>::set(kernel_, t11);
+ SetArg<12, T12>::set(kernel_, t12);
+ SetArg<13, T13>::set(kernel_, t13);
+ SetArg<14, T14>::set(kernel_, t14);
+ SetArg<15, T15>::set(kernel_, t15);
+ SetArg<16, T16>::set(kernel_, t16);
+ SetArg<17, T17>::set(kernel_, t17);
+ SetArg<18, T18>::set(kernel_, t18);
+ SetArg<19, T19>::set(kernel_, t19);
+ SetArg<20, T20>::set(kernel_, t20);
+ SetArg<21, T21>::set(kernel_, t21);
+ SetArg<22, T22>::set(kernel_, t22);
+ SetArg<23, T23>::set(kernel_, t23);
+ SetArg<24, T24>::set(kernel_, t24);
+ SetArg<25, T25>::set(kernel_, t25);
+ SetArg<26, T26>::set(kernel_, t26);
+ SetArg<27, T27>::set(kernel_, t27);
+ SetArg<28, T28>::set(kernel_, t28);
+ SetArg<29, T29>::set(kernel_, t29);
+ SetArg<30, T30>::set(kernel_, t30);
+ SetArg<31, T31>::set(kernel_, t31);
+//@@@@EXCESSIVE-ARG-START
+ SetArg<32, T32>::set(kernel_, t32);
+ SetArg<33, T33>::set(kernel_, t33);
+ SetArg<34, T34>::set(kernel_, t34);
+ SetArg<35, T35>::set(kernel_, t35);
+ SetArg<36, T36>::set(kernel_, t36);
+ SetArg<37, T37>::set(kernel_, t37);
+ SetArg<38, T38>::set(kernel_, t38);
+ SetArg<39, T39>::set(kernel_, t39);
+ SetArg<40, T40>::set(kernel_, t40);
+ SetArg<41, T41>::set(kernel_, t41);
+ SetArg<42, T42>::set(kernel_, t42);
+ SetArg<43, T43>::set(kernel_, t43);
+ SetArg<44, T44>::set(kernel_, t44);
+ SetArg<45, T45>::set(kernel_, t45);
+ SetArg<46, T46>::set(kernel_, t46);
+ SetArg<47, T47>::set(kernel_, t47);
+ SetArg<48, T48>::set(kernel_, t48);
+ SetArg<49, T49>::set(kernel_, t49);
+ SetArg<50, T50>::set(kernel_, t50);
+ SetArg<51, T51>::set(kernel_, t51);
+ SetArg<52, T52>::set(kernel_, t52);
+ SetArg<53, T53>::set(kernel_, t53);
+ SetArg<54, T54>::set(kernel_, t54);
+ SetArg<55, T55>::set(kernel_, t55);
+ SetArg<56, T56>::set(kernel_, t56);
+ SetArg<57, T57>::set(kernel_, t57);
+ SetArg<58, T58>::set(kernel_, t58);
+ SetArg<59, T59>::set(kernel_, t59);
+ SetArg<60, T60>::set(kernel_, t60);
+ SetArg<61, T61>::set(kernel_, t61);
+ SetArg<62, T62>::set(kernel_, t62);
+ SetArg<63, T63>::set(kernImageGL(const Image3DGL& img)el_, t63);
+ SetArg<64, T64>::set(kernel_, t64);
+ SetArg<65, T65>::set(kernel_, t65);
+ SetArg<66, T66>::set(kernel_, t66);
+ SetArg<67, T67>::set(kernel_, t67);
+ SetArg<68, T68>::set(kernel_, t68);
+ SetArg<69, T69>::set(kernel_, t69);
+ SetArg<70, T70>::set(kernel_, t70);
+ SetArg<71, T71>::set(kernel_, t71);
+ SetArg<72, T72>::set(kernel_, t72);
+ SetArg<73, T73>::set(kernel_, t73);
+ SetArg<74, T74>::set(kernel_, t74);
+ SetArg<75, T75>::set(kernel_, t75);
+ SetArg<76, T76>::set(kernel_, t76);
+ SetArg<77, T77>::set(kernel_, t77);
+ SetArg<78, T78>::set(kernel_, t78);
+ SetArg<79, T79>::set(kernel_, t79);
+ SetArg<80, T80>::set(kernel_, t80);
+ SetArg<81, T81>::set(kernel_, t81);
+ SetArg<82, T82>::set(kernel_, t82);
+ SetArg<83, T83>::set(kernel_, t83);
+ SetArg<84, T84>::set(kernel_, t84);
+ SetArg<85, T85>::set(kernel_, t85);
+ SetArg<86, T86>::set(kernel_, t86);
+ SetArg<87, T87>::set(kernel_, t87);
+ SetArg<88, T88>::set(kernel_, t88);
+ SetArg<89, T89>::set(kernel_, t89);
+ SetArg<90, T90>::set(kernel_, t90);
+ SetArg<91, T91>::set(kernel_, t91);
+ SetArg<92, T92>::set(kernel_, t92);
+ SetArg<93, T93>::set(kernel_, t93);
+ SetArg<94, T94>::set(kernel_, t94);
+ SetArg<95, T95>::set(kernel_, t95);
+ SetArg<96, T96>::set(kernel_, t96);
+ SetArg<97, T97>::set(kernel_, t97);
+ SetArg<98, T98>::set(kernel_, t98);
+ SetArg<99, T99>::set(kernel_, t99);
+ SetArg<100, T100>::set(kernel_, t100);
+ SetArg<101, T101>::set(kernel_, t101);
+ SetArg<102, T102>::set(kernel_, t102);
+ SetArg<103, T103>::set(kernel_, t103);
+ SetArg<104, T104>::set(kernel_, t104);
+ SetArg<105, T105>::set(kernel_, t105);
+ SetArg<106, T106>::set(kernel_, t106);
+ SetArg<107, T107>::set(kernel_, t107);
+ SetArg<108, T108>::set(kernel_, t108);
+ SetArg<109, T109>::set(kernel_, t109);
+ SetArg<110, T110>::set(kernel_, t110);
+ SetArg<111, T111>::set(kernel_, t111);
+ SetArg<112, T112>::set(kernel_, t112);
+ SetArg<113, T113>::set(kernel_, t113);
+ SetArg<114, T114>::set(kernel_, t114);
+ SetArg<115, T115>::set(kernel_, t115);
+ SetArg<116, T116>::set(kernel_, t116);
+ SetArg<117, T117>::set(kernel_, t117);
+ SetArg<118, T118>::set(kernel_, t118);
+ SetArg<119, T119>::set(kernel_, t119);
+ SetArg<120, T120>::set(kernel_, t120);
+ SetArg<121, T121>::set(kernel_, t121);
+ SetArg<122, T122>::set(kernel_, t122);
+ SetArg<123, T123>::set(kernel_, t123);
+ SetArg<124, T124>::set(kernel_, t124);
+ SetArg<125, T125>::set(kernel_, t125);
+ SetArg<126, T126>::set(kernel_, t126);
+ SetArg<127, T127>::set(kernel_, t127);
+//@@@@EXCESSIVE-ARG-END
+
+ args.queue_.enqueueNDRangeKernel(
+ kernel_,
+ args.offset_,
+ args.global_,
+ args.local_,
+ &args.events_,
+ &event);
+
+ return event;
+ }
+
+};
+
+//------------------------------------------------------------------------------------------------------
+
+
+%FUNCTION_IMPLEMENTATION_REPLACEMENT_POINT%
+
+
+
+} // namespace detail
+
+//----------------------------------------------------------------------------------------------
+
+template <
+ typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType,
+ typename T3 = detail::NullType, typename T4 = detail::NullType,
+ typename T5 = detail::NullType, typename T6 = detail::NullType,
+ typename T7 = detail::NullType, typename T8 = detail::NullType,
+ typename T9 = detail::NullType, typename T10 = detail::NullType,
+ typename T11 = detail::NullType, typename T12 = detail::NullType,
+ typename T13 = detail::NullType, typename T14 = detail::NullType,
+ typename T15 = detail::NullType, typename T16 = detail::NullType,
+ typename T17 = detail::NullType, typename T18 = detail::NullType,
+ typename T19 = detail::NullType, typename T20 = detail::NullType,
+ typename T21 = detail::NullType, typename T22 = detail::NullType,
+ typename T23 = detail::NullType, typename T24 = detail::NullType,
+ typename T25 = detail::NullType, typename T26 = detail::NullType,
+ typename T27 = detail::NullType, typename T28 = detail::NullType,
+ typename T29 = detail::NullType, typename T30 = detail::NullType,
+ typename T31 = detail::NullType
+//@@@@EXCESSIVE-ARG-START
+
+ , typename T32 = detail::NullType,
+ typename T33 = detail::NullType, typename T34 = detail::NullType,
+ typename T35 = detail::NullType, typename T36 = detail::NullType,
+ typename T37 = detail::NullType, typename T38 = detail::NullType,
+ typename T39 = detail::NullType, typename T40 = detail::NullType,
+ typename T41 = detail::NullType, typename T42 = detail::NullType,
+ typename T43 = detail::NullType, typename T44 = detail::NullType,
+ typename T45 = detail::NullType, typename T46 = detail::NullType,
+ typename T47 = detail::NullType, typename T48 = detail::NullType,
+ typename T49 = detail::NullType, typename T50 = detail::NullType,
+ typename T51 = detail::NullType, typename T52 = detail::NullType,
+ typename T53 = detail::NullType, typename T54 = detail::NullType,
+ typename T55 = detail::NullType, typename T56 = detail::NullType,
+ typename T57 = detail::NullType, typename T58 = detail::NullType,
+ typename T59 = detail::NullType, typename T60 = detail::NullType,
+ typename T61 = detail::NullType, typename T62 = detail::NullType,
+ typename T63 = detail::NullType, typename T64 = detail::NullType,
+ typename T65 = detail::NullType, typename T66 = detail::NullType,
+ typename T67 = detail::NullType, typename T68 = detail::NullType,
+ typename T69 = detail::NullType, typename T70 = detail::NullType,
+ typename T71 = detail::NullType, typename T72 = detail::NullType,
+ typename T73 = detail::NullType, typename T74 = detail::NullType,
+ typename T75 = detail::NullType, typename T76 = detail::NullType,
+ typename T77 = detail::NullType, typename T78 = detail::NullType,
+ typename T79 = detail::NullType, typename T80 = detail::NullType,
+ typename T81 = detail::NullType, typename T82 = detail::NullType,
+ typename T83 = detail::NullType, typename T84 = detail::NullType,
+ typename T85 = detail::NullType, typename T86 = detail::NullType,
+ typename T87 = detail::NullType, typename T88 = detail::NullType,
+ typename T89 = detail::NullType, typename T90 = detail::NullType,
+ typename T91 = detail::NullType, typename T92 = detail::NullType,
+ typename T93 = detail::NullType, typename T94 = detail::NullType,
+ typename T95 = detail::NullType, typename T96 = detail::NullType,
+ typename T97 = detail::NullType, typename T98 = detail::NullType,
+ typename T99 = detail::NullType, typename T100 = detail::NullType,
+ typename T101 = detail::NullType, typename T102 = detail::NullType,
+ typename T103 = detail::NullType, typename T104 = detail::NullType,
+ typename T105 = detail::NullType, typename T106 = detail::NullType,
+ typename T107 = detail::NullType, typename T108 = detail::NullType,
+ typename T109 = detail::NullType, typename T110 = detail::NullType,
+ typename T111 = detail::NullType, typename T112 = detail::NullType,
+ typename T113 = detail::NullType, typename T114 = detail::NullType,
+ typename T115 = detail::NullType, typename T116 = detail::NullType,
+ typename T117 = detail::NullType, typename T118 = detail::NullType,
+ typename T119 = detail::NullType, typename T120 = detail::NullType,
+ typename T121 = detail::NullType, typename T122 = detail::NullType,
+ typename T123 = detail::NullType, typename T124 = detail::NullType,
+ typename T125 = detail::NullType, typename T126 = detail::NullType,
+ typename T127 = detail::NullType
+//@@@@EXCESSIVE-ARG-END
+>
+struct make_kernel :
+ public detail::functionImplementation_<
+ T0, T1, T2, T3,
+ T4, T5, T6, T7,
+ T8, T9, T10, T11,
+ T12, T13, T14, T15,
+ T16, T17, T18, T19,
+ T20, T21, T22, T23,
+ T24, T25, T26, T27,
+ T28, T29, T30, T31
+//@@@@EXCESSIVE-ARG-START
+ ,
+ T32, T33, T34, T35,
+ T36, T37, T38, T39,
+ T40, T41, T42, T43,
+ T44, T45, T46, T47,
+ T48, T49, T50, T51,
+ T52, T53, T54, T55,
+ T56, T57, T58, T59,
+ T60, T61, T62, T63,
+ T64, T65, T66, T67,
+ T68, T69, T70, T71,
+ T72, T73, T74, T75,
+ T76, T77, T78, T79,
+ T80, T81, T82, T83,
+ T84, T85, T86, T87,
+ T88, T89, T90, T91,
+ T92, T93, T94, T95,
+ T96, T97, T98, T99,
+ T100, T101, T102, T103,
+ T104, T105, T106, T107,
+ T108, T109, T110, T111,
+ T112, T113, T114, T115,
+ T116, T117, T118, T119,
+ T120, T121, T122, T123,
+ T124, T125, T126, T127
+//@@@@EXCESSIVE-ARG-END
+ >
+{
+public:
+ typedef detail::KernelFunctorGlobal<
+ T0, T1, T2, T3,
+ T4, T5, T6, T7,
+ T8, T9, T10, T11,
+ T12, T13, T14, T15,
+ T16, T17, T18, T19,
+ T20, T21, T22, T23,
+ T24, T25, T26, T27,
+ T28, T29, T30, T31
+//@@@@EXCESSIVE-ARG-START
+ ,
+ T32, T33, T34, T35,
+ T36, T37, T38, T39,
+ T40, T41, T42, T43,
+ T44, T45, T46, T47,
+ T48, T49, T50, T51,
+ T52, T53, T54, T55,
+ T56, T57, T58, T59,
+ T60, T61, T62, T63,
+ T64, T65, T66, T67,
+ T68, T69, T70, T71,
+ T72, T73, T74, T75,
+ T76, T77, T78, T79,
+ T80, T81, T82, T83,
+ T84, T85, T86, T87,
+ T88, T89, T90, T91,
+ T92, T93, T94, T95,
+ T96, T97, T98, T99,
+ T100, T101, T102, T103,
+ T104, T105, T106, T107,
+ T108, T109, T110, T111,
+ T112, T113, T114, T115,
+ T116, T117, T118, T119,
+ T120, T121, T122, T123,
+ T124, T125, T126, T127
+//@@@@EXCESSIVE-ARG-END
+ > FunctorType;
+
+ make_kernel(
+ const Program& program,
+ const STRING_CLASS name,
+ cl_int * err = NULL) :
+ detail::functionImplementation_<
+ T0, T1, T2, T3,
+ T4, T5, T6, T7,
+ T8, T9, T10, T11,
+ T12, T13, T14, T15,
+ T16, T17, T18, T19,
+ T20, T21, T22, T23,
+ T24, T25, T26, T27,
+ T28, T29, T30, T31
+//@@@@EXCESSIVE-ARG-START
+ ,
+ T32, T33, T34, T35,
+ T36, T37, T38, T39,
+ T40, T41, T42, T43,
+ T44, T45, T46, T47,
+ T48, T49, T50, T51,
+ T52, T53, T54, T55,
+ T56, T57, T58, T59,
+ T60, T61, T62, T63,
+ T64, T65, T66, T67,
+ T68, T69, T70, T71,
+ T72, T73, T74, T75,
+ T76, T77, T78, T79,
+ T80, T81, T82, T83,
+ T84, T85, T86, T87,
+ T88, T89, T90, T91,
+ T92, T93, T94, T95,
+ T96, T97, T98, T99,
+ T100, T101, T102, T103,
+ T104, T105, T106, T107,
+ T108, T109, T110, T111,
+ T112, T113, T114, T115,
+ T116, T117, T118, T119,
+ T120, T121, T122, T123,
+ T124, T125, T126, T127
+//@@@@EXCESSIVE-ARG-END
+ >(
+ FunctorType(program, name, err))
+ {}
+
+ make_kernel(
+ const Kernel kernel) :
+ detail::functionImplementation_<
+ T0, T1, T2, T3,
+ T4, T5, T6, T7,
+ T8, T9, T10, T11,
+ T12, T13, T14, T15,
+ T16, T17, T18, T19,
+ T20, T21, T22, T23,
+ T24, T25, T26, T27,
+ T28, T29, T30, T31
+//@@@@EXCESSIVE-ARG-START
+ ,
+ T32, T33, T34, T35,
+ T36, T37, T38, T39,
+ T40, T41, T42, T43,
+ T44, T45, T46, T47,
+ T48, T49, T50, T51,
+ T52, T53, T54, T55,
+ T56, T57, T58, T59,
+ T60, T61, T62, T63,
+ T64, T65, T66, T67,
+ T68, T69, T70, T71,
+ T72, T73, T74, T75,
+ T76, T77, T78, T79,
+ T80, T81, T82, T83,
+ T84, T85, T86, T87,
+ T88, T89, T90, T91,
+ T92, T93, T94, T95,
+ T96, T97, T98, T99,
+ T100, T101, T102, T103,
+ T104, T105, T106, T107,
+ T108, T109, T110, T111,
+ T112, T113, T114, T115,
+ T116, T117, T118, T119,
+ T120, T121, T122, T123,
+ T124, T125, T126, T127
+//@@@@EXCESSIVE-ARG-END
+ >(
+ FunctorType(kernel))
+ {}
+};
+
+
+//----------------------------------------------------------------------------------------------------------------------
+
+#undef __ERR_STR
+#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
+#undef __GET_DEVICE_INFO_ERR
+#undef __GET_PLATFORM_INFO_ERR
+#undef __GET_DEVICE_IDS_ERR
+#undef __GET_CONTEXT_INFO_ERR
+#undef __GET_EVENT_INFO_ERR
+#undef __GET_EVENT_PROFILE_INFO_ERR
+#undef __GET_MEM_OBJECT_INFO_ERR
+#undef __GET_IMAGE_INFO_ERR
+#undef __GET_SAMPLER_INFO_ERR
+#undef __GET_KERNEL_INFO_ERR
+#undef __GET_KERNEL_ARG_INFO_ERR
+#undef __GET_KERNEL_WORK_GROUP_INFO_ERR
+#undef __GET_PROGRAM_INFO_ERR
+#undef __GET_PROGRAM_BUILD_INFO_ERR
+#undef __GET_COMMAND_QUEUE_INFO_ERR
+
+#undef __CREATE_CONTEXT_ERR
+#undef __CREATE_CONTEXT_FROM_TYPE_ERR
+#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
+
+#undef __CREATE_BUFFER_ERR
+#undef __CREATE_SUBBUFFER_ERR
+#undef __CREATE_IMAGE2D_ERR
+#undef __CREATE_IMAGE3D_ERR
+#undef __CREATE_SAMPLER_ERR
+#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
+
+#undef __CREATE_USER_EVENT_ERR
+#undef __SET_USER_EVENT_STATUS_ERR
+#undef __SET_EVENT_CALLBACK_ERR
+#undef __SET_PRINTF_CALLBACK_ERR
+
+#undef __WAIT_FOR_EVENTS_ERR
+
+#undef __CREATE_KERNEL_ERR
+#undef __SET_KERNEL_ARGS_ERR
+#undef __CREATE_PROGRAM_WITH_SOURCE_ERR
+#undef __CREATE_PROGRAM_WITH_BINARY_ERR
+#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
+#undef __BUILD_PROGRAM_ERR
+#undef __CREATE_KERNELS_IN_PROGRAM_ERR
+
+#undef __CREATE_COMMAND_QUEUE_ERR
+#undef __SET_COMMAND_QUEUE_PROPERTY_ERR
+#undef __ENQUEUE_READ_BUFFER_ERR
+#undef __ENQUEUE_WRITE_BUFFER_ERR
+#undef __ENQUEUE_READ_BUFFER_RECT_ERR
+#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
+#undef __ENQEUE_COPY_BUFFER_ERR
+#undef __ENQEUE_COPY_BUFFER_RECT_ERR
+#undef __ENQUEUE_READ_IMAGE_ERR
+#undef __ENQUEUE_WRITE_IMAGE_ERR
+#undef __ENQUEUE_COPY_IMAGE_ERR
+#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
+#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
+#undef __ENQUEUE_MAP_BUFFER_ERR
+#undef __ENQUEUE_MAP_IMAGE_ERR
+#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
+#undef __ENQUEUE_NDRANGE_KERNEL_ERR
+#undef __ENQUEUE_TASK_ERR
+#undef __ENQUEUE_NATIVE_KERNEL
+
+#undef __CL_EXPLICIT_CONSTRUCTORS
+
+#undef __UNLOAD_COMPILER_ERR
+#endif //__CL_USER_OVERRIDE_ERROR_STRINGS
+
+#undef __CL_FUNCTION_TYPE
+
+// Extensions
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_VERSION_1_1)
+#undef __INIT_CL_EXT_FCN_PTR
+#endif // #if defined(CL_VERSION_1_1)
+#undef __CREATE_SUB_DEVICES
+
+#if defined(USE_CL_DEVICE_FISSION)
+#undef __PARAM_NAME_DEVICE_FISSION
+#endif // USE_CL_DEVICE_FISSION
+
+#undef __DEFAULT_NOT_INITIALIZED
+#undef __DEFAULT_BEING_INITIALIZED
+#undef __DEFAULT_INITIALIZED
+
+#undef CL_HPP_RVALUE_REFERENCES_SUPPORTED
+#undef CL_HPP_NOEXCEPT
+
+} // namespace cl
+
+#endif // CL_HPP_
diff --git a/input_cl2.hpp b/input_cl2.hpp
new file mode 100644
index 0000000..0d6e805
--- /dev/null
+++ b/input_cl2.hpp
@@ -0,0 +1,9570 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2016 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and/or associated documentation files (the
+ * "Materials"), to deal in the Materials without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Materials, and to
+ * permit persons to whom the Materials are furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
+ * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
+ * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
+ * https://www.khronos.org/registry/
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ ******************************************************************************/
+
+/*! \file
+ *
+ * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33),
+ * OpenCL 1.2 (rev 15) and OpenCL 2.0 (rev 29)
+ * \author Lee Howes and Bruce Merry
+ *
+ * Derived from the OpenCL 1.x C++ bindings written by
+ * Benedict R. Gaster, Laurent Morichetti and Lee Howes
+ * With additions and fixes from:
+ * Brian Cole, March 3rd 2010 and April 2012
+ * Matt Gruenke, April 2012.
+ * Bruce Merry, February 2013.
+ * Tom Deakin and Simon McIntosh-Smith, July 2013
+ * James Price, 2015-
+ *
+ * \version 2.0.10
+ * \date 2016-07-20
+ *
+ * Optional extension support
+ *
+ * cl_ext_device_fission
+ * #define CL_HPP_USE_CL_DEVICE_FISSION
+ * cl_khr_d3d10_sharing
+ * #define CL_HPP_USE_DX_INTEROP
+ * cl_khr_sub_groups
+ * #define CL_HPP_USE_CL_SUB_GROUPS_KHR
+ *
+ * Doxygen documentation for this header is available here:
+ *
+ * http://khronosgroup.github.io/OpenCL-CLHPP/
+ *
+ * The latest version of this header can be found on the GitHub releases page:
+ *
+ * https://github.com/KhronosGroup/OpenCL-CLHPP/releases
+ *
+ * Bugs and patches can be submitted to the GitHub repository:
+ *
+ * https://github.com/KhronosGroup/OpenCL-CLHPP
+ */
+
+/*! \mainpage
+ * \section intro Introduction
+ * For many large applications C++ is the language of choice and so it seems
+ * reasonable to define C++ bindings for OpenCL.
+ *
+ * The interface is contained with a single C++ header file \em cl2.hpp and all
+ * definitions are contained within the namespace \em cl. There is no additional
+ * requirement to include \em cl.h and to use either the C++ or original C
+ * bindings; it is enough to simply include \em cl2.hpp.
+ *
+ * The bindings themselves are lightweight and correspond closely to the
+ * underlying C API. Using the C++ bindings introduces no additional execution
+ * overhead.
+ *
+ * There are numerous compatibility, portability and memory management
+ * fixes in the new header as well as additional OpenCL 2.0 features.
+ * As a result the header is not directly backward compatible and for this
+ * reason we release it as cl2.hpp rather than a new version of cl.hpp.
+ *
+ *
+ * \section compatibility Compatibility
+ * Due to the evolution of the underlying OpenCL API the 2.0 C++ bindings
+ * include an updated approach to defining supported feature versions
+ * and the range of valid underlying OpenCL runtime versions supported.
+ *
+ * The combination of preprocessor macros CL_HPP_TARGET_OPENCL_VERSION and
+ * CL_HPP_MINIMUM_OPENCL_VERSION control this range. These are three digit
+ * decimal values representing OpenCL runime versions. The default for
+ * the target is 200, representing OpenCL 2.0 and the minimum is also
+ * defined as 200. These settings would use 2.0 API calls only.
+ * If backward compatibility with a 1.2 runtime is required, the minimum
+ * version may be set to 120.
+ *
+ * Note that this is a compile-time setting, and so affects linking against
+ * a particular SDK version rather than the versioning of the loaded runtime.
+ *
+ * The earlier versions of the header included basic vector and string
+ * classes based loosely on STL versions. These were difficult to
+ * maintain and very rarely used. For the 2.0 header we now assume
+ * the presence of the standard library unless requested otherwise.
+ * We use std::array, std::vector, std::shared_ptr and std::string
+ * throughout to safely manage memory and reduce the chance of a
+ * recurrance of earlier memory management bugs.
+ *
+ * These classes are used through typedefs in the cl namespace:
+ * cl::array, cl::vector, cl::pointer and cl::string.
+ * In addition cl::allocate_pointer forwards to std::allocate_shared
+ * by default.
+ * In all cases these standard library classes can be replaced with
+ * custom interface-compatible versions using the CL_HPP_NO_STD_ARRAY,
+ * CL_HPP_NO_STD_VECTOR, CL_HPP_NO_STD_UNIQUE_PTR and
+ * CL_HPP_NO_STD_STRING macros.
+ *
+ * The OpenCL 1.x versions of the C++ bindings included a size_t wrapper
+ * class to interface with kernel enqueue. This caused unpleasant interactions
+ * with the standard size_t declaration and led to namespacing bugs.
+ * In the 2.0 version we have replaced this with a std::array-based interface.
+ * However, the old behaviour can be regained for backward compatibility
+ * using the CL_HPP_ENABLE_SIZE_T_COMPATIBILITY macro.
+ *
+ * Finally, the program construction interface used a clumsy vector-of-pairs
+ * design in the earlier versions. We have replaced that with a cleaner
+ * vector-of-vectors and vector-of-strings design. However, for backward
+ * compatibility old behaviour can be regained with the
+ * CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY macro.
+ *
+ * In OpenCL 2.0 OpenCL C is not entirely backward compatibility with
+ * earlier versions. As a result a flag must be passed to the OpenCL C
+ * compiled to request OpenCL 2.0 compilation of kernels with 1.2 as
+ * the default in the absence of the flag.
+ * In some cases the C++ bindings automatically compile code for ease.
+ * For those cases the compilation defaults to OpenCL C 2.0.
+ * If this is not wanted, the CL_HPP_CL_1_2_DEFAULT_BUILD macro may
+ * be specified to assume 1.2 compilation.
+ * If more fine-grained decisions on a per-kernel bases are required
+ * then explicit build operations that take the flag should be used.
+ *
+ *
+ * \section parameterization Parameters
+ * This header may be parameterized by a set of preprocessor macros.
+ *
+ * - CL_HPP_TARGET_OPENCL_VERSION
+ *
+ * Defines the target OpenCL runtime version to build the header
+ * against. Defaults to 200, representing OpenCL 2.0.
+ *
+ * - CL_HPP_NO_STD_STRING
+ *
+ * Do not use the standard library string class. cl::string is not
+ * defined and may be defined by the user before cl2.hpp is
+ * included.
+ *
+ * - CL_HPP_NO_STD_VECTOR
+ *
+ * Do not use the standard library vector class. cl::vector is not
+ * defined and may be defined by the user before cl2.hpp is
+ * included.
+ *
+ * - CL_HPP_NO_STD_ARRAY
+ *
+ * Do not use the standard library array class. cl::array is not
+ * defined and may be defined by the user before cl2.hpp is
+ * included.
+ *
+ * - CL_HPP_NO_STD_UNIQUE_PTR
+ *
+ * Do not use the standard library unique_ptr class. cl::pointer and
+ * the cl::allocate_pointer functions are not defined and may be
+ * defined by the user before cl2.hpp is included.
+ *
+ * - CL_HPP_ENABLE_DEVICE_FISSION
+ *
+ * Enables device fission for OpenCL 1.2 platforms.
+ *
+ * - CL_HPP_ENABLE_EXCEPTIONS
+ *
+ * Enable exceptions for use in the C++ bindings header. This is the
+ * preferred error handling mechanism but is not required.
+ *
+ * - CL_HPP_ENABLE_SIZE_T_COMPATIBILITY
+ *
+ * Backward compatibility option to support cl.hpp-style size_t
+ * class. Replaces the updated std::array derived version and
+ * removal of size_t from the namespace. Note that in this case the
+ * new size_t class is placed in the cl::compatibility namespace and
+ * thus requires an additional using declaration for direct backward
+ * compatibility.
+ *
+ * - CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY
+ *
+ * Enable older vector of pairs interface for construction of
+ * programs.
+ *
+ * - CL_HPP_CL_1_2_DEFAULT_BUILD
+ *
+ * Default to OpenCL C 1.2 compilation rather than OpenCL C 2.0
+ * applies to use of cl::Program construction and other program
+ * build variants.
+ *
+ *
+ * \section example Example
+ *
+ * The following example shows a general use case for the C++
+ * bindings, including support for the optional exception feature and
+ * also the supplied vector and string classes, see following sections for
+ * decriptions of these features.
+ *
+ * \code
+ #define CL_HPP_ENABLE_EXCEPTIONS
+ #define CL_HPP_TARGET_OPENCL_VERSION 200
+
+ #include <CL/cl2.hpp>
+ #include <iostream>
+ #include <vector>
+ #include <memory>
+ #include <algorithm>
+
+ const int numElements = 32;
+
+ int main(void)
+ {
+ // Filter for a 2.0 platform and set it as the default
+ std::vector<cl::Platform> platforms;
+ cl::Platform::get(&platforms);
+ cl::Platform plat;
+ for (auto &p : platforms) {
+ std::string platver = p.getInfo<CL_PLATFORM_VERSION>();
+ if (platver.find("OpenCL 2.") != std::string::npos) {
+ plat = p;
+ }
+ }
+ if (plat() == 0) {
+ std::cout << "No OpenCL 2.0 platform found.";
+ return -1;
+ }
+
+ cl::Platform newP = cl::Platform::setDefault(plat);
+ if (newP != plat) {
+ std::cout << "Error setting default platform.";
+ return -1;
+ }
+
+ // Use C++11 raw string literals for kernel source code
+ std::string kernel1{R"CLC(
+ global int globalA;
+ kernel void updateGlobal()
+ {
+ globalA = 75;
+ }
+ )CLC"};
+ std::string kernel2{R"CLC(
+ typedef struct { global int *bar; } Foo;
+ kernel void vectorAdd(global const Foo* aNum, global const int *inputA, global const int *inputB,
+ global int *output, int val, write_only pipe int outPipe, queue_t childQueue)
+ {
+ output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar);
+ write_pipe(outPipe, &val);
+ queue_t default_queue = get_default_queue();
+ ndrange_t ndrange = ndrange_1D(get_global_size(0)/2, get_global_size(0)/2);
+
+ // Have a child kernel write into third quarter of output
+ enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
+ ^{
+ output[get_global_size(0)*2 + get_global_id(0)] =
+ inputA[get_global_size(0)*2 + get_global_id(0)] + inputB[get_global_size(0)*2 + get_global_id(0)] + globalA;
+ });
+
+ // Have a child kernel write into last quarter of output
+ enqueue_kernel(childQueue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
+ ^{
+ output[get_global_size(0)*3 + get_global_id(0)] =
+ inputA[get_global_size(0)*3 + get_global_id(0)] + inputB[get_global_size(0)*3 + get_global_id(0)] + globalA + 2;
+ });
+ }
+ )CLC"};
+
+ // New simpler string interface style
+ std::vector<std::string> programStrings {kernel1, kernel2};
+
+ cl::Program vectorAddProgram(programStrings);
+ try {
+ vectorAddProgram.build("-cl-std=CL2.0");
+ }
+ catch (...) {
+ // Print build info for all devices
+ cl_int buildErr = CL_SUCCESS;
+ auto buildInfo = vectorAddProgram.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&buildErr);
+ for (auto &pair : buildInfo) {
+ std::cerr << pair.second << std::endl << std::endl;
+ }
+
+ return 1;
+ }
+
+ typedef struct { int *bar; } Foo;
+
+ // Get and run kernel that initializes the program-scope global
+ // A test for kernels that take no arguments
+ auto program2Kernel =
+ cl::KernelFunctor<>(vectorAddProgram, "updateGlobal");
+ program2Kernel(
+ cl::EnqueueArgs(
+ cl::NDRange(1)));
+
+ //////////////////
+ // SVM allocations
+
+ auto anSVMInt = cl::allocate_svm<int, cl::SVMTraitCoarse<>>();
+ *anSVMInt = 5;
+ cl::SVMAllocator<Foo, cl::SVMTraitCoarse<cl::SVMTraitReadOnly<>>> svmAllocReadOnly;
+ auto fooPointer = cl::allocate_pointer<Foo>(svmAllocReadOnly);
+ fooPointer->bar = anSVMInt.get();
+ cl::SVMAllocator<int, cl::SVMTraitCoarse<>> svmAlloc;
+ std::vector<int, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>> inputA(numElements, 1, svmAlloc);
+ cl::coarse_svm_vector<int> inputB(numElements, 2, svmAlloc);
+
+ //
+ //////////////
+
+ // Traditional cl_mem allocations
+ std::vector<int> output(numElements, 0xdeadbeef);
+ cl::Buffer outputBuffer(begin(output), end(output), false);
+ cl::Pipe aPipe(sizeof(cl_int), numElements / 2);
+
+ // Default command queue, also passed in as a parameter
+ cl::DeviceCommandQueue defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault(
+ cl::Context::getDefault(), cl::Device::getDefault());
+
+ auto vectorAddKernel =
+ cl::KernelFunctor<
+ decltype(fooPointer)&,
+ int*,
+ cl::coarse_svm_vector<int>&,
+ cl::Buffer,
+ int,
+ cl::Pipe&,
+ cl::DeviceCommandQueue
+ >(vectorAddProgram, "vectorAdd");
+
+ // Ensure that the additional SVM pointer is available to the kernel
+ // This one was not passed as a parameter
+ vectorAddKernel.setSVMPointers(anSVMInt);
+
+ // Hand control of coarse allocations to runtime
+ cl::enqueueUnmapSVM(anSVMInt);
+ cl::enqueueUnmapSVM(fooPointer);
+ cl::unmapSVM(inputB);
+ cl::unmapSVM(output2);
+
+ cl_int error;
+ vectorAddKernel(
+ cl::EnqueueArgs(
+ cl::NDRange(numElements/2),
+ cl::NDRange(numElements/2)),
+ fooPointer,
+ inputA.data(),
+ inputB,
+ outputBuffer,
+ 3,
+ aPipe,
+ defaultDeviceQueue,
+ error
+ );
+
+ cl::copy(outputBuffer, begin(output), end(output));
+ // Grab the SVM output vector using a map
+ cl::mapSVM(output2);
+
+ cl::Device d = cl::Device::getDefault();
+
+ std::cout << "Output:\n";
+ for (int i = 1; i < numElements; ++i) {
+ std::cout << "\t" << output[i] << "\n";
+ }
+ std::cout << "\n\n";
+
+ return 0;
+ }
+ *
+ * \endcode
+ *
+ */
+#ifndef CL_HPP_
+#define CL_HPP_
+
+/* Handle deprecated preprocessor definitions. In each case, we only check for
+ * the old name if the new name is not defined, so that user code can define
+ * both and hence work with either version of the bindings.
+ */
+#if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
+# pragma message("cl2.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
+# define CL_HPP_USE_DX_INTEROP
+#endif
+#if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
+# pragma message("cl2.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
+# define CL_HPP_USE_CL_DEVICE_FISSION
+#endif
+#if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
+# pragma message("cl2.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
+# define CL_HPP_ENABLE_EXCEPTIONS
+#endif
+#if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
+# pragma message("cl2.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
+# define CL_HPP_NO_STD_VECTOR
+#endif
+#if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
+# pragma message("cl2.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
+# define CL_HPP_NO_STD_STRING
+#endif
+#if defined(VECTOR_CLASS)
+# pragma message("cl2.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
+#endif
+#if defined(STRING_CLASS)
+# pragma message("cl2.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
+#endif
+#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
+# pragma message("cl2.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
+# define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
+#endif
+
+/* Warn about features that are no longer supported
+ */
+#if defined(__USE_DEV_VECTOR)
+# pragma message("cl2.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
+#endif
+#if defined(__USE_DEV_STRING)
+# pragma message("cl2.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
+#endif
+
+/* Detect which version to target */
+#if !defined(CL_HPP_TARGET_OPENCL_VERSION)
+# pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 200 (OpenCL 2.0)")
+# define CL_HPP_TARGET_OPENCL_VERSION 200
+#endif
+#if CL_HPP_TARGET_OPENCL_VERSION != 100 && CL_HPP_TARGET_OPENCL_VERSION != 110 && CL_HPP_TARGET_OPENCL_VERSION != 120 && CL_HPP_TARGET_OPENCL_VERSION != 200
+# pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120 or 200). It will be set to 200")
+# undef CL_HPP_TARGET_OPENCL_VERSION
+# define CL_HPP_TARGET_OPENCL_VERSION 200
+#endif
+
+#if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
+# define CL_HPP_MINIMUM_OPENCL_VERSION 200
+#endif
+#if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && CL_HPP_MINIMUM_OPENCL_VERSION != 110 && CL_HPP_MINIMUM_OPENCL_VERSION != 120 && CL_HPP_MINIMUM_OPENCL_VERSION != 200
+# pragma message("cl2.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120 or 200). It will be set to 100")
+# undef CL_HPP_MINIMUM_OPENCL_VERSION
+# define CL_HPP_MINIMUM_OPENCL_VERSION 100
+#endif
+#if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
+# error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
+#endif
+
+#if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
+# define CL_USE_DEPRECATED_OPENCL_1_0_APIS
+#endif
+#if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+# define CL_USE_DEPRECATED_OPENCL_1_1_APIS
+#endif
+#if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
+# define CL_USE_DEPRECATED_OPENCL_1_2_APIS
+#endif
+#if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
+# define CL_USE_DEPRECATED_OPENCL_2_0_APIS
+#endif
+
+#ifdef _WIN32
+
+#include <malloc.h>
+
+#if defined(CL_HPP_USE_DX_INTEROP)
+#include <CL/cl_d3d10.h>
+#include <CL/cl_dx9_media_sharing.h>
+#endif
+#endif // _WIN32
+
+#if defined(_MSC_VER)
+#include <intrin.h>
+#endif // _MSC_VER
+
+ // Check for a valid C++ version
+
+// Need to do both tests here because for some reason __cplusplus is not
+// updated in visual studio
+#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
+#error Visual studio 2013 or another C++11-supporting compiler required
+#endif
+
+//
+#if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
+#include <CL/cl_ext.h>
+#endif
+
+#if defined(__APPLE__) || defined(__MACOSX)
+#include <OpenCL/opencl.h>
+#else
+#include <CL/opencl.h>
+#endif // !__APPLE__
+
+#if (__cplusplus >= 201103L)
+#define CL_HPP_NOEXCEPT_ noexcept
+#else
+#define CL_HPP_NOEXCEPT_
+#endif
+
+#if defined(_MSC_VER)
+# define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
+#else
+# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
+#endif // !_MSC_VER
+
+// Define deprecated prefixes and suffixes to ensure compilation
+// in case they are not pre-defined
+#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
+#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
+#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
+#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
+
+#if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
+#define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
+#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
+#if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED)
+#define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
+#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
+
+#if !defined(CL_CALLBACK)
+#define CL_CALLBACK
+#endif //CL_CALLBACK
+
+#include <utility>
+#include <limits>
+#include <iterator>
+#include <mutex>
+#include <cstring>
+#include <functional>
+
+
+// Define a size_type to represent a correctly resolved size_t
+#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
+namespace cl {
+ using size_type = ::size_t;
+} // namespace cl
+#else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
+namespace cl {
+ using size_type = size_t;
+} // namespace cl
+#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
+
+
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+#include <exception>
+#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
+
+#if !defined(CL_HPP_NO_STD_VECTOR)
+#include <vector>
+namespace cl {
+ template < class T, class Alloc = std::allocator<T> >
+ using vector = std::vector<T, Alloc>;
+} // namespace cl
+#endif // #if !defined(CL_HPP_NO_STD_VECTOR)
+
+#if !defined(CL_HPP_NO_STD_STRING)
+#include <string>
+namespace cl {
+ using string = std::string;
+} // namespace cl
+#endif // #if !defined(CL_HPP_NO_STD_STRING)
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
+#include <memory>
+namespace cl {
+ // Replace unique_ptr and allocate_pointer for internal use
+ // to allow user to replace them
+ template<class T, class D>
+ using pointer = std::unique_ptr<T, D>;
+} // namespace cl
+#endif
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+#if !defined(CL_HPP_NO_STD_ARRAY)
+#include <array>
+namespace cl {
+ template < class T, size_type N >
+ using array = std::array<T, N>;
+} // namespace cl
+#endif // #if !defined(CL_HPP_NO_STD_ARRAY)
+
+// Define size_type appropriately to allow backward-compatibility
+// use of the old size_t interface class
+#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
+namespace cl {
+ namespace compatibility {
+ /*! \brief class used to interface between C++ and
+ * OpenCL C calls that require arrays of size_t values, whose
+ * size is known statically.
+ */
+ template <int N>
+ class size_t
+ {
+ private:
+ size_type data_[N];
+
+ public:
+ //! \brief Initialize size_t to all 0s
+ size_t()
+ {
+ for (int i = 0; i < N; ++i) {
+ data_[i] = 0;
+ }
+ }
+
+ size_t(const array<size_type, N> &rhs)
+ {
+ for (int i = 0; i < N; ++i) {
+ data_[i] = rhs[i];
+ }
+ }
+
+ size_type& operator[](int index)
+ {
+ return data_[index];
+ }
+
+ const size_type& operator[](int index) const
+ {
+ return data_[index];
+ }
+
+ //! \brief Conversion operator to T*.
+ operator size_type* () { return data_; }
+
+ //! \brief Conversion operator to const T*.
+ operator const size_type* () const { return data_; }
+
+ operator array<size_type, N>() const
+ {
+ array<size_type, N> ret;
+
+ for (int i = 0; i < N; ++i) {
+ ret[i] = data_[i];
+ }
+ return ret;
+ }
+ };
+ } // namespace compatibility
+
+ template<int N>
+ using size_t = compatibility::size_t<N>;
+} // namespace cl
+#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
+
+// Helper alias to avoid confusing the macros
+namespace cl {
+ namespace detail {
+ using size_t_array = array<size_type, 3>;
+ } // namespace detail
+} // namespace cl
+
+
+/*! \namespace cl
+ *
+ * \brief The OpenCL C++ bindings are defined within this namespace.
+ *
+ */
+namespace cl {
+ class Memory;
+
+#define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
+ if (!pfn_##name) { \
+ pfn_##name = (PFN_##name) \
+ clGetExtensionFunctionAddress(#name); \
+ if (!pfn_##name) { \
+ } \
+ }
+
+#define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
+ if (!pfn_##name) { \
+ pfn_##name = (PFN_##name) \
+ clGetExtensionFunctionAddressForPlatform(platform, #name); \
+ if (!pfn_##name) { \
+ } \
+ }
+
+ class Program;
+ class Device;
+ class Context;
+ class CommandQueue;
+ class DeviceCommandQueue;
+ class Memory;
+ class Buffer;
+ class Pipe;
+
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ /*! \brief Exception class
+ *
+ * This may be thrown by API functions when CL_HPP_ENABLE_EXCEPTIONS is defined.
+ */
+ class Error : public std::exception
+ {
+ private:
+ cl_int err_;
+ const char * errStr_;
+ public:
+ /*! \brief Create a new CL error exception for a given error code
+ * and corresponding message.
+ *
+ * \param err error code value.
+ *
+ * \param errStr a descriptive string that must remain in scope until
+ * handling of the exception has concluded. If set, it
+ * will be returned by what().
+ */
+ Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
+ {}
+
+ ~Error() throw() {}
+
+ /*! \brief Get error string associated with exception
+ *
+ * \return A memory pointer to the error message string.
+ */
+ virtual const char * what() const throw ()
+ {
+ if (errStr_ == NULL) {
+ return "empty";
+ }
+ else {
+ return errStr_;
+ }
+ }
+
+ /*! \brief Get error code associated with exception
+ *
+ * \return The error code.
+ */
+ cl_int err(void) const { return err_; }
+ };
+#define CL_HPP_ERR_STR_(x) #x
+#else
+#define CL_HPP_ERR_STR_(x) NULL
+#endif // CL_HPP_ENABLE_EXCEPTIONS
+
+
+namespace detail
+{
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+static inline cl_int errHandler (
+ cl_int err,
+ const char * errStr = NULL)
+{
+ if (err != CL_SUCCESS) {
+ throw Error(err, errStr);
+ }
+ return err;
+}
+#else
+static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
+{
+ (void) errStr; // suppress unused variable warning
+ return err;
+}
+#endif // CL_HPP_ENABLE_EXCEPTIONS
+}
+
+
+
+//! \cond DOXYGEN_DETAIL
+#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
+#define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
+#define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
+#define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
+#define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
+#define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
+#define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
+#define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
+#define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
+#define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
+#define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
+#define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
+#define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
+#define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
+#define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
+
+#define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
+#define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
+#define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
+
+#define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
+#define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
+#define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
+#define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
+#define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
+#define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
+#define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
+#define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
+
+#define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
+#define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
+#define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
+#define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
+
+#define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
+#define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
+#define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
+#define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
+#define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+#define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
+#define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
+#define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
+#define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
+#define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
+#define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
+#define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
+#define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
+#define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
+#define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
+#define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
+#define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
+#define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
+#define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
+#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
+#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
+#define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
+#define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
+#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
+#define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
+#define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+#define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
+#define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
+
+#define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
+#define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
+
+
+#define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
+#define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
+#define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
+#define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
+#define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
+
+/**
+ * CL 1.2 version that uses device fission.
+ */
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
+#else
+#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+#define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
+#define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
+#define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
+#define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
+#define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
+#define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
+#define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
+#define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
+#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+
+/**
+ * Deprecated APIs for 2.0
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
+#define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
+#define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
+#define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
+#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+
+/**
+ * CL 1.2 marker and barrier commands
+ */
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+#define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
+#define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+#endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
+//! \endcond
+
+
+namespace detail {
+
+// Generic getInfoHelper. The final parameter is used to guide overload
+// resolution: the actual parameter passed is an int, which makes this
+// a worse conversion sequence than a specialization that declares the
+// parameter as an int.
+template<typename Functor, typename T>
+inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
+{
+ return f(name, sizeof(T), param, NULL);
+}
+
+// Specialized for getInfo<CL_PROGRAM_BINARIES>
+// Assumes that the output vector was correctly resized on the way in
+template <typename Func>
+inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
+{
+ if (name != CL_PROGRAM_BINARIES) {
+ return CL_INVALID_VALUE;
+ }
+ if (param) {
+ // Create array of pointers, calculate total size and pass pointer array in
+ size_type numBinaries = param->size();
+ vector<unsigned char*> binariesPointers(numBinaries);
+
+ for (size_type i = 0; i < numBinaries; ++i)
+ {
+ binariesPointers[i] = (*param)[i].data();
+ }
+
+ cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL);
+
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ }
+
+
+ return CL_SUCCESS;
+}
+
+// Specialized getInfoHelper for vector params
+template <typename Func, typename T>
+inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
+{
+ size_type required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ const size_type elements = required / sizeof(T);
+
+ // Temporary to avoid changing param on an error
+ vector<T> localData(elements);
+ err = f(name, required, localData.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ if (param) {
+ *param = std::move(localData);
+ }
+
+ return CL_SUCCESS;
+}
+
+/* Specialization for reference-counted types. This depends on the
+ * existence of Wrapper<T>::cl_type, and none of the other types having the
+ * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
+ * does not work, because when using a derived type (e.g. Context) the generic
+ * template will provide a better match.
+ */
+template <typename Func, typename T>
+inline cl_int getInfoHelper(
+ Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
+{
+ size_type required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ const size_type elements = required / sizeof(typename T::cl_type);
+
+ vector<typename T::cl_type> value(elements);
+ err = f(name, required, value.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ if (param) {
+ // Assign to convert CL type to T for each element
+ param->resize(elements);
+
+ // Assign to param, constructing with retain behaviour
+ // to correctly capture each underlying CL object
+ for (size_type i = 0; i < elements; i++) {
+ (*param)[i] = T(value[i], true);
+ }
+ }
+ return CL_SUCCESS;
+}
+
+// Specialized GetInfoHelper for string params
+template <typename Func>
+inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
+{
+ size_type required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ // std::string has a constant data member
+ // a char vector does not
+ if (required > 0) {
+ vector<char> value(required);
+ err = f(name, required, value.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ if (param) {
+ param->assign(begin(value), prev(end(value)));
+ }
+ }
+ else if (param) {
+ param->assign("");
+ }
+ return CL_SUCCESS;
+}
+
+// Specialized GetInfoHelper for clsize_t params
+template <typename Func, size_type N>
+inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
+{
+ size_type required;
+ cl_int err = f(name, 0, NULL, &required);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ size_type elements = required / sizeof(size_type);
+ vector<size_type> value(elements, 0);
+
+ err = f(name, required, value.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+
+ // Bound the copy with N to prevent overruns
+ // if passed N > than the amount copied
+ if (elements > N) {
+ elements = N;
+ }
+ for (size_type i = 0; i < elements; ++i) {
+ (*param)[i] = value[i];
+ }
+
+ return CL_SUCCESS;
+}
+
+template<typename T> struct ReferenceHandler;
+
+/* Specialization for reference-counted types. This depends on the
+ * existence of Wrapper<T>::cl_type, and none of the other types having the
+ * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
+ * does not work, because when using a derived type (e.g. Context) the generic
+ * template will provide a better match.
+ */
+template<typename Func, typename T>
+inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
+{
+ typename T::cl_type value;
+ cl_int err = f(name, sizeof(value), &value, NULL);
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ *param = value;
+ if (value != NULL)
+ {
+ err = param->retain();
+ if (err != CL_SUCCESS) {
+ return err;
+ }
+ }
+ return CL_SUCCESS;
+}
+
+#define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
+ F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
+ F(cl_platform_info, CL_PLATFORM_VERSION, string) \
+ F(cl_platform_info, CL_PLATFORM_NAME, string) \
+ F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
+ F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
+ \
+ F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
+ F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
+ F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
+ F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
+ F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
+ F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
+ F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
+ F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
+ F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
+ F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
+ F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
+ F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
+ F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
+ F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
+ F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
+ F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
+ F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
+ F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
+ F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
+ F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
+ F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
+ F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
+ F(cl_device_info, CL_DEVICE_NAME, string) \
+ F(cl_device_info, CL_DEVICE_VENDOR, string) \
+ F(cl_device_info, CL_DRIVER_VERSION, string) \
+ F(cl_device_info, CL_DEVICE_PROFILE, string) \
+ F(cl_device_info, CL_DEVICE_VERSION, string) \
+ F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
+ \
+ F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
+ F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
+ F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
+ \
+ F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
+ F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
+ F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
+ F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
+ \
+ F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
+ F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
+ F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
+ F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
+ \
+ F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
+ F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
+ F(cl_mem_info, CL_MEM_SIZE, size_type) \
+ F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
+ F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
+ F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
+ F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
+ \
+ F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
+ F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
+ F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
+ F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
+ F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
+ F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
+ F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
+ \
+ F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
+ F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
+ F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
+ F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
+ F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
+ \
+ F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
+ F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
+ F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
+ F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
+ F(cl_program_info, CL_PROGRAM_SOURCE, string) \
+ F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
+ F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
+ \
+ F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
+ F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
+ F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
+ \
+ F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
+ F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
+ F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
+ F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
+ F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
+ \
+ F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
+ F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
+ F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
+ \
+ F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
+ F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
+ F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
+ F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
+
+
+#define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
+ F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
+ F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
+ F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
+ F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
+ F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
+ \
+ F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
+ F(cl_mem_info, CL_MEM_OFFSET, size_type) \
+ \
+ F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
+ F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
+ \
+ F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
+
+#define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
+ F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
+ F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
+ \
+ F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
+ \
+ F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
+ \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
+ F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
+ \
+ F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
+ F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
+ F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
+ F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \
+ F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
+ F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
+ \
+ F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
+ F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
+ F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
+
+#define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
+ F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
+ F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
+ F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
+ F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
+ F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
+ F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
+ F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
+ F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
+ F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
+ F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
+
+#define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
+ F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
+ F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
+ F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
+ F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
+ F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
+
+template <typename enum_type, cl_int Name>
+struct param_traits {};
+
+#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
+struct token; \
+template<> \
+struct param_traits<detail:: token,param_name> \
+{ \
+ enum { value = param_name }; \
+ typedef T param_type; \
+};
+
+CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
+#if CL_HPP_TARGET_OPENCL_VERSION >= 110
+CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+
+
+// Flags deprecated in OpenCL 2.0
+#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
+ F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
+
+#define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
+ F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
+
+#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
+ F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
+
+// Include deprecated query flags based on versions
+// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
+#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
+CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
+#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
+#if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
+CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
+#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
+#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
+CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
+#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
+
+#if defined(CL_HPP_USE_CL_DEVICE_FISSION)
+CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
+#endif // CL_HPP_USE_CL_DEVICE_FISSION
+
+#ifdef CL_PLATFORM_ICD_SUFFIX_KHR
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
+#endif
+
+#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
+#endif
+
+#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
+#endif
+#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_SIMD_WIDTH_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
+#endif
+#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
+#endif
+
+#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
+#endif
+#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
+#endif
+#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
+#endif
+#ifdef CL_DEVICE_WARP_SIZE_NV
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
+#endif
+#ifdef CL_DEVICE_GPU_OVERLAP_NV
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
+#endif
+#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
+#endif
+#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
+CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
+#endif
+
+// Convenience functions
+
+template <typename Func, typename T>
+inline cl_int
+getInfo(Func f, cl_uint name, T* param)
+{
+ return getInfoHelper(f, name, param, 0);
+}
+
+template <typename Func, typename Arg0>
+struct GetInfoFunctor0
+{
+ Func f_; const Arg0& arg0_;
+ cl_int operator ()(
+ cl_uint param, size_type size, void* value, size_type* size_ret)
+ { return f_(arg0_, param, size, value, size_ret); }
+};
+
+template <typename Func, typename Arg0, typename Arg1>
+struct GetInfoFunctor1
+{
+ Func f_; const Arg0& arg0_; const Arg1& arg1_;
+ cl_int operator ()(
+ cl_uint param, size_type size, void* value, size_type* size_ret)
+ { return f_(arg0_, arg1_, param, size, value, size_ret); }
+};
+
+template <typename Func, typename Arg0, typename T>
+inline cl_int
+getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
+{
+ GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
+ return getInfoHelper(f0, name, param, 0);
+}
+
+template <typename Func, typename Arg0, typename Arg1, typename T>
+inline cl_int
+getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
+{
+ GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
+ return getInfoHelper(f0, name, param, 0);
+}
+
+
+template<typename T>
+struct ReferenceHandler
+{ };
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+/**
+ * OpenCL 1.2 devices do have retain/release.
+ */
+template <>
+struct ReferenceHandler<cl_device_id>
+{
+ /**
+ * Retain the device.
+ * \param device A valid device created using createSubDevices
+ * \return
+ * CL_SUCCESS if the function executed successfully.
+ * CL_INVALID_DEVICE if device was not a valid subdevice
+ * CL_OUT_OF_RESOURCES
+ * CL_OUT_OF_HOST_MEMORY
+ */
+ static cl_int retain(cl_device_id device)
+ { return ::clRetainDevice(device); }
+ /**
+ * Retain the device.
+ * \param device A valid device created using createSubDevices
+ * \return
+ * CL_SUCCESS if the function executed successfully.
+ * CL_INVALID_DEVICE if device was not a valid subdevice
+ * CL_OUT_OF_RESOURCES
+ * CL_OUT_OF_HOST_MEMORY
+ */
+ static cl_int release(cl_device_id device)
+ { return ::clReleaseDevice(device); }
+};
+#else // CL_HPP_TARGET_OPENCL_VERSION >= 120
+/**
+ * OpenCL 1.1 devices do not have retain/release.
+ */
+template <>
+struct ReferenceHandler<cl_device_id>
+{
+ // cl_device_id does not have retain().
+ static cl_int retain(cl_device_id)
+ { return CL_SUCCESS; }
+ // cl_device_id does not have release().
+ static cl_int release(cl_device_id)
+ { return CL_SUCCESS; }
+};
+#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
+
+template <>
+struct ReferenceHandler<cl_platform_id>
+{
+ // cl_platform_id does not have retain().
+ static cl_int retain(cl_platform_id)
+ { return CL_SUCCESS; }
+ // cl_platform_id does not have release().
+ static cl_int release(cl_platform_id)
+ { return CL_SUCCESS; }
+};
+
+template <>
+struct ReferenceHandler<cl_context>
+{
+ static cl_int retain(cl_context context)
+ { return ::clRetainContext(context); }
+ static cl_int release(cl_context context)
+ { return ::clReleaseContext(context); }
+};
+
+template <>
+struct ReferenceHandler<cl_command_queue>
+{
+ static cl_int retain(cl_command_queue queue)
+ { return ::clRetainCommandQueue(queue); }
+ static cl_int release(cl_command_queue queue)
+ { return ::clReleaseCommandQueue(queue); }
+};
+
+template <>
+struct ReferenceHandler<cl_mem>
+{
+ static cl_int retain(cl_mem memory)
+ { return ::clRetainMemObject(memory); }
+ static cl_int release(cl_mem memory)
+ { return ::clReleaseMemObject(memory); }
+};
+
+template <>
+struct ReferenceHandler<cl_sampler>
+{
+ static cl_int retain(cl_sampler sampler)
+ { return ::clRetainSampler(sampler); }
+ static cl_int release(cl_sampler sampler)
+ { return ::clReleaseSampler(sampler); }
+};
+
+template <>
+struct ReferenceHandler<cl_program>
+{
+ static cl_int retain(cl_program program)
+ { return ::clRetainProgram(program); }
+ static cl_int release(cl_program program)
+ { return ::clReleaseProgram(program); }
+};
+
+template <>
+struct ReferenceHandler<cl_kernel>
+{
+ static cl_int retain(cl_kernel kernel)
+ { return ::clRetainKernel(kernel); }
+ static cl_int release(cl_kernel kernel)
+ { return ::clReleaseKernel(kernel); }
+};
+
+template <>
+struct ReferenceHandler<cl_event>
+{
+ static cl_int retain(cl_event event)
+ { return ::clRetainEvent(event); }
+ static cl_int release(cl_event event)
+ { return ::clReleaseEvent(event); }
+};
+
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
+// Extracts version number with major in the upper 16 bits, minor in the lower 16
+static cl_uint getVersion(const vector<char> &versionInfo)
+{
+ int highVersion = 0;
+ int lowVersion = 0;
+ int index = 7;
+ while(versionInfo[index] != '.' ) {
+ highVersion *= 10;
+ highVersion += versionInfo[index]-'0';
+ ++index;
+ }
+ ++index;
+ while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
+ lowVersion *= 10;
+ lowVersion += versionInfo[index]-'0';
+ ++index;
+ }
+ return (highVersion << 16) | lowVersion;
+}
+
+static cl_uint getPlatformVersion(cl_platform_id platform)
+{
+ size_type size = 0;
+ clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
+
+ vector<char> versionInfo(size);
+ clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
+ return getVersion(versionInfo);
+}
+
+static cl_uint getDevicePlatformVersion(cl_device_id device)
+{
+ cl_platform_id platform;
+ clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
+ return getPlatformVersion(platform);
+}
+
+static cl_uint getContextPlatformVersion(cl_context context)
+{
+ // The platform cannot be queried directly, so we first have to grab a
+ // device and obtain its context
+ size_type size = 0;
+ clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
+ if (size == 0)
+ return 0;
+ vector<cl_device_id> devices(size/sizeof(cl_device_id));
+ clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
+ return getDevicePlatformVersion(devices[0]);
+}
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
+
+template <typename T>
+class Wrapper
+{
+public:
+ typedef T cl_type;
+
+protected:
+ cl_type object_;
+
+public:
+ Wrapper() : object_(NULL) { }
+
+ Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
+ {
+ if (retainObject) {
+ detail::errHandler(retain(), __RETAIN_ERR);
+ }
+ }
+
+ ~Wrapper()
+ {
+ if (object_ != NULL) { release(); }
+ }
+
+ Wrapper(const Wrapper<cl_type>& rhs)
+ {
+ object_ = rhs.object_;
+ detail::errHandler(retain(), __RETAIN_ERR);
+ }
+
+ Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
+ {
+ object_ = rhs.object_;
+ rhs.object_ = NULL;
+ }
+
+ Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
+ {
+ if (this != &rhs) {
+ detail::errHandler(release(), __RELEASE_ERR);
+ object_ = rhs.object_;
+ detail::errHandler(retain(), __RETAIN_ERR);
+ }
+ return *this;
+ }
+
+ Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
+ {
+ if (this != &rhs) {
+ detail::errHandler(release(), __RELEASE_ERR);
+ object_ = rhs.object_;
+ rhs.object_ = NULL;
+ }
+ return *this;
+ }
+
+ Wrapper<cl_type>& operator = (const cl_type &rhs)
+ {
+ detail::errHandler(release(), __RELEASE_ERR);
+ object_ = rhs;
+ return *this;
+ }
+
+ const cl_type& operator ()() const { return object_; }
+
+ cl_type& operator ()() { return object_; }
+
+ const cl_type get() const { return object_; }
+
+ cl_type get() { return object_; }
+
+
+protected:
+ template<typename Func, typename U>
+ friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
+
+ cl_int retain() const
+ {
+ if (object_ != nullptr) {
+ return ReferenceHandler<cl_type>::retain(object_);
+ }
+ else {
+ return CL_SUCCESS;
+ }
+ }
+
+ cl_int release() const
+ {
+ if (object_ != nullptr) {
+ return ReferenceHandler<cl_type>::release(object_);
+ }
+ else {
+ return CL_SUCCESS;
+ }
+ }
+};
+
+template <>
+class Wrapper<cl_device_id>
+{
+public:
+ typedef cl_device_id cl_type;
+
+protected:
+ cl_type object_;
+ bool referenceCountable_;
+
+ static bool isReferenceCountable(cl_device_id device)
+ {
+ bool retVal = false;
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
+ if (device != NULL) {
+ int version = getDevicePlatformVersion(device);
+ if(version > ((1 << 16) + 1)) {
+ retVal = true;
+ }
+ }
+#else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
+ retVal = true;
+#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+ return retVal;
+ }
+
+public:
+ Wrapper() : object_(NULL), referenceCountable_(false)
+ {
+ }
+
+ Wrapper(const cl_type &obj, bool retainObject) :
+ object_(obj),
+ referenceCountable_(false)
+ {
+ referenceCountable_ = isReferenceCountable(obj);
+
+ if (retainObject) {
+ detail::errHandler(retain(), __RETAIN_ERR);
+ }
+ }
+
+ ~Wrapper()
+ {
+ release();
+ }
+
+ Wrapper(const Wrapper<cl_type>& rhs)
+ {
+ object_ = rhs.object_;
+ referenceCountable_ = isReferenceCountable(object_);
+ detail::errHandler(retain(), __RETAIN_ERR);
+ }
+
+ Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
+ {
+ object_ = rhs.object_;
+ referenceCountable_ = rhs.referenceCountable_;
+ rhs.object_ = NULL;
+ rhs.referenceCountable_ = false;
+ }
+
+ Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
+ {
+ if (this != &rhs) {
+ detail::errHandler(release(), __RELEASE_ERR);
+ object_ = rhs.object_;
+ referenceCountable_ = rhs.referenceCountable_;
+ detail::errHandler(retain(), __RETAIN_ERR);
+ }
+ return *this;
+ }
+
+ Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
+ {
+ if (this != &rhs) {
+ detail::errHandler(release(), __RELEASE_ERR);
+ object_ = rhs.object_;
+ referenceCountable_ = rhs.referenceCountable_;
+ rhs.object_ = NULL;
+ rhs.referenceCountable_ = false;
+ }
+ return *this;
+ }
+
+ Wrapper<cl_type>& operator = (const cl_type &rhs)
+ {
+ detail::errHandler(release(), __RELEASE_ERR);
+ object_ = rhs;
+ referenceCountable_ = isReferenceCountable(object_);
+ return *this;
+ }
+
+ const cl_type& operator ()() const { return object_; }
+
+ cl_type& operator ()() { return object_; }
+
+ const cl_type get() const { return object_; }
+
+ cl_type get() { return object_; }
+
+protected:
+ template<typename Func, typename U>
+ friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
+
+ template<typename Func, typename U>
+ friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
+
+ cl_int retain() const
+ {
+ if( object_ != nullptr && referenceCountable_ ) {
+ return ReferenceHandler<cl_type>::retain(object_);
+ }
+ else {
+ return CL_SUCCESS;
+ }
+ }
+
+ cl_int release() const
+ {
+ if (object_ != nullptr && referenceCountable_) {
+ return ReferenceHandler<cl_type>::release(object_);
+ }
+ else {
+ return CL_SUCCESS;
+ }
+ }
+};
+
+template <typename T>
+inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
+{
+ return lhs() == rhs();
+}
+
+template <typename T>
+inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
+{
+ return !operator==(lhs, rhs);
+}
+
+} // namespace detail
+//! \endcond
+
+
+using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+/**
+* Exception class for build errors to carry build info
+*/
+class BuildError : public Error
+{
+private:
+ BuildLogType buildLogs;
+public:
+ BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
+ {
+ }
+
+ BuildLogType getBuildLog() const
+ {
+ return buildLogs;
+ }
+};
+namespace detail {
+ static inline cl_int buildErrHandler(
+ cl_int err,
+ const char * errStr,
+ const BuildLogType &buildLogs)
+ {
+ if (err != CL_SUCCESS) {
+ throw BuildError(err, errStr, buildLogs);
+ }
+ return err;
+ }
+} // namespace detail
+
+#else
+namespace detail {
+ static inline cl_int buildErrHandler(
+ cl_int err,
+ const char * errStr,
+ const BuildLogType &buildLogs)
+ {
+ (void)buildLogs; // suppress unused variable warning
+ (void)errStr;
+ return err;
+ }
+} // namespace detail
+#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
+
+
+/*! \stuct ImageFormat
+ * \brief Adds constructors and member functions for cl_image_format.
+ *
+ * \see cl_image_format
+ */
+struct ImageFormat : public cl_image_format
+{
+ //! \brief Default constructor - performs no initialization.
+ ImageFormat(){}
+
+ //! \brief Initializing constructor.
+ ImageFormat(cl_channel_order order, cl_channel_type type)
+ {
+ image_channel_order = order;
+ image_channel_data_type = type;
+ }
+
+ //! \brief Assignment operator.
+ ImageFormat& operator = (const ImageFormat& rhs)
+ {
+ if (this != &rhs) {
+ this->image_channel_data_type = rhs.image_channel_data_type;
+ this->image_channel_order = rhs.image_channel_order;
+ }
+ return *this;
+ }
+};
+
+/*! \brief Class interface for cl_device_id.
+ *
+ * \note Copies of these objects are inexpensive, since they don't 'own'
+ * any underlying resources or data structures.
+ *
+ * \see cl_device_id
+ */
+class Device : public detail::Wrapper<cl_device_id>
+{
+private:
+ static std::once_flag default_initialized_;
+ static Device default_;
+ static cl_int default_error_;
+
+ /*! \brief Create the default context.
+ *
+ * This sets @c default_ and @c default_error_. It does not throw
+ * @c cl::Error.
+ */
+ static void makeDefault();
+
+ /*! \brief Create the default platform from a provided platform.
+ *
+ * This sets @c default_. It does not throw
+ * @c cl::Error.
+ */
+ static void makeDefaultProvided(const Device &p) {
+ default_ = p;
+ }
+
+public:
+#ifdef CL_HPP_UNIT_TEST_ENABLE
+ /*! \brief Reset the default.
+ *
+ * This sets @c default_ to an empty value to support cleanup in
+ * the unit test framework.
+ * This function is not thread safe.
+ */
+ static void unitTestClearDefault() {
+ default_ = Device();
+ }
+#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
+
+ //! \brief Default constructor - initializes to NULL.
+ Device() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_device_id.
+ *
+ * This simply copies the device ID value, which is an inexpensive operation.
+ */
+ explicit Device(const cl_device_id &device, bool retainObject = false) :
+ detail::Wrapper<cl_type>(device, retainObject) { }
+
+ /*! \brief Returns the first device on the default context.
+ *
+ * \see Context::getDefault()
+ */
+ static Device getDefault(
+ cl_int *errResult = NULL)
+ {
+ std::call_once(default_initialized_, makeDefault);
+ detail::errHandler(default_error_);
+ if (errResult != NULL) {
+ *errResult = default_error_;
+ }
+ return default_;
+ }
+
+ /**
+ * Modify the default device to be used by
+ * subsequent operations.
+ * Will only set the default if no default was previously created.
+ * @return updated default device.
+ * Should be compared to the passed value to ensure that it was updated.
+ */
+ static Device setDefault(const Device &default_device)
+ {
+ std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
+ detail::errHandler(default_error_);
+ return default_;
+ }
+
+ /*! \brief Assignment operator from cl_device_id.
+ *
+ * This simply copies the device ID value, which is an inexpensive operation.
+ */
+ Device& operator = (const cl_device_id& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Device& operator = (const Device &dev)
+ {
+ detail::Wrapper<cl_type>::operator=(dev);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(dev)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Device& operator = (Device &&dev)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(dev));
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetDeviceInfo().
+ template <typename T>
+ cl_int getInfo(cl_device_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetDeviceInfo, object_, name, param),
+ __GET_DEVICE_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetDeviceInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_device_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_device_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /**
+ * CL 1.2 version
+ */
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ //! \brief Wrapper for clCreateSubDevices().
+ cl_int createSubDevices(
+ const cl_device_partition_property * properties,
+ vector<Device>* devices)
+ {
+ cl_uint n = 0;
+ cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
+ }
+
+ vector<cl_device_id> ids(n);
+ err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
+ }
+
+ // Cannot trivially assign because we need to capture intermediates
+ // with safe construction
+ if (devices) {
+ devices->resize(ids.size());
+
+ // Assign to param, constructing with retain behaviour
+ // to correctly capture each underlying CL object
+ for (size_type i = 0; i < ids.size(); i++) {
+ // We do not need to retain because this device is being created
+ // by the runtime
+ (*devices)[i] = Device(ids[i], false);
+ }
+ }
+
+ return CL_SUCCESS;
+ }
+#elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
+
+/**
+ * CL 1.1 version that uses device fission extension.
+ */
+ cl_int createSubDevices(
+ const cl_device_partition_property_ext * properties,
+ vector<Device>* devices)
+ {
+ typedef CL_API_ENTRY cl_int
+ ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
+ cl_device_id /*in_device*/,
+ const cl_device_partition_property_ext * /* properties */,
+ cl_uint /*num_entries*/,
+ cl_device_id * /*out_devices*/,
+ cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
+
+ static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
+ CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
+
+ cl_uint n = 0;
+ cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
+ }
+
+ vector<cl_device_id> ids(n);
+ err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
+ }
+ // Cannot trivially assign because we need to capture intermediates
+ // with safe construction
+ if (devices) {
+ devices->resize(ids.size());
+
+ // Assign to param, constructing with retain behaviour
+ // to correctly capture each underlying CL object
+ for (size_type i = 0; i < ids.size(); i++) {
+ // We do not need to retain because this device is being created
+ // by the runtime
+ (*devices)[i] = Device(ids[i], false);
+ }
+ }
+ return CL_SUCCESS;
+ }
+#endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
+};
+
+CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
+CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
+CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
+
+/*! \brief Class interface for cl_platform_id.
+ *
+ * \note Copies of these objects are inexpensive, since they don't 'own'
+ * any underlying resources or data structures.
+ *
+ * \see cl_platform_id
+ */
+class Platform : public detail::Wrapper<cl_platform_id>
+{
+private:
+ static std::once_flag default_initialized_;
+ static Platform default_;
+ static cl_int default_error_;
+
+ /*! \brief Create the default context.
+ *
+ * This sets @c default_ and @c default_error_. It does not throw
+ * @c cl::Error.
+ */
+ static void makeDefault() {
+ /* Throwing an exception from a call_once invocation does not do
+ * what we wish, so we catch it and save the error.
+ */
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ try
+#endif
+ {
+ // If default wasn't passed ,generate one
+ // Otherwise set it
+ cl_uint n = 0;
+
+ cl_int err = ::clGetPlatformIDs(0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ default_error_ = err;
+ return;
+ }
+ if (n == 0) {
+ default_error_ = CL_INVALID_PLATFORM;
+ return;
+ }
+
+ vector<cl_platform_id> ids(n);
+ err = ::clGetPlatformIDs(n, ids.data(), NULL);
+ if (err != CL_SUCCESS) {
+ default_error_ = err;
+ return;
+ }
+
+ default_ = Platform(ids[0]);
+ }
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ catch (cl::Error &e) {
+ default_error_ = e.err();
+ }
+#endif
+ }
+
+ /*! \brief Create the default platform from a provided platform.
+ *
+ * This sets @c default_. It does not throw
+ * @c cl::Error.
+ */
+ static void makeDefaultProvided(const Platform &p) {
+ default_ = p;
+ }
+
+public:
+#ifdef CL_HPP_UNIT_TEST_ENABLE
+ /*! \brief Reset the default.
+ *
+ * This sets @c default_ to an empty value to support cleanup in
+ * the unit test framework.
+ * This function is not thread safe.
+ */
+ static void unitTestClearDefault() {
+ default_ = Platform();
+ }
+#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
+
+ //! \brief Default constructor - initializes to NULL.
+ Platform() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_platform_id.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * This simply copies the platform ID value, which is an inexpensive operation.
+ */
+ explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
+ detail::Wrapper<cl_type>(platform, retainObject) { }
+
+ /*! \brief Assignment operator from cl_platform_id.
+ *
+ * This simply copies the platform ID value, which is an inexpensive operation.
+ */
+ Platform& operator = (const cl_platform_id& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ static Platform getDefault(
+ cl_int *errResult = NULL)
+ {
+ std::call_once(default_initialized_, makeDefault);
+ detail::errHandler(default_error_);
+ if (errResult != NULL) {
+ *errResult = default_error_;
+ }
+ return default_;
+ }
+
+ /**
+ * Modify the default platform to be used by
+ * subsequent operations.
+ * Will only set the default if no default was previously created.
+ * @return updated default platform.
+ * Should be compared to the passed value to ensure that it was updated.
+ */
+ static Platform setDefault(const Platform &default_platform)
+ {
+ std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
+ detail::errHandler(default_error_);
+ return default_;
+ }
+
+ //! \brief Wrapper for clGetPlatformInfo().
+ cl_int getInfo(cl_platform_info name, string* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetPlatformInfo, object_, name, param),
+ __GET_PLATFORM_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetPlatformInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_platform_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_platform_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /*! \brief Gets a list of devices for this platform.
+ *
+ * Wraps clGetDeviceIDs().
+ */
+ cl_int getDevices(
+ cl_device_type type,
+ vector<Device>* devices) const
+ {
+ cl_uint n = 0;
+ if( devices == NULL ) {
+ return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
+ }
+ cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
+ }
+
+ vector<cl_device_id> ids(n);
+ err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
+ }
+
+ // Cannot trivially assign because we need to capture intermediates
+ // with safe construction
+ // We must retain things we obtain from the API to avoid releasing
+ // API-owned objects.
+ if (devices) {
+ devices->resize(ids.size());
+
+ // Assign to param, constructing with retain behaviour
+ // to correctly capture each underlying CL object
+ for (size_type i = 0; i < ids.size(); i++) {
+ (*devices)[i] = Device(ids[i], true);
+ }
+ }
+ return CL_SUCCESS;
+ }
+
+#if defined(CL_HPP_USE_DX_INTEROP)
+ /*! \brief Get the list of available D3D10 devices.
+ *
+ * \param d3d_device_source.
+ *
+ * \param d3d_object.
+ *
+ * \param d3d_device_set.
+ *
+ * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
+ * values returned in devices can be used to identify a specific OpenCL
+ * device. If \a devices argument is NULL, this argument is ignored.
+ *
+ * \return One of the following values:
+ * - CL_SUCCESS if the function is executed successfully.
+ *
+ * The application can query specific capabilities of the OpenCL device(s)
+ * returned by cl::getDevices. This can be used by the application to
+ * determine which device(s) to use.
+ *
+ * \note In the case that exceptions are enabled and a return value
+ * other than CL_SUCCESS is generated, then cl::Error exception is
+ * generated.
+ */
+ cl_int getDevices(
+ cl_d3d10_device_source_khr d3d_device_source,
+ void * d3d_object,
+ cl_d3d10_device_set_khr d3d_device_set,
+ vector<Device>* devices) const
+ {
+ typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
+ cl_platform_id platform,
+ cl_d3d10_device_source_khr d3d_device_source,
+ void * d3d_object,
+ cl_d3d10_device_set_khr d3d_device_set,
+ cl_uint num_entries,
+ cl_device_id * devices,
+ cl_uint* num_devices);
+
+ if( devices == NULL ) {
+ return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
+ }
+
+ static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
+ CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
+
+ cl_uint n = 0;
+ cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
+ object_,
+ d3d_device_source,
+ d3d_object,
+ d3d_device_set,
+ 0,
+ NULL,
+ &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
+ }
+
+ vector<cl_device_id> ids(n);
+ err = pfn_clGetDeviceIDsFromD3D10KHR(
+ object_,
+ d3d_device_source,
+ d3d_object,
+ d3d_device_set,
+ n,
+ ids.data(),
+ NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
+ }
+
+ // Cannot trivially assign because we need to capture intermediates
+ // with safe construction
+ // We must retain things we obtain from the API to avoid releasing
+ // API-owned objects.
+ if (devices) {
+ devices->resize(ids.size());
+
+ // Assign to param, constructing with retain behaviour
+ // to correctly capture each underlying CL object
+ for (size_type i = 0; i < ids.size(); i++) {
+ (*devices)[i] = Device(ids[i], true);
+ }
+ }
+ return CL_SUCCESS;
+ }
+#endif
+
+ /*! \brief Gets a list of available platforms.
+ *
+ * Wraps clGetPlatformIDs().
+ */
+ static cl_int get(
+ vector<Platform>* platforms)
+ {
+ cl_uint n = 0;
+
+ if( platforms == NULL ) {
+ return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
+ }
+
+ cl_int err = ::clGetPlatformIDs(0, NULL, &n);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
+ }
+
+ vector<cl_platform_id> ids(n);
+ err = ::clGetPlatformIDs(n, ids.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
+ }
+
+ if (platforms) {
+ platforms->resize(ids.size());
+
+ // Platforms don't reference count
+ for (size_type i = 0; i < ids.size(); i++) {
+ (*platforms)[i] = Platform(ids[i]);
+ }
+ }
+ return CL_SUCCESS;
+ }
+
+ /*! \brief Gets the first available platform.
+ *
+ * Wraps clGetPlatformIDs(), returning the first result.
+ */
+ static cl_int get(
+ Platform * platform)
+ {
+ cl_int err;
+ Platform default_platform = Platform::getDefault(&err);
+ if (platform) {
+ *platform = default_platform;
+ }
+ return err;
+ }
+
+ /*! \brief Gets the first available platform, returning it by value.
+ *
+ * \return Returns a valid platform if one is available.
+ * If no platform is available will return a null platform.
+ * Throws an exception if no platforms are available
+ * or an error condition occurs.
+ * Wraps clGetPlatformIDs(), returning the first result.
+ */
+ static Platform get(
+ cl_int * errResult = NULL)
+ {
+ cl_int err;
+ Platform default_platform = Platform::getDefault(&err);
+ if (errResult) {
+ *errResult = err;
+ }
+ return default_platform;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ //! \brief Wrapper for clUnloadCompiler().
+ cl_int
+ unloadCompiler()
+ {
+ return ::clUnloadPlatformCompiler(object_);
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+}; // class Platform
+
+CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
+CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
+CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
+
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+/**
+ * Unload the OpenCL compiler.
+ * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead.
+ */
+inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
+UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+inline cl_int
+UnloadCompiler()
+{
+ return ::clUnloadCompiler();
+}
+#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+
+/*! \brief Class interface for cl_context.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_context as the original. For details, see
+ * clRetainContext() and clReleaseContext().
+ *
+ * \see cl_context
+ */
+class Context
+ : public detail::Wrapper<cl_context>
+{
+private:
+ static std::once_flag default_initialized_;
+ static Context default_;
+ static cl_int default_error_;
+
+ /*! \brief Create the default context from the default device type in the default platform.
+ *
+ * This sets @c default_ and @c default_error_. It does not throw
+ * @c cl::Error.
+ */
+ static void makeDefault() {
+ /* Throwing an exception from a call_once invocation does not do
+ * what we wish, so we catch it and save the error.
+ */
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ try
+#endif
+ {
+#if !defined(__APPLE__) && !defined(__MACOS)
+ const Platform &p = Platform::getDefault();
+ cl_platform_id defaultPlatform = p();
+ cl_context_properties properties[3] = {
+ CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
+ };
+#else // #if !defined(__APPLE__) && !defined(__MACOS)
+ cl_context_properties *properties = nullptr;
+#endif // #if !defined(__APPLE__) && !defined(__MACOS)
+
+ default_ = Context(
+ CL_DEVICE_TYPE_DEFAULT,
+ properties,
+ NULL,
+ NULL,
+ &default_error_);
+ }
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ catch (cl::Error &e) {
+ default_error_ = e.err();
+ }
+#endif
+ }
+
+
+ /*! \brief Create the default context from a provided Context.
+ *
+ * This sets @c default_. It does not throw
+ * @c cl::Error.
+ */
+ static void makeDefaultProvided(const Context &c) {
+ default_ = c;
+ }
+
+public:
+#ifdef CL_HPP_UNIT_TEST_ENABLE
+ /*! \brief Reset the default.
+ *
+ * This sets @c default_ to an empty value to support cleanup in
+ * the unit test framework.
+ * This function is not thread safe.
+ */
+ static void unitTestClearDefault() {
+ default_ = Context();
+ }
+#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
+
+ /*! \brief Constructs a context including a list of specified devices.
+ *
+ * Wraps clCreateContext().
+ */
+ Context(
+ const vector<Device>& devices,
+ cl_context_properties* properties = NULL,
+ void (CL_CALLBACK * notifyFptr)(
+ const char *,
+ const void *,
+ size_type,
+ void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ size_type numDevices = devices.size();
+ vector<cl_device_id> deviceIDs(numDevices);
+
+ for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
+ deviceIDs[deviceIndex] = (devices[deviceIndex])();
+ }
+
+ object_ = ::clCreateContext(
+ properties, (cl_uint) numDevices,
+ deviceIDs.data(),
+ notifyFptr, data, &error);
+
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Context(
+ const Device& device,
+ cl_context_properties* properties = NULL,
+ void (CL_CALLBACK * notifyFptr)(
+ const char *,
+ const void *,
+ size_type,
+ void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ cl_device_id deviceID = device();
+
+ object_ = ::clCreateContext(
+ properties, 1,
+ &deviceID,
+ notifyFptr, data, &error);
+
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Constructs a context including all or a subset of devices of a specified type.
+ *
+ * Wraps clCreateContextFromType().
+ */
+ Context(
+ cl_device_type type,
+ cl_context_properties* properties = NULL,
+ void (CL_CALLBACK * notifyFptr)(
+ const char *,
+ const void *,
+ size_type,
+ void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+#if !defined(__APPLE__) && !defined(__MACOS)
+ cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
+
+ if (properties == NULL) {
+ // Get a valid platform ID as we cannot send in a blank one
+ vector<Platform> platforms;
+ error = Platform::get(&platforms);
+ if (error != CL_SUCCESS) {
+ detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ return;
+ }
+
+ // Check the platforms we found for a device of our specified type
+ cl_context_properties platform_id = 0;
+ for (unsigned int i = 0; i < platforms.size(); i++) {
+
+ vector<Device> devices;
+
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ try {
+#endif
+
+ error = platforms[i].getDevices(type, &devices);
+
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ } catch (Error) {}
+ // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
+ // We do error checking next anyway, and can throw there if needed
+#endif
+
+ // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
+ if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
+ detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ if (devices.size() > 0) {
+ platform_id = (cl_context_properties)platforms[i]();
+ break;
+ }
+ }
+
+ if (platform_id == 0) {
+ detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
+ if (err != NULL) {
+ *err = CL_DEVICE_NOT_FOUND;
+ }
+ return;
+ }
+
+ prop[1] = platform_id;
+ properties = &prop[0];
+ }
+#endif
+ object_ = ::clCreateContextFromType(
+ properties, type, notifyFptr, data, &error);
+
+ detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Context& operator = (const Context &ctx)
+ {
+ detail::Wrapper<cl_type>::operator=(ctx);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(ctx)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Context& operator = (Context &&ctx)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(ctx));
+ return *this;
+ }
+
+
+ /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
+ *
+ * \note All calls to this function return the same cl_context as the first.
+ */
+ static Context getDefault(cl_int * err = NULL)
+ {
+ std::call_once(default_initialized_, makeDefault);
+ detail::errHandler(default_error_);
+ if (err != NULL) {
+ *err = default_error_;
+ }
+ return default_;
+ }
+
+ /**
+ * Modify the default context to be used by
+ * subsequent operations.
+ * Will only set the default if no default was previously created.
+ * @return updated default context.
+ * Should be compared to the passed value to ensure that it was updated.
+ */
+ static Context setDefault(const Context &default_context)
+ {
+ std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
+ detail::errHandler(default_error_);
+ return default_;
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Context() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_context - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the cl_context
+ * into the new Context object.
+ */
+ explicit Context(const cl_context& context, bool retainObject = false) :
+ detail::Wrapper<cl_type>(context, retainObject) { }
+
+ /*! \brief Assignment operator from cl_context - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseContext() on the value previously held by this instance.
+ */
+ Context& operator = (const cl_context& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetContextInfo().
+ template <typename T>
+ cl_int getInfo(cl_context_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetContextInfo, object_, name, param),
+ __GET_CONTEXT_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetContextInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_context_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_context_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /*! \brief Gets a list of supported image formats.
+ *
+ * Wraps clGetSupportedImageFormats().
+ */
+ cl_int getSupportedImageFormats(
+ cl_mem_flags flags,
+ cl_mem_object_type type,
+ vector<ImageFormat>* formats) const
+ {
+ cl_uint numEntries;
+
+ if (!formats) {
+ return CL_SUCCESS;
+ }
+
+ cl_int err = ::clGetSupportedImageFormats(
+ object_,
+ flags,
+ type,
+ 0,
+ NULL,
+ &numEntries);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
+ }
+
+ if (numEntries > 0) {
+ vector<ImageFormat> value(numEntries);
+ err = ::clGetSupportedImageFormats(
+ object_,
+ flags,
+ type,
+ numEntries,
+ (cl_image_format*)value.data(),
+ NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
+ }
+
+ formats->assign(begin(value), end(value));
+ }
+ else {
+ // If no values are being returned, ensure an empty vector comes back
+ formats->clear();
+ }
+
+ return CL_SUCCESS;
+ }
+};
+
+inline void Device::makeDefault()
+{
+ /* Throwing an exception from a call_once invocation does not do
+ * what we wish, so we catch it and save the error.
+ */
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ try
+#endif
+ {
+ cl_int error = 0;
+
+ Context context = Context::getDefault(&error);
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+
+ if (error != CL_SUCCESS) {
+ default_error_ = error;
+ }
+ else {
+ default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
+ default_error_ = CL_SUCCESS;
+ }
+ }
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ catch (cl::Error &e) {
+ default_error_ = e.err();
+ }
+#endif
+}
+
+CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
+CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
+CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
+
+/*! \brief Class interface for cl_event.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_event as the original. For details, see
+ * clRetainEvent() and clReleaseEvent().
+ *
+ * \see cl_event
+ */
+class Event : public detail::Wrapper<cl_event>
+{
+public:
+ //! \brief Default constructor - initializes to NULL.
+ Event() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_event - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * This effectively transfers ownership of a refcount on the cl_event
+ * into the new Event object.
+ */
+ explicit Event(const cl_event& event, bool retainObject = false) :
+ detail::Wrapper<cl_type>(event, retainObject) { }
+
+ /*! \brief Assignment operator from cl_event - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseEvent() on the value previously held by this instance.
+ */
+ Event& operator = (const cl_event& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetEventInfo().
+ template <typename T>
+ cl_int getInfo(cl_event_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetEventInfo, object_, name, param),
+ __GET_EVENT_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetEventInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_event_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_event_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ //! \brief Wrapper for clGetEventProfilingInfo().
+ template <typename T>
+ cl_int getProfilingInfo(cl_profiling_info name, T* param) const
+ {
+ return detail::errHandler(detail::getInfo(
+ &::clGetEventProfilingInfo, object_, name, param),
+ __GET_EVENT_PROFILE_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetEventProfilingInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_profiling_info, name>::param_type
+ getProfilingInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_profiling_info, name>::param_type param;
+ cl_int result = getProfilingInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /*! \brief Blocks the calling thread until this event completes.
+ *
+ * Wraps clWaitForEvents().
+ */
+ cl_int wait() const
+ {
+ return detail::errHandler(
+ ::clWaitForEvents(1, &object_),
+ __WAIT_FOR_EVENTS_ERR);
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 110
+ /*! \brief Registers a user callback function for a specific command execution status.
+ *
+ * Wraps clSetEventCallback().
+ */
+ cl_int setCallback(
+ cl_int type,
+ void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
+ void * user_data = NULL)
+ {
+ return detail::errHandler(
+ ::clSetEventCallback(
+ object_,
+ type,
+ pfn_notify,
+ user_data),
+ __SET_EVENT_CALLBACK_ERR);
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+
+ /*! \brief Blocks the calling thread until every event specified is complete.
+ *
+ * Wraps clWaitForEvents().
+ */
+ static cl_int
+ waitForEvents(const vector<Event>& events)
+ {
+ return detail::errHandler(
+ ::clWaitForEvents(
+ (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
+ __WAIT_FOR_EVENTS_ERR);
+ }
+};
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 110
+/*! \brief Class interface for user events (a subset of cl_event's).
+ *
+ * See Event for details about copy semantics, etc.
+ */
+class UserEvent : public Event
+{
+public:
+ /*! \brief Constructs a user event on a given context.
+ *
+ * Wraps clCreateUserEvent().
+ */
+ UserEvent(
+ const Context& context,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateUserEvent(
+ context(),
+ &error);
+
+ detail::errHandler(error, __CREATE_USER_EVENT_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ UserEvent() : Event() { }
+
+ /*! \brief Sets the execution status of a user event object.
+ *
+ * Wraps clSetUserEventStatus().
+ */
+ cl_int setStatus(cl_int status)
+ {
+ return detail::errHandler(
+ ::clSetUserEventStatus(object_,status),
+ __SET_USER_EVENT_STATUS_ERR);
+ }
+};
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+
+/*! \brief Blocks the calling thread until every event specified is complete.
+ *
+ * Wraps clWaitForEvents().
+ */
+inline static cl_int
+WaitForEvents(const vector<Event>& events)
+{
+ return detail::errHandler(
+ ::clWaitForEvents(
+ (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
+ __WAIT_FOR_EVENTS_ERR);
+}
+
+/*! \brief Class interface for cl_mem.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_mem as the original. For details, see
+ * clRetainMemObject() and clReleaseMemObject().
+ *
+ * \see cl_mem
+ */
+class Memory : public detail::Wrapper<cl_mem>
+{
+public:
+ //! \brief Default constructor - initializes to NULL.
+ Memory() : detail::Wrapper<cl_type>() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * Optionally transfer ownership of a refcount on the cl_mem
+ * into the new Memory object.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ *
+ * See Memory for further details.
+ */
+ explicit Memory(const cl_mem& memory, bool retainObject) :
+ detail::Wrapper<cl_type>(memory, retainObject) { }
+
+ /*! \brief Assignment operator from cl_mem - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseMemObject() on the value previously held by this instance.
+ */
+ Memory& operator = (const cl_mem& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Memory& operator = (const Memory &mem)
+ {
+ detail::Wrapper<cl_type>::operator=(mem);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(mem)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Memory& operator = (Memory &&mem)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(mem));
+ return *this;
+ }
+
+
+ //! \brief Wrapper for clGetMemObjectInfo().
+ template <typename T>
+ cl_int getInfo(cl_mem_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
+ __GET_MEM_OBJECT_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_mem_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_mem_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 110
+ /*! \brief Registers a callback function to be called when the memory object
+ * is no longer needed.
+ *
+ * Wraps clSetMemObjectDestructorCallback().
+ *
+ * Repeated calls to this function, for a given cl_mem value, will append
+ * to the list of functions called (in reverse order) when memory object's
+ * resources are freed and the memory object is deleted.
+ *
+ * \note
+ * The registered callbacks are associated with the underlying cl_mem
+ * value - not the Memory class instance.
+ */
+ cl_int setDestructorCallback(
+ void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
+ void * user_data = NULL)
+ {
+ return detail::errHandler(
+ ::clSetMemObjectDestructorCallback(
+ object_,
+ pfn_notify,
+ user_data),
+ __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+
+};
+
+// Pre-declare copy functions
+class Buffer;
+template< typename IteratorType >
+cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
+template< typename IteratorType >
+cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
+template< typename IteratorType >
+cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
+template< typename IteratorType >
+cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
+
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+namespace detail
+{
+ class SVMTraitNull
+ {
+ public:
+ static cl_svm_mem_flags getSVMMemFlags()
+ {
+ return 0;
+ }
+ };
+} // namespace detail
+
+template<class Trait = detail::SVMTraitNull>
+class SVMTraitReadWrite
+{
+public:
+ static cl_svm_mem_flags getSVMMemFlags()
+ {
+ return CL_MEM_READ_WRITE |
+ Trait::getSVMMemFlags();
+ }
+};
+
+template<class Trait = detail::SVMTraitNull>
+class SVMTraitReadOnly
+{
+public:
+ static cl_svm_mem_flags getSVMMemFlags()
+ {
+ return CL_MEM_READ_ONLY |
+ Trait::getSVMMemFlags();
+ }
+};
+
+template<class Trait = detail::SVMTraitNull>
+class SVMTraitWriteOnly
+{
+public:
+ static cl_svm_mem_flags getSVMMemFlags()
+ {
+ return CL_MEM_WRITE_ONLY |
+ Trait::getSVMMemFlags();
+ }
+};
+
+template<class Trait = SVMTraitReadWrite<>>
+class SVMTraitCoarse
+{
+public:
+ static cl_svm_mem_flags getSVMMemFlags()
+ {
+ return Trait::getSVMMemFlags();
+ }
+};
+
+template<class Trait = SVMTraitReadWrite<>>
+class SVMTraitFine
+{
+public:
+ static cl_svm_mem_flags getSVMMemFlags()
+ {
+ return CL_MEM_SVM_FINE_GRAIN_BUFFER |
+ Trait::getSVMMemFlags();
+ }
+};
+
+template<class Trait = SVMTraitReadWrite<>>
+class SVMTraitAtomic
+{
+public:
+ static cl_svm_mem_flags getSVMMemFlags()
+ {
+ return
+ CL_MEM_SVM_FINE_GRAIN_BUFFER |
+ CL_MEM_SVM_ATOMICS |
+ Trait::getSVMMemFlags();
+ }
+};
+
+// Pre-declare SVM map function
+template<typename T>
+inline cl_int enqueueMapSVM(
+ T* ptr,
+ cl_bool blocking,
+ cl_map_flags flags,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL);
+
+/**
+ * STL-like allocator class for managing SVM objects provided for convenience.
+ *
+ * Note that while this behaves like an allocator for the purposes of constructing vectors and similar objects,
+ * care must be taken when using with smart pointers.
+ * The allocator should not be used to construct a unique_ptr if we are using coarse-grained SVM mode because
+ * the coarse-grained management behaviour would behave incorrectly with respect to reference counting.
+ *
+ * Instead the allocator embeds a Deleter which may be used with unique_ptr and is used
+ * with the allocate_shared and allocate_ptr supplied operations.
+ */
+template<typename T, class SVMTrait>
+class SVMAllocator {
+private:
+ Context context_;
+
+public:
+ typedef T value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+
+ template<typename U>
+ struct rebind
+ {
+ typedef SVMAllocator<U, SVMTrait> other;
+ };
+
+ template<typename U, typename V>
+ friend class SVMAllocator;
+
+ SVMAllocator() :
+ context_(Context::getDefault())
+ {
+ }
+
+ explicit SVMAllocator(cl::Context context) :
+ context_(context)
+ {
+ }
+
+
+ SVMAllocator(const SVMAllocator &other) :
+ context_(other.context_)
+ {
+ }
+
+ template<typename U>
+ SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
+ context_(other.context_)
+ {
+ }
+
+ ~SVMAllocator()
+ {
+ }
+
+ pointer address(reference r) CL_HPP_NOEXCEPT_
+ {
+ return std::addressof(r);
+ }
+
+ const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
+ {
+ return std::addressof(r);
+ }
+
+ /**
+ * Allocate an SVM pointer.
+ *
+ * If the allocator is coarse-grained, this will take ownership to allow
+ * containers to correctly construct data in place.
+ */
+ pointer allocate(
+ size_type size,
+ typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0)
+ {
+ // Allocate memory with default alignment matching the size of the type
+ void* voidPointer =
+ clSVMAlloc(
+ context_(),
+ SVMTrait::getSVMMemFlags(),
+ size*sizeof(T),
+ 0);
+ pointer retValue = reinterpret_cast<pointer>(
+ voidPointer);
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ if (!retValue) {
+ std::bad_alloc excep;
+ throw excep;
+ }
+#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
+
+ // If allocation was coarse-grained then map it
+ if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
+ cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
+ if (err != CL_SUCCESS) {
+ std::bad_alloc excep;
+ throw excep;
+ }
+ }
+
+ // If exceptions disabled, return null pointer from allocator
+ return retValue;
+ }
+
+ void deallocate(pointer p, size_type)
+ {
+ clSVMFree(context_(), p);
+ }
+
+ /**
+ * Return the maximum possible allocation size.
+ * This is the minimum of the maximum sizes of all devices in the context.
+ */
+ size_type max_size() const CL_HPP_NOEXCEPT_
+ {
+ size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
+
+ for (Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
+ maxSize = std::min(
+ maxSize,
+ static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
+ }
+
+ return maxSize;
+ }
+
+ template< class U, class... Args >
+ void construct(U* p, Args&&... args)
+ {
+ new(p)T(args...);
+ }
+
+ template< class U >
+ void destroy(U* p)
+ {
+ p->~U();
+ }
+
+ /**
+ * Returns true if the contexts match.
+ */
+ inline bool operator==(SVMAllocator const& rhs)
+ {
+ return (context_==rhs.context_);
+ }
+
+ inline bool operator!=(SVMAllocator const& a)
+ {
+ return !operator==(a);
+ }
+}; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
+
+
+template<class SVMTrait>
+class SVMAllocator<void, SVMTrait> {
+public:
+ typedef void value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+
+ template<typename U>
+ struct rebind
+ {
+ typedef SVMAllocator<U, SVMTrait> other;
+ };
+
+ template<typename U, typename V>
+ friend class SVMAllocator;
+};
+
+#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
+namespace detail
+{
+ template<class Alloc>
+ class Deleter {
+ private:
+ Alloc alloc_;
+ size_type copies_;
+
+ public:
+ typedef typename std::allocator_traits<Alloc>::pointer pointer;
+
+ Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
+ {
+ }
+
+ void operator()(pointer ptr) const {
+ Alloc tmpAlloc{ alloc_ };
+ std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
+ std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
+ }
+ };
+} // namespace detail
+
+/**
+ * Allocation operation compatible with std::allocate_ptr.
+ * Creates a unique_ptr<T> by default.
+ * This requirement is to ensure that the control block is not
+ * allocated in memory inaccessible to the host.
+ */
+template <class T, class Alloc, class... Args>
+cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
+{
+ Alloc alloc(alloc_);
+ static const size_type copies = 1;
+
+ // Ensure that creation of the management block and the
+ // object are dealt with separately such that we only provide a deleter
+
+ T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
+ if (!tmp) {
+ std::bad_alloc excep;
+ throw excep;
+ }
+ try {
+ std::allocator_traits<Alloc>::construct(
+ alloc,
+ std::addressof(*tmp),
+ std::forward<Args>(args)...);
+
+ return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
+ }
+ catch (std::bad_alloc b)
+ {
+ std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
+ throw;
+ }
+}
+
+template< class T, class SVMTrait, class... Args >
+cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
+{
+ SVMAllocator<T, SVMTrait> alloc;
+ return cl::allocate_pointer<T>(alloc, args...);
+}
+
+template< class T, class SVMTrait, class... Args >
+cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
+{
+ SVMAllocator<T, SVMTrait> alloc(c);
+ return cl::allocate_pointer<T>(alloc, args...);
+}
+#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
+
+/*! \brief Vector alias to simplify contruction of coarse-grained SVM containers.
+ *
+ */
+template < class T >
+using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
+
+/*! \brief Vector alias to simplify contruction of fine-grained SVM containers.
+*
+*/
+template < class T >
+using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
+
+/*! \brief Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics.
+*
+*/
+template < class T >
+using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
+
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+
+/*! \brief Class interface for Buffer Memory Objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Buffer : public Memory
+{
+public:
+
+ /*! \brief Constructs a Buffer in a specified context.
+ *
+ * Wraps clCreateBuffer().
+ *
+ * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
+ * specified. Note alignment & exclusivity requirements.
+ */
+ Buffer(
+ const Context& context,
+ cl_mem_flags flags,
+ size_type size,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Constructs a Buffer in the default context.
+ *
+ * Wraps clCreateBuffer().
+ *
+ * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
+ * specified. Note alignment & exclusivity requirements.
+ *
+ * \see Context::getDefault()
+ */
+ Buffer(
+ cl_mem_flags flags,
+ size_type size,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ Context context = Context::getDefault(err);
+
+ object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*!
+ * \brief Construct a Buffer from a host container via iterators.
+ * IteratorType must be random access.
+ * If useHostPtr is specified iterators must represent contiguous data.
+ */
+ template< typename IteratorType >
+ Buffer(
+ IteratorType startIterator,
+ IteratorType endIterator,
+ bool readOnly,
+ bool useHostPtr = false,
+ cl_int* err = NULL)
+ {
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ cl_mem_flags flags = 0;
+ if( readOnly ) {
+ flags |= CL_MEM_READ_ONLY;
+ }
+ else {
+ flags |= CL_MEM_READ_WRITE;
+ }
+ if( useHostPtr ) {
+ flags |= CL_MEM_USE_HOST_PTR;
+ }
+
+ size_type size = sizeof(DataType)*(endIterator - startIterator);
+
+ Context context = Context::getDefault(err);
+
+ if( useHostPtr ) {
+ object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
+ } else {
+ object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
+ }
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ if( !useHostPtr ) {
+ error = cl::copy(startIterator, endIterator, *this);
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+ }
+
+ /*!
+ * \brief Construct a Buffer from a host container via iterators using a specified context.
+ * IteratorType must be random access.
+ * If useHostPtr is specified iterators must represent contiguous data.
+ */
+ template< typename IteratorType >
+ Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
+ bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
+
+ /*!
+ * \brief Construct a Buffer from a host container via iterators using a specified queue.
+ * If useHostPtr is specified iterators must be random access.
+ */
+ template< typename IteratorType >
+ Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
+ bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
+
+ //! \brief Default constructor - initializes to NULL.
+ Buffer() : Memory() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with earlier versions.
+ *
+ * See Memory for further details.
+ */
+ explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
+ Memory(buffer, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Buffer& operator = (const cl_mem& rhs)
+ {
+ Memory::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Buffer(const Buffer& buf) : Memory(buf) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Buffer& operator = (const Buffer &buf)
+ {
+ Memory::operator=(buf);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Buffer& operator = (Buffer &&buf)
+ {
+ Memory::operator=(std::move(buf));
+ return *this;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 110
+ /*! \brief Creates a new buffer object from this.
+ *
+ * Wraps clCreateSubBuffer().
+ */
+ Buffer createSubBuffer(
+ cl_mem_flags flags,
+ cl_buffer_create_type buffer_create_type,
+ const void * buffer_create_info,
+ cl_int * err = NULL)
+ {
+ Buffer result;
+ cl_int error;
+ result.object_ = ::clCreateSubBuffer(
+ object_,
+ flags,
+ buffer_create_type,
+ buffer_create_info,
+ &error);
+
+ detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ return result;
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+};
+
+#if defined (CL_HPP_USE_DX_INTEROP)
+/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's.
+ *
+ * This is provided to facilitate interoperability with Direct3D.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class BufferD3D10 : public Buffer
+{
+public:
+
+
+ /*! \brief Constructs a BufferD3D10, in a specified context, from a
+ * given ID3D10Buffer.
+ *
+ * Wraps clCreateFromD3D10BufferKHR().
+ */
+ BufferD3D10(
+ const Context& context,
+ cl_mem_flags flags,
+ ID3D10Buffer* bufobj,
+ cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
+ {
+ typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
+ cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
+ cl_int* errcode_ret);
+ PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
+ cl_platform platform = -1;
+ for( int i = 0; i < props.size(); ++i ) {
+ if( props[i] == CL_CONTEXT_PLATFORM ) {
+ platform = props[i+1];
+ }
+ }
+ CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
+#elif CL_HPP_TARGET_OPENCL_VERSION >= 110
+ CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
+#endif
+
+ cl_int error;
+ object_ = pfn_clCreateFromD3D10BufferKHR(
+ context(),
+ flags,
+ bufobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ BufferD3D10() : Buffer() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
+ Buffer(buffer, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ BufferD3D10& operator = (const cl_mem& rhs)
+ {
+ Buffer::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferD3D10(const BufferD3D10& buf) :
+ Buffer(buf) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferD3D10& operator = (const BufferD3D10 &buf)
+ {
+ Buffer::operator=(buf);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferD3D10& operator = (BufferD3D10 &&buf)
+ {
+ Buffer::operator=(std::move(buf));
+ return *this;
+ }
+};
+#endif
+
+/*! \brief Class interface for GL Buffer Memory Objects.
+ *
+ * This is provided to facilitate interoperability with OpenGL.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class BufferGL : public Buffer
+{
+public:
+ /*! \brief Constructs a BufferGL in a specified context, from a given
+ * GL buffer.
+ *
+ * Wraps clCreateFromGLBuffer().
+ */
+ BufferGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLuint bufobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLBuffer(
+ context(),
+ flags,
+ bufobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ BufferGL() : Buffer() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
+ Buffer(buffer, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ BufferGL& operator = (const cl_mem& rhs)
+ {
+ Buffer::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferGL(const BufferGL& buf) : Buffer(buf) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferGL& operator = (const BufferGL &buf)
+ {
+ Buffer::operator=(buf);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferGL& operator = (BufferGL &&buf)
+ {
+ Buffer::operator=(std::move(buf));
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetGLObjectInfo().
+ cl_int getObjectInfo(
+ cl_gl_object_type *type,
+ cl_GLuint * gl_object_name)
+ {
+ return detail::errHandler(
+ ::clGetGLObjectInfo(object_,type,gl_object_name),
+ __GET_GL_OBJECT_INFO_ERR);
+ }
+};
+
+/*! \brief Class interface for GL Render Buffer Memory Objects.
+ *
+ * This is provided to facilitate interoperability with OpenGL.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class BufferRenderGL : public Buffer
+{
+public:
+ /*! \brief Constructs a BufferRenderGL in a specified context, from a given
+ * GL Renderbuffer.
+ *
+ * Wraps clCreateFromGLRenderbuffer().
+ */
+ BufferRenderGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLuint bufobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLRenderbuffer(
+ context(),
+ flags,
+ bufobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ BufferRenderGL() : Buffer() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
+ Buffer(buffer, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ BufferRenderGL& operator = (const cl_mem& rhs)
+ {
+ Buffer::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferRenderGL& operator = (const BufferRenderGL &buf)
+ {
+ Buffer::operator=(buf);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ BufferRenderGL& operator = (BufferRenderGL &&buf)
+ {
+ Buffer::operator=(std::move(buf));
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetGLObjectInfo().
+ cl_int getObjectInfo(
+ cl_gl_object_type *type,
+ cl_GLuint * gl_object_name)
+ {
+ return detail::errHandler(
+ ::clGetGLObjectInfo(object_,type,gl_object_name),
+ __GET_GL_OBJECT_INFO_ERR);
+ }
+};
+
+/*! \brief C++ base class for Image Memory objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image : public Memory
+{
+protected:
+ //! \brief Default constructor - initializes to NULL.
+ Image() : Memory() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image(const cl_mem& image, bool retainObject = false) :
+ Memory(image, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image& operator = (const cl_mem& rhs)
+ {
+ Memory::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image(const Image& img) : Memory(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image& operator = (const Image &img)
+ {
+ Memory::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image& operator = (Image &&img)
+ {
+ Memory::operator=(std::move(img));
+ return *this;
+ }
+
+
+public:
+ //! \brief Wrapper for clGetImageInfo().
+ template <typename T>
+ cl_int getImageInfo(cl_image_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetImageInfo, object_, name, param),
+ __GET_IMAGE_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetImageInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_image_info, name>::param_type
+ getImageInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_image_info, name>::param_type param;
+ cl_int result = getImageInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+};
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+/*! \brief Class interface for 1D Image Memory objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image1D : public Image
+{
+public:
+ /*! \brief Constructs a 1D Image in a specified context.
+ *
+ * Wraps clCreateImage().
+ */
+ Image1D(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ size_type width,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE1D,
+ width,
+ 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image1D() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
+ Image(image1D, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image1D& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1D(const Image1D& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1D& operator = (const Image1D &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1D& operator = (Image1D &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+
+};
+
+/*! \class Image1DBuffer
+ * \brief Image interface for 1D buffer images.
+ */
+class Image1DBuffer : public Image
+{
+public:
+ Image1DBuffer(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ size_type width,
+ const Buffer &buffer,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE1D_BUFFER,
+ width,
+ 0, 0, 0, 0, 0, 0, 0,
+ buffer()
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ NULL,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Image1DBuffer() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
+ Image(image1D, retainObject) { }
+
+ Image1DBuffer& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DBuffer& operator = (const Image1DBuffer &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DBuffer& operator = (Image1DBuffer &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+
+};
+
+/*! \class Image1DArray
+ * \brief Image interface for arrays of 1D images.
+ */
+class Image1DArray : public Image
+{
+public:
+ Image1DArray(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ size_type arraySize,
+ size_type width,
+ size_type rowPitch,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE1D_ARRAY,
+ width,
+ 0, 0, // height, depth (unused)
+ arraySize,
+ rowPitch,
+ 0, 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Image1DArray() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
+ Image(imageArray, retainObject) { }
+
+
+ Image1DArray& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DArray(const Image1DArray& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DArray& operator = (const Image1DArray &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image1DArray& operator = (Image1DArray &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+
+};
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+
+/*! \brief Class interface for 2D Image Memory objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image2D : public Image
+{
+public:
+ /*! \brief Constructs a 2D Image in a specified context.
+ *
+ * Wraps clCreateImage().
+ */
+ Image2D(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ size_type width,
+ size_type height,
+ size_type row_pitch = 0,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ bool useCreateImage;
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
+ // Run-time decision based on the actual platform
+ {
+ cl_uint version = detail::getContextPlatformVersion(context());
+ useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
+ }
+#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
+ useCreateImage = true;
+#else
+ useCreateImage = false;
+#endif
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ if (useCreateImage)
+ {
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE2D,
+ width,
+ height,
+ 0, 0, // depth, array size (unused)
+ row_pitch,
+ 0, 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
+ if (!useCreateImage)
+ {
+ object_ = ::clCreateImage2D(
+ context(), flags,&format, width, height, row_pitch, host_ptr, &error);
+
+ detail::errHandler(error, __CREATE_IMAGE2D_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ /*! \brief Constructs a 2D Image from a buffer.
+ * \note This will share storage with the underlying buffer.
+ *
+ * Wraps clCreateImage().
+ */
+ Image2D(
+ const Context& context,
+ ImageFormat format,
+ const Buffer &sourceBuffer,
+ size_type width,
+ size_type height,
+ size_type row_pitch = 0,
+ cl_int* err = nullptr)
+ {
+ cl_int error;
+
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE2D,
+ width,
+ height,
+ 0, 0, // depth, array size (unused)
+ row_pitch,
+ 0, 0, 0,
+ // Use buffer as input to image
+ sourceBuffer()
+ };
+ object_ = ::clCreateImage(
+ context(),
+ 0, // flags inherited from buffer
+ &format,
+ &desc,
+ nullptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != nullptr) {
+ *err = error;
+ }
+ }
+#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ /*! \brief Constructs a 2D Image from an image.
+ * \note This will share storage with the underlying image but may
+ * reinterpret the channel order and type.
+ *
+ * The image will be created matching with a descriptor matching the source.
+ *
+ * \param order is the channel order to reinterpret the image data as.
+ * The channel order may differ as described in the OpenCL
+ * 2.0 API specification.
+ *
+ * Wraps clCreateImage().
+ */
+ Image2D(
+ const Context& context,
+ cl_channel_order order,
+ const Image &sourceImage,
+ cl_int* err = nullptr)
+ {
+ cl_int error;
+
+ // Descriptor fields have to match source image
+ size_type sourceWidth =
+ sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
+ size_type sourceHeight =
+ sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
+ size_type sourceRowPitch =
+ sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
+ cl_uint sourceNumMIPLevels =
+ sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
+ cl_uint sourceNumSamples =
+ sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
+ cl_image_format sourceFormat =
+ sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
+
+ // Update only the channel order.
+ // Channel format inherited from source.
+ sourceFormat.image_channel_order = order;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE2D,
+ sourceWidth,
+ sourceHeight,
+ 0, 0, // depth (unused), array size (unused)
+ sourceRowPitch,
+ 0, // slice pitch (unused)
+ sourceNumMIPLevels,
+ sourceNumSamples,
+ // Use buffer as input to image
+ sourceImage()
+ };
+ object_ = ::clCreateImage(
+ context(),
+ 0, // flags should be inherited from mem_object
+ &sourceFormat,
+ &desc,
+ nullptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != nullptr) {
+ *err = error;
+ }
+ }
+#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+ //! \brief Default constructor - initializes to NULL.
+ Image2D() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
+ Image(image2D, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image2D& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2D(const Image2D& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2D& operator = (const Image2D &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2D& operator = (Image2D &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+
+};
+
+
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+/*! \brief Class interface for GL 2D Image Memory objects.
+ *
+ * This is provided to facilitate interoperability with OpenGL.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ * \note Deprecated for OpenCL 1.2. Please use ImageGL instead.
+ */
+class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
+{
+public:
+ /*! \brief Constructs an Image2DGL in a specified context, from a given
+ * GL Texture.
+ *
+ * Wraps clCreateFromGLTexture2D().
+ */
+ Image2DGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLenum target,
+ cl_GLint miplevel,
+ cl_GLuint texobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLTexture2D(
+ context(),
+ flags,
+ target,
+ miplevel,
+ texobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image2DGL() : Image2D() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
+ Image2D(image, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *c
+ * See Memory for further details.
+ */
+ Image2DGL& operator = (const cl_mem& rhs)
+ {
+ Image2D::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DGL(const Image2DGL& img) : Image2D(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DGL& operator = (const Image2DGL &img)
+ {
+ Image2D::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DGL& operator = (Image2DGL &&img)
+ {
+ Image2D::operator=(std::move(img));
+ return *this;
+ }
+
+} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+/*! \class Image2DArray
+ * \brief Image interface for arrays of 2D images.
+ */
+class Image2DArray : public Image
+{
+public:
+ Image2DArray(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ size_type arraySize,
+ size_type width,
+ size_type height,
+ size_type rowPitch,
+ size_type slicePitch,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE2D_ARRAY,
+ width,
+ height,
+ 0, // depth (unused)
+ arraySize,
+ rowPitch,
+ slicePitch,
+ 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Image2DArray() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
+
+ Image2DArray& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DArray(const Image2DArray& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DArray& operator = (const Image2DArray &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image2DArray& operator = (Image2DArray &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+};
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+/*! \brief Class interface for 3D Image Memory objects.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image3D : public Image
+{
+public:
+ /*! \brief Constructs a 3D Image in a specified context.
+ *
+ * Wraps clCreateImage().
+ */
+ Image3D(
+ const Context& context,
+ cl_mem_flags flags,
+ ImageFormat format,
+ size_type width,
+ size_type height,
+ size_type depth,
+ size_type row_pitch = 0,
+ size_type slice_pitch = 0,
+ void* host_ptr = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ bool useCreateImage;
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
+ // Run-time decision based on the actual platform
+ {
+ cl_uint version = detail::getContextPlatformVersion(context());
+ useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
+ }
+#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
+ useCreateImage = true;
+#else
+ useCreateImage = false;
+#endif
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ if (useCreateImage)
+ {
+ cl_image_desc desc =
+ {
+ CL_MEM_OBJECT_IMAGE3D,
+ width,
+ height,
+ depth,
+ 0, // array size (unused)
+ row_pitch,
+ slice_pitch,
+ 0, 0, 0
+ };
+ object_ = ::clCreateImage(
+ context(),
+ flags,
+ &format,
+ &desc,
+ host_ptr,
+ &error);
+
+ detail::errHandler(error, __CREATE_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
+ if (!useCreateImage)
+ {
+ object_ = ::clCreateImage3D(
+ context(), flags, &format, width, height, depth, row_pitch,
+ slice_pitch, host_ptr, &error);
+
+ detail::errHandler(error, __CREATE_IMAGE3D_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image3D() : Image() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
+ Image(image3D, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image3D& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3D(const Image3D& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3D& operator = (const Image3D &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3D& operator = (Image3D &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+};
+
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+/*! \brief Class interface for GL 3D Image Memory objects.
+ *
+ * This is provided to facilitate interoperability with OpenGL.
+ *
+ * See Memory for details about copy semantics, etc.
+ *
+ * \see Memory
+ */
+class Image3DGL : public Image3D
+{
+public:
+ /*! \brief Constructs an Image3DGL in a specified context, from a given
+ * GL Texture.
+ *
+ * Wraps clCreateFromGLTexture3D().
+ */
+ Image3DGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLenum target,
+ cl_GLint miplevel,
+ cl_GLuint texobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLTexture3D(
+ context(),
+ flags,
+ target,
+ miplevel,
+ texobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Image3DGL() : Image3D() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
+ Image3D(image, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Image3DGL& operator = (const cl_mem& rhs)
+ {
+ Image3D::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3DGL(const Image3DGL& img) : Image3D(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3DGL& operator = (const Image3DGL &img)
+ {
+ Image3D::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Image3DGL& operator = (Image3DGL &&img)
+ {
+ Image3D::operator=(std::move(img));
+ return *this;
+ }
+};
+#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+/*! \class ImageGL
+ * \brief general image interface for GL interop.
+ * We abstract the 2D and 3D GL images into a single instance here
+ * that wraps all GL sourced images on the grounds that setup information
+ * was performed by OpenCL anyway.
+ */
+class ImageGL : public Image
+{
+public:
+ ImageGL(
+ const Context& context,
+ cl_mem_flags flags,
+ cl_GLenum target,
+ cl_GLint miplevel,
+ cl_GLuint texobj,
+ cl_int * err = NULL)
+ {
+ cl_int error;
+ object_ = ::clCreateFromGLTexture(
+ context(),
+ flags,
+ target,
+ miplevel,
+ texobj,
+ &error);
+
+ detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ ImageGL() : Image() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * See Memory for further details.
+ */
+ explicit ImageGL(const cl_mem& image, bool retainObject = false) :
+ Image(image, retainObject) { }
+
+ ImageGL& operator = (const cl_mem& rhs)
+ {
+ Image::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ ImageGL(const ImageGL& img) : Image(img) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ ImageGL& operator = (const ImageGL &img)
+ {
+ Image::operator=(img);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ ImageGL& operator = (ImageGL &&img)
+ {
+ Image::operator=(std::move(img));
+ return *this;
+ }
+};
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+/*! \brief Class interface for Pipe Memory Objects.
+*
+* See Memory for details about copy semantics, etc.
+*
+* \see Memory
+*/
+class Pipe : public Memory
+{
+public:
+
+ /*! \brief Constructs a Pipe in a specified context.
+ *
+ * Wraps clCreatePipe().
+ * @param context Context in which to create the pipe.
+ * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid.
+ * @param packet_size Size in bytes of a single packet of the pipe.
+ * @param max_packets Number of packets that may be stored in the pipe.
+ *
+ */
+ Pipe(
+ const Context& context,
+ cl_uint packet_size,
+ cl_uint max_packets,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
+ object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
+
+ detail::errHandler(error, __CREATE_PIPE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Constructs a Pipe in a the default context.
+ *
+ * Wraps clCreatePipe().
+ * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid.
+ * @param packet_size Size in bytes of a single packet of the pipe.
+ * @param max_packets Number of packets that may be stored in the pipe.
+ *
+ */
+ Pipe(
+ cl_uint packet_size,
+ cl_uint max_packets,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ Context context = Context::getDefault(err);
+
+ cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
+ object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
+
+ detail::errHandler(error, __CREATE_PIPE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ //! \brief Default constructor - initializes to NULL.
+ Pipe() : Memory() { }
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with earlier versions.
+ *
+ * See Memory for further details.
+ */
+ explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
+ Memory(pipe, retainObject) { }
+
+ /*! \brief Assignment from cl_mem - performs shallow copy.
+ *
+ * See Memory for further details.
+ */
+ Pipe& operator = (const cl_mem& rhs)
+ {
+ Memory::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Pipe(const Pipe& pipe) : Memory(pipe) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Pipe& operator = (const Pipe &pipe)
+ {
+ Memory::operator=(pipe);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Pipe& operator = (Pipe &&pipe)
+ {
+ Memory::operator=(std::move(pipe));
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetMemObjectInfo().
+ template <typename T>
+ cl_int getInfo(cl_pipe_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetPipeInfo, object_, name, param),
+ __GET_PIPE_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_pipe_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_pipe_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+}; // class Pipe
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+
+/*! \brief Class interface for cl_sampler.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_sampler as the original. For details, see
+ * clRetainSampler() and clReleaseSampler().
+ *
+ * \see cl_sampler
+ */
+class Sampler : public detail::Wrapper<cl_sampler>
+{
+public:
+ //! \brief Default constructor - initializes to NULL.
+ Sampler() { }
+
+ /*! \brief Constructs a Sampler in a specified context.
+ *
+ * Wraps clCreateSampler().
+ */
+ Sampler(
+ const Context& context,
+ cl_bool normalized_coords,
+ cl_addressing_mode addressing_mode,
+ cl_filter_mode filter_mode,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ cl_sampler_properties sampler_properties[] = {
+ CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
+ CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
+ CL_SAMPLER_FILTER_MODE, filter_mode,
+ 0 };
+ object_ = ::clCreateSamplerWithProperties(
+ context(),
+ sampler_properties,
+ &error);
+
+ detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#else
+ object_ = ::clCreateSampler(
+ context(),
+ normalized_coords,
+ addressing_mode,
+ filter_mode,
+ &error);
+
+ detail::errHandler(error, __CREATE_SAMPLER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#endif
+ }
+
+ /*! \brief Constructor from cl_sampler - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * This effectively transfers ownership of a refcount on the cl_sampler
+ * into the new Sampler object.
+ */
+ explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
+ detail::Wrapper<cl_type>(sampler, retainObject) { }
+
+ /*! \brief Assignment operator from cl_sampler - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseSampler() on the value previously held by this instance.
+ */
+ Sampler& operator = (const cl_sampler& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Sampler& operator = (const Sampler &sam)
+ {
+ detail::Wrapper<cl_type>::operator=(sam);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(sam)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Sampler& operator = (Sampler &&sam)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(sam));
+ return *this;
+ }
+
+ //! \brief Wrapper for clGetSamplerInfo().
+ template <typename T>
+ cl_int getInfo(cl_sampler_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetSamplerInfo, object_, name, param),
+ __GET_SAMPLER_INFO_ERR);
+ }
+
+ //! \brief Wrapper for clGetSamplerInfo() that returns by value.
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_sampler_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_sampler_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+};
+
+class Program;
+class CommandQueue;
+class DeviceCommandQueue;
+class Kernel;
+
+//! \brief Class interface for specifying NDRange values.
+class NDRange
+{
+private:
+ size_type sizes_[3];
+ cl_uint dimensions_;
+
+public:
+ //! \brief Default constructor - resulting range has zero dimensions.
+ NDRange()
+ : dimensions_(0)
+ {
+ sizes_[0] = 0;
+ sizes_[1] = 0;
+ sizes_[2] = 0;
+ }
+
+ //! \brief Constructs one-dimensional range.
+ NDRange(size_type size0)
+ : dimensions_(1)
+ {
+ sizes_[0] = size0;
+ sizes_[1] = 1;
+ sizes_[2] = 1;
+ }
+
+ //! \brief Constructs two-dimensional range.
+ NDRange(size_type size0, size_type size1)
+ : dimensions_(2)
+ {
+ sizes_[0] = size0;
+ sizes_[1] = size1;
+ sizes_[2] = 1;
+ }
+
+ //! \brief Constructs three-dimensional range.
+ NDRange(size_type size0, size_type size1, size_type size2)
+ : dimensions_(3)
+ {
+ sizes_[0] = size0;
+ sizes_[1] = size1;
+ sizes_[2] = size2;
+ }
+
+ /*! \brief Conversion operator to const size_type *.
+ *
+ * \returns a pointer to the size of the first dimension.
+ */
+ operator const size_type*() const {
+ return sizes_;
+ }
+
+ //! \brief Queries the number of dimensions in the range.
+ size_type dimensions() const
+ {
+ return dimensions_;
+ }
+
+ //! \brief Returns the size of the object in bytes based on the
+ // runtime number of dimensions
+ size_type size() const
+ {
+ return dimensions_*sizeof(size_type);
+ }
+
+ size_type* get()
+ {
+ return sizes_;
+ }
+
+ const size_type* get() const
+ {
+ return sizes_;
+ }
+};
+
+//! \brief A zero-dimensional range.
+static const NDRange NullRange;
+
+//! \brief Local address wrapper for use with Kernel::setArg
+struct LocalSpaceArg
+{
+ size_type size_;
+};
+
+namespace detail {
+
+template <typename T, class Enable = void>
+struct KernelArgumentHandler;
+
+// Enable for objects that are not subclasses of memory
+// Pointers, constants etc
+template <typename T>
+struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
+{
+ static size_type size(const T&) { return sizeof(T); }
+ static const T* ptr(const T& value) { return &value; }
+};
+
+// Enable for subclasses of memory where we want to get a reference to the cl_mem out
+// and pass that in for safety
+template <typename T>
+struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
+{
+ static size_type size(const T&) { return sizeof(cl_mem); }
+ static const cl_mem* ptr(const T& value) { return &(value()); }
+};
+
+// Specialization for DeviceCommandQueue defined later
+
+template <>
+struct KernelArgumentHandler<LocalSpaceArg, void>
+{
+ static size_type size(const LocalSpaceArg& value) { return value.size_; }
+ static const void* ptr(const LocalSpaceArg&) { return NULL; }
+};
+
+}
+//! \endcond
+
+/*! Local
+ * \brief Helper function for generating LocalSpaceArg objects.
+ */
+inline LocalSpaceArg
+Local(size_type size)
+{
+ LocalSpaceArg ret = { size };
+ return ret;
+}
+
+/*! \brief Class interface for cl_kernel.
+ *
+ * \note Copies of these objects are shallow, meaning that the copy will refer
+ * to the same underlying cl_kernel as the original. For details, see
+ * clRetainKernel() and clReleaseKernel().
+ *
+ * \see cl_kernel
+ */
+class Kernel : public detail::Wrapper<cl_kernel>
+{
+public:
+ inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
+
+ //! \brief Default constructor - initializes to NULL.
+ Kernel() { }
+
+ /*! \brief Constructor from cl_kernel - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ * This effectively transfers ownership of a refcount on the cl_kernel
+ * into the new Kernel object.
+ */
+ explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
+ detail::Wrapper<cl_type>(kernel, retainObject) { }
+
+ /*! \brief Assignment operator from cl_kernel - takes ownership.
+ *
+ * This effectively transfers ownership of a refcount on the rhs and calls
+ * clReleaseKernel() on the value previously held by this instance.
+ */
+ Kernel& operator = (const cl_kernel& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Kernel& operator = (const Kernel &kernel)
+ {
+ detail::Wrapper<cl_type>::operator=(kernel);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(kernel)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Kernel& operator = (Kernel &&kernel)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(kernel));
+ return *this;
+ }
+
+ template <typename T>
+ cl_int getInfo(cl_kernel_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetKernelInfo, object_, name, param),
+ __GET_KERNEL_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_kernel_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_kernel_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ template <typename T>
+ cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
+ __GET_KERNEL_ARG_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
+ getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_kernel_arg_info, name>::param_type param;
+ cl_int result = getArgInfo(argIndex, name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+ template <typename T>
+ cl_int getWorkGroupInfo(
+ const Device& device, cl_kernel_work_group_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(
+ &::clGetKernelWorkGroupInfo, object_, device(), name, param),
+ __GET_KERNEL_WORK_GROUP_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
+ getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_kernel_work_group_info, name>::param_type param;
+ cl_int result = getWorkGroupInfo(device, name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
+ cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
+ {
+ typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
+ static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
+ CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
+
+ return detail::errHandler(
+ pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
+ __GET_KERNEL_ARG_INFO_ERR);
+ }
+
+ template <cl_int name>
+ size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const
+ {
+ size_type param;
+ cl_int result = getSubGroupInfo(dev, name, range, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+#endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ /*! \brief setArg overload taking a shared_ptr type
+ */
+ template<typename T, class D>
+ cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
+ {
+ return detail::errHandler(
+ ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
+ __SET_KERNEL_ARGS_ERR);
+ }
+
+ /*! \brief setArg overload taking a vector type.
+ */
+ template<typename T, class Alloc>
+ cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
+ {
+ return detail::errHandler(
+ ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
+ __SET_KERNEL_ARGS_ERR);
+ }
+
+ /*! \brief setArg overload taking a pointer type
+ */
+ template<typename T>
+ typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
+ setArg(cl_uint index, const T argPtr)
+ {
+ return detail::errHandler(
+ ::clSetKernelArgSVMPointer(object_, index, argPtr),
+ __SET_KERNEL_ARGS_ERR);
+ }
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+ /*! \brief setArg overload taking a POD type
+ */
+ template <typename T>
+ typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
+ setArg(cl_uint index, const T &value)
+ {
+ return detail::errHandler(
+ ::clSetKernelArg(
+ object_,
+ index,
+ detail::KernelArgumentHandler<T>::size(value),
+ detail::KernelArgumentHandler<T>::ptr(value)),
+ __SET_KERNEL_ARGS_ERR);
+ }
+
+ cl_int setArg(cl_uint index, size_type size, const void* argPtr)
+ {
+ return detail::errHandler(
+ ::clSetKernelArg(object_, index, size, argPtr),
+ __SET_KERNEL_ARGS_ERR);
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ /*!
+ * Specify a vector of SVM pointers that the kernel may access in
+ * addition to its arguments.
+ */
+ cl_int setSVMPointers(const vector<void*> &pointerList)
+ {
+ return detail::errHandler(
+ ::clSetKernelExecInfo(
+ object_,
+ CL_KERNEL_EXEC_INFO_SVM_PTRS,
+ sizeof(void*)*pointerList.size(),
+ pointerList.data()));
+ }
+
+ /*!
+ * Specify a std::array of SVM pointers that the kernel may access in
+ * addition to its arguments.
+ */
+ template<int ArrayLength>
+ cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
+ {
+ return detail::errHandler(
+ ::clSetKernelExecInfo(
+ object_,
+ CL_KERNEL_EXEC_INFO_SVM_PTRS,
+ sizeof(void*)*pointerList.size(),
+ pointerList.data()));
+ }
+
+ /*! \brief Enable fine-grained system SVM.
+ *
+ * \note It is only possible to enable fine-grained system SVM if all devices
+ * in the context associated with kernel support it.
+ *
+ * \param svmEnabled True if fine-grained system SVM is requested. False otherwise.
+ * \return CL_SUCCESS if the function was executed succesfully. CL_INVALID_OPERATION
+ * if no devices in the context support fine-grained system SVM.
+ *
+ * \see clSetKernelExecInfo
+ */
+ cl_int enableFineGrainedSystemSVM(bool svmEnabled)
+ {
+ cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
+ return detail::errHandler(
+ ::clSetKernelExecInfo(
+ object_,
+ CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
+ sizeof(cl_bool),
+ &svmEnabled_
+ )
+ );
+ }
+
+ template<int index, int ArrayLength, class D, typename T0, typename... Ts>
+ void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, Ts... ts)
+ {
+ pointerList[index] = static_cast<void*>(t0.get());
+ setSVMPointersHelper<index + 1, Ts...>(ts...);
+ }
+
+ template<int index, int ArrayLength, typename T0, typename... Ts>
+ typename std::enable_if<std::is_pointer<T0>::value, void>::type
+ setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, Ts... ts)
+ {
+ pointerList[index] = static_cast<void*>(t0);
+ setSVMPointersHelper<index + 1, Ts...>(ts...);
+ }
+
+ template<int index, int ArrayLength, typename T0, class D>
+ void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
+ {
+ pointerList[index] = static_cast<void*>(t0.get());
+ }
+
+ template<int index, int ArrayLength, typename T0>
+ typename std::enable_if<std::is_pointer<T0>::value, void>::type
+ setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
+ {
+ pointerList[index] = static_cast<void*>(t0);
+ }
+
+ template<typename T0, typename... Ts>
+ cl_int setSVMPointers(const T0 &t0, Ts... ts)
+ {
+ std::array<void*, 1 + sizeof...(Ts)> pointerList;
+
+ setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
+ return detail::errHandler(
+ ::clSetKernelExecInfo(
+ object_,
+ CL_KERNEL_EXEC_INFO_SVM_PTRS,
+ sizeof(void*)*(1 + sizeof...(Ts)),
+ pointerList.data()));
+ }
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+};
+
+/*! \class Program
+ * \brief Program interface that implements cl_program.
+ */
+class Program : public detail::Wrapper<cl_program>
+{
+public:
+#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ typedef vector<vector<unsigned char>> Binaries;
+ typedef vector<string> Sources;
+#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ typedef vector<std::pair<const void*, size_type> > Binaries;
+ typedef vector<std::pair<const char*, size_type> > Sources;
+#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+
+ Program(
+ const string& source,
+ bool build = false,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ const char * strings = source.c_str();
+ const size_type length = source.size();
+
+ Context context = Context::getDefault(err);
+
+ object_ = ::clCreateProgramWithSource(
+ context(), (cl_uint)1, &strings, &length, &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
+
+ if (error == CL_SUCCESS && build) {
+
+ error = ::clBuildProgram(
+ object_,
+ 0,
+ NULL,
+#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
+ "-cl-std=CL2.0",
+#else
+ "",
+#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
+ NULL,
+ NULL);
+
+ detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
+ }
+
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ Program(
+ const Context& context,
+ const string& source,
+ bool build = false,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ const char * strings = source.c_str();
+ const size_type length = source.size();
+
+ object_ = ::clCreateProgramWithSource(
+ context(), (cl_uint)1, &strings, &length, &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
+
+ if (error == CL_SUCCESS && build) {
+ error = ::clBuildProgram(
+ object_,
+ 0,
+ NULL,
+#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
+ "-cl-std=CL2.0",
+#else
+ "",
+#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
+ NULL,
+ NULL);
+
+ detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
+ }
+
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /**
+ * Create a program from a vector of source strings and the default context.
+ * Does not compile or link the program.
+ */
+ Program(
+ const Sources& sources,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ Context context = Context::getDefault(err);
+
+ const size_type n = (size_type)sources.size();
+
+ vector<size_type> lengths(n);
+ vector<const char*> strings(n);
+
+ for (size_type i = 0; i < n; ++i) {
+#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ strings[i] = sources[(int)i].data();
+ lengths[i] = sources[(int)i].length();
+#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ strings[i] = sources[(int)i].first;
+ lengths[i] = sources[(int)i].second;
+#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ }
+
+ object_ = ::clCreateProgramWithSource(
+ context(), (cl_uint)n, strings.data(), lengths.data(), &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /**
+ * Create a program from a vector of source strings and a provided context.
+ * Does not compile or link the program.
+ */
+ Program(
+ const Context& context,
+ const Sources& sources,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ const size_type n = (size_type)sources.size();
+
+ vector<size_type> lengths(n);
+ vector<const char*> strings(n);
+
+ for (size_type i = 0; i < n; ++i) {
+#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ strings[i] = sources[(int)i].data();
+ lengths[i] = sources[(int)i].length();
+#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ strings[i] = sources[(int)i].first;
+ lengths[i] = sources[(int)i].second;
+#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ }
+
+ object_ = ::clCreateProgramWithSource(
+ context(), (cl_uint)n, strings.data(), lengths.data(), &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /**
+ * Construct a program object from a list of devices and a per-device list of binaries.
+ * \param context A valid OpenCL context in which to construct the program.
+ * \param devices A vector of OpenCL device objects for which the program will be created.
+ * \param binaries A vector of pairs of a pointer to a binary object and its length.
+ * \param binaryStatus An optional vector that on completion will be resized to
+ * match the size of binaries and filled with values to specify if each binary
+ * was successfully loaded.
+ * Set to CL_SUCCESS if the binary was successfully loaded.
+ * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL.
+ * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device.
+ * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors:
+ * CL_INVALID_CONTEXT if context is not a valid context.
+ * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices;
+ * or if any entry in binaries is NULL or has length 0.
+ * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context.
+ * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device.
+ * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
+ */
+ Program(
+ const Context& context,
+ const vector<Device>& devices,
+ const Binaries& binaries,
+ vector<cl_int>* binaryStatus = NULL,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ const size_type numDevices = devices.size();
+
+ // Catch size mismatch early and return
+ if(binaries.size() != numDevices) {
+ error = CL_INVALID_VALUE;
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ return;
+ }
+
+
+ vector<size_type> lengths(numDevices);
+ vector<const unsigned char*> images(numDevices);
+#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ for (size_type i = 0; i < numDevices; ++i) {
+ images[i] = binaries[i].data();
+ lengths[i] = binaries[(int)i].size();
+ }
+#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+ for (size_type i = 0; i < numDevices; ++i) {
+ images[i] = (const unsigned char*)binaries[i].first;
+ lengths[i] = binaries[(int)i].second;
+ }
+#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
+
+ vector<cl_device_id> deviceIDs(numDevices);
+ for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
+ deviceIDs[deviceIndex] = (devices[deviceIndex])();
+ }
+
+ if(binaryStatus) {
+ binaryStatus->resize(numDevices);
+ }
+
+ object_ = ::clCreateProgramWithBinary(
+ context(), (cl_uint) devices.size(),
+ deviceIDs.data(),
+ lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
+ ? &binaryStatus->front()
+ : NULL, &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ /**
+ * Create program using builtin kernels.
+ * \param kernelNames Semi-colon separated list of builtin kernel names
+ */
+ Program(
+ const Context& context,
+ const vector<Device>& devices,
+ const string& kernelNames,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+
+ size_type numDevices = devices.size();
+ vector<cl_device_id> deviceIDs(numDevices);
+ for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
+ deviceIDs[deviceIndex] = (devices[deviceIndex])();
+ }
+
+ object_ = ::clCreateProgramWithBuiltInKernels(
+ context(),
+ (cl_uint) devices.size(),
+ deviceIDs.data(),
+ kernelNames.c_str(),
+ &error);
+
+ detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+ Program() { }
+
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ */
+ explicit Program(const cl_program& program, bool retainObject = false) :
+ detail::Wrapper<cl_type>(program, retainObject) { }
+
+ Program& operator = (const cl_program& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ Program& operator = (const Program &program)
+ {
+ detail::Wrapper<cl_type>::operator=(program);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(program)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ Program& operator = (Program &&program)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(program));
+ return *this;
+ }
+
+ cl_int build(
+ const vector<Device>& devices,
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL) const
+ {
+ size_type numDevices = devices.size();
+ vector<cl_device_id> deviceIDs(numDevices);
+
+ for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
+ deviceIDs[deviceIndex] = (devices[deviceIndex])();
+ }
+
+ cl_int buildError = ::clBuildProgram(
+ object_,
+ (cl_uint)
+ devices.size(),
+ deviceIDs.data(),
+ options,
+ notifyFptr,
+ data);
+
+ return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
+ }
+
+ cl_int build(
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL) const
+ {
+ cl_int buildError = ::clBuildProgram(
+ object_,
+ 0,
+ NULL,
+ options,
+ notifyFptr,
+ data);
+
+
+ return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ cl_int compile(
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL) const
+ {
+ cl_int error = ::clCompileProgram(
+ object_,
+ 0,
+ NULL,
+ options,
+ 0,
+ NULL,
+ NULL,
+ notifyFptr,
+ data);
+ return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+ template <typename T>
+ cl_int getInfo(cl_program_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(&::clGetProgramInfo, object_, name, param),
+ __GET_PROGRAM_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_program_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_program_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ template <typename T>
+ cl_int getBuildInfo(
+ const Device& device, cl_program_build_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(
+ &::clGetProgramBuildInfo, object_, device(), name, param),
+ __GET_PROGRAM_BUILD_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_program_build_info, name>::param_type
+ getBuildInfo(const Device& device, cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_program_build_info, name>::param_type param;
+ cl_int result = getBuildInfo(device, name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /**
+ * Build info function that returns a vector of device/info pairs for the specified
+ * info type and for all devices in the program.
+ * On an error reading the info for any device, an empty vector of info will be returned.
+ */
+ template <cl_int name>
+ vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
+ getBuildInfo(cl_int *err = NULL) const
+ {
+ cl_int result = CL_SUCCESS;
+
+ auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
+ vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
+ devInfo;
+
+ // If there was an initial error from getInfo return the error
+ if (result != CL_SUCCESS) {
+ if (err != NULL) {
+ *err = result;
+ }
+ return devInfo;
+ }
+
+ for (cl::Device d : devs) {
+ typename detail::param_traits<
+ detail::cl_program_build_info, name>::param_type param;
+ result = getBuildInfo(d, name, ¶m);
+ devInfo.push_back(
+ std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>
+ (d, param));
+ if (result != CL_SUCCESS) {
+ // On error, leave the loop and return the error code
+ break;
+ }
+ }
+ if (err != NULL) {
+ *err = result;
+ }
+ if (result != CL_SUCCESS) {
+ devInfo.clear();
+ }
+ return devInfo;
+ }
+
+ cl_int createKernels(vector<Kernel>* kernels)
+ {
+ cl_uint numKernels;
+ cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
+ }
+
+ vector<cl_kernel> value(numKernels);
+
+ err = ::clCreateKernelsInProgram(
+ object_, numKernels, value.data(), NULL);
+ if (err != CL_SUCCESS) {
+ return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
+ }
+
+ if (kernels) {
+ kernels->resize(value.size());
+
+ // Assign to param, constructing with retain behaviour
+ // to correctly capture each underlying CL object
+ for (size_type i = 0; i < value.size(); i++) {
+ // We do not need to retain because this kernel is being created
+ // by the runtime
+ (*kernels)[i] = Kernel(value[i], false);
+ }
+ }
+ return CL_SUCCESS;
+ }
+};
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+inline Program linkProgram(
+ Program input1,
+ Program input2,
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+{
+ cl_int error_local = CL_SUCCESS;
+
+ cl_program programs[2] = { input1(), input2() };
+
+ Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
+ if(error_local!=CL_SUCCESS) {
+ detail::errHandler(error_local, __LINK_PROGRAM_ERR);
+ }
+
+ cl_program prog = ::clLinkProgram(
+ ctx(),
+ 0,
+ NULL,
+ options,
+ 2,
+ programs,
+ notifyFptr,
+ data,
+ &error_local);
+
+ detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
+ if (err != NULL) {
+ *err = error_local;
+ }
+
+ return Program(prog);
+}
+
+inline Program linkProgram(
+ vector<Program> inputPrograms,
+ const char* options = NULL,
+ void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
+ void* data = NULL,
+ cl_int* err = NULL)
+{
+ cl_int error_local = CL_SUCCESS;
+
+ vector<cl_program> programs(inputPrograms.size());
+
+ for (unsigned int i = 0; i < inputPrograms.size(); i++) {
+ programs[i] = inputPrograms[i]();
+ }
+
+ Context ctx;
+ if(inputPrograms.size() > 0) {
+ ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
+ if(error_local!=CL_SUCCESS) {
+ detail::errHandler(error_local, __LINK_PROGRAM_ERR);
+ }
+ }
+ cl_program prog = ::clLinkProgram(
+ ctx(),
+ 0,
+ NULL,
+ options,
+ (cl_uint)inputPrograms.size(),
+ programs.data(),
+ notifyFptr,
+ data,
+ &error_local);
+
+ detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
+ if (err != NULL) {
+ *err = error_local;
+ }
+
+ return Program(prog, false);
+}
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+// Template specialization for CL_PROGRAM_BINARIES
+template <>
+inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
+{
+ if (name != CL_PROGRAM_BINARIES) {
+ return CL_INVALID_VALUE;
+ }
+ if (param) {
+ // Resize the parameter array appropriately for each allocation
+ // and pass down to the helper
+
+ vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
+ size_type numBinaries = sizes.size();
+
+ // Resize the parameter array and constituent arrays
+ param->resize(numBinaries);
+ for (size_type i = 0; i < numBinaries; ++i) {
+ (*param)[i].resize(sizes[i]);
+ }
+
+ return detail::errHandler(
+ detail::getInfo(&::clGetProgramInfo, object_, name, param),
+ __GET_PROGRAM_INFO_ERR);
+ }
+
+ return CL_SUCCESS;
+}
+
+template<>
+inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
+{
+ vector<vector<unsigned char>> binariesVectors;
+
+ cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
+ if (err != NULL) {
+ *err = result;
+ }
+ return binariesVectors;
+}
+
+inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
+{
+ cl_int error;
+
+ object_ = ::clCreateKernel(program(), name, &error);
+ detail::errHandler(error, __CREATE_KERNEL_ERR);
+
+ if (err != NULL) {
+ *err = error;
+ }
+
+}
+
+enum class QueueProperties : cl_command_queue_properties
+{
+ None = 0,
+ Profiling = CL_QUEUE_PROFILING_ENABLE,
+ OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
+};
+
+inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
+{
+ return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
+}
+
+/*! \class CommandQueue
+ * \brief CommandQueue interface for cl_command_queue.
+ */
+class CommandQueue : public detail::Wrapper<cl_command_queue>
+{
+private:
+ static std::once_flag default_initialized_;
+ static CommandQueue default_;
+ static cl_int default_error_;
+
+ /*! \brief Create the default command queue returned by @ref getDefault.
+ *
+ * It sets default_error_ to indicate success or failure. It does not throw
+ * @c cl::Error.
+ */
+ static void makeDefault()
+ {
+ /* We don't want to throw an error from this function, so we have to
+ * catch and set the error flag.
+ */
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ try
+#endif
+ {
+ int error;
+ Context context = Context::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ default_error_ = error;
+ }
+ else {
+ Device device = Device::getDefault();
+ default_ = CommandQueue(context, device, 0, &default_error_);
+ }
+ }
+#if defined(CL_HPP_ENABLE_EXCEPTIONS)
+ catch (cl::Error &e) {
+ default_error_ = e.err();
+ }
+#endif
+ }
+
+ /*! \brief Create the default command queue.
+ *
+ * This sets @c default_. It does not throw
+ * @c cl::Error.
+ */
+ static void makeDefaultProvided(const CommandQueue &c) {
+ default_ = c;
+ }
+
+public:
+#ifdef CL_HPP_UNIT_TEST_ENABLE
+ /*! \brief Reset the default.
+ *
+ * This sets @c default_ to an empty value to support cleanup in
+ * the unit test framework.
+ * This function is not thread safe.
+ */
+ static void unitTestClearDefault() {
+ default_ = CommandQueue();
+ }
+#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
+
+
+ /*!
+ * \brief Constructs a CommandQueue based on passed properties.
+ * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
+ */
+ CommandQueue(
+ cl_command_queue_properties properties,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ Context context = Context::getDefault(&error);
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+
+ if (error != CL_SUCCESS) {
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+ else {
+ Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, properties, 0 };
+ if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error);
+ }
+ else {
+ error = CL_INVALID_QUEUE_PROPERTIES;
+ }
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#else
+ object_ = ::clCreateCommandQueue(
+ context(), device(), properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#endif
+ }
+ }
+
+ /*!
+ * \brief Constructs a CommandQueue based on passed properties.
+ * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
+ */
+ CommandQueue(
+ QueueProperties properties,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ Context context = Context::getDefault(&error);
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+
+ if (error != CL_SUCCESS) {
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+ else {
+ Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
+
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error);
+
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#else
+ object_ = ::clCreateCommandQueue(
+ context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#endif
+ }
+ }
+
+ /*!
+ * \brief Constructs a CommandQueue for an implementation defined device in the given context
+ * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
+ */
+ explicit CommandQueue(
+ const Context& context,
+ cl_command_queue_properties properties = 0,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ vector<cl::Device> devices;
+ error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
+
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+
+ if (error != CL_SUCCESS)
+ {
+ if (err != NULL) {
+ *err = error;
+ }
+ return;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, properties, 0 };
+ if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), devices[0](), queue_properties, &error);
+ }
+ else {
+ error = CL_INVALID_QUEUE_PROPERTIES;
+ }
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#else
+ object_ = ::clCreateCommandQueue(
+ context(), devices[0](), properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#endif
+
+ }
+
+ /*!
+ * \brief Constructs a CommandQueue for an implementation defined device in the given context
+ * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
+ */
+ explicit CommandQueue(
+ const Context& context,
+ QueueProperties properties,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+ vector<cl::Device> devices;
+ error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
+
+ detail::errHandler(error, __CREATE_CONTEXT_ERR);
+
+ if (error != CL_SUCCESS)
+ {
+ if (err != NULL) {
+ *err = error;
+ }
+ return;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), devices[0](), queue_properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#else
+ object_ = ::clCreateCommandQueue(
+ context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#endif
+
+ }
+
+ /*!
+ * \brief Constructs a CommandQueue for a passed device and context
+ * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
+ */
+ CommandQueue(
+ const Context& context,
+ const Device& device,
+ cl_command_queue_properties properties = 0,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, properties, 0 };
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#else
+ object_ = ::clCreateCommandQueue(
+ context(), device(), properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#endif
+ }
+
+ /*!
+ * \brief Constructs a CommandQueue for a passed device and context
+ * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
+ */
+ CommandQueue(
+ const Context& context,
+ const Device& device,
+ QueueProperties properties,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#else
+ object_ = ::clCreateCommandQueue(
+ context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+#endif
+ }
+
+ static CommandQueue getDefault(cl_int * err = NULL)
+ {
+ std::call_once(default_initialized_, makeDefault);
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+#else // CL_HPP_TARGET_OPENCL_VERSION >= 200
+ detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
+ if (err != NULL) {
+ *err = default_error_;
+ }
+ return default_;
+ }
+
+ /**
+ * Modify the default command queue to be used by
+ * subsequent operations.
+ * Will only set the default if no default was previously created.
+ * @return updated default command queue.
+ * Should be compared to the passed value to ensure that it was updated.
+ */
+ static CommandQueue setDefault(const CommandQueue &default_queue)
+ {
+ std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
+ detail::errHandler(default_error_);
+ return default_;
+ }
+
+ CommandQueue() { }
+
+
+ /*! \brief Constructor from cl_mem - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ */
+ explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
+ detail::Wrapper<cl_type>(commandQueue, retainObject) { }
+
+ CommandQueue& operator = (const cl_command_queue& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ CommandQueue& operator = (const CommandQueue &queue)
+ {
+ detail::Wrapper<cl_type>::operator=(queue);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ CommandQueue& operator = (CommandQueue &&queue)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(queue));
+ return *this;
+ }
+
+ template <typename T>
+ cl_int getInfo(cl_command_queue_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(
+ &::clGetCommandQueueInfo, object_, name, param),
+ __GET_COMMAND_QUEUE_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_command_queue_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_command_queue_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ cl_int enqueueReadBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ size_type offset,
+ size_type size,
+ void* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueReadBuffer(
+ object_, buffer(), blocking, offset, size,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_READ_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueWriteBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ size_type offset,
+ size_type size,
+ const void* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueWriteBuffer(
+ object_, buffer(), blocking, offset, size,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_WRITE_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueCopyBuffer(
+ const Buffer& src,
+ const Buffer& dst,
+ size_type src_offset,
+ size_type dst_offset,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyBuffer(
+ object_, src(), dst(), src_offset, dst_offset, size,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQEUE_COPY_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueReadBufferRect(
+ const Buffer& buffer,
+ cl_bool blocking,
+ const array<size_type, 3>& buffer_offset,
+ const array<size_type, 3>& host_offset,
+ const array<size_type, 3>& region,
+ size_type buffer_row_pitch,
+ size_type buffer_slice_pitch,
+ size_type host_row_pitch,
+ size_type host_slice_pitch,
+ void *ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueReadBufferRect(
+ object_,
+ buffer(),
+ blocking,
+ buffer_offset.data(),
+ host_offset.data(),
+ region.data(),
+ buffer_row_pitch,
+ buffer_slice_pitch,
+ host_row_pitch,
+ host_slice_pitch,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_READ_BUFFER_RECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueWriteBufferRect(
+ const Buffer& buffer,
+ cl_bool blocking,
+ const array<size_type, 3>& buffer_offset,
+ const array<size_type, 3>& host_offset,
+ const array<size_type, 3>& region,
+ size_type buffer_row_pitch,
+ size_type buffer_slice_pitch,
+ size_type host_row_pitch,
+ size_type host_slice_pitch,
+ const void *ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueWriteBufferRect(
+ object_,
+ buffer(),
+ blocking,
+ buffer_offset.data(),
+ host_offset.data(),
+ region.data(),
+ buffer_row_pitch,
+ buffer_slice_pitch,
+ host_row_pitch,
+ host_slice_pitch,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_WRITE_BUFFER_RECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueCopyBufferRect(
+ const Buffer& src,
+ const Buffer& dst,
+ const array<size_type, 3>& src_origin,
+ const array<size_type, 3>& dst_origin,
+ const array<size_type, 3>& region,
+ size_type src_row_pitch,
+ size_type src_slice_pitch,
+ size_type dst_row_pitch,
+ size_type dst_slice_pitch,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyBufferRect(
+ object_,
+ src(),
+ dst(),
+ src_origin.data(),
+ dst_origin.data(),
+ region.data(),
+ src_row_pitch,
+ src_slice_pitch,
+ dst_row_pitch,
+ dst_slice_pitch,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQEUE_COPY_BUFFER_RECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ /**
+ * Enqueue a command to fill a buffer object with a pattern
+ * of a given size. The pattern is specified as a vector type.
+ * \tparam PatternType The datatype of the pattern field.
+ * The pattern type must be an accepted OpenCL data type.
+ * \tparam offset Is the offset in bytes into the buffer at
+ * which to start filling. This must be a multiple of
+ * the pattern size.
+ * \tparam size Is the size in bytes of the region to fill.
+ * This must be a multiple of the pattern size.
+ */
+ template<typename PatternType>
+ cl_int enqueueFillBuffer(
+ const Buffer& buffer,
+ PatternType pattern,
+ size_type offset,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueFillBuffer(
+ object_,
+ buffer(),
+ static_cast<void*>(&pattern),
+ sizeof(PatternType),
+ offset,
+ size,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_FILL_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+ cl_int enqueueReadImage(
+ const Image& image,
+ cl_bool blocking,
+ const array<size_type, 3>& origin,
+ const array<size_type, 3>& region,
+ size_type row_pitch,
+ size_type slice_pitch,
+ void* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueReadImage(
+ object_,
+ image(),
+ blocking,
+ origin.data(),
+ region.data(),
+ row_pitch,
+ slice_pitch,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_READ_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueWriteImage(
+ const Image& image,
+ cl_bool blocking,
+ const array<size_type, 3>& origin,
+ const array<size_type, 3>& region,
+ size_type row_pitch,
+ size_type slice_pitch,
+ const void* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueWriteImage(
+ object_,
+ image(),
+ blocking,
+ origin.data(),
+ region.data(),
+ row_pitch,
+ slice_pitch,
+ ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_WRITE_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueCopyImage(
+ const Image& src,
+ const Image& dst,
+ const array<size_type, 3>& src_origin,
+ const array<size_type, 3>& dst_origin,
+ const array<size_type, 3>& region,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyImage(
+ object_,
+ src(),
+ dst(),
+ src_origin.data(),
+ dst_origin.data(),
+ region.data(),
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_COPY_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ /**
+ * Enqueue a command to fill an image object with a specified color.
+ * \param fillColor is the color to use to fill the image.
+ * This is a four component RGBA floating-point color value if
+ * the image channel data type is not an unnormalized signed or
+ * unsigned data type.
+ */
+ cl_int enqueueFillImage(
+ const Image& image,
+ cl_float4 fillColor,
+ const array<size_type, 3>& origin,
+ const array<size_type, 3>& region,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueFillImage(
+ object_,
+ image(),
+ static_cast<void*>(&fillColor),
+ origin.data(),
+ region.data(),
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_FILL_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueue a command to fill an image object with a specified color.
+ * \param fillColor is the color to use to fill the image.
+ * This is a four component RGBA signed integer color value if
+ * the image channel data type is an unnormalized signed integer
+ * type.
+ */
+ cl_int enqueueFillImage(
+ const Image& image,
+ cl_int4 fillColor,
+ const array<size_type, 3>& origin,
+ const array<size_type, 3>& region,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueFillImage(
+ object_,
+ image(),
+ static_cast<void*>(&fillColor),
+ origin.data(),
+ region.data(),
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_FILL_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueue a command to fill an image object with a specified color.
+ * \param fillColor is the color to use to fill the image.
+ * This is a four component RGBA unsigned integer color value if
+ * the image channel data type is an unnormalized unsigned integer
+ * type.
+ */
+ cl_int enqueueFillImage(
+ const Image& image,
+ cl_uint4 fillColor,
+ const array<size_type, 3>& origin,
+ const array<size_type, 3>& region,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueFillImage(
+ object_,
+ image(),
+ static_cast<void*>(&fillColor),
+ origin.data(),
+ region.data(),
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_FILL_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+ cl_int enqueueCopyImageToBuffer(
+ const Image& src,
+ const Buffer& dst,
+ const array<size_type, 3>& src_origin,
+ const array<size_type, 3>& region,
+ size_type dst_offset,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyImageToBuffer(
+ object_,
+ src(),
+ dst(),
+ src_origin.data(),
+ region.data(),
+ dst_offset,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueCopyBufferToImage(
+ const Buffer& src,
+ const Image& dst,
+ size_type src_offset,
+ const array<size_type, 3>& dst_origin,
+ const array<size_type, 3>& region,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueCopyBufferToImage(
+ object_,
+ src(),
+ dst(),
+ src_offset,
+ dst_origin.data(),
+ region.data(),
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ void* enqueueMapBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ cl_map_flags flags,
+ size_type offset,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL,
+ cl_int* err = NULL) const
+ {
+ cl_event tmp;
+ cl_int error;
+ void * result = ::clEnqueueMapBuffer(
+ object_, buffer(), blocking, flags, offset, size,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL,
+ &error);
+
+ detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ if (event != NULL && error == CL_SUCCESS)
+ *event = tmp;
+
+ return result;
+ }
+
+ void* enqueueMapImage(
+ const Image& buffer,
+ cl_bool blocking,
+ cl_map_flags flags,
+ const array<size_type, 3>& origin,
+ const array<size_type, 3>& region,
+ size_type * row_pitch,
+ size_type * slice_pitch,
+ const vector<Event>* events = NULL,
+ Event* event = NULL,
+ cl_int* err = NULL) const
+ {
+ cl_event tmp;
+ cl_int error;
+ void * result = ::clEnqueueMapImage(
+ object_, buffer(), blocking, flags,
+ origin.data(),
+ region.data(),
+ row_pitch, slice_pitch,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL,
+ &error);
+
+ detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ if (event != NULL && error == CL_SUCCESS)
+ *event = tmp;
+ return result;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ /**
+ * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
+ * This variant takes a raw SVM pointer.
+ */
+ template<typename T>
+ cl_int enqueueMapSVM(
+ T* ptr,
+ cl_bool blocking,
+ cl_map_flags flags,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(::clEnqueueSVMMap(
+ object_, blocking, flags, static_cast<void*>(ptr), size,
+ (events != NULL) ? (cl_uint)events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_MAP_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+
+ /**
+ * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
+ * This variant takes a cl::pointer instance.
+ */
+ template<typename T, class D>
+ cl_int enqueueMapSVM(
+ cl::pointer<T, D> &ptr,
+ cl_bool blocking,
+ cl_map_flags flags,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(::clEnqueueSVMMap(
+ object_, blocking, flags, static_cast<void*>(ptr.get()), size,
+ (events != NULL) ? (cl_uint)events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_MAP_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
+ * This variant takes a cl::vector instance.
+ */
+ template<typename T, class Alloc>
+ cl_int enqueueMapSVM(
+ cl::vector<T, Alloc> &container,
+ cl_bool blocking,
+ cl_map_flags flags,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(::clEnqueueSVMMap(
+ object_, blocking, flags, static_cast<void*>(container.data()), container.size(),
+ (events != NULL) ? (cl_uint)events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_MAP_BUFFER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+ cl_int enqueueUnmapMemObject(
+ const Memory& memory,
+ void* mapped_ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueUnmapMemObject(
+ object_, memory(), mapped_ptr,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ /**
+ * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
+ * This variant takes a raw SVM pointer.
+ */
+ template<typename T>
+ cl_int enqueueUnmapSVM(
+ T* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueSVMUnmap(
+ object_, static_cast<void*>(ptr),
+ (events != NULL) ? (cl_uint)events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
+ * This variant takes a cl::pointer instance.
+ */
+ template<typename T, class D>
+ cl_int enqueueUnmapSVM(
+ cl::pointer<T, D> &ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueSVMUnmap(
+ object_, static_cast<void*>(ptr.get()),
+ (events != NULL) ? (cl_uint)events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
+ * This variant takes a cl::vector instance.
+ */
+ template<typename T, class Alloc>
+ cl_int enqueueUnmapSVM(
+ cl::vector<T, Alloc> &container,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueSVMUnmap(
+ object_, static_cast<void*>(container.data()),
+ (events != NULL) ? (cl_uint)events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ /**
+ * Enqueues a marker command which waits for either a list of events to complete,
+ * or all previously enqueued commands to complete.
+ *
+ * Enqueues a marker command which waits for either a list of events to complete,
+ * or if the list is empty it waits for all commands previously enqueued in command_queue
+ * to complete before it completes. This command returns an event which can be waited on,
+ * i.e. this event can be waited on to insure that all events either in the event_wait_list
+ * or all previously enqueued commands, queued before this command to command_queue,
+ * have completed.
+ */
+ cl_int enqueueMarkerWithWaitList(
+ const vector<Event> *events = 0,
+ Event *event = 0)
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueMarkerWithWaitList(
+ object_,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_MARKER_WAIT_LIST_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * A synchronization point that enqueues a barrier operation.
+ *
+ * Enqueues a barrier command which waits for either a list of events to complete,
+ * or if the list is empty it waits for all commands previously enqueued in command_queue
+ * to complete before it completes. This command blocks command execution, that is, any
+ * following commands enqueued after it do not execute until it completes. This command
+ * returns an event which can be waited on, i.e. this event can be waited on to insure that
+ * all events either in the event_wait_list or all previously enqueued commands, queued
+ * before this command to command_queue, have completed.
+ */
+ cl_int enqueueBarrierWithWaitList(
+ const vector<Event> *events = 0,
+ Event *event = 0)
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueBarrierWithWaitList(
+ object_,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_BARRIER_WAIT_LIST_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ /**
+ * Enqueues a command to indicate with which device a set of memory objects
+ * should be associated.
+ */
+ cl_int enqueueMigrateMemObjects(
+ const vector<Memory> &memObjects,
+ cl_mem_migration_flags flags,
+ const vector<Event>* events = NULL,
+ Event* event = NULL
+ )
+ {
+ cl_event tmp;
+
+ vector<cl_mem> localMemObjects(memObjects.size());
+
+ for( int i = 0; i < (int)memObjects.size(); ++i ) {
+ localMemObjects[i] = memObjects[i]();
+ }
+
+
+ cl_int err = detail::errHandler(
+ ::clEnqueueMigrateMemObjects(
+ object_,
+ (cl_uint)memObjects.size(),
+ localMemObjects.data(),
+ flags,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+
+ cl_int enqueueNDRangeKernel(
+ const Kernel& kernel,
+ const NDRange& offset,
+ const NDRange& global,
+ const NDRange& local = NullRange,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueNDRangeKernel(
+ object_, kernel(), (cl_uint) global.dimensions(),
+ offset.dimensions() != 0 ? (const size_type*) offset : NULL,
+ (const size_type*) global,
+ local.dimensions() != 0 ? (const size_type*) local : NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_NDRANGE_KERNEL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
+ CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
+ const Kernel& kernel,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueTask(
+ object_, kernel(),
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_TASK_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
+
+ cl_int enqueueNativeKernel(
+ void (CL_CALLBACK *userFptr)(void *),
+ std::pair<void*, size_type> args,
+ const vector<Memory>* mem_objects = NULL,
+ const vector<const void*>* mem_locs = NULL,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ size_type elements = 0;
+ if (mem_objects != NULL) {
+ elements = mem_objects->size();
+ }
+ vector<cl_mem> mems(elements);
+ for (unsigned int i = 0; i < elements; i++) {
+ mems[i] = ((*mem_objects)[i])();
+ }
+
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueNativeKernel(
+ object_, userFptr, args.first, args.second,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ mems.data(),
+ (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_NATIVE_KERNEL);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+ CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+ cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueMarker(
+ object_,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_MARKER_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+ cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+ {
+ return detail::errHandler(
+ ::clEnqueueWaitForEvents(
+ object_,
+ (cl_uint) events.size(),
+ events.size() > 0 ? (const cl_event*) &events.front() : NULL),
+ __ENQUEUE_WAIT_FOR_EVENTS_ERR);
+ }
+#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+
+ cl_int enqueueAcquireGLObjects(
+ const vector<Memory>* mem_objects = NULL,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueAcquireGLObjects(
+ object_,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_ACQUIRE_GL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueReleaseGLObjects(
+ const vector<Memory>* mem_objects = NULL,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueReleaseGLObjects(
+ object_,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_RELEASE_GL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+#if defined (CL_HPP_USE_DX_INTEROP)
+typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
+ cl_command_queue command_queue, cl_uint num_objects,
+ const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
+ const cl_event* event_wait_list, cl_event* event);
+typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
+ cl_command_queue command_queue, cl_uint num_objects,
+ const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
+ const cl_event* event_wait_list, cl_event* event);
+
+ cl_int enqueueAcquireD3D10Objects(
+ const vector<Memory>* mem_objects = NULL,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ cl_context context = getInfo<CL_QUEUE_CONTEXT>();
+ cl::Device device(getInfo<CL_QUEUE_DEVICE>());
+ cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
+ CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
+#endif
+#if CL_HPP_TARGET_OPENCL_VERSION >= 110
+ CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
+#endif
+
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ pfn_clEnqueueAcquireD3D10ObjectsKHR(
+ object_,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_ACQUIRE_GL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+
+ cl_int enqueueReleaseD3D10Objects(
+ const vector<Memory>* mem_objects = NULL,
+ const vector<Event>* events = NULL,
+ Event* event = NULL) const
+ {
+ static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
+#if CL_HPP_TARGET_OPENCL_VERSION >= 120
+ cl_context context = getInfo<CL_QUEUE_CONTEXT>();
+ cl::Device device(getInfo<CL_QUEUE_DEVICE>());
+ cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
+ CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
+#if CL_HPP_TARGET_OPENCL_VERSION >= 110
+ CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ pfn_clEnqueueReleaseD3D10ObjectsKHR(
+ object_,
+ (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
+ (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_RELEASE_GL_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+ }
+#endif
+
+/**
+ * Deprecated APIs for 1.2
+ */
+#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
+ CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+ cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+ {
+ return detail::errHandler(
+ ::clEnqueueBarrier(object_),
+ __ENQUEUE_BARRIER_ERR);
+ }
+#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
+
+ cl_int flush() const
+ {
+ return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
+ }
+
+ cl_int finish() const
+ {
+ return detail::errHandler(::clFinish(object_), __FINISH_ERR);
+ }
+}; // CommandQueue
+
+CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
+CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
+CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
+
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+enum class DeviceQueueProperties : cl_command_queue_properties
+{
+ None = 0,
+ Profiling = CL_QUEUE_PROFILING_ENABLE,
+};
+
+inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
+{
+ return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
+}
+
+/*! \class DeviceCommandQueue
+ * \brief DeviceCommandQueue interface for device cl_command_queues.
+ */
+class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
+{
+public:
+
+ /*!
+ * Trivial empty constructor to create a null queue.
+ */
+ DeviceCommandQueue() { }
+
+ /*!
+ * Default construct device command queue on default context and device
+ */
+ DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL)
+ {
+ cl_int error;
+ cl::Context context = cl::Context::getDefault();
+ cl::Device device = cl::Device::getDefault();
+
+ cl_command_queue_properties mergedProperties =
+ CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
+
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, mergedProperties, 0 };
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*!
+ * Create a device command queue for a specified device in the passed context.
+ */
+ DeviceCommandQueue(
+ const Context& context,
+ const Device& device,
+ DeviceQueueProperties properties = DeviceQueueProperties::None,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ cl_command_queue_properties mergedProperties =
+ CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, mergedProperties, 0 };
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*!
+ * Create a device command queue for a specified device in the passed context.
+ */
+ DeviceCommandQueue(
+ const Context& context,
+ const Device& device,
+ cl_uint queueSize,
+ DeviceQueueProperties properties = DeviceQueueProperties::None,
+ cl_int* err = NULL)
+ {
+ cl_int error;
+
+ cl_command_queue_properties mergedProperties =
+ CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, mergedProperties,
+ CL_QUEUE_SIZE, queueSize,
+ 0 };
+ object_ = ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error);
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+
+ /*! \brief Constructor from cl_command_queue - takes ownership.
+ *
+ * \param retainObject will cause the constructor to retain its cl object.
+ * Defaults to false to maintain compatibility with
+ * earlier versions.
+ */
+ explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
+ detail::Wrapper<cl_type>(commandQueue, retainObject) { }
+
+ DeviceCommandQueue& operator = (const cl_command_queue& rhs)
+ {
+ detail::Wrapper<cl_type>::operator=(rhs);
+ return *this;
+ }
+
+ /*! \brief Copy constructor to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
+
+ /*! \brief Copy assignment to forward copy to the superclass correctly.
+ * Required for MSVC.
+ */
+ DeviceCommandQueue& operator = (const DeviceCommandQueue &queue)
+ {
+ detail::Wrapper<cl_type>::operator=(queue);
+ return *this;
+ }
+
+ /*! \brief Move constructor to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
+
+ /*! \brief Move assignment to forward move to the superclass correctly.
+ * Required for MSVC.
+ */
+ DeviceCommandQueue& operator = (DeviceCommandQueue &&queue)
+ {
+ detail::Wrapper<cl_type>::operator=(std::move(queue));
+ return *this;
+ }
+
+ template <typename T>
+ cl_int getInfo(cl_command_queue_info name, T* param) const
+ {
+ return detail::errHandler(
+ detail::getInfo(
+ &::clGetCommandQueueInfo, object_, name, param),
+ __GET_COMMAND_QUEUE_INFO_ERR);
+ }
+
+ template <cl_int name> typename
+ detail::param_traits<detail::cl_command_queue_info, name>::param_type
+ getInfo(cl_int* err = NULL) const
+ {
+ typename detail::param_traits<
+ detail::cl_command_queue_info, name>::param_type param;
+ cl_int result = getInfo(name, ¶m);
+ if (err != NULL) {
+ *err = result;
+ }
+ return param;
+ }
+
+ /*!
+ * Create a new default device command queue for the default device,
+ * in the default context and of the default size.
+ * If there is already a default queue for the specified device this
+ * function will return the pre-existing queue.
+ */
+ static DeviceCommandQueue makeDefault(
+ cl_int *err = nullptr)
+ {
+ cl_int error;
+ cl::Context context = cl::Context::getDefault();
+ cl::Device device = cl::Device::getDefault();
+
+ cl_command_queue_properties properties =
+ CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, properties,
+ 0 };
+ DeviceCommandQueue deviceQueue(
+ ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error));
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ return deviceQueue;
+ }
+
+ /*!
+ * Create a new default device command queue for the specified device
+ * and of the default size.
+ * If there is already a default queue for the specified device this
+ * function will return the pre-existing queue.
+ */
+ static DeviceCommandQueue makeDefault(
+ const Context &context, const Device &device, cl_int *err = nullptr)
+ {
+ cl_int error;
+
+ cl_command_queue_properties properties =
+ CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, properties,
+ 0 };
+ DeviceCommandQueue deviceQueue(
+ ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error));
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ return deviceQueue;
+ }
+
+ /*!
+ * Create a new default device command queue for the specified device
+ * and of the requested size in bytes.
+ * If there is already a default queue for the specified device this
+ * function will return the pre-existing queue.
+ */
+ static DeviceCommandQueue makeDefault(
+ const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
+ {
+ cl_int error;
+
+ cl_command_queue_properties properties =
+ CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
+ cl_queue_properties queue_properties[] = {
+ CL_QUEUE_PROPERTIES, properties,
+ CL_QUEUE_SIZE, queueSize,
+ 0 };
+ DeviceCommandQueue deviceQueue(
+ ::clCreateCommandQueueWithProperties(
+ context(), device(), queue_properties, &error));
+
+ detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ return deviceQueue;
+ }
+}; // DeviceCommandQueue
+
+namespace detail
+{
+ // Specialization for device command queue
+ template <>
+ struct KernelArgumentHandler<cl::DeviceCommandQueue, void>
+ {
+ static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
+ static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
+ };
+} // namespace detail
+
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+
+template< typename IteratorType >
+Buffer::Buffer(
+ const Context &context,
+ IteratorType startIterator,
+ IteratorType endIterator,
+ bool readOnly,
+ bool useHostPtr,
+ cl_int* err)
+{
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ cl_mem_flags flags = 0;
+ if( readOnly ) {
+ flags |= CL_MEM_READ_ONLY;
+ }
+ else {
+ flags |= CL_MEM_READ_WRITE;
+ }
+ if( useHostPtr ) {
+ flags |= CL_MEM_USE_HOST_PTR;
+ }
+
+ size_type size = sizeof(DataType)*(endIterator - startIterator);
+
+ if( useHostPtr ) {
+ object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
+ } else {
+ object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
+ }
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ if( !useHostPtr ) {
+ CommandQueue queue(context, 0, &error);
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ error = cl::copy(queue, startIterator, endIterator, *this);
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+}
+
+template< typename IteratorType >
+Buffer::Buffer(
+ const CommandQueue &queue,
+ IteratorType startIterator,
+ IteratorType endIterator,
+ bool readOnly,
+ bool useHostPtr,
+ cl_int* err)
+{
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ cl_mem_flags flags = 0;
+ if (readOnly) {
+ flags |= CL_MEM_READ_ONLY;
+ }
+ else {
+ flags |= CL_MEM_READ_WRITE;
+ }
+ if (useHostPtr) {
+ flags |= CL_MEM_USE_HOST_PTR;
+ }
+
+ size_type size = sizeof(DataType)*(endIterator - startIterator);
+
+ Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
+
+ if (useHostPtr) {
+ object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
+ }
+ else {
+ object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
+ }
+
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ if (!useHostPtr) {
+ error = cl::copy(queue, startIterator, endIterator, *this);
+ detail::errHandler(error, __CREATE_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ }
+}
+
+inline cl_int enqueueReadBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ size_type offset,
+ size_type size,
+ void* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
+}
+
+inline cl_int enqueueWriteBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ size_type offset,
+ size_type size,
+ const void* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
+}
+
+inline void* enqueueMapBuffer(
+ const Buffer& buffer,
+ cl_bool blocking,
+ cl_map_flags flags,
+ size_type offset,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL,
+ cl_int* err = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+
+ void * result = ::clEnqueueMapBuffer(
+ queue(), buffer(), blocking, flags, offset, size,
+ (events != NULL) ? (cl_uint) events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
+ (cl_event*) event,
+ &error);
+
+ detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ if (err != NULL) {
+ *err = error;
+ }
+ return result;
+}
+
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+/**
+ * Enqueues to the default queue a command that will allow the host to
+ * update a region of a coarse-grained SVM buffer.
+ * This variant takes a raw SVM pointer.
+ */
+template<typename T>
+inline cl_int enqueueMapSVM(
+ T* ptr,
+ cl_bool blocking,
+ cl_map_flags flags,
+ size_type size,
+ const vector<Event>* events,
+ Event* event)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS) {
+ return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ }
+
+ return queue.enqueueMapSVM(
+ ptr, blocking, flags, size, events, event);
+}
+
+/**
+ * Enqueues to the default queue a command that will allow the host to
+ * update a region of a coarse-grained SVM buffer.
+ * This variant takes a cl::pointer instance.
+ */
+template<typename T, class D>
+inline cl_int enqueueMapSVM(
+ cl::pointer<T, D> ptr,
+ cl_bool blocking,
+ cl_map_flags flags,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS) {
+ return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ }
+
+ return queue.enqueueMapSVM(
+ ptr, blocking, flags, size, events, event);
+}
+
+/**
+ * Enqueues to the default queue a command that will allow the host to
+ * update a region of a coarse-grained SVM buffer.
+ * This variant takes a cl::vector instance.
+ */
+template<typename T, class Alloc>
+inline cl_int enqueueMapSVM(
+ cl::vector<T, Alloc> container,
+ cl_bool blocking,
+ cl_map_flags flags,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS) {
+ return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ }
+
+ return queue.enqueueMapSVM(
+ container, blocking, flags, events, event);
+}
+
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+inline cl_int enqueueUnmapMemObject(
+ const Memory& memory,
+ void* mapped_ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ cl_event tmp;
+ cl_int err = detail::errHandler(
+ ::clEnqueueUnmapMemObject(
+ queue(), memory(), mapped_ptr,
+ (events != NULL) ? (cl_uint)events->size() : 0,
+ (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
+ (event != NULL) ? &tmp : NULL),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+ if (event != NULL && err == CL_SUCCESS)
+ *event = tmp;
+
+ return err;
+}
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+/**
+ * Enqueues to the default queue a command that will release a coarse-grained
+ * SVM buffer back to the OpenCL runtime.
+ * This variant takes a raw SVM pointer.
+ */
+template<typename T>
+inline cl_int enqueueUnmapSVM(
+ T* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS) {
+ return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+ }
+
+ return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+
+}
+
+/**
+ * Enqueues to the default queue a command that will release a coarse-grained
+ * SVM buffer back to the OpenCL runtime.
+ * This variant takes a cl::pointer instance.
+ */
+template<typename T, class D>
+inline cl_int enqueueUnmapSVM(
+ cl::pointer<T, D> &ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS) {
+ return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+ }
+
+ return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+}
+
+/**
+ * Enqueues to the default queue a command that will release a coarse-grained
+ * SVM buffer back to the OpenCL runtime.
+ * This variant takes a cl::vector instance.
+ */
+template<typename T, class Alloc>
+inline cl_int enqueueUnmapSVM(
+ cl::vector<T, Alloc> &container,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS) {
+ return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+ }
+
+ return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
+ __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
+}
+
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+inline cl_int enqueueCopyBuffer(
+ const Buffer& src,
+ const Buffer& dst,
+ size_type src_offset,
+ size_type dst_offset,
+ size_type size,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
+}
+
+/**
+ * Blocking copy operation between iterators and a buffer.
+ * Host to Device.
+ * Uses default command queue.
+ */
+template< typename IteratorType >
+inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS)
+ return error;
+
+ return cl::copy(queue, startIterator, endIterator, buffer);
+}
+
+/**
+ * Blocking copy operation between iterators and a buffer.
+ * Device to Host.
+ * Uses default command queue.
+ */
+template< typename IteratorType >
+inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+ if (error != CL_SUCCESS)
+ return error;
+
+ return cl::copy(queue, buffer, startIterator, endIterator);
+}
+
+/**
+ * Blocking copy operation between iterators and a buffer.
+ * Host to Device.
+ * Uses specified queue.
+ */
+template< typename IteratorType >
+inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
+{
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ size_type length = endIterator-startIterator;
+ size_type byteLength = length*sizeof(DataType);
+
+ DataType *pointer =
+ static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
+ // if exceptions enabled, enqueueMapBuffer will throw
+ if( error != CL_SUCCESS ) {
+ return error;
+ }
+#if defined(_MSC_VER)
+ std::copy(
+ startIterator,
+ endIterator,
+ stdext::checked_array_iterator<DataType*>(
+ pointer, length));
+#else
+ std::copy(startIterator, endIterator, pointer);
+#endif
+ Event endEvent;
+ error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
+ // if exceptions enabled, enqueueUnmapMemObject will throw
+ if( error != CL_SUCCESS ) {
+ return error;
+ }
+ endEvent.wait();
+ return CL_SUCCESS;
+}
+
+/**
+ * Blocking copy operation between iterators and a buffer.
+ * Device to Host.
+ * Uses specified queue.
+ */
+template< typename IteratorType >
+inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
+{
+ typedef typename std::iterator_traits<IteratorType>::value_type DataType;
+ cl_int error;
+
+ size_type length = endIterator-startIterator;
+ size_type byteLength = length*sizeof(DataType);
+
+ DataType *pointer =
+ static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
+ // if exceptions enabled, enqueueMapBuffer will throw
+ if( error != CL_SUCCESS ) {
+ return error;
+ }
+ std::copy(pointer, pointer + length, startIterator);
+ Event endEvent;
+ error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
+ // if exceptions enabled, enqueueUnmapMemObject will throw
+ if( error != CL_SUCCESS ) {
+ return error;
+ }
+ endEvent.wait();
+ return CL_SUCCESS;
+}
+
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+/**
+ * Blocking SVM map operation - performs a blocking map underneath.
+ */
+template<typename T, class Alloc>
+inline cl_int mapSVM(cl::vector<T, Alloc> &container)
+{
+ return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
+}
+
+/**
+* Blocking SVM map operation - performs a blocking map underneath.
+*/
+template<typename T, class Alloc>
+inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
+{
+ return enqueueUnmapSVM(container);
+}
+
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 110
+inline cl_int enqueueReadBufferRect(
+ const Buffer& buffer,
+ cl_bool blocking,
+ const array<size_type, 3>& buffer_offset,
+ const array<size_type, 3>& host_offset,
+ const array<size_type, 3>& region,
+ size_type buffer_row_pitch,
+ size_type buffer_slice_pitch,
+ size_type host_row_pitch,
+ size_type host_slice_pitch,
+ void *ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueReadBufferRect(
+ buffer,
+ blocking,
+ buffer_offset,
+ host_offset,
+ region,
+ buffer_row_pitch,
+ buffer_slice_pitch,
+ host_row_pitch,
+ host_slice_pitch,
+ ptr,
+ events,
+ event);
+}
+
+inline cl_int enqueueWriteBufferRect(
+ const Buffer& buffer,
+ cl_bool blocking,
+ const array<size_type, 3>& buffer_offset,
+ const array<size_type, 3>& host_offset,
+ const array<size_type, 3>& region,
+ size_type buffer_row_pitch,
+ size_type buffer_slice_pitch,
+ size_type host_row_pitch,
+ size_type host_slice_pitch,
+ const void *ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueWriteBufferRect(
+ buffer,
+ blocking,
+ buffer_offset,
+ host_offset,
+ region,
+ buffer_row_pitch,
+ buffer_slice_pitch,
+ host_row_pitch,
+ host_slice_pitch,
+ ptr,
+ events,
+ event);
+}
+
+inline cl_int enqueueCopyBufferRect(
+ const Buffer& src,
+ const Buffer& dst,
+ const array<size_type, 3>& src_origin,
+ const array<size_type, 3>& dst_origin,
+ const array<size_type, 3>& region,
+ size_type src_row_pitch,
+ size_type src_slice_pitch,
+ size_type dst_row_pitch,
+ size_type dst_slice_pitch,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyBufferRect(
+ src,
+ dst,
+ src_origin,
+ dst_origin,
+ region,
+ src_row_pitch,
+ src_slice_pitch,
+ dst_row_pitch,
+ dst_slice_pitch,
+ events,
+ event);
+}
+#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
+
+inline cl_int enqueueReadImage(
+ const Image& image,
+ cl_bool blocking,
+ const array<size_type, 3>& origin,
+ const array<size_type, 3>& region,
+ size_type row_pitch,
+ size_type slice_pitch,
+ void* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueReadImage(
+ image,
+ blocking,
+ origin,
+ region,
+ row_pitch,
+ slice_pitch,
+ ptr,
+ events,
+ event);
+}
+
+inline cl_int enqueueWriteImage(
+ const Image& image,
+ cl_bool blocking,
+ const array<size_type, 3>& origin,
+ const array<size_type, 3>& region,
+ size_type row_pitch,
+ size_type slice_pitch,
+ const void* ptr,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueWriteImage(
+ image,
+ blocking,
+ origin,
+ region,
+ row_pitch,
+ slice_pitch,
+ ptr,
+ events,
+ event);
+}
+
+inline cl_int enqueueCopyImage(
+ const Image& src,
+ const Image& dst,
+ const array<size_type, 3>& src_origin,
+ const array<size_type, 3>& dst_origin,
+ const array<size_type, 3>& region,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyImage(
+ src,
+ dst,
+ src_origin,
+ dst_origin,
+ region,
+ events,
+ event);
+}
+
+inline cl_int enqueueCopyImageToBuffer(
+ const Image& src,
+ const Buffer& dst,
+ const array<size_type, 3>& src_origin,
+ const array<size_type, 3>& region,
+ size_type dst_offset,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyImageToBuffer(
+ src,
+ dst,
+ src_origin,
+ region,
+ dst_offset,
+ events,
+ event);
+}
+
+inline cl_int enqueueCopyBufferToImage(
+ const Buffer& src,
+ const Image& dst,
+ size_type src_offset,
+ const array<size_type, 3>& dst_origin,
+ const array<size_type, 3>& region,
+ const vector<Event>* events = NULL,
+ Event* event = NULL)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.enqueueCopyBufferToImage(
+ src,
+ dst,
+ src_offset,
+ dst_origin,
+ region,
+ events,
+ event);
+}
+
+
+inline cl_int flush(void)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+ return queue.flush();
+}
+
+inline cl_int finish(void)
+{
+ cl_int error;
+ CommandQueue queue = CommandQueue::getDefault(&error);
+
+ if (error != CL_SUCCESS) {
+ return error;
+ }
+
+
+ return queue.finish();
+}
+
+class EnqueueArgs
+{
+private:
+ CommandQueue queue_;
+ const NDRange offset_;
+ const NDRange global_;
+ const NDRange local_;
+ vector<Event> events_;
+
+ template<typename... Ts>
+ friend class KernelFunctor;
+
+public:
+ EnqueueArgs(NDRange global) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange)
+ {
+
+ }
+
+ EnqueueArgs(NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(local)
+ {
+
+ }
+
+ EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(offset),
+ global_(global),
+ local_(local)
+ {
+
+ }
+
+ EnqueueArgs(Event e, NDRange global) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(Event e, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(local)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(offset),
+ global_(global),
+ local_(local)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(const vector<Event> &events, NDRange global) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(NullRange),
+ global_(global),
+ local_(local),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
+ queue_(CommandQueue::getDefault()),
+ offset_(offset),
+ global_(global),
+ local_(local),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, NDRange global) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(local)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(offset),
+ global_(global),
+ local_(local)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(local)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(offset),
+ global_(global),
+ local_(local)
+ {
+ events_.push_back(e);
+ }
+
+ EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(NullRange),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(NullRange),
+ global_(global),
+ local_(local),
+ events_(events)
+ {
+
+ }
+
+ EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
+ queue_(queue),
+ offset_(offset),
+ global_(global),
+ local_(local),
+ events_(events)
+ {
+
+ }
+};
+
+
+//----------------------------------------------------------------------------------------------
+
+
+/**
+ * Type safe kernel functor.
+ *
+ */
+template<typename... Ts>
+class KernelFunctor
+{
+private:
+ Kernel kernel_;
+
+ template<int index, typename T0, typename... T1s>
+ void setArgs(T0&& t0, T1s&&... t1s)
+ {
+ kernel_.setArg(index, t0);
+ setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
+ }
+
+ template<int index, typename T0>
+ void setArgs(T0&& t0)
+ {
+ kernel_.setArg(index, t0);
+ }
+
+ template<int index>
+ void setArgs()
+ {
+ }
+
+
+public:
+ KernelFunctor(Kernel kernel) : kernel_(kernel)
+ {}
+
+ KernelFunctor(
+ const Program& program,
+ const string name,
+ cl_int * err = NULL) :
+ kernel_(program, name.c_str(), err)
+ {}
+
+ //! \brief Return type of the functor
+ typedef Event result_type;
+
+ /**
+ * Enqueue kernel.
+ * @param args Launch parameters of the kernel.
+ * @param t0... List of kernel arguments based on the template type of the functor.
+ */
+ Event operator() (
+ const EnqueueArgs& args,
+ Ts... ts)
+ {
+ Event event;
+ setArgs<0>(std::forward<Ts>(ts)...);
+
+ args.queue_.enqueueNDRangeKernel(
+ kernel_,
+ args.offset_,
+ args.global_,
+ args.local_,
+ &args.events_,
+ &event);
+
+ return event;
+ }
+
+ /**
+ * Enqueue kernel with support for error code.
+ * @param args Launch parameters of the kernel.
+ * @param t0... List of kernel arguments based on the template type of the functor.
+ * @param error Out parameter returning the error code from the execution.
+ */
+ Event operator() (
+ const EnqueueArgs& args,
+ Ts... ts,
+ cl_int &error)
+ {
+ Event event;
+ setArgs<0>(std::forward<Ts>(ts)...);
+
+ error = args.queue_.enqueueNDRangeKernel(
+ kernel_,
+ args.offset_,
+ args.global_,
+ args.local_,
+ &args.events_,
+ &event);
+
+ return event;
+ }
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ cl_int setSVMPointers(const vector<void*> &pointerList)
+ {
+ return kernel_.setSVMPointers(pointerList);
+ }
+
+ template<typename T0, typename... T1s>
+ cl_int setSVMPointers(const T0 &t0, T1s... ts)
+ {
+ return kernel_.setSVMPointers(t0, ts...);
+ }
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+ Kernel getKernel()
+ {
+ return kernel_;
+ }
+};
+
+namespace compatibility {
+ /**
+ * Backward compatibility class to ensure that cl.hpp code works with cl2.hpp.
+ * Please use KernelFunctor directly.
+ */
+ template<typename... Ts>
+ struct make_kernel
+ {
+ typedef KernelFunctor<Ts...> FunctorType;
+
+ FunctorType functor_;
+
+ make_kernel(
+ const Program& program,
+ const string name,
+ cl_int * err = NULL) :
+ functor_(FunctorType(program, name, err))
+ {}
+
+ make_kernel(
+ const Kernel kernel) :
+ functor_(FunctorType(kernel))
+ {}
+
+ //! \brief Return type of the functor
+ typedef Event result_type;
+
+ //! \brief Function signature of kernel functor with no event dependency.
+ typedef Event type_(
+ const EnqueueArgs&,
+ Ts...);
+
+ Event operator()(
+ const EnqueueArgs& enqueueArgs,
+ Ts... args)
+ {
+ return functor_(
+ enqueueArgs, args...);
+ }
+ };
+} // namespace compatibility
+
+
+//----------------------------------------------------------------------------------------------------------------------
+
+#undef CL_HPP_ERR_STR_
+#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
+#undef __GET_DEVICE_INFO_ERR
+#undef __GET_PLATFORM_INFO_ERR
+#undef __GET_DEVICE_IDS_ERR
+#undef __GET_CONTEXT_INFO_ERR
+#undef __GET_EVENT_INFO_ERR
+#undef __GET_EVENT_PROFILE_INFO_ERR
+#undef __GET_MEM_OBJECT_INFO_ERR
+#undef __GET_IMAGE_INFO_ERR
+#undef __GET_SAMPLER_INFO_ERR
+#undef __GET_KERNEL_INFO_ERR
+#undef __GET_KERNEL_ARG_INFO_ERR
+#undef __GET_KERNEL_WORK_GROUP_INFO_ERR
+#undef __GET_PROGRAM_INFO_ERR
+#undef __GET_PROGRAM_BUILD_INFO_ERR
+#undef __GET_COMMAND_QUEUE_INFO_ERR
+
+#undef __CREATE_CONTEXT_ERR
+#undef __CREATE_CONTEXT_FROM_TYPE_ERR
+#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
+
+#undef __CREATE_BUFFER_ERR
+#undef __CREATE_SUBBUFFER_ERR
+#undef __CREATE_IMAGE2D_ERR
+#undef __CREATE_IMAGE3D_ERR
+#undef __CREATE_SAMPLER_ERR
+#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
+
+#undef __CREATE_USER_EVENT_ERR
+#undef __SET_USER_EVENT_STATUS_ERR
+#undef __SET_EVENT_CALLBACK_ERR
+#undef __SET_PRINTF_CALLBACK_ERR
+
+#undef __WAIT_FOR_EVENTS_ERR
+
+#undef __CREATE_KERNEL_ERR
+#undef __SET_KERNEL_ARGS_ERR
+#undef __CREATE_PROGRAM_WITH_SOURCE_ERR
+#undef __CREATE_PROGRAM_WITH_BINARY_ERR
+#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
+#undef __BUILD_PROGRAM_ERR
+#undef __CREATE_KERNELS_IN_PROGRAM_ERR
+
+#undef __CREATE_COMMAND_QUEUE_ERR
+#undef __SET_COMMAND_QUEUE_PROPERTY_ERR
+#undef __ENQUEUE_READ_BUFFER_ERR
+#undef __ENQUEUE_WRITE_BUFFER_ERR
+#undef __ENQUEUE_READ_BUFFER_RECT_ERR
+#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
+#undef __ENQEUE_COPY_BUFFER_ERR
+#undef __ENQEUE_COPY_BUFFER_RECT_ERR
+#undef __ENQUEUE_READ_IMAGE_ERR
+#undef __ENQUEUE_WRITE_IMAGE_ERR
+#undef __ENQUEUE_COPY_IMAGE_ERR
+#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
+#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
+#undef __ENQUEUE_MAP_BUFFER_ERR
+#undef __ENQUEUE_MAP_IMAGE_ERR
+#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
+#undef __ENQUEUE_NDRANGE_KERNEL_ERR
+#undef __ENQUEUE_TASK_ERR
+#undef __ENQUEUE_NATIVE_KERNEL
+
+#undef __UNLOAD_COMPILER_ERR
+#undef __CREATE_SUB_DEVICES_ERR
+
+#undef __CREATE_PIPE_ERR
+#undef __GET_PIPE_INFO_ERR
+
+#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
+
+// Extensions
+#undef CL_HPP_INIT_CL_EXT_FCN_PTR_
+#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
+
+#if defined(CL_HPP_USE_CL_DEVICE_FISSION)
+#undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
+#endif // CL_HPP_USE_CL_DEVICE_FISSION
+
+#undef CL_HPP_NOEXCEPT_
+#undef CL_HPP_DEFINE_STATIC_MEMBER_
+
+} // namespace cl
+
+#endif // CL_HPP_
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..ce91b66
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,98 @@
+add_custom_command(
+ OUTPUT stripped/cl.h
+ COMMAND ${CMAKE_COMMAND} -E make_directory stripped
+ COMMAND ${CMAKE_COMMAND} -E make_directory mocks
+ COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/strip_defines.py ${OPENCL_INCLUDE_DIR}/CL/cl.h stripped/cl.h
+ COMMENT "Stripping defines from cl.h"
+ DEPENDS ${OPENCL_INCLUDE_DIR}/CL/cl.h strip_defines.py)
+
+add_custom_command(
+ OUTPUT mocks/Mockcl.c mocks/Mockcl.h
+ COMMAND ruby ${CMOCK_DIR}/lib/cmock.rb -o${CMAKE_CURRENT_SOURCE_DIR}/cmock.yml stripped/cl.h
+ COMMENT "Generating mocks"
+ DEPENDS stripped/cl.h cmock.yml)
+
+add_custom_command(
+ OUTPUT test_clhpp_Runner.c
+ COMMAND ruby ${UNITY_DIR}/auto/generate_test_runner.rb test_clhpp.cpp cmock.yml ${CMAKE_CURRENT_BINARY_DIR}/test_clhpp_Runner.c
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMENT "Generating test runner"
+ DEPENDS test_clhpp.cpp cmock.yml)
+
+add_custom_command(
+ OUTPUT test_cl2hpp_Runner.c
+ COMMAND ruby ${UNITY_DIR}/auto/generate_test_runner.rb test_cl2hpp.cpp cmock.yml ${CMAKE_CURRENT_BINARY_DIR}/test_cl2hpp_Runner.c
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMENT "Generating test runner for 2.0"
+ DEPENDS test_cl2hpp.cpp cmock.yml)
+
+include_directories(
+ ${CLCPP_BINARY_DIR}/include
+ ${CMAKE_CURRENT_BINARY_DIR}/mocks
+ ${OPENCL_DIST_DIR}/include
+ ${OPENCL_INCLUDE_DIR}
+ ${OPENCL_INCLUDE_DIR}/CL
+ ${UNITY_DIR}/src
+ ${CMOCK_DIR}/src)
+
+add_definitions(-DUNITY_SUPPORT_64)
+if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
+ add_definitions(-DUNITY_POINTER_WIDTH=64)
+ add_definitions("-DCMOCK_MEM_PTR_AS_INT=unsigned long long")
+ add_definitions(-DCMOCK_MEM_ALIGN=3)
+endif()
+if( CMAKE_SIZEOF_LONG EQUAL 8 )
+ add_definitions(-DUNITY_LONG_WIDTH=64)
+endif()
+
+set(TEST_CLHPP_HEADERS
+ ${CLCPP_BINARY_DIR}/include/CL/cl.hpp
+ mocks/Mockcl.h)
+set_source_files_properties(${CLCPP_BINARY_DIR}/include/CL/cl.hpp PROPERTIES GENERATED 1)
+
+set(TEST_CL2HPP_HEADERS
+ ${CLCPP_BINARY_DIR}/include/CL/cl2.hpp
+ mocks/Mockcl.h)
+set_source_files_properties(${CLCPP_BINARY_DIR}/include/CL/cl2.hpp PROPERTIES GENERATED 1)
+
+set(TEST_CLHPP_SOURCES_COMMON
+ ${CMAKE_CURRENT_BINARY_DIR}/mocks/Mockcl.c
+ ${CMOCK_DIR}/src/cmock.c
+ ${UNITY_DIR}/src/unity.c)
+
+set(TEST_CLHPP_SOURCES
+ ${TEST_CLHPP_SOURCES_COMMON}
+ ${CMAKE_CURRENT_BINARY_DIR}/test_clhpp_Runner.c
+ test_clhpp.cpp)
+
+set(TEST_CL2HPP_SOURCES
+ ${TEST_CLHPP_SOURCES_COMMON}
+ ${CMAKE_CURRENT_BINARY_DIR}/test_cl2hpp_Runner.c
+ test_cl2hpp.cpp)
+
+
+#set_source_files_properties(test_cl2hpp_Runner.c PROPERTIES LANGUAGE "CXX")
+#set_source_files_properties(test_clhpp_Runner.c PROPERTIES LANGUAGE "CXX")
+add_executable(test_clhpp ${TEST_CLHPP_SOURCES} ${TEST_CLHPP_HEADERS})
+add_executable(test_clhpp_deprecated_1_1 ${TEST_CLHPP_SOURCES} ${TEST_CLHPP_HEADERS})
+set_target_properties(test_clhpp_deprecated_1_1 PROPERTIES COMPILE_DEFINITIONS "CL_USE_DEPRECATED_OPENCL_1_1_APIS")
+add_executable(test_clhpp_deprecated_1_2 ${TEST_CLHPP_SOURCES} ${TEST_CLHPP_HEADERS})
+set_target_properties(test_clhpp_deprecated_1_2 PROPERTIES COMPILE_DEFINITIONS "CL_USE_DEPRECATED_OPENCL_1_1_APIS")
+set_target_properties(test_clhpp_deprecated_1_2 PROPERTIES COMPILE_DEFINITIONS "CL_USE_DEPRECATED_OPENCL_1_2_APIS")
+add_dependencies(test_clhpp generate_clhpp)
+add_executable(test_cl2hpp ${TEST_CL2HPP_SOURCES} ${TEST_CL2HPP_HEADERS})
+add_dependencies(test_cl2hpp generate_cl2hpp)
+add_test(run_test_clhpp test_clhpp)
+add_test(run_test_clhpp_deprecated_1_1 test_clhpp_deprecated_1_1)
+add_test(run_test_cl2hpp test_cl2hpp)
+
+if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
+ set(TEST_CLHPP_CXX11_SOURCES
+ ${TEST_CLHPP_SOURCES_COMMON}
+ ${CMAKE_CURRENT_BINARY_DIR}/test_clhpp_Runner.c
+ test_clhpp_cxx11.cpp)
+ set_source_files_properties(test_clhpp_cxx11.cpp PROPERTIES COMPILE_FLAGS "-std=c++11")
+ set_source_files_properties(test_cl2hpp.cpp PROPERTIES COMPILE_FLAGS "-std=c++11")
+ add_executable(test_clhpp_cxx11 ${TEST_CLHPP_CXX11_SOURCES} ${TEST_CLHPP_HEADERS})
+ add_test(run_test_clhpp_cxx11 test_clhpp_cxx11)
+endif()
diff --git a/tests/ToAdd.txt b/tests/ToAdd.txt
new file mode 100644
index 0000000..0d073dc
--- /dev/null
+++ b/tests/ToAdd.txt
@@ -0,0 +1,8 @@
+Test for create program from binaries.
+Tests for linkProgram.
+Tests for SVM -
+ enableFineGrainedSystemSVM
+ setSVMPointers
+ SVM setArg variants
+ SVM allocators
+ SVM shared pointer
diff --git a/tests/cmock.yml b/tests/cmock.yml
new file mode 100644
index 0000000..dc504db
--- /dev/null
+++ b/tests/cmock.yml
@@ -0,0 +1,9 @@
+:cmock:
+ :includes:
+ - CL/cl_platform.h
+ :treat_externs: :include
+ :enforce_strict_ordering: :true
+ :c_calling_conventions:
+ - CL_API_CALL
+ :plugins:
+ - :callback
diff --git a/tests/strip_defines.py b/tests/strip_defines.py
new file mode 100755
index 0000000..7dbd8dc
--- /dev/null
+++ b/tests/strip_defines.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+from __future__ import print_function
+import sys
+import re
+
+"""
+Removes macros that might otherwise cause confusion for CMock.
+"""
+
+if len(sys.argv) != 3:
+ print("Usage: strip_defines.py <input> <output>")
+ sys.exit(1)
+with open(sys.argv[1], 'r') as inf:
+ text = inf.read()
+text = re.sub(r'\bCL_(?:API_ENTRY|API_SUFFIX|EXT|CALLBACK)[A-Z0-9_]*\b', '', text)
+text2 = re.sub(r'\*\[\]', '\*\*', text)
+with open(sys.argv[2], 'w') as outf:
+ outf.write(text2)
diff --git a/tests/test_cl2hpp.cpp b/tests/test_cl2hpp.cpp
new file mode 100644
index 0000000..d9ac7d5
--- /dev/null
+++ b/tests/test_cl2hpp.cpp
@@ -0,0 +1,581 @@
+#define TEST_CL2
+#define CL_HPP_UNIT_TEST_ENABLE
+#define CL_HPP_USE_CL_SUB_GROUPS_KHR
+
+// Want to support 2.0 but also test that 1.1 is ok
+#define CL_HPP_TARGET_OPENCL_VERSION 200
+#define CL_HPP_MINIMUM_OPENCL_VERSION 100
+
+extern "C" {
+ // Headers required to make unity use mocks correctly
+ #include <unity.h>
+ #include <cmock.h>
+ #include "Mockcl.h"
+ #include <string.h>
+
+ // Declarations for the benefit of the runner generator
+ // to import tests from test_clhpp.cpp
+ // Saves duplication of tests and the runner generator
+ // does not process through the include below
+
+ void testCompareExchange();
+ void testFence();
+ void testCopyContextNonNull();
+ void testMoveAssignContextNonNull();
+ void testMoveAssignContextNull();
+ void testMoveConstructContextNonNull();
+ void testMoveConstructContextNull();
+ void testContextGetDevices1_1();
+ void testContextGetDevices1_2();
+ void testContextFromType();
+ void testMoveAssignCommandQueueNonNull();
+ void testMoveAssignCommandQueueNull();
+ void testMoveConstructCommandQueueNonNull();
+ void testMoveConstructCommandQueueNull();
+ void testCommandQueueGetContext();
+ void testCommandQueueGetDevice1_1();
+ void testCommandQueueGetDevice1_2();
+ void testCommandQueueFromSpecifiedContext();
+ void testCopyDeviceNonNull1_1();
+ void testCopyDeviceNonNull1_2();
+ void testCopyDeviceFromNull1_1();
+ void testCopyDeviceFromNull1_2();
+ void testCopyDeviceToNull1_1();
+ void testCopyDeviceToNull1_2();
+ void testCopyDeviceSelf();
+ void testAssignDeviceNull();
+ void testMoveAssignDeviceNonNull();
+ void testMoveAssignDeviceNull();
+ void testMoveConstructDeviceNonNull();
+ void testMoveConstructDeviceNull();
+ void testDestroyDevice1_1();
+ void testDestroyDevice1_2();
+ void testMoveAssignBufferNonNull();
+ void testMoveAssignBufferNull();
+ void testMoveConstructBufferNonNull();
+ void testMoveConstructBufferNull();
+ void testBufferConstructorContextIterator();
+ void testBufferConstructorQueueIterator();
+ void testGetImageInfoBuffer();
+ void testGetImageInfoBufferNull();
+ void testGetImageInfoBufferOverwrite();
+ void testConstructImageFromBuffer();
+ void testMoveAssignImage2DNonNull();
+ void testMoveAssignImage2DNull();
+ void testMoveConstructImage2DNonNull();
+ void testMoveConstructImage2DNull();
+ void testCreateImage2D_1_1();
+ void testCreateImage2D_1_2();
+ void testMoveAssignImage3DNonNull();
+ void testMoveAssignImage3DNull();
+ void testMoveConstructImage3DNonNull();
+ void testMoveConstructImage3DNull();
+ void testCreateImage3D_1_1();
+ void testCreateImage3D_1_2();
+ void testMoveAssignKernelNonNull();
+ void testMoveAssignKernelNull();
+ void testMoveConstructKernelNonNull();
+ void testMoveConstructKernelNull();
+ void testKernelSetArgScalar();
+ void testKernelSetArgVector();
+ void testKernelSetArgMem();
+ void testKernelSetArgLocal();
+ void testCopyHostToBuffer();
+ void testGetBuildInfo();
+ void testGetSupportedImageFormats();
+ void testCreateSubDevice();
+ void testGetContextInfoDevices();
+} // extern "C"
+
+#include "test_clhpp.cpp"
+
+
+extern "C" {
+
+static cl_mem clCreateImage_testCreateImage2DFromBuffer_2_0(
+ cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_NOT_NULL(image_format);
+ TEST_ASSERT_NOT_NULL(image_desc);
+ TEST_ASSERT_NULL(host_ptr);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_OBJECT_IMAGE2D, image_desc->image_type);
+
+ // Return the passed buffer as the cl_mem and success for the error code
+ if (errcode_ret) {
+ *errcode_ret = CL_SUCCESS;
+ }
+ return image_desc->buffer;
+}
+
+void testCreateImage2DFromBuffer_2_0()
+{
+ clGetContextInfo_StubWithCallback(clGetContextInfo_device);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_2_0);
+ clCreateImage_StubWithCallback(clCreateImage_testCreateImage2DFromBuffer_2_0);
+ clReleaseMemObject_ExpectAndReturn(make_mem(0), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(0), CL_SUCCESS);
+
+ cl_int err;
+ cl::Context context(make_context(0));
+
+ // Create buffer
+ // Create image from buffer
+ cl::Buffer buffer(make_mem(0));
+ cl::Image2D imageFromBuffer(
+ context,
+ cl::ImageFormat(CL_R, CL_FLOAT), buffer, 64, 32, 256, &err);
+
+ TEST_ASSERT_EQUAL_PTR(buffer(), imageFromBuffer());
+ TEST_ASSERT_EQUAL(CL_SUCCESS, err);
+
+ buffer() = NULL;
+}
+
+static cl_mem clCreateImage_testCreateImage2D_2_0(
+ cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(0, num_calls);
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_READ_WRITE, flags);
+
+ TEST_ASSERT_NOT_NULL(image_format);
+ TEST_ASSERT_EQUAL_HEX(CL_RGBA, image_format->image_channel_order);
+ TEST_ASSERT_EQUAL_HEX(CL_FLOAT, image_format->image_channel_data_type);
+
+ TEST_ASSERT_NOT_NULL(image_desc);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_OBJECT_IMAGE2D, image_desc->image_type);
+ TEST_ASSERT_EQUAL(64, image_desc->image_width);
+ TEST_ASSERT_EQUAL(32, image_desc->image_height);
+ TEST_ASSERT_EQUAL(256, image_desc->image_row_pitch);
+ TEST_ASSERT_EQUAL(0, image_desc->num_mip_levels);
+ TEST_ASSERT_EQUAL(0, image_desc->num_samples);
+ TEST_ASSERT_NULL(image_desc->buffer);
+
+ TEST_ASSERT_NULL(host_ptr);
+
+ if (errcode_ret != NULL)
+ *errcode_ret = CL_SUCCESS;
+ return make_mem(0);
+}
+
+static cl_mem clCreateImage_testCreateImage2DFromImage_2_0(
+ cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_NOT_NULL(image_format);
+ TEST_ASSERT_NOT_NULL(image_desc);
+ TEST_ASSERT_NULL(host_ptr);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_OBJECT_IMAGE2D, image_desc->image_type);
+
+ // Return the passed buffer as the cl_mem and success for the error code
+ if (errcode_ret) {
+ *errcode_ret = CL_SUCCESS;
+ }
+ return image_desc->buffer;
+}
+
+static cl_int clGetImageInfo_testCreateImage2DFromImage_2_0(
+ cl_mem image,
+ cl_image_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ TEST_ASSERT_INT_WITHIN(6, 0, num_calls);
+ return CL_SUCCESS;
+}
+
+void testCreateImage2DFromImage_2_0()
+{
+ clGetContextInfo_StubWithCallback(clGetContextInfo_device);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_2_0);
+ clCreateImage_StubWithCallback(clCreateImage_testCreateImage2D_2_0);
+
+
+ cl_int err;
+ cl::Context context(make_context(0));
+
+ // As in 1.2 2D image test, needed as source for image-from-image
+ cl::Image2D image(
+ context, CL_MEM_READ_WRITE,
+ cl::ImageFormat(CL_RGBA, CL_FLOAT), 64, 32, 256, NULL, &err);
+
+ TEST_ASSERT_EQUAL(CL_SUCCESS, err);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), image());
+
+ // Continue state for next phase
+ clGetImageInfo_StubWithCallback(clGetImageInfo_testCreateImage2DFromImage_2_0);
+ clCreateImage_StubWithCallback(clCreateImage_testCreateImage2DFromImage_2_0);
+ clReleaseMemObject_ExpectAndReturn(make_mem(0), CL_SUCCESS);
+ clReleaseMemObject_ExpectAndReturn(make_mem(0), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(0), CL_SUCCESS);
+
+ // Create 2D image from 2D Image with a new channel order
+ cl::Image2D imageFromImage(
+ context,
+ CL_sRGB,
+ image,
+ &err
+ );
+
+ TEST_ASSERT_EQUAL(CL_SUCCESS, err);
+ TEST_ASSERT_EQUAL_PTR(image(), imageFromImage());
+
+ //imageFromImage() = NULL;
+ //image() = NULL;
+ //context() = NULL;
+}
+
+// Note that default tests maintain state when run from the same
+// unit process.
+// One default setting test will maintain the defaults until the end.
+void testSetDefaultPlatform()
+{
+ cl::Platform p(make_platform_id(1));
+ cl::Platform p2 = cl::Platform::setDefault(p);
+ cl::Platform p3 = cl::Platform::getDefault();
+ TEST_ASSERT_EQUAL(p(), p2());
+ TEST_ASSERT_EQUAL(p(), p3());
+}
+
+// Note that default tests maintain state when run from the same
+// unit process.
+// One default setting test will maintain the defaults until the end.
+void testSetDefaultPlatformTwice()
+{
+ cl::Platform p(make_platform_id(2));
+ cl::Platform p2 = cl::Platform::getDefault();
+ cl::Platform p3 = cl::Platform::setDefault(p);
+ // Set default should have failed
+ TEST_ASSERT_EQUAL(p2(), p3());
+ TEST_ASSERT_NOT_EQUAL(p(), p3());
+}
+
+// Note that default tests maintain state when run from the same
+// unit process.
+// One default setting test will maintain the defaults until the end.
+void testSetDefaultContext()
+{
+
+ clRetainContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clRetainContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clRetainContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+
+ cl::Context c(make_context(1));
+ cl::Context c2 = cl::Context::setDefault(c);
+ cl::Context c3 = cl::Context::getDefault();
+ TEST_ASSERT_EQUAL(c(), c2());
+ TEST_ASSERT_EQUAL(c(), c3());
+}
+
+// Note that default tests maintain state when run from the same
+// unit process.
+// One default setting test will maintain the defaults until the end.
+void testSetDefaultCommandQueue()
+{
+ clRetainCommandQueue_ExpectAndReturn(make_command_queue(1), CL_SUCCESS);
+ clRetainCommandQueue_ExpectAndReturn(make_command_queue(1), CL_SUCCESS);
+ clRetainCommandQueue_ExpectAndReturn(make_command_queue(1), CL_SUCCESS);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(1), CL_SUCCESS);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(1), CL_SUCCESS);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(1), CL_SUCCESS);
+
+ cl::CommandQueue c(make_command_queue(1));
+ cl::CommandQueue c2 = cl::CommandQueue::setDefault(c);
+ cl::CommandQueue c3 = cl::CommandQueue::getDefault();
+ TEST_ASSERT_EQUAL(c(), c2());
+ TEST_ASSERT_EQUAL(c(), c3());
+}
+
+// Note that default tests maintain state when run from the same
+// unit process.
+// One default setting test will maintain the defaults until the end.
+void testSetDefaultDevice()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_2_0);
+
+ clRetainDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+ clRetainDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+ clRetainDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+ clReleaseDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+ clReleaseDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+ clReleaseDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+
+ cl::Device d(make_device_id(1));
+ cl::Device d2 = cl::Device::setDefault(d);
+ cl::Device d3 = cl::Device::getDefault();
+ TEST_ASSERT_EQUAL(d(), d2());
+ TEST_ASSERT_EQUAL(d(), d3());
+}
+
+static cl_command_queue clCreateCommandQueueWithProperties_testCommandQueueDevice(
+ cl_context context,
+ cl_device_id device,
+ const cl_queue_properties *properties,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ (void)num_calls;
+ TEST_ASSERT_EQUAL_PTR(make_context(1), context);
+ TEST_ASSERT_EQUAL_PTR(make_device_id(1), device);
+ TEST_ASSERT_EQUAL(properties[0], CL_QUEUE_PROPERTIES);
+ static cl_command_queue default_ = 0;
+
+ if ((properties[1] & CL_QUEUE_ON_DEVICE_DEFAULT) == 0) {
+ TEST_ASSERT_EQUAL(properties[1], (CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE));
+ if (properties[2] == CL_QUEUE_SIZE) {
+ TEST_ASSERT_EQUAL(properties[3], 256);
+ TEST_ASSERT_EQUAL(properties[4], 0);
+ return make_command_queue(2);
+ }
+ else {
+ TEST_ASSERT_EQUAL(properties[2], 0);
+ return make_command_queue(3);
+ }
+ }
+ else {
+ TEST_ASSERT_EQUAL(properties[1], (CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT));
+ if (default_ == 0) {
+ default_ = make_command_queue(4);
+ }
+ return default_;
+ }
+}
+
+
+void testCreateDeviceCommandQueue()
+{
+ clRetainContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_2_0);
+ clCreateCommandQueueWithProperties_StubWithCallback(clCreateCommandQueueWithProperties_testCommandQueueDevice);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(4), CL_SUCCESS);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(4), CL_SUCCESS);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(2), CL_SUCCESS);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(3), CL_SUCCESS);
+ clReleaseDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+
+ cl::Context c(make_context(1));
+ cl::Context c2 = cl::Context::setDefault(c);
+ cl::Device d(make_device_id(1));
+
+ cl::DeviceCommandQueue dq(c, d);
+ cl::DeviceCommandQueue dq2(c, d, 256);
+
+ cl::DeviceCommandQueue dqd = cl::DeviceCommandQueue::makeDefault(c, d);
+ cl::DeviceCommandQueue dqd2 = cl::DeviceCommandQueue::makeDefault(c, d);
+
+ TEST_ASSERT_EQUAL(dqd(), dqd2());
+}
+
+static cl_mem clCreatePipe_testCreatePipe(
+ cl_context context,
+ cl_mem_flags flags,
+ cl_uint packet_size,
+ cl_uint num_packets,
+ const cl_pipe_properties *props,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ if (flags == 0) {
+ flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
+ }
+ TEST_ASSERT_EQUAL(flags, CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS);
+ TEST_ASSERT_NULL(props);
+
+ if (errcode_ret)
+ *errcode_ret = CL_SUCCESS;
+ return make_mem(0);
+}
+
+static cl_int clGetPipeInfo_testCreatePipe(
+ cl_mem pipe,
+ cl_pipe_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ TEST_ASSERT_NOT_NULL(param_value);
+ if (param_name == CL_PIPE_PACKET_SIZE) {
+ *static_cast<cl_uint*>(param_value) = 16;
+ if (param_value_size_ret) {
+ *param_value_size_ret = param_value_size;
+ }
+ return CL_SUCCESS;
+ }
+ else if (param_name == CL_PIPE_MAX_PACKETS) {
+ *static_cast<cl_uint*>(param_value) = 32;
+ if (param_value_size_ret) {
+ *param_value_size_ret = param_value_size;
+ }
+ return CL_SUCCESS;
+ }
+ else {
+ TEST_FAIL();
+ }
+}
+
+void testCreatePipe()
+{
+ clCreatePipe_StubWithCallback(clCreatePipe_testCreatePipe);
+ clGetPipeInfo_StubWithCallback(clGetPipeInfo_testCreatePipe);
+ clRetainContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clReleaseMemObject_ExpectAndReturn(make_mem(0), CL_SUCCESS);
+ clReleaseMemObject_ExpectAndReturn(make_mem(0), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+
+ cl::Context c(make_context(1));
+ cl::Pipe p(c, 16, 32);
+ cl::Pipe p2(16, 32);
+
+ cl_uint size = p2.getInfo<CL_PIPE_PACKET_SIZE>();
+ cl_uint packets;
+ p2.getInfo(CL_PIPE_MAX_PACKETS, &packets);
+
+ TEST_ASSERT_EQUAL(size, 16);
+ TEST_ASSERT_EQUAL(packets, 32);
+}
+
+#if defined(_WIN32)
+#define CL_API_CALL __stdcall
+#else
+#define CL_API_CALL
+#endif
+
+static cl_int CL_API_CALL clGetKernelSubGroupInfoKHR_testSubGroups(cl_kernel kernel,
+ cl_device_id device,
+ cl_kernel_sub_group_info param_name,
+ size_t input_value_size,
+ const void *input_value,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret)
+{
+ TEST_ASSERT_NOT_NULL(input_value);
+ TEST_ASSERT_NOT_NULL(param_value);
+
+ if (param_name == CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR) {
+ *static_cast<size_t*>(param_value) = 32;
+ if (param_value_size_ret) {
+ *param_value_size_ret = sizeof(size_t);
+ }
+ }
+ else if (param_name == CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR) {
+ *static_cast<size_t*>(param_value) = 2;
+ if (param_value_size_ret) {
+ *param_value_size_ret = sizeof(size_t);
+ }
+ }
+ else {
+ TEST_ABORT();
+ }
+}
+
+void testSubGroups()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_2_0);
+ clGetExtensionFunctionAddress_ExpectAndReturn("clGetKernelSubGroupInfoKHR", (void *) &clGetKernelSubGroupInfoKHR_testSubGroups);
+ //clGetKernelSubGroupInfoKHR_StubWithCallback(clGetKernelSubGroupInfoKHR_testSubGroups);
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+ clReleaseKernel_ExpectAndReturn(make_kernel(0), CL_SUCCESS);
+
+ cl::Kernel k(make_kernel(0));
+ cl::Device d(make_device_id(0));
+ cl_int err;
+ cl::NDRange ndrange(8, 8);
+ size_t res1 = k.getSubGroupInfo<CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR>(
+ d, ndrange, &err);
+ size_t res2 = 0;
+ err = k.getSubGroupInfo(
+ d, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, ndrange, &res2);
+
+ TEST_ASSERT_EQUAL(res1, 32);
+ TEST_ASSERT_EQUAL(res2, 2);
+}
+
+/**
+* Stub implementation of clGetDeviceInfo that returns an absense of builtin kernels
+*/
+static cl_int clGetDeviceInfo_builtin(
+ cl_device_id id,
+ cl_device_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ // Test to verify case where empty string is returned - so size is 0
+ (void)num_calls;
+ TEST_ASSERT_EQUAL_HEX(CL_DEVICE_BUILT_IN_KERNELS, param_name);
+ if (param_value == NULL) {
+ if (param_value_size_ret != NULL) {
+ *param_value_size_ret = 0;
+ }
+ }
+ return CL_SUCCESS;
+}
+
+void testBuiltInKernels()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_2_0);
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+
+ cl::Device d0(make_device_id(0));
+
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_builtin);
+ cl::string s = d0.getInfo<CL_DEVICE_BUILT_IN_KERNELS>();
+
+}
+
+// Run after other tests to clear the default state in the header
+// using special unit test bypasses.
+// We cannot remove the once_flag, so this is a hard fix
+// but it means we won't hit cmock release callbacks at the end.
+// This is a lot like tearDown but for the header default
+// so we do not want to run it for every test.
+// The alternative would be to manually modify the test runner
+// but we avoid that for now.
+void testCleanupHeaderState()
+{
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(1), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+ clReleaseDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+
+ cl::CommandQueue::unitTestClearDefault();
+ cl::Context::unitTestClearDefault();
+ cl::Device::unitTestClearDefault();
+ cl::Platform::unitTestClearDefault();
+}
+
+
+} // extern "C"
diff --git a/tests/test_clhpp.cpp b/tests/test_clhpp.cpp
new file mode 100644
index 0000000..d1eaa7d
--- /dev/null
+++ b/tests/test_clhpp.cpp
@@ -0,0 +1,1802 @@
+#ifdef TEST_CL2
+# include <CL/cl2.hpp>
+# define TEST_RVALUE_REFERENCES
+# define VECTOR_CLASS cl::vector
+# define STRING_CLASS cl::string
+
+#else
+# include <CL/cl.hpp>
+// cl.hpp will switch to C++11 atomics in certain cases, for testing internal use we need to include support here too
+# if (_MSC_VER >= 1700) || (__cplusplus >= 201103L)
+# define TEST_RVALUE_REFERENCES
+# define TEST_CPP11_ATOMICS
+# endif // (_MSC_VER >= 1700) || (__cplusplus >= 201103L)
+
+#endif // !CL_HPP_TEST_CL2
+
+#undef _UP
+
+extern "C"
+{
+#include <unity.h>
+#include <cmock.h>
+#include "Mockcl.h"
+#include <string.h>
+
+/// Creates fake IDs that are easy to identify
+
+static inline cl_platform_id make_platform_id(int index)
+{
+ return (cl_platform_id) (size_t) (0x1a1a1a1a + index);
+}
+
+static inline cl_context make_context(int index)
+{
+ return (cl_context) (size_t) (0xcccccccc + index);
+}
+
+static inline cl_device_id make_device_id(int index)
+{
+ return (cl_device_id) (size_t) (0xdededede + index);
+}
+
+static inline cl_mem make_mem(int index)
+{
+ return (cl_mem) (size_t) (0x33333333 + index);
+}
+
+static inline cl_command_queue make_command_queue(int index)
+{
+ return (cl_command_queue) (size_t) (0xc0c0c0c0 + index);
+}
+
+static inline cl_kernel make_kernel(int index)
+{
+ return (cl_kernel) (size_t) (0xcececece + index);
+}
+
+static inline cl_program make_program(int index)
+{
+ return (cl_program)(size_t)(0xcfcfcfcf + index);
+}
+
+/* Pools of pre-allocated wrapped objects for tests. There is no device pool,
+ * because there is no way to know whether the test wants the device to be
+ * reference countable or not.
+ */
+static const int POOL_MAX = 5;
+static cl::Platform platformPool[POOL_MAX];
+static cl::Context contextPool[POOL_MAX];
+static cl::CommandQueue commandQueuePool[POOL_MAX];
+static cl::Buffer bufferPool[POOL_MAX];
+static cl::Image2D image2DPool[POOL_MAX];
+static cl::Image3D image3DPool[POOL_MAX];
+static cl::Kernel kernelPool[POOL_MAX];
+
+/****************************************************************************
+ * Stub functions shared by multiple tests
+ ****************************************************************************/
+
+/**
+ * Stub implementation of clGetCommandQueueInfo that returns the first context.
+ */
+static cl_int clGetCommandQueueInfo_context(
+ cl_command_queue id,
+ cl_command_queue_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void)num_calls;
+
+
+ TEST_ASSERT_EQUAL_HEX(CL_QUEUE_CONTEXT, param_name);
+ TEST_ASSERT(param_value == NULL || param_value_size >= sizeof(cl_context));
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = sizeof(cl_context);
+ if (param_value != NULL)
+ *(cl_context *)param_value = make_context(0);
+
+ return CL_SUCCESS;
+}
+
+/**
+ * Stub implementation of clGetDeviceInfo that just returns the first platform.
+ */
+static cl_int clGetDeviceInfo_platform(
+ cl_device_id id,
+ cl_device_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void) num_calls;
+
+ TEST_ASSERT_EQUAL_HEX(CL_DEVICE_PLATFORM, param_name);
+ TEST_ASSERT(param_value == NULL || param_value_size >= sizeof(cl_platform_id));
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = sizeof(cl_platform_id);
+ if (param_value != NULL)
+ *(cl_platform_id *) param_value = make_platform_id(0);
+ return CL_SUCCESS;
+}
+
+/**
+ * Stub implementation of clGetContextInfo that just returns the first device.
+ */
+static cl_int clGetContextInfo_device(
+ cl_context id,
+ cl_context_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void) num_calls;
+
+ TEST_ASSERT_EQUAL_HEX(CL_CONTEXT_DEVICES, param_name);
+ TEST_ASSERT(param_value == NULL || param_value_size >= sizeof(cl_device_id));
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = sizeof(cl_device_id);
+ if (param_value != NULL)
+ *(cl_device_id *) param_value = make_device_id(0);
+ return CL_SUCCESS;
+}
+
+
+/**
+ * Stub implementation of clGetPlatformInfo that returns a specific version.
+ * It also checks that the id is the zeroth platform.
+ */
+static cl_int clGetPlatformInfo_version(
+ cl_platform_id id,
+ cl_platform_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ const char *version)
+{
+ size_t bytes = strlen(version) + 1;
+
+ TEST_ASSERT_NOT_NULL(id);
+ TEST_ASSERT_EQUAL_PTR(make_platform_id(0), id);
+ TEST_ASSERT_EQUAL_HEX(CL_PLATFORM_VERSION, param_name);
+ TEST_ASSERT(param_value == NULL || param_value_size >= bytes);
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = bytes;
+ if (param_value != NULL)
+ strcpy((char *) param_value, version);
+ return CL_SUCCESS;
+}
+
+/**
+ * A stub for clGetPlatformInfo that will only support querying
+ * CL_PLATFORM_VERSION, and will return version 1.1.
+ */
+static cl_int clGetPlatformInfo_version_1_1(
+ cl_platform_id id,
+ cl_platform_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void) num_calls;
+ return clGetPlatformInfo_version(
+ id, param_name, param_value_size, param_value,
+ param_value_size_ret, "OpenCL 1.1 Mock");
+}
+
+/**
+ * A stub for clGetPlatformInfo that will only support querying
+ * CL_PLATFORM_VERSION, and will return version 1.2.
+ */
+static cl_int clGetPlatformInfo_version_1_2(
+ cl_platform_id id,
+ cl_platform_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void) num_calls;
+ return clGetPlatformInfo_version(
+ id, param_name, param_value_size, param_value,
+ param_value_size_ret, "OpenCL 1.2 Mock");
+}
+
+/**
+ * A stub for clGetPlatformInfo that will only support querying
+ * CL_PLATFORM_VERSION, and will return version 2.0.
+ */
+static cl_int clGetPlatformInfo_version_2_0(
+ cl_platform_id id,
+ cl_platform_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void) num_calls;
+ return clGetPlatformInfo_version(
+ id, param_name, param_value_size, param_value,
+ param_value_size_ret, "OpenCL 2.0 Mock");
+}
+
+/* Simulated reference counts. The table points to memory held by the caller.
+ * This makes things simpler in the common case of only one object to be
+ * reference counted.
+ */
+class RefcountTable
+{
+private:
+ int n; // number of objects
+ void * const *objects; // object IDs
+ int *refcounts; // current refcounts
+
+ int find(void *object)
+ {
+ int idx = 0;
+ while (idx < n && objects[idx] != object)
+ idx++;
+ TEST_ASSERT(idx < n);
+ TEST_ASSERT(refcounts[idx] > 0); // otherwise object has been destroyed
+ return idx;
+ }
+
+public:
+ RefcountTable() : n(0), objects(NULL), refcounts(NULL) {}
+
+ void init(int n, void * const *objects, int *refcounts)
+ {
+ this->n = n;
+ this->objects = objects;
+ this->refcounts = refcounts;
+ }
+
+ void reset()
+ {
+ init(0, NULL, NULL);
+ }
+
+ cl_int retain(void *object)
+ {
+ int idx = find(object);
+ ++refcounts[idx];
+ return CL_SUCCESS;
+ }
+
+ cl_int release(void *object)
+ {
+ int idx = find(object);
+ --refcounts[idx];
+ return CL_SUCCESS;
+ }
+};
+
+/* Stubs for retain/release calls that track reference counts. The stubs
+ * check that the reference count never becomes negative and that a zero
+ * reference count is never incremented.
+ *
+ * Use the prepareRefcount* calls to set up the global variables first.
+ */
+
+#define MAKE_REFCOUNT_STUBS(cl_type, retainfunc, releasefunc, table) \
+ static RefcountTable table; \
+ static cl_int retainfunc ## _refcount(cl_type object, int num_calls) \
+ { \
+ (void) num_calls; \
+ return table.retain(object); \
+ } \
+ static cl_int releasefunc ## _refcount(cl_type object, int num_calls) \
+ { \
+ (void) num_calls; \
+ return table.release(object); \
+ } \
+ static void prepare_ ## table(int n, cl_type const *objects, int *refcounts) \
+ { \
+ table.init(n, (void * const *) objects, refcounts); \
+ retainfunc ## _StubWithCallback(retainfunc ## _refcount); \
+ releasefunc ## _StubWithCallback(releasefunc ## _refcount); \
+ }
+
+MAKE_REFCOUNT_STUBS(cl_device_id, clRetainDevice, clReleaseDevice, deviceRefcounts)
+MAKE_REFCOUNT_STUBS(cl_context, clRetainContext, clReleaseContext, contextRefcounts)
+MAKE_REFCOUNT_STUBS(cl_mem, clRetainMemObject, clReleaseMemObject, memRefcounts)
+
+/* The indirection through MAKE_MOVE_TESTS2 with a prefix parameter is to
+ * prevent the simple-minded parser from Unity from identifying tests from the
+ * macro value.
+ */
+#ifdef TEST_RVALUE_REFERENCES
+#define MAKE_MOVE_TESTS2(prefix, type, makeFunc, releaseFunc, pool) \
+ void prefix ## MoveAssign ## type ## NonNull() \
+ { \
+ releaseFunc ## _ExpectAndReturn(makeFunc(0), CL_SUCCESS); \
+ pool[0] = std::move(pool[1]); \
+ TEST_ASSERT_EQUAL_PTR(makeFunc(1), pool[0]()); \
+ TEST_ASSERT_NULL(pool[1]()); \
+ } \
+ \
+ void prefix ## MoveAssign ## type ## Null() \
+ { \
+ pool[0]() = NULL; \
+ pool[0] = std::move(pool[1]); \
+ TEST_ASSERT_EQUAL_PTR(makeFunc(1), pool[0]()); \
+ TEST_ASSERT_NULL(pool[1]()); \
+ } \
+ \
+ void prefix ## MoveConstruct ## type ## NonNull() \
+ { \
+ cl::type tmp(std::move(pool[0])); \
+ TEST_ASSERT_EQUAL_PTR(makeFunc(0), tmp()); \
+ TEST_ASSERT_NULL(pool[0]()); \
+ tmp() = NULL; \
+ } \
+ \
+ void prefix ## MoveConstruct ## type ## Null() \
+ { \
+ cl::type empty; \
+ cl::type tmp(std::move(empty)); \
+ TEST_ASSERT_NULL(tmp()); \
+ TEST_ASSERT_NULL(empty()); \
+ }
+#else
+#define MAKE_MOVE_TESTS2(prefix, type, makeFunc, releaseFunc, pool) \
+ void prefix ## MoveAssign ## type ## NonNull() {} \
+ void prefix ## MoveAssign ## type ## Null() {} \
+ void prefix ## MoveConstruct ## type ## NonNull() {} \
+ void prefix ## MoveConstruct ## type ## Null() {}
+#endif // !TEST_RVALUE_REFERENCES
+#define MAKE_MOVE_TESTS(type, makeFunc, releaseFunc, pool) \
+ MAKE_MOVE_TESTS2(test, type, makeFunc, releaseFunc, pool)
+
+void setUp()
+{
+ /* We reach directly into the objects rather than using assignment to
+ * avoid the reference counting functions from being called.
+ */
+ for (int i = 0; i < POOL_MAX; i++)
+ {
+ platformPool[i]() = make_platform_id(i);
+ contextPool[i]() = make_context(i);
+ commandQueuePool[i]() = make_command_queue(i);
+ bufferPool[i]() = make_mem(i);
+ image2DPool[i]() = make_mem(i);
+ image3DPool[i]() = make_mem(i);
+ kernelPool[i]() = make_kernel(i);
+ }
+
+ deviceRefcounts.reset();
+ contextRefcounts.reset();
+ memRefcounts.reset();
+}
+
+void tearDown()
+{
+ /* Wipe out the internal state to avoid a release call being made */
+ for (int i = 0; i < POOL_MAX; i++)
+ {
+ platformPool[i]() = NULL;
+ contextPool[i]() = NULL;
+ commandQueuePool[i]() = NULL;
+ bufferPool[i]() = NULL;
+ image2DPool[i]() = NULL;
+ image3DPool[i]() = NULL;
+ kernelPool[i]() = NULL;
+ }
+}
+
+/****************************************************************************
+ * Tests for atomic wrappers
+ ****************************************************************************/
+
+void testCompareExchange()
+{
+#ifndef TEST_CL2
+ /* This just tests that a compare-and-swap happens - there is no reliable
+ * way to ensure that it is atomic and performs a memory barrier.
+ */
+
+ // Test success case
+#ifdef TEST_CPP11_ATOMICS
+ std::atomic<int> dest(123);
+#else // #if defined(TEST_CPP11_ATOMICS)
+ volatile int dest = 123;
+#endif // #if defined(TEST_CPP11_ATOMICS)
+ int old = cl::detail::compare_exchange(&dest, 456, 123);
+ TEST_ASSERT_EQUAL(456, dest);
+ TEST_ASSERT_EQUAL(123, old);
+
+ // Test failure case
+ dest = 234;
+ old = cl::detail::compare_exchange(&dest, 345, 456);
+ TEST_ASSERT_EQUAL(234, dest);
+ TEST_ASSERT_EQUAL(234, old);
+#endif // !TEST_CL2
+}
+
+void testFence()
+{
+#ifndef TEST_CL2
+ /* No reliable way to test that it actually does what it says on the tin.
+ * Just test that it can be called without exploding.
+ */
+ cl::detail::fence();
+#endif // !TEST_CL2
+}
+
+/****************************************************************************
+ * Tests for cl::Context
+ ****************************************************************************/
+
+void testCopyContextNonNull()
+{
+ clReleaseContext_ExpectAndReturn(make_context(0), CL_SUCCESS);
+ clRetainContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
+
+ contextPool[0] = contextPool[1];
+ TEST_ASSERT_EQUAL_PTR(make_context(1), contextPool[0]());
+}
+
+void testMoveAssignContextNonNull();
+void testMoveAssignContextNull();
+void testMoveConstructContextNonNull();
+void testMoveConstructContextNull();
+MAKE_MOVE_TESTS(Context, make_context, clReleaseContext, contextPool)
+
+/// Stub for querying CL_CONTEXT_DEVICES that returns two devices
+static cl_int clGetContextInfo_testContextGetDevices(
+ cl_context context,
+ cl_context_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void) num_calls;
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_EQUAL_HEX(CL_CONTEXT_DEVICES, param_name);
+ TEST_ASSERT(param_value == NULL || param_value_size >= 2 * sizeof(cl_device_id));
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = 2 * sizeof(cl_device_id);
+ if (param_value != NULL)
+ {
+ cl_device_id *devices = (cl_device_id *) param_value;
+ devices[0] = make_device_id(0);
+ devices[1] = make_device_id(1);
+ }
+ return CL_SUCCESS;
+}
+
+/// Test that queried devices are not refcounted
+void testContextGetDevices1_1()
+{
+ clGetContextInfo_StubWithCallback(clGetContextInfo_testContextGetDevices);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_1);
+
+ VECTOR_CLASS<cl::Device> devices = contextPool[0].getInfo<CL_CONTEXT_DEVICES>();
+ TEST_ASSERT_EQUAL(2, devices.size());
+ TEST_ASSERT_EQUAL_PTR(make_device_id(0), devices[0]());
+ TEST_ASSERT_EQUAL_PTR(make_device_id(1), devices[1]());
+}
+
+/// Test that queried devices are correctly refcounted
+void testContextGetDevices1_2()
+{
+ clGetContextInfo_StubWithCallback(clGetContextInfo_testContextGetDevices);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+
+ clRetainDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+ clRetainDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+
+ VECTOR_CLASS<cl::Device> devices = contextPool[0].getInfo<CL_CONTEXT_DEVICES>();
+ TEST_ASSERT_EQUAL(2, devices.size());
+ TEST_ASSERT_EQUAL_PTR(make_device_id(0), devices[0]());
+ TEST_ASSERT_EQUAL_PTR(make_device_id(1), devices[1]());
+
+ // Prevent release in the destructor
+ devices[0]() = NULL;
+ devices[1]() = NULL;
+}
+
+// This is used to get a list of all platforms, so expect two calls
+// First, return to say we have two platforms
+// Then return the two platform id_s
+static cl_int clGetPlatformIDs_testContextFromType(
+ cl_uint num_entries,
+ cl_platform_id *platforms,
+ cl_uint *num_platforms,
+ int num_calls)
+{
+ if (num_calls == 0)
+ {
+ TEST_ASSERT_NULL(platforms);
+ TEST_ASSERT_NOT_NULL(num_platforms);
+ *num_platforms = 2;
+ return CL_SUCCESS;
+ }
+ else if (num_calls == 1)
+ {
+ TEST_ASSERT_NOT_NULL(platforms);
+ TEST_ASSERT_EQUAL(2, num_entries);
+ platforms[0] = make_platform_id(0);
+ platforms[1] = make_platform_id(1);
+ return CL_SUCCESS;
+ }
+ else
+ {
+ TEST_FAIL_MESSAGE("clGetPlatformIDs called too many times");
+ return CL_INVALID_VALUE;
+ }
+}
+
+// Expect three calls to this
+// 1. Platform 1, we have no GPUs
+// 2. Platform 2, we have two GPUs
+// 3. Here are the two cl_device_id's
+static cl_int clGetDeviceIDs_testContextFromType(
+ cl_platform_id platform,
+ cl_device_type device_type,
+ cl_uint num_entries,
+ cl_device_id *devices,
+ cl_uint *num_devices,
+ int num_calls)
+{
+ if (num_calls == 0)
+ {
+ TEST_ASSERT_EQUAL_PTR(make_platform_id(0), platform);
+ TEST_ASSERT_EQUAL(CL_DEVICE_TYPE_GPU, device_type);
+ TEST_ASSERT_NOT_NULL(num_devices);
+ return CL_DEVICE_NOT_FOUND;
+ }
+ else if (num_calls == 1)
+ {
+ TEST_ASSERT_EQUAL_PTR(make_platform_id(1), platform);
+ TEST_ASSERT_EQUAL(CL_DEVICE_TYPE_GPU, device_type);
+ TEST_ASSERT_NOT_NULL(num_devices);
+ *num_devices = 2;
+ return CL_SUCCESS;
+ }
+ else if (num_calls == 2)
+ {
+ TEST_ASSERT_EQUAL_PTR(make_platform_id(1), platform);
+ TEST_ASSERT_EQUAL(CL_DEVICE_TYPE_GPU, device_type);
+ TEST_ASSERT_EQUAL(2, num_entries);
+ TEST_ASSERT_NOT_NULL(devices);
+ devices[0] = make_device_id(0);
+ devices[1] = make_device_id(1);
+ return CL_SUCCESS;
+ }
+ else
+ {
+ TEST_FAIL_MESSAGE("clGetDeviceIDs called too many times");
+ return CL_INVALID_VALUE;
+ }
+}
+
+// Stub for clCreateContextFromType
+// - expect platform 1 with GPUs and non-null properties
+static cl_context clCreateContextFromType_testContextFromType(
+ const cl_context_properties *properties,
+ cl_device_type device_type,
+ void (CL_CALLBACK *pfn_notify) (const char *errinfo,
+ const void *private_info,
+ size_t cb,
+ void *user_data),
+ void *user_data,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_NOT_NULL(properties);
+ TEST_ASSERT_EQUAL(CL_DEVICE_TYPE_GPU, device_type);
+ TEST_ASSERT_EQUAL(CL_CONTEXT_PLATFORM, properties[0]);
+ TEST_ASSERT_EQUAL(make_platform_id(1), properties[1]);
+ return make_context(0);
+
+}
+
+void testContextFromType()
+{
+ clGetPlatformIDs_StubWithCallback(clGetPlatformIDs_testContextFromType);
+ clGetDeviceIDs_StubWithCallback(clGetDeviceIDs_testContextFromType);
+#if defined(TEST_CL2)
+ // The cl2.hpp header will perform an extra retain here to be consistent
+ // with other APIs retaining runtime-owned objects before releasing them
+ clRetainDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+ clRetainDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+#endif
+
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+
+ // End of scope of vector of devices within constructor
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+ clReleaseDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+
+ clCreateContextFromType_StubWithCallback(clCreateContextFromType_testContextFromType);
+
+ cl::Context context(CL_DEVICE_TYPE_GPU);
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context());
+
+ clReleaseContext_ExpectAndReturn(make_context(0), CL_SUCCESS);
+
+}
+
+/****************************************************************************
+ * Tests for cl::CommandQueue
+ ****************************************************************************/
+
+void testMoveAssignCommandQueueNonNull();
+void testMoveAssignCommandQueueNull();
+void testMoveConstructCommandQueueNonNull();
+void testMoveConstructCommandQueueNull();
+MAKE_MOVE_TESTS(CommandQueue, make_command_queue, clReleaseCommandQueue, commandQueuePool);
+
+// Stub for clGetCommandQueueInfo that returns context 0
+static cl_int clGetCommandQueueInfo_testCommandQueueGetContext(
+ cl_command_queue command_queue,
+ cl_command_queue_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void) num_calls;
+ TEST_ASSERT_EQUAL_PTR(make_command_queue(0), command_queue);
+ TEST_ASSERT_EQUAL_HEX(CL_QUEUE_CONTEXT, param_name);
+ TEST_ASSERT(param_value == NULL || param_value_size >= sizeof(cl_context));
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = sizeof(cl_context);
+ if (param_value != NULL)
+ *(cl_context *) param_value = make_context(0);
+ return CL_SUCCESS;
+}
+
+void testCommandQueueGetContext()
+{
+ cl_context expected = make_context(0);
+ int refcount = 1;
+
+ clGetCommandQueueInfo_StubWithCallback(clGetCommandQueueInfo_testCommandQueueGetContext);
+ prepare_contextRefcounts(1, &expected, &refcount);
+
+ cl::Context ctx = commandQueuePool[0].getInfo<CL_QUEUE_CONTEXT>();
+ TEST_ASSERT_EQUAL_PTR(expected, ctx());
+ TEST_ASSERT_EQUAL(2, refcount);
+
+ ctx() = NULL;
+}
+
+// Stub for clGetCommandQueueInfo that returns device 0
+static cl_int clGetCommandQueueInfo_testCommandQueueGetDevice(
+ cl_command_queue command_queue,
+ cl_command_queue_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ (void) num_calls;
+ TEST_ASSERT_EQUAL_PTR(make_command_queue(0), command_queue);
+ TEST_ASSERT_EQUAL_HEX(CL_QUEUE_DEVICE, param_name);
+ TEST_ASSERT(param_value == NULL || param_value_size >= sizeof(cl_device_id));
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = sizeof(cl_device_id);
+ if (param_value != NULL)
+ *(cl_device_id *) param_value = make_device_id(0);
+ return CL_SUCCESS;
+}
+
+void testCommandQueueGetDevice1_1()
+{
+ cl_device_id expected = make_device_id(0);
+
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_1);
+ clGetCommandQueueInfo_StubWithCallback(clGetCommandQueueInfo_testCommandQueueGetDevice);
+
+ cl::Device device = commandQueuePool[0].getInfo<CL_QUEUE_DEVICE>();
+ TEST_ASSERT_EQUAL_PTR(expected, device());
+
+ device() = NULL;
+}
+
+void testCommandQueueGetDevice1_2()
+{
+ cl_device_id expected = make_device_id(0);
+ int refcount = 1;
+
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clGetCommandQueueInfo_StubWithCallback(clGetCommandQueueInfo_testCommandQueueGetDevice);
+ prepare_deviceRefcounts(1, &expected, &refcount);
+
+ cl::Device device = commandQueuePool[0].getInfo<CL_QUEUE_DEVICE>();
+ TEST_ASSERT_EQUAL_PTR(expected, device());
+ TEST_ASSERT_EQUAL(2, refcount);
+
+ device() = NULL;
+}
+
+// stub for clCreateCommandQueue - returns queue zero
+static cl_command_queue clCreateCommandQueue_testCommandQueueFromSpecifiedContext(
+ cl_context context,
+ cl_device_id device,
+ cl_command_queue_properties properties,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ (void) num_calls;
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_EQUAL_PTR(make_device_id(0), device);
+ TEST_ASSERT(properties == 0);
+ return make_command_queue(0);
+}
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+// stub for clCreateCommandQueueWithProperties - returns queue zero
+static cl_command_queue clCreateCommandQueueWithProperties_testCommandQueueFromSpecifiedContext(
+ cl_context context,
+ cl_device_id device,
+ const cl_queue_properties *properties,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ (void)num_calls;
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_EQUAL_PTR(make_device_id(0), device);
+ TEST_ASSERT(properties[0] == CL_QUEUE_PROPERTIES);
+ TEST_ASSERT(properties[1] == 0);
+ return make_command_queue(0);
+}
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+
+void testCommandQueueFromSpecifiedContext()
+{
+ cl_command_queue expected = make_command_queue(0);
+ cl_context expected_context = make_context(0);
+ cl_device_id expected_device = make_device_id(0);
+
+ int context_refcount = 1;
+ int device_refcount = 1;
+ prepare_contextRefcounts(1, &expected_context, &context_refcount);
+ prepare_deviceRefcounts(1, &expected_device, &device_refcount);
+
+ // This is the context we will pass in to test
+ cl::Context context = contextPool[0];
+
+ // Assumes the context contains the fi rst device
+ clGetContextInfo_StubWithCallback(clGetContextInfo_device);
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clCreateCommandQueueWithProperties_StubWithCallback(clCreateCommandQueueWithProperties_testCommandQueueFromSpecifiedContext);
+#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clCreateCommandQueue_StubWithCallback(clCreateCommandQueue_testCommandQueueFromSpecifiedContext);
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_2_0);
+#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clReleaseCommandQueue_ExpectAndReturn(expected, CL_SUCCESS);
+
+ cl::CommandQueue queue(context);
+ TEST_ASSERT_EQUAL_PTR(expected, queue());
+
+ // Context not destroyed yet
+ TEST_ASSERT_EQUAL(2, context_refcount);
+ // Device object destroyed at end of scope
+ TEST_ASSERT_EQUAL(1, device_refcount);
+
+}
+
+/****************************************************************************
+ * Tests for cl::Device
+ ****************************************************************************/
+
+void testCopyDeviceNonNull1_1()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_1);
+
+ cl::Device d0(make_device_id(0));
+ cl::Device d1(make_device_id(1));
+ d0 = d1;
+}
+
+void testCopyDeviceNonNull1_2()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+ clRetainDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+
+ cl::Device d0(make_device_id(0));
+ cl::Device d1(make_device_id(1));
+ d0 = d1;
+
+ // Prevent destructor from interfering with the test
+ d0() = NULL;
+ d1() = NULL;
+}
+
+void testCopyDeviceFromNull1_1()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_1);
+ // No other calls expected
+
+ cl::Device d(make_device_id(0));
+ d = cl::Device();
+}
+
+void testCopyDeviceFromNull1_2()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+
+ cl::Device d(make_device_id(0));
+ d = cl::Device();
+}
+
+void testCopyDeviceToNull1_1()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_1);
+ // No other calls expected
+
+ cl::Device d0;
+ cl::Device d1(make_device_id(0));
+ d0 = d1;
+}
+
+void testCopyDeviceToNull1_2()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clRetainDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+
+ cl::Device d0;
+ cl::Device d1(make_device_id(0));
+ d0 = d1;
+
+ // Prevent destructor from interfering with the test
+ d0() = NULL;
+ d1() = NULL;
+}
+
+void testCopyDeviceSelf()
+{
+ // Use 1.2 to check the retain/release calls
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+ clRetainDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+
+ cl::Device d0(make_device_id(0));
+ cl::Device d1(make_device_id(1));
+ d0 = d1;
+
+ // Prevent destructor from interfering with the test
+ d0() = NULL;
+ d1() = NULL;
+}
+
+void testAssignDeviceNull()
+{
+ // Any version will do here
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+
+ cl::Device d(make_device_id(0));
+ d = (cl_device_id) NULL;
+}
+
+// These tests do not use the MAKE_MOVE_TESTS helper because they need to
+// check whether the device is reference-countable, and to check that
+// the reference-countable flag is correctly moved.
+void testMoveAssignDeviceNonNull()
+{
+#ifdef TEST_RVALUE_REFERENCES
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+
+ // Release called when trg overwritten
+ clReleaseDevice_ExpectAndReturn(make_device_id(1), CL_SUCCESS);
+
+ cl::Device src(make_device_id(0));
+ cl::Device trg(make_device_id(1));
+ trg = std::move(src);
+ TEST_ASSERT_EQUAL_PTR(make_device_id(0), trg());
+ TEST_ASSERT_NULL(src());
+
+ // Prevent destructor from interfering with the test
+ trg() = NULL;
+#endif
+}
+
+void testMoveAssignDeviceNull()
+{
+#ifdef TEST_RVALUE_REFERENCES
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+
+ cl::Device trg;
+ cl::Device src(make_device_id(1));
+ trg = std::move(src);
+ TEST_ASSERT_EQUAL_PTR(make_device_id(1), trg());
+ TEST_ASSERT_NULL(src());
+
+ // Prevent destructor from interfering with the test
+ trg() = NULL;
+#endif
+}
+
+void testMoveConstructDeviceNonNull()
+{
+#ifdef TEST_RVALUE_REFERENCES
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+
+ cl::Device src(make_device_id(0));
+ cl::Device trg(std::move(src));
+ TEST_ASSERT_EQUAL_PTR(make_device_id(0), trg());
+ TEST_ASSERT_NULL(src());
+
+ // Prevent destructor from interfering with the test
+ trg() = NULL;
+#endif
+}
+
+void testMoveConstructDeviceNull()
+{
+#ifdef TEST_RVALUE_REFERENCES
+ cl::Device empty;
+ cl::Device trg(std::move(empty));
+ TEST_ASSERT_NULL(trg());
+ TEST_ASSERT_NULL(empty());
+#endif
+}
+
+void testDestroyDevice1_1()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_1);
+ // No other calls expected
+
+ cl::Device d(make_device_id(0));
+}
+
+void testDestroyDevice1_2()
+{
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+
+ cl::Device d(make_device_id(0));
+}
+
+/****************************************************************************
+ * Tests for cl::Buffer
+ ****************************************************************************/
+
+void testMoveAssignBufferNonNull();
+void testMoveAssignBufferNull();
+void testMoveConstructBufferNonNull();
+void testMoveConstructBufferNull();
+MAKE_MOVE_TESTS(Buffer, make_mem, clReleaseMemObject, bufferPool);
+
+// Stub of clCreateBuffer for testBufferConstructorContextInterator
+// - return the first memory location
+
+static cl_mem clCreateBuffer_testBufferConstructorContextIterator(
+ cl_context context,
+ cl_mem_flags flags,
+ size_t size,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_BITS(CL_MEM_COPY_HOST_PTR, flags, !CL_MEM_COPY_HOST_PTR);
+ TEST_ASSERT_BITS(CL_MEM_READ_ONLY, flags, CL_MEM_READ_ONLY);
+ TEST_ASSERT_EQUAL(sizeof(int)*1024, size);
+ TEST_ASSERT_NULL(host_ptr);
+ if (errcode_ret)
+ errcode_ret = CL_SUCCESS;
+ return make_mem(0);
+}
+
+// Declare forward these functions
+static void * clEnqueueMapBuffer_testCopyHostToBuffer(
+ cl_command_queue command_queue,
+ cl_mem buffer,
+ cl_bool blocking_map,
+ cl_map_flags map_flags,
+ size_t offset,
+ size_t size,
+ cl_uint num_events_in_wait_list,
+ const cl_event *event_wait_list,
+ cl_event *event,
+ cl_int *errcode_ret,
+ int num_calls);
+
+static cl_int clEnqueueUnmapMemObject_testCopyHostToBuffer(
+ cl_command_queue command_queue ,
+ cl_mem memobj,
+ void *mapped_ptr,
+ cl_uint num_events_in_wait_list ,
+ const cl_event *event_wait_list ,
+ cl_event *event,
+ int num_calls);
+
+static cl_int clWaitForEvents_testCopyHostToBuffer(
+ cl_uint num_events,
+ const cl_event *event_list,
+ int num_calls);
+
+static cl_int clReleaseEvent_testCopyHostToBuffer(
+ cl_event event,
+ int num_calls);
+
+void testBufferConstructorContextIterator()
+{
+ cl_mem expected = make_mem(0);
+
+ // Assume this context includes make_device_id(0) for stub clGetContextInfo_device
+ cl::Context context(make_context(0));
+
+ clCreateBuffer_StubWithCallback(clCreateBuffer_testBufferConstructorContextIterator);
+ clGetContextInfo_StubWithCallback(clGetContextInfo_device);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clRetainDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+
+#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clCreateCommandQueueWithProperties_StubWithCallback(clCreateCommandQueueWithProperties_testCommandQueueFromSpecifiedContext);
+#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clCreateCommandQueue_StubWithCallback(clCreateCommandQueue_testCommandQueueFromSpecifiedContext);
+#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
+ clReleaseDevice_ExpectAndReturn(make_device_id(0), CL_SUCCESS);
+ clEnqueueMapBuffer_StubWithCallback(clEnqueueMapBuffer_testCopyHostToBuffer);
+ clEnqueueUnmapMemObject_StubWithCallback(clEnqueueUnmapMemObject_testCopyHostToBuffer);
+ clWaitForEvents_StubWithCallback(clWaitForEvents_testCopyHostToBuffer);
+ clReleaseEvent_StubWithCallback(clReleaseEvent_testCopyHostToBuffer);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(0), CL_SUCCESS);
+
+ std::vector<int> host(1024);
+
+ cl::Buffer buffer(context, host.begin(), host.end(), true);
+
+ TEST_ASSERT_EQUAL_PTR(expected, buffer());
+
+ // Tidy up at end of test
+ clReleaseMemObject_ExpectAndReturn(expected, CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(0), CL_SUCCESS);
+}
+
+void testBufferConstructorQueueIterator()
+{
+ cl_context expected_context = make_context(0);
+ int context_refcount = 1;
+ cl_mem expected = make_mem(0);
+
+ cl::CommandQueue queue(make_command_queue(0));
+
+ prepare_contextRefcounts(1, &expected_context, &context_refcount);
+ clGetCommandQueueInfo_StubWithCallback(clGetCommandQueueInfo_context);
+ clCreateBuffer_StubWithCallback(clCreateBuffer_testBufferConstructorContextIterator);
+
+ clEnqueueMapBuffer_StubWithCallback(clEnqueueMapBuffer_testCopyHostToBuffer);
+ clEnqueueUnmapMemObject_StubWithCallback(clEnqueueUnmapMemObject_testCopyHostToBuffer);
+ clWaitForEvents_StubWithCallback(clWaitForEvents_testCopyHostToBuffer);
+ clReleaseEvent_StubWithCallback(clReleaseEvent_testCopyHostToBuffer);
+
+ std::vector<int> host(1024);
+
+ cl::Buffer buffer(queue, host.begin(), host.end(), true);
+
+ TEST_ASSERT_EQUAL_PTR(expected, buffer());
+ TEST_ASSERT_EQUAL(1, context_refcount);
+
+ // Tidy up at end of test
+ clReleaseMemObject_ExpectAndReturn(expected, CL_SUCCESS);
+ clReleaseCommandQueue_ExpectAndReturn(make_command_queue(0), CL_SUCCESS);
+}
+
+/****************************************************************************
+ * Tests for cl::Image1DBuffer
+ ****************************************************************************/
+
+/**
+ * Stub for querying CL_IMAGE_BUFFER and returning make_mem(1).
+ */
+cl_int clGetImageInfo_testGetImageInfoBuffer(
+ cl_mem image, cl_image_info param_name,
+ size_t param_value_size, void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(0, num_calls);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), image);
+ TEST_ASSERT_EQUAL_HEX(CL_IMAGE_BUFFER, param_name);
+ TEST_ASSERT_EQUAL(sizeof(cl_mem), param_value_size);
+
+ if (param_value != NULL)
+ {
+ *(cl_mem *) param_value = make_mem(1);
+ }
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = sizeof(cl_mem);
+ return CL_SUCCESS;
+}
+
+void testGetImageInfoBuffer()
+{
+ cl_mem expected = make_mem(1);
+ int refcount = 1;
+
+ clGetImageInfo_StubWithCallback(clGetImageInfo_testGetImageInfoBuffer);
+ prepare_memRefcounts(1, &expected, &refcount);
+
+ cl::Image1DBuffer image(make_mem(0));
+ const cl::Buffer &buffer = image.getImageInfo<CL_IMAGE_BUFFER>();
+ TEST_ASSERT_EQUAL_PTR(make_mem(1), buffer());
+ // Ref count should be 2 here because buffer has not been destroyed yet
+ TEST_ASSERT_EQUAL(2, refcount);
+
+ // prevent destructor from interfering with the test
+ image() = NULL;
+}
+
+/**
+ * Stub for querying CL_IMAGE_BUFFER and returning NULL.
+ */
+cl_int clGetImageInfo_testGetImageInfoBufferNull(
+ cl_mem image, cl_image_info param_name,
+ size_t param_value_size, void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(0, num_calls);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), image);
+ TEST_ASSERT_EQUAL_HEX(CL_IMAGE_BUFFER, param_name);
+ TEST_ASSERT_EQUAL(sizeof(cl_mem), param_value_size);
+
+ if (param_value != NULL)
+ {
+ *(cl_mem *) param_value = NULL;
+ }
+ if (param_value_size_ret != NULL)
+ *param_value_size_ret = sizeof(cl_mem);
+ return CL_SUCCESS;
+}
+
+void testGetImageInfoBufferNull()
+{
+ clGetImageInfo_StubWithCallback(clGetImageInfo_testGetImageInfoBufferNull);
+
+ cl::Image2D image(make_mem(0));
+ cl::Buffer buffer = image.getImageInfo<CL_IMAGE_BUFFER>();
+ TEST_ASSERT_NULL(buffer());
+
+ // prevent destructor from interfering with the test
+ image() = NULL;
+}
+
+void testGetImageInfoBufferOverwrite()
+{
+ clGetImageInfo_StubWithCallback(clGetImageInfo_testGetImageInfoBuffer);
+ clReleaseMemObject_ExpectAndReturn(make_mem(2), CL_SUCCESS);
+ clRetainMemObject_ExpectAndReturn(make_mem(1), CL_SUCCESS);
+
+ cl::Image2D image(make_mem(0));
+ cl::Buffer buffer(make_mem(2));
+ cl_int status = image.getImageInfo(CL_IMAGE_BUFFER, &buffer);
+ TEST_ASSERT_EQUAL(CL_SUCCESS, status);
+ TEST_ASSERT_EQUAL_PTR(make_mem(1), buffer());
+
+ // prevent destructor from interfering with the test
+ image() = NULL;
+ buffer() = NULL;
+}
+
+/**
+ * A stub for clCreateImage that creates an image from a buffer
+ * passing the buffer's cl_mem straight through.
+ */
+cl_mem clCreateImage_image1dbuffer(
+ cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_NOT_NULL(image_format);
+ TEST_ASSERT_NOT_NULL(image_desc);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_OBJECT_IMAGE1D_BUFFER, image_desc->image_type);
+
+ // Return the passed buffer as the cl_mem
+ return image_desc->buffer;
+}
+
+void testConstructImageFromBuffer()
+{
+ const size_t width = 64;
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clCreateImage_StubWithCallback(clCreateImage_image1dbuffer);
+ clReleaseMemObject_ExpectAndReturn(make_mem(0), CL_SUCCESS);
+ clReleaseContext_ExpectAndReturn(make_context(0), CL_SUCCESS);
+
+ cl::Context context(make_context(0));
+ cl::Buffer buffer(make_mem(0));
+ cl::Image1DBuffer image(
+ context,
+ CL_MEM_READ_ONLY,
+ cl::ImageFormat(CL_R, CL_SIGNED_INT32),
+ width,
+ buffer);
+
+ // Check that returned buffer matches the original
+ TEST_ASSERT_EQUAL_PTR(buffer(), image());
+
+ buffer() = NULL;
+}
+
+/****************************************************************************
+ * Tests for cl::Image2D
+ ****************************************************************************/
+
+void testMoveAssignImage2DNonNull();
+void testMoveAssignImage2DNull();
+void testMoveConstructImage2DNonNull();
+void testMoveConstructImage2DNull();
+MAKE_MOVE_TESTS(Image2D, make_mem, clReleaseMemObject, image2DPool);
+
+#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS
+static cl_mem clCreateImage2D_testCreateImage2D_1_1(
+ cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ size_t image_width,
+ size_t image_height,
+ size_t image_row_pitch,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(0, num_calls);
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_READ_WRITE, flags);
+
+ TEST_ASSERT_NOT_NULL(image_format);
+ TEST_ASSERT_EQUAL_HEX(CL_R, image_format->image_channel_order);
+ TEST_ASSERT_EQUAL_HEX(CL_FLOAT, image_format->image_channel_data_type);
+
+ TEST_ASSERT_EQUAL(64, image_width);
+ TEST_ASSERT_EQUAL(32, image_height);
+ TEST_ASSERT_EQUAL(256, image_row_pitch);
+ TEST_ASSERT_NULL(host_ptr);
+
+ if (errcode_ret != NULL)
+ *errcode_ret = CL_SUCCESS;
+ return make_mem(0);
+}
+#endif
+
+void testCreateImage2D_1_1()
+{
+#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS
+ clGetContextInfo_StubWithCallback(clGetContextInfo_device);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_1);
+ clCreateImage2D_StubWithCallback(clCreateImage2D_testCreateImage2D_1_1);
+
+ cl_int err;
+ cl::Context context;
+ context() = make_context(0);
+ cl::Image2D image(
+ context, CL_MEM_READ_WRITE,
+ cl::ImageFormat(CL_R, CL_FLOAT), 64, 32, 256, NULL, &err);
+
+ TEST_ASSERT_EQUAL(CL_SUCCESS, err);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), image());
+
+ context() = NULL;
+ image() = NULL;
+#endif
+}
+
+static cl_mem clCreateImage_testCreateImage2D_1_2(
+ cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(0, num_calls);
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_READ_WRITE, flags);
+
+ TEST_ASSERT_NOT_NULL(image_format);
+ TEST_ASSERT_EQUAL_HEX(CL_R, image_format->image_channel_order);
+ TEST_ASSERT_EQUAL_HEX(CL_FLOAT, image_format->image_channel_data_type);
+
+ TEST_ASSERT_NOT_NULL(image_desc);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_OBJECT_IMAGE2D, image_desc->image_type);
+ TEST_ASSERT_EQUAL(64, image_desc->image_width);
+ TEST_ASSERT_EQUAL(32, image_desc->image_height);
+ TEST_ASSERT_EQUAL(256, image_desc->image_row_pitch);
+ TEST_ASSERT_EQUAL(0, image_desc->num_mip_levels);
+ TEST_ASSERT_EQUAL(0, image_desc->num_samples);
+ TEST_ASSERT_NULL(image_desc->buffer);
+
+ TEST_ASSERT_NULL(host_ptr);
+
+ if (errcode_ret != NULL)
+ *errcode_ret = CL_SUCCESS;
+ return make_mem(0);
+}
+
+void testCreateImage2D_1_2()
+{
+ clGetContextInfo_StubWithCallback(clGetContextInfo_device);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clCreateImage_StubWithCallback(clCreateImage_testCreateImage2D_1_2);
+
+ cl_int err;
+ cl::Context context;
+ context() = make_context(0);
+ cl::Image2D image(
+ context, CL_MEM_READ_WRITE,
+ cl::ImageFormat(CL_R, CL_FLOAT), 64, 32, 256, NULL, &err);
+
+ TEST_ASSERT_EQUAL(CL_SUCCESS, err);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), image());
+
+ context() = NULL;
+ image() = NULL;
+}
+
+/****************************************************************************
+ * Tests for cl::Image3D
+ ****************************************************************************/
+
+void testMoveAssignImage3DNonNull();
+void testMoveAssignImage3DNull();
+void testMoveConstructImage3DNonNull();
+void testMoveConstructImage3DNull();
+MAKE_MOVE_TESTS(Image3D, make_mem, clReleaseMemObject, image3DPool);
+
+#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS
+static cl_mem clCreateImage3D_testCreateImage3D_1_1(
+ cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ size_t image_width,
+ size_t image_height,
+ size_t image_depth,
+ size_t image_row_pitch,
+ size_t image_slice_pitch,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(0, num_calls);
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, flags);
+
+ TEST_ASSERT_NOT_NULL(image_format);
+ TEST_ASSERT_EQUAL_HEX(CL_R, image_format->image_channel_order);
+ TEST_ASSERT_EQUAL_HEX(CL_FLOAT, image_format->image_channel_data_type);
+
+ TEST_ASSERT_EQUAL(64, image_width);
+ TEST_ASSERT_EQUAL(32, image_height);
+ TEST_ASSERT_EQUAL(16, image_depth);
+ TEST_ASSERT_EQUAL(256, image_row_pitch);
+ TEST_ASSERT_EQUAL(65536, image_slice_pitch);
+ TEST_ASSERT_EQUAL_PTR((void *) 0xdeadbeef, host_ptr);
+
+ if (errcode_ret != NULL)
+ *errcode_ret = CL_SUCCESS;
+ return make_mem(0);
+}
+#endif
+
+void testCreateImage3D_1_1()
+{
+#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS
+ clGetContextInfo_StubWithCallback(clGetContextInfo_device);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_1);
+ clCreateImage3D_StubWithCallback(clCreateImage3D_testCreateImage3D_1_1);
+
+ cl_int err;
+ cl::Context context;
+ context() = make_context(0);
+ cl::Image3D image(
+ context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
+ cl::ImageFormat(CL_R, CL_FLOAT), 64, 32, 16, 256, 65536, (void *) 0xdeadbeef, &err);
+
+ TEST_ASSERT_EQUAL(CL_SUCCESS, err);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), image());
+
+ context() = NULL;
+ image() = NULL;
+#endif
+}
+
+static cl_mem clCreateImage_testCreateImage3D_1_2(
+ cl_context context,
+ cl_mem_flags flags,
+ const cl_image_format *image_format,
+ const cl_image_desc *image_desc,
+ void *host_ptr,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(0, num_calls);
+ TEST_ASSERT_EQUAL_PTR(make_context(0), context);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, flags);
+
+ TEST_ASSERT_NOT_NULL(image_format);
+ TEST_ASSERT_EQUAL_HEX(CL_R, image_format->image_channel_order);
+ TEST_ASSERT_EQUAL_HEX(CL_FLOAT, image_format->image_channel_data_type);
+
+ TEST_ASSERT_NOT_NULL(image_desc);
+ TEST_ASSERT_EQUAL_HEX(CL_MEM_OBJECT_IMAGE3D, image_desc->image_type);
+ TEST_ASSERT_EQUAL(64, image_desc->image_width);
+ TEST_ASSERT_EQUAL(32, image_desc->image_height);
+ TEST_ASSERT_EQUAL(16, image_desc->image_depth);
+ TEST_ASSERT_EQUAL(256, image_desc->image_row_pitch);
+ TEST_ASSERT_EQUAL(65536, image_desc->image_slice_pitch);
+ TEST_ASSERT_EQUAL(0, image_desc->num_mip_levels);
+ TEST_ASSERT_EQUAL(0, image_desc->num_samples);
+ TEST_ASSERT_NULL(image_desc->buffer);
+
+ TEST_ASSERT_EQUAL_PTR((void *) 0xdeadbeef, host_ptr);
+
+ if (errcode_ret != NULL)
+ *errcode_ret = CL_SUCCESS;
+ return make_mem(0);
+}
+
+void testCreateImage3D_1_2()
+{
+ clGetContextInfo_StubWithCallback(clGetContextInfo_device);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_platform);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clCreateImage_StubWithCallback(clCreateImage_testCreateImage3D_1_2);
+
+ cl_int err;
+ cl::Context context;
+ context() = make_context(0);
+ cl::Image3D image(
+ context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
+ cl::ImageFormat(CL_R, CL_FLOAT), 64, 32, 16, 256, 65536, (void *) 0xdeadbeef, &err);
+
+ TEST_ASSERT_EQUAL(CL_SUCCESS, err);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), image());
+
+ context() = NULL;
+ image() = NULL;
+}
+
+/****************************************************************************
+ * Tests for cl::Kernel
+ ****************************************************************************/
+void testMoveAssignKernelNonNull();
+void testMoveAssignKernelNull();
+void testMoveConstructKernelNonNull();
+void testMoveConstructKernelNull();
+MAKE_MOVE_TESTS(Kernel, make_kernel, clReleaseKernel, kernelPool);
+
+static cl_int scalarArg;
+static cl_int3 vectorArg;
+
+void testKernelSetArgScalar()
+{
+ scalarArg = 0xcafebabe;
+ clSetKernelArg_ExpectAndReturn(make_kernel(0), 3, 4, &scalarArg, CL_SUCCESS);
+ kernelPool[0].setArg(3, scalarArg);
+}
+
+void testKernelSetArgVector()
+{
+ vectorArg.s[0] = 0x12345678;
+ vectorArg.s[1] = 0x23456789;
+ vectorArg.s[2] = 0x87654321;
+ clSetKernelArg_ExpectAndReturn(make_kernel(0), 2, 16, &vectorArg, CL_SUCCESS);
+ kernelPool[0].setArg(2, vectorArg);
+}
+
+void testKernelSetArgMem()
+{
+ clSetKernelArg_ExpectAndReturn(make_kernel(0), 1, sizeof(cl_mem), &bufferPool[1](), CL_SUCCESS);
+ kernelPool[0].setArg(1, bufferPool[1]);
+}
+
+void testKernelSetArgLocal()
+{
+ clSetKernelArg_ExpectAndReturn(make_kernel(0), 2, 123, NULL, CL_SUCCESS);
+ kernelPool[0].setArg(2, cl::Local(123));
+}
+
+/****************************************************************************
+ * Tests for cl::copy
+ ****************************************************************************/
+
+// This method should allocate some host accesible memory
+// so we must do this ourselves
+void *some_host_memory;
+
+static void * clEnqueueMapBuffer_testCopyHostToBuffer(
+ cl_command_queue command_queue,
+ cl_mem buffer,
+ cl_bool blocking_map,
+ cl_map_flags map_flags,
+ size_t offset,
+ size_t size,
+ cl_uint num_events_in_wait_list,
+ const cl_event *event_wait_list,
+ cl_event *event,
+ cl_int *errcode_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL_PTR(make_command_queue(0), command_queue);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), buffer);
+ TEST_ASSERT_EQUAL(CL_TRUE, blocking_map);
+ TEST_ASSERT_EQUAL(CL_MAP_WRITE, map_flags);
+ TEST_ASSERT_EQUAL(sizeof(int)*1024, size);
+
+ some_host_memory = malloc(sizeof(int) * 1024);
+
+ // Set the return event
+ if (event)
+ *event = NULL;
+
+ // Set the return error code
+ if (errcode_ret)
+ *errcode_ret = CL_SUCCESS;
+
+ return some_host_memory;
+}
+
+static cl_int clEnqueueUnmapMemObject_testCopyHostToBuffer(
+ cl_command_queue command_queue ,
+ cl_mem memobj,
+ void *mapped_ptr,
+ cl_uint num_events_in_wait_list ,
+ const cl_event *event_wait_list ,
+ cl_event *event,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL_PTR(make_command_queue(0), command_queue);
+ TEST_ASSERT_EQUAL_PTR(make_mem(0), memobj);
+ TEST_ASSERT_EQUAL_PTR(some_host_memory, mapped_ptr);
+ TEST_ASSERT_NOT_NULL(event);
+ return CL_SUCCESS;
+}
+
+static cl_int clWaitForEvents_testCopyHostToBuffer(
+ cl_uint num_events,
+ const cl_event *event_list,
+ int num_calls)
+{
+ TEST_ASSERT_NOT_NULL(event_list);
+ TEST_ASSERT_EQUAL(1, num_events);
+ return CL_SUCCESS;
+}
+
+static cl_int clReleaseEvent_testCopyHostToBuffer(
+ cl_event event,
+ int num_calls)
+{
+ TEST_ASSERT_NOT_NULL(event);
+ return CL_SUCCESS;
+}
+
+void testCopyHostToBuffer()
+{
+ cl_context context_expect = make_context(0);
+ int context_refcount = 1;
+ prepare_contextRefcounts(1, &context_expect, &context_refcount);
+ cl::Context context = contextPool[0];
+
+ cl_mem mem_expect = make_mem(0);
+ int mem_refcount = 1;
+ prepare_memRefcounts(1, &mem_expect, &mem_refcount);
+ cl::Buffer buffer(make_mem(0));
+
+ cl_command_queue queue_expect = make_command_queue(0);
+ cl::CommandQueue queue(queue_expect);
+ clReleaseCommandQueue_ExpectAndReturn(queue_expect, CL_SUCCESS);
+
+ // Returns the pointer to host memory
+ clEnqueueMapBuffer_StubWithCallback(clEnqueueMapBuffer_testCopyHostToBuffer);
+ clEnqueueUnmapMemObject_StubWithCallback(clEnqueueUnmapMemObject_testCopyHostToBuffer);
+
+ clWaitForEvents_StubWithCallback(clWaitForEvents_testCopyHostToBuffer);
+ clReleaseEvent_StubWithCallback(clReleaseEvent_testCopyHostToBuffer);
+
+ std::vector<int> host(1024);
+ for (int i = 0; i < 1024; i++)
+ host[i] = i;
+
+ cl::copy(queue, host.begin(), host.end(), buffer);
+
+ // Check that the memory was copied to some_host_memory
+ TEST_ASSERT_EQUAL_MEMORY(&host[0], some_host_memory, sizeof(int) * 1024);
+
+ free(some_host_memory);
+
+}
+
+
+/****************************************************************************
+* Tests for getBuildInfo
+****************************************************************************/
+
+static cl_int clGetDeviceInfo_testGetBuildInfo(
+ cl_device_id device,
+ cl_device_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(param_name, CL_DEVICE_PLATFORM);
+ TEST_ASSERT_EQUAL(param_value_size, sizeof(cl_platform_id));
+ TEST_ASSERT_NOT_EQUAL(param_value, NULL);
+ TEST_ASSERT_EQUAL(param_value_size_ret, NULL);
+ cl_platform_id temp = make_platform_id(0);
+ memcpy(param_value, &temp, sizeof(cl_platform_id));
+ return CL_SUCCESS;
+}
+
+
+static cl_int clGetProgramBuildInfo_testGetBuildInfo(
+ cl_program program,
+ cl_device_id device,
+ cl_program_build_info param_name,
+ size_t param_value_size,
+ void *param_value,
+ size_t *param_value_size_ret,
+ int num_calls)
+{
+ TEST_ASSERT_EQUAL(param_name, CL_PROGRAM_BUILD_LOG);
+
+ const char returnString[] =
+ "This is the string returned by the build info function.";
+ if (param_value) {
+ ::size_t returnSize = param_value_size;
+ if (sizeof(returnString) < returnSize) {
+ returnSize = sizeof(returnString);
+ }
+ memcpy(param_value, returnString, returnSize);
+ }
+ else {
+ if (param_value_size_ret) {
+ *param_value_size_ret = sizeof(returnString);
+ }
+ }
+
+ return CL_SUCCESS;
+}
+
+void testGetBuildInfo()
+{
+ cl_device_id fakeDevice = make_device_id(0);
+ clGetDeviceInfo_ExpectAndReturn(fakeDevice, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), NULL, NULL, CL_SUCCESS);
+ clGetDeviceInfo_StubWithCallback(clGetDeviceInfo_testGetBuildInfo);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clGetPlatformInfo_StubWithCallback(clGetPlatformInfo_version_1_2);
+ clGetProgramBuildInfo_StubWithCallback(clGetProgramBuildInfo_testGetBuildInfo);
+ clGetProgramBuildInfo_StubWithCallback(clGetProgramBuildInfo_testGetBuildInfo);
+
+ cl::Program prog(make_program(0));
+ cl::Device dev(fakeDevice);
+
+ cl_int err;
+ std::string log = prog.getBuildInfo<CL_PROGRAM_BUILD_LOG>(dev, &err);
+
+ prog() = NULL;
+ dev() = NULL;
+}
+
+/**
+* Stub implementation of clGetCommandQueueInfo that returns first one image then none
+*/
+static cl_int clGetSupportedImageFormats_testGetSupportedImageFormats(
+ cl_context context,
+ cl_mem_flags flags,
+ cl_mem_object_type image_type,
+ cl_uint num_entries,
+ cl_image_format *image_formats,
+ cl_uint *num_image_formats,
+ int num_calls)
+{
+ // Catch failure case that causes error in bugzilla 13355:
+ // returns CL_INVALID_VALUE if flags or image_type are not valid,
+ // or if num_entries is 0 and image_formats is not NULL.
+ if (num_entries == 0 && image_formats != NULL) {
+ return CL_INVALID_VALUE;
+ }
+ if (num_entries == 0) {
+ // If num_entries was 0 this is the query for number
+ if (num_image_formats) {
+ if (num_calls == 0) {
+ *num_image_formats = 1;
+ }
+ else {
+ *num_image_formats = 0;
+ }
+ }
+ }
+ else {
+ // Should return something
+ TEST_ASSERT_NOT_NULL(image_formats);
+
+ // For first call we should return one format here
+ if (num_calls == 1) {
+ TEST_ASSERT_EQUAL(num_entries, 1);
+ image_formats[0] = cl::ImageFormat(CL_RGB, CL_FLOAT);
+ }
+ }
+
+ return CL_SUCCESS;
+}
+
+void testGetSupportedImageFormats()
+{
+ cl_context ctx_cl = make_context(0);
+
+ clGetSupportedImageFormats_StubWithCallback(clGetSupportedImageFormats_testGetSupportedImageFormats);
+ clGetSupportedImageFormats_StubWithCallback(clGetSupportedImageFormats_testGetSupportedImageFormats);
+ clReleaseContext_ExpectAndReturn(make_context(0), CL_SUCCESS);
+
+ cl::Context ctx(ctx_cl);
+ std::vector<cl::ImageFormat> formats;
+ cl_int ret = CL_SUCCESS;
+
+ ret = ctx.getSupportedImageFormats(
+ CL_MEM_READ_WRITE,
+ CL_MEM_OBJECT_IMAGE2D,
+ &formats);
+ TEST_ASSERT_EQUAL(ret, CL_SUCCESS);
+ TEST_ASSERT_EQUAL(formats.size(), 1);
+ ret = ctx.getSupportedImageFormats(
+ CL_MEM_READ_WRITE,
+ CL_MEM_OBJECT_IMAGE2D,
+ &formats);
+ TEST_ASSERT_EQUAL(formats.size(), 0);
+ TEST_ASSERT_EQUAL(ret, CL_SUCCESS);
+}
+
+void testCreateSubDevice()
+{
+ // TODO
+
+}
+
+void testGetContextInfoDevices()
+{
+ // TODO
+}
+
+} // extern "C"
diff --git a/tests/test_clhpp_cxx11.cpp b/tests/test_clhpp_cxx11.cpp
new file mode 100644
index 0000000..81e29f6
--- /dev/null
+++ b/tests/test_clhpp_cxx11.cpp
@@ -0,0 +1 @@
+#include "test_clhpp.cpp"
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opencl/khronos-opencl-clhpp.git
More information about the Pkg-opencl-commits
mailing list