Initial load of pre 2.0 modularised zcl.
authorMichael Zucchi <michael@swordfish.com.au>
Mon, 22 Apr 2019 02:38:18 +0000 (12:08 +0930)
committerMichael Zucchi <michael@swordfish.com.au>
Mon, 22 Apr 2019 02:38:18 +0000 (12:08 +0930)
71 files changed:
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
README [new file with mode: 0644]
build.xml [new file with mode: 0644]
config.make [new file with mode: 0644]
java.make [new file with mode: 0644]
nbproject/build-impl.xml [new file with mode: 0644]
nbproject/genfiles.properties [new file with mode: 0644]
nbproject/project.properties [new file with mode: 0644]
nbproject/project.xml [new file with mode: 0644]
src/notzed.zcl.demo/classes/au/notzed/zcl/tools/clinfo.java [new file with mode: 0644]
src/notzed.zcl.demo/classes/module-info.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CL.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLBuffer.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLBufferInfo.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLChannelOrder.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLChannelType.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLCommandType.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLContext.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLContextNotify.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLContextProperty.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLDevice.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLDeviceProperty.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLEvent.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLEventList.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLEventNotify.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLException.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLExtendable.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLExtension.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLImage.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLImageDesc.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLImageFormat.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLKernel.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLNativeKernel.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLObject.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLPipe.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLPipeProperty.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLPlatform.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLProgram.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLProperty.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLQueueProperty.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLRuntimeException.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLSampler.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLSamplerProperty.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/CLTask.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/khr/GLEvent.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/khr/GLSharing.java [new file with mode: 0644]
src/notzed.zcl/classes/au/notzed/zcl/package-info.java [new file with mode: 0644]
src/notzed.zcl/classes/module-info.java [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl_d3d10.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl_d3d11.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl_dx9_media_sharing.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl_egl.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl_ext.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl_gl.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl_gl_ext.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/cl_platform.h [new file with mode: 0644]
src/notzed.zcl/jni/include/CL/opencl.h [new file with mode: 0644]
src/notzed.zcl/jni/jni.make [new file with mode: 0644]
src/notzed.zcl/jni/zcl-extension.h [new file with mode: 0644]
src/notzed.zcl/jni/zcl-generate [new file with mode: 0755]
src/notzed.zcl/jni/zcl-init-dll.c [new file with mode: 0644]
src/notzed.zcl/jni/zcl-init-so.c [new file with mode: 0644]
src/notzed.zcl/jni/zcl-jni.c [new file with mode: 0644]
src/notzed.zcl/jni/zcl-khr-gl-event.c [new file with mode: 0644]
src/notzed.zcl/jni/zcl-khr-gl-sharing.c [new file with mode: 0644]
src/notzed.zcl/legal/LICENSE [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..470b0ea
--- /dev/null
@@ -0,0 +1,5 @@
+/nbproject/private/
+/bin/
+/build/
+/dist/
+
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..b4bb908
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,16 @@
+
+dist_VERSION=1.99
+dist_NAME=zcl
+dist_EXTRA=README                              \
+ build.xml                                     \
+ nbproject/build-impl.xml                      \
+ nbproject/genfiles.properties                 \
+ nbproject/project.properties                  \
+ nbproject/project.xml
+
+include config.make
+
+java_MODULES=notzed.zcl notzed.zcl.demo
+notzed.zcl.demo_JDEPMOD=notzed.zcl
+
+include java.make
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..f09204d
--- /dev/null
+++ b/README
@@ -0,0 +1,336 @@
+
+INTRODUCTION
+------------
+
+This is a direct Java binding for OpenCL 2.1 and Java 8.
+
+I originally wrote it over a few days mostly just to pass the time and
+the goals were:
+
+ * Minimal C and Java code;
+ * Lightweight Java objects;
+ * Feature complete for every OpenCL api;
+ * Follow the OpenCL api closely;
+ * Use primitive Java types instead of or as well as ByteBuffers
+   where it makes sense;
+ * Object-oriented and type-safe;
+ * Robust and fault-tolerant;
+ * Erring on the side of usability when constraints conflict;
+ * Simple to build.
+
+The approach taken was to put most of the code into C so that
+32/64-bit portability is provided soley by the non-java code.  This
+simplifies the Java and doesn't add much complication to the C code.
+To this end a 64-bit type is used on all platforms to store or
+transfer values which may change across platforms (void * and size_t).
+
+The Java instances of each OpenCL object are effectively just empty
+interfaces - they hold nothing but the pointer to the underlying
+object and pass all function calls to the jni layer.
+
+All API enty points are defined including event callbacks and the
+ability to write native kernels in Java.
+
+As with any 'simple' project, it's grown to be somewhat complex but it
+is still basic and portable code which is easy to build and maintain.
+
+There have been a couple of important additions to the feature list:
+
+ * Object references are now globally unqiue;
+ * Automatic and manual resource reclaimation via garbage collection;
+ * Lambda interfaces (experimental);
+ * Runtime API version checking.
+
+These all go hand in hand and allow for simplified application
+development with a few caveats.  Garbage detection is via referent
+queues for efficiency.
+
+
+PLATFORMS
+---------
+
+As the binding is mostly native interfaces the code is platform
+specific.
+
+The only supported target is 64-bit GNU systems and is obviously the
+default when running make.  But it should also compile on 32-bit
+platforms in a straightforward manner.
+
+A NON-SUPPORTED 64-bit ming32 cross-compilation makefile is also
+included.  It is not supported.
+
+The library supports full OpenCL 2.1 and two OpenGL related
+extensions.
+
+COMPILING
+---------
+
+Standard GNU development tools and a Java JDK are required in order to
+compile zcl (ant is not used).  Java 8 is required.  As of version 0.6
+the Jva code is compiled using my java.make makefile which provides
+some additional targets.
+
+The jni source includes the KHR OpenCL headers so an OpenCL SDK is not
+required but one may be used instead by defining CL_HOME on the
+command line.
+
+The environmental variable $JAVA_HOME is used to resolve the location
+of the Java SDK - required for jni.h.  A default is set in
+jni/Makefile and may be edited manually.
+
+$ make
+
+  Will build the class library and native library for the default
+  target (gnu-amd64).  The jar file is created in `bin/zcl.jar' and the
+  native library will be written to `jni/bin/<target>/libzcl.so'.
+
+$ make TARGETS=foo
+
+  Will build the class library and native library for the "foo" native
+  target.  See jni/Makefile.<target> for a list of targets possible.
+  Multiple targets may be specified.
+
+The other `java.make' targets are also supported:
+
+$ make javadocs
+
+  Build javadocs in `bin/zcl-${version}-doc.jar'.  They are somewhat
+  incomplete but cover some of the zcl specific features.
+
+$ make sources
+
+  Build a IDE (NetBeans?) compatible source archive in
+  `bin/zcl-${version}-src.jar'.
+  
+$ make all
+
+  Build everything (jar, javadocs, sources, and native libraries).
+  TARGET may also be specified.
+
+$ make tar
+
+  Create a source distribution in standard GNU format; everything in a
+  sub-directory matching the basename of the archive.  This is not
+  called `make dist' to avoid clashing with ant/netbeans being used.
+
+$ make clean
+
+OPENCL VERSION
+--------------
+
+For the most part it is up to applications to determine the OpenCL
+version in use and call functions appropriately.
+
+As of version 0.6 runtime version checking has been implemented for
+most api calls for version 2.0 or later.  The version check is
+relatively cheap but has not been implemented on all versioned
+interfaces for performance reasons (i.e. CLKernel).
+
+The binding should be compilable against OpenCL headers from 1.0 or
+later, although as the headers are included this is not required (or
+tested).
+
+Linking
+- - - -
+
+As of 0.5 the library only uses dynamic linking.  A function table
+is loaded at init time and all methods are invoked via the table.
+
+A script is used to generate the function table from CL/cl.h.  It
+assumes a very specific formatting.
+
+Although it is not a reliable indicator of platform support, NULL
+function pointers are protected against.
+
+Currently the OpenCL version the SDK the library is compiled against
+sets the highest supported API level and by default it uses the
+bundled headers which is at OpenCL 2.1.
+
+USING
+-----
+
+The directory containing libzcl.so must be added to the
+java.library.path or LD_LIBRARY_PATH during execution.
+
+The API follows the C api closely together with some convenient
+property getters and some overloaded functions for native arrays.
+
+Setting the environment variable ZCL_SYNC to non-zero will print all
+kernel executions and force a clFlush() and clFinish() at each.
+
+clinfo
+------
+
+A simple and incomplete implementation of the 'clinfo' tool is part of
+the package.  After building it can be used as a basic functionality
+test.
+
+$ java -Djava.library.path=jni/bin/gnu-amd64 -cp dist/zcl.jar au.notzed.zcl.tools.clinfo
+
+Note that clinfo will crash on coprthr 1.6.0 due to a bug.
+
+STATUS
+------
+
+As of 0.5 this should be considered beta quality.  It is in use for
+prototype development in a research context.
+
+It implements every base OpenCL 2.1 api, even some that aren't very
+useful for Java.  All deprecated functions and constants from
+OpenCL 2.1 are (should be) correctly marked as such.
+
+Most interfaces are protected from null pointers, bad ranges, and
+runtime failures.  This will protect against many common api errors
+with Java exceptions but it is still (easily) possible to crash
+applications with no obvious cause.
+
+Two KHR extensions have been (mostly) implemented: GLSharing and
+GLEvent.  They reside in the au.notzed.zcl.khr namespace so have
+dropped some mess from the names.
+
+Beyond property getters there are few 'helper' functions so that
+methods take all the parameters of their C counterparts.  This is not
+always terribly convenient.
+
+Documentation is limited.
+
+None of OpenCL 2.1 has been tested and may be broken.
+
+Automatic Resource Reclamation
+- - - - - - - - - - - - - - - -
+
+All objects should be automatically garbage collected.  This is mostly
+automagic but in some cases requires the user to maintain references
+to parent objects explicitly.  Objects may also be manually disposed
+of using release().  It is not recommended that retain() be used from
+Java at all.
+
+This automatic resource reclaimation comes with the same usual caveats
+with native resources - the impedence mismatch between Java and native
+can cause allocation problems.  Somebody Else's Problem (it seems to
+work quite well in practice).
+
+Primitive arrays buffers
+- - - - - - - - - - - - -
+
+There is support for passing primitive arrays to functions which would
+otherwise only take a direct ByteBuffer.
+
+This (currently) forces any enqueue operations to blocking mode and
+also bloats out the api and implementation - so the limited
+convenience they provide might not be worth their cost.
+
+Note that this only affects 'asynchronous memory' and does not affect
+small arrays used for things like dimensions, ranges, or patterns
+which are copied by the jni and OpenCL API at method invocation time.
+
+Lambdas
+- - - -
+
+A design-in-progress lambda based mechanism for encapsulating
+enqueuable tasks is defined by CLTask.  Some operations have been
+added to the target objects such as ofRead(byte[]) to the CLBuffer
+interface.
+
+The primary goal of this interface is to provide a cleaner api by
+removing the need to pass a pair of CLEventLists and a CLCommandQueue
+to every work function.  As a side-effect of garbage collection and
+features of lambdas it provides extra convenience as well.
+
+For example, rather than calling this every time:
+
+ q.enqueueReadBuffer(src, false, 0, size, dst, 0, null, null);
+ q.enqueueReadBuffer(src, false, 0, size, dst, 0, waits, events);
+
+One can instead do this:
+
+ // this once
+ CLTask task = src.ofRead(dst, size);
+
+ // multiple times
+ q.offer(task);
+ q.offer(task, waits, events);
+
+And so on, with a few other little lambda treats along the way like
+'andThen()'.
+
+Although this mechanism allows for flexible "pre-compiled" expressions
+the inability to change parameters are invocation time have proved to
+be somewhat limiting.  This is still work in progress.
+
+Extensions
+----------
+
+OpenCL extensions and function entry points must be resolved via the
+CLPlatform.
+
+Extension interfaces are handled by a two-layer mechanism.  Firstly a
+Java/JNI combination implements one specific extension and contains
+all constants and entry points for the extension.  The java object
+must derive from CLExtension.  These may be used as is but are
+inconvenient.
+
+So relevent entry points are then added to each target object
+(i.e. first parameter of function) which handles the extension lookup.
+Each object which may have extented function on it must derive from
+CLExtendable which provides an efficient way to cache and resolve the
+extension object.
+
+Core extension objects are instantiated via CLPlatform but may be
+created by independent JNI code and used without modifying the core
+api.
+
+They are currently never unloaded.  There may be some changes but the
+current design seems sufficient.
+
+FUTURE PLANS
+------------
+
+I'll see.  It is quite close to a 1.0 release.
+
+LICENSE
+-------
+
+Most of the code is licensed under GNU General Public License version
+3, see COPYING for full details.
+
+    Copyright (C) 2014,2015 Michael Zucchi
+
+    This program is free software: you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see
+    <http://www.gnu.org/licenses/>.
+
+Certain content was copied from cl.h from OpenCL 1.2, these files
+include the following header:
+
+    Copyright (c) 2008 - 2012 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.
+
+    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.
diff --git a/build.xml b/build.xml
new file mode 100644 (file)
index 0000000..8543e7c
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- You may freely edit this file. See commented blocks below for -->
+<!-- some examples of how to customize the build. -->
+<!-- (If you delete it and reopen the project it will be recreated.) -->
+<!-- By default, only the Clean and Build commands use this build script. -->
+<!-- Commands such as Run, Debug, and Test only use this build script if -->
+<!-- the Compile on Save feature is turned off for the project. -->
+<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
+<!-- in the project's Project Properties dialog box.-->
+<project name="notzed.zcl" default="default" basedir="." xmlns:j2semodularproject="http://www.netbeans.org/ns/j2se-modular-project/1">
+    <description>Builds, tests, and runs the project notzed.zcl.</description>
+    <import file="nbproject/build-impl.xml"/>
+    <!--
+
+    There exist several targets which are by default empty and which can be 
+    used for execution of your tasks. These targets are usually executed 
+    before and after some main targets. They are: 
+
+      -pre-init:                 called before initialization of project properties
+      -post-init:                called after initialization of project properties
+      -pre-compile:              called before javac compilation
+      -post-compile:             called after javac compilation
+      -pre-compile-single:       called before javac compilation of single file
+      -post-compile-single:      called after javac compilation of single file
+      -pre-compile-test:         called before javac compilation of JUnit tests
+      -post-compile-test:        called after javac compilation of JUnit tests
+      -pre-compile-test-single:  called before javac compilation of single JUnit test
+      -post-compile-test-single: called after javac compilation of single JUunit test
+      -pre-jar:                  called before JAR building
+      -post-jar:                 called after JAR building
+      -post-clean:               called after cleaning build products
+
+    (Targets beginning with '-' are not intended to be called on their own.)
+
+    Example of inserting an obfuscator after compilation could look like this:
+
+        <target name="-post-compile">
+            <obfuscate>
+                <fileset dir="${build.classes.dir}"/>
+            </obfuscate>
+        </target>
+
+    For list of available properties check the imported 
+    nbproject/build-impl.xml file. 
+
+
+    Another way to customize the build is by overriding existing main targets.
+    The targets of interest are: 
+
+      -init-macrodef-javac:     defines macro for javac compilation
+      -init-macrodef-junit:     defines macro for junit execution
+      -init-macrodef-debug:     defines macro for class debugging
+      -init-macrodef-java:      defines macro for class execution
+      -do-jar:                  JAR building
+      run:                      execution of project 
+      -javadoc-build:           Javadoc generation
+      test-report:              JUnit report generation
+
+    Notice that the overridden target depends on the jar target and not only on 
+    the compile target as the regular run target does. Again, for a list of available 
+    properties which you can use, check the target you are overriding in the
+    nbproject/build-impl.xml file. 
+
+    -->
+</project>
diff --git a/config.make b/config.make
new file mode 100644 (file)
index 0000000..ce5b5d1
--- /dev/null
@@ -0,0 +1,40 @@
+
+TARGET ?= linux-amd64
+
+JAVA_HOME ?= /usr/local/jdk-11.0.2
+JAVAFX_HOME ?= /usr/local/javafx-sdk-11.0.2
+FFMPEG_HOME ?= /opt/ffmpeg/4.0
+
+NATIVEZ_HOME=../nativez/bin/notzed.nativez/$(TARGET)
+
+JAVACFLAGS+= --module-path ../nativez/bin/notzed.nativez
+JAVACFLAGS+= -source 11
+
+JAVAC ?= javac
+JAR ?= jar
+JMOD ?= jmod
+
+
+# Linux options
+linux-amd64_CPPFLAGS = \
+       -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
+linux-amd64_CFLAGS = -fPIC -Wall
+linux-amd64_CC = cc
+linux-amd64_LD = ld
+
+linux-amd64_SO = .so
+linux-amd64_LIB = lib
+linux-amd64_JMOD_LIBS = --libs
+
+# Windows options
+windows-amd64_CPPFLAGS= \
+       -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux \
+       -DHAVE_ALIGNED_MALLOC \
+       -DWIN32
+windows-amd64_CC = x86_64-w64-mingw32-gcc
+windows-amd64_LD = x86_64-w64-mingw32-ld
+windows-amd64_LDFLAGS = -Wl,--subsystem,windows
+
+windows-amd64_SO = .dll
+windows-amd64_LIB =
+windows-amd64_JMOD_LIBS = --cmds
diff --git a/java.make b/java.make
new file mode 100644 (file)
index 0000000..ac60f16
--- /dev/null
+++ b/java.make
@@ -0,0 +1,308 @@
+#
+# Copyright (C) 2019 Michael Zucchi
+#
+# This is the copyright for java.make
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# General purpose modular java makefile that supports native library
+# compilation directly.  Non-recrusve implementation.
+#
+# Uses metamake programming with some file conventions to implement
+# auto-make-like features.
+
+# Define modules
+# --------------
+# java_MODULES list of java modules to compile.  The sources must
+#              exist in src/<module>/classes.  Resource files are
+#              stored in src/<module>/classes.  Source-code
+#              generators must exist in src/<module>/gen.  Native
+#              libraries must exist in src/<module>/jni.
+
+# Global variables
+
+# JAVA_HOME            location of jdk.
+# JAVAC                        java compiler to use.  Default is 'javac' on the path.
+# JAVACFLAGS           javac flags applied to all invocations.
+# JAR                  jar command.
+# JARFLAGS             jar flags
+# JMOD                 jmod command.
+# JMODFLAGS            jmod flags.
+
+# Module specific variables
+
+# <module>_JDEPMOD     Lists modules which this one depends on.
+
+# <module>_JAVACFLAGS  Extra module-specific flags for each command.
+# <module>_JARFLAGS
+# <module>_JMODFLAGS
+
+# <module>_JAVA                Java sources.  If not set it is found from src/<module>/classes/(*.java)
+# <module>_RESOURCES   .jar resources.  If not set it is found from src/<module>/classes/(not *.java)
+# <module>_JAVA_GENERATED      Java generated sources.  These must be relative to the package name.
+
+# Variables for use in fragments
+
+# gen.make and jni.make can additionally make use of these variables
+
+# <module>_gendir      Location for files used in Java generation process (per project).
+# <module>_genjavadir  Location where _JAVA_GENERATED .java files will be created (per project).
+# <module>_jnidir      Location for jni generated files (per target).
+# <module>_objdir      Location for c objects (per target).
+# <module>_incdir      Location for output includes, .jmod staging.
+# <module>_libdir      Location for output libraries, .jmod staging.
+
+# Define libraries
+# ----------------
+
+# Each module can define one or more native libraries.
+
+# These are compiled after the java sources have been compiled as that
+# process also generates any native binding headers.
+
+# <module>_JNI_LIBRARIES       list of libraries to build.
+# library names match System.loadLibrary().
+
+# Global variables
+
+# <target>_LDFLAGS
+# <target>_LDLIBS
+# <target>_CPPFLAGS
+# <target>_CFLAGS
+# SO           shared library suffix
+# LIB          shared library prefix
+
+# Utility functions
+#
+# $(call library-path,<module>,<libname>) will resolve to the library file name.
+
+# Per library variables.
+
+# <library>_SOURCES    .c, .cc, .C - source files for library.  Paths are relative to src/<module>/jni.
+# <library>_HEADERS    header files for jmod
+
+# <library>_LDFLAGS    link flags
+# <library>_LIBADD     extra objects to add to link line
+# <library>_LDLIBS     link libraries
+# <library>_CPPFLAGS   c pre-processor flags.  "-Isrc/<module>/jni -Ibin/include/<module>" is implicit.
+# <library>_CCFLAGS    c compiler flags
+
+# <library>_DEPENDENCIES       A list of other objects on which this library depends before linking.
+
+# .c files have dependencies automatically generated
+
+# Targets
+# -------
+
+# make gen             only generate java sources
+# make clean           rm -rf bin
+# make dist            create dist tar in bin/
+# make | make jar      make all jars and jmods
+# make bin             make everything but jars and mods
+
+# Outputs
+# -------
+
+# All intermediate and output files are written to bin/
+
+# This layout is enforced by javac
+#  bin/include/<module>/        .h files from javac -h
+#  bin/modules/<module>/        .class files from javac
+
+# This layout is convenient for netbeans
+#  bin/gen/<module>/gen/       .c, exe files for generator     free use
+#  bin/gen/<module>/classes/   .java files from generator      <module>_JAVA_GENERATED
+
+#  bin/status/                 marker files for makefile
+
+#  bin/<module>/<module>.jar   .jar modular
+
+# Native code
+
+#  bin/<module>/<target>/lib   .so librareies for jmod         <module>_LIBRARIES = libname
+#  bin/<module>/<target>/obj   .o, .d files for library        <libname>_SOURCES
+#  bin/<module>/<target>/include .h files for jmod             <libname>_HEADERS
+#  bin/<module>/<target>/<module>.jmod .jmod module
+
+# ######################################################################
+
+E:=
+S:=$(E) $(E)
+
+# All modules with native code
+java_JMODS=$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/jni/jni.make),$(module)))
+# Only modules with no native code
+java_JARS=$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/jni/jni.make),,$(module)))
+# Modules with generated java source
+java_JGEN=$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/gen/gen.make),$(module)))
+
+# Define some useful variables before including fragments
+define java_variables=
+$(1)_gendir:=bin/gen/$(1)/gen
+$(1)_genjavadir:=bin/gen/$(1)/classes
+$(1)_jnidir:=bin/$(1)/$(TARGET)/jni
+$(1)_objdir:=bin/$(1)/$(TARGET)/obj
+$(1)_incdir:=bin/$(1)/$(TARGET)/include
+$(1)_libdir:=bin/$(1)/$(TARGET)/lib
+ifndef $(1)_JAVA
+$(1)_JAVA := $$(shell find src/$(1)/classes -type f -name '*.java')
+endif
+ifndef $(1)_RESOURCES
+$(1)_RESOURCES := $$(shell find src/$(1)/classes -type f \! -name '*.java')
+endif
+endef
+
+$(foreach module,$(java_MODULES),$(eval $(call java_variables,$(module))))
+
+# ######################################################################
+
+all: jar
+bin:
+gen:
+
+.PHONY: all clean jar bin gen
+clean:
+       rm -rf bin
+
+include $(patsubst %,src/%/gen/gen.make,$(java_JGEN))
+include $(patsubst %,src/%/jni/jni.make,$(java_JMODS))
+
+# ######################################################################
+# Java
+# ######################################################################
+
+define java_targets=
+# Rules for module $(1)
+$(1)_JAVA_generated = $$(addprefix $$($(1)_genjavadir)/,$$($(1)_JAVA_GENERATED))
+
+bin/status/$(1).data: $$($(1)_RESOURCES)
+bin/status/$(1).classes: $(patsubst %,bin/status/%.classes,$($(1)_JDEPMOD)) $$($(1)_JAVA) $$($(1)_JAVA_generated)
+jar $(1): bin/$(1)/$(1).jar $(if $(wildcard src/$(1)/jni/jni.make),bin/$(1)/$(TARGET)/$(1).jmod)
+bin: bin/status/$(1).classes bin/status/$(1).data
+sources: bin/$(1)/$(1)-sources.zip
+gen: $$($(1)_JAVA_generated)
+
+# Create modular jar
+bin/$(1)/$(1).jar: bin/status/$(1).classes bin/status/$(1).data
+       @install -d $$(@D)
+       $(JAR) cf $$@ \
+         $(JARFLAGS) $$($(1)_JARFLAGS) \
+         -C bin/modules/$(1) .
+
+# Create a jmod
+bin/$(1)/$(TARGET)/$(1).jmod: bin/status/$(1).classes bin/status/$(1).data
+       rm -f $$@
+       @install -d $$(@D)
+       $$(JMOD) create \
+         $$(JMODFLAGS) $$($(1)_JMODFLAGS) \
+         --target-platform $(TARGET) \
+         --class-path bin/modules/$(1) \
+         $$(if $$(wildcard bin/$(1)/$(TARGET)/include),--header-files bin/$(1)/$(TARGET)/include) \
+         $$(if $$(wildcard src/$(1)/legal),--legal-notices src/$(1)/legal) \
+         $$($(TARGET)_JMOD_LIBS) bin/$(1)/$(TARGET)/lib \
+         $$@
+
+# Create an IDE source zip, paths have to match --module-source-path
+bin/$(1)/$(1)-sources.zip: bin/status/$(1).classes
+       @install -d $$(@D)
+       jar -c -f $$@ -M \
+               $$(patsubst src/$(1)/classes/%,-C src/$(1)/classes %,$$(filter src/$(1)/classes/%,$$($(1)_JAVA))) \
+               $$(patsubst bin/gen/$(1)/classes/%,-C bin/gen/$(1)/classes %,$$(filter bin/gen/$(1)/classes/%,$$($(1)_JAVA)))
+
+endef
+
+#$(foreach module,$(java_MODULES),$(info $(call java_targets,$(module))))
+$(foreach module,$(java_MODULES),$(eval $(call java_targets,$(module))))
+
+# ######################################################################
+# Global pattern rules
+
+# Stage resources
+bin/status/%.data:
+       @install -d $(@D)
+       for data in $(patsubst src/$*/classes/%,"%",$($*_RESOURCES)) ; do \
+               install -vDC "src/$*/classes/$$data" "bin/modules/$*/$$data" || exit 1 ; \
+       done
+       touch $@
+
+# Compile one module.  This only updates (javac -h) headers if they changed.
+bin/status/%.classes:
+       @install -d $(@D)
+       $(JAVAC) \
+               --module-source-path "src/*/classes:bin/gen/*/classes" \
+               $(JAVACFLAGS) $($*_JAVACFLAGS) \
+               -h bin/inc \
+               -d bin/modules \
+               -m $* \
+               $($*_JAVA) $($*_JAVA_generated)
+       if [ -d bin/inc/$* ] ; then \
+               install -DC -t bin/include/$* bin/inc/$*/*.h ; \
+       fi
+       touch $@
+
+# ######################################################################
+# C stuff
+# ######################################################################
+
+SUFFIXES=.c .C .cc
+SO=$($(TARGET)_SO)
+LIB=$($(TARGET)_LIB)
+
+# functions to find cross-module stuff $(call library-path,modname,libname)
+library-path=bin/$(1)/$(TARGET)/lib/$(LIB)$(2)$(SO)
+library-dir=bin/$(1)/$(TARGET)/lib/
+
+define jni_library=
+# Rule for library $(2) in module $(1)
+$(2)_OBJS = $(foreach sx,$(SUFFIXES),$(patsubst %$(sx), $($(1)_objdir)/%.o, $(filter %$(sx),$($(2)_SOURCES))))
+$(2)_SRCS = $(addprefix src/$(1)/jni/,$($(2)_SOURCES))
+
+$($(1)_libdir)/$(LIB)$(2)$(SO): $$($(2)_OBJS) $($(2)_LIBADD) $($(2)_DEPENDENCIES)
+       @install -d $$(@D)
+       $($(TARGET)_CC) -o $$@ -shared \
+               $($(TARGET)_LDFLAGS) $($(2)_LDFLAGS) $$($(2)_OBJS) $($(2)_LIBADD) $($(TARGET)_LDLIBS) $($(2)_LDLIBS)
+
+$($(1)_objdir)/%.o: src/$(1)/jni/%.c bin/status/$(1).classes
+       @install -d $$(@D)
+       $($(TARGET)_CC) -Isrc/$(1)/jni -Ibin/include/$(1) $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) \
+               $($(TARGET)_CFLAGS) $($(2)_CFLAGS) -c -o $$@ $$<
+
+$($(1)_incdir)/%.h: src/$(1)/jni/%.h
+       install -D $$< $$@
+
+$($(1)_objdir)/%.d: src/$(1)/jni/%.c bin/status/$(1).classes
+       @install -d $$(@D)
+       @rm -f $$@
+       @$($(TARGET)_CC) -MM -MT "bin/$(1)/$(TARGET)/obj/$$*.o" -Isrc/$(1)/jni -Ibin/include/$(1) \
+               $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) $$< -o $$@.d 2>/dev/null
+       @sed 's,\($$*\.o\) *:,\1 $$@ : ,g' $$@.d > $$@ ; rm $$@.d
+
+bin jni $(1) bin/$(1)/$(TARGET)/$(1).jmod: $($(1)_libdir)/$(LIB)$(2)$(SO) $(addprefix $($(1)_incdir)/,$($(2)_HEADERS))
+
+$(if $(filter clean dist gen,$(MAKECMDGOALS)),,-include $$($(2)_OBJS:.o=.d))
+endef
+
+#$(foreach module,$(java_JMODS),$(foreach library,$($(module)_JNI_LIBRARIES),$(info $(call jni_library,$(module),$(library)))))
+$(foreach module,$(java_JMODS),$(foreach library,$($(module)_JNI_LIBRARIES),$(eval $(call jni_library,$(module),$(library)))))
+
+# ######################################################################
+
+dist:
+       @install -d bin
+       tar cfz bin/$(dist_NAME)-$(dist_VERSION).tar.gz \
+        --transform=s,^,$(dist_NAME)-$(dist_VERSION)/, \
+        config.make java.make Makefile src             \
+        $(dist_EXTRA)
+
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
new file mode 100644 (file)
index 0000000..489097b
--- /dev/null
@@ -0,0 +1,1737 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+*** GENERATED FROM project.xml - DO NOT EDIT  ***
+***         EDIT ../build.xml INSTEAD         ***
+
+For the purpose of easier reading the script
+is divided into following sections:
+
+  - initialization
+  - compilation
+  - jar
+  - execution
+  - debugging
+  - javadoc
+  - test compilation
+  - test execution
+  - test debugging
+  - applet
+  - cleanup
+
+        -->
+<project xmlns:if="ant:if" xmlns:unless="ant:unless" basedir=".." default="default" name="notzed.zcl-impl">
+    <fail message="Please build using Ant 1.9.7 or higher.">
+        <condition>
+            <not>
+                <antversion atleast="1.9.7"/>
+            </not>
+        </condition>
+    </fail>
+    <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
+    <!-- 
+                ======================
+                INITIALIZATION SECTION 
+                ======================
+            -->
+    <target name="-pre-init">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="-pre-init" name="-init-private">
+        <property file="nbproject/private/config.properties"/>
+        <property file="nbproject/private/configs/${config}.properties"/>
+        <property file="nbproject/private/private.properties"/>
+    </target>
+    <target depends="-pre-init,-init-private" name="-init-user">
+        <property file="${user.properties.file}"/>
+        <!-- The two properties below are usually overridden -->
+        <!-- by the active platform. Just a fallback. -->
+        <property name="default.javac.source" value="9"/>
+        <property name="default.javac.target" value="9"/>
+    </target>
+    <target depends="-pre-init,-init-private,-init-user" name="-init-project">
+        <property file="nbproject/configs/${config}.properties"/>
+        <property file="nbproject/project.properties"/>
+    </target>
+    <target name="-init-source-module-properties">
+        <property name="javac.modulepath" value=""/>
+        <property name="run.modulepath" value="${javac.modulepath}:${build.modules.dir}"/>
+        <property name="debug.modulepath" value="${run.modulepath}"/>
+        <property name="javac.upgrademodulepath" value=""/>
+        <property name="run.upgrademodulepath" value="${javac.upgrademodulepath}"/>
+        <condition else="" property="javac.systemmodulepath.cmd.line.arg" value="-system '${javac.systemmodulepath}'">
+            <and>
+                <isset property="javac.systemmodulepath"/>
+                <length length="0" string="${javac.systemmodulepath}" when="greater"/>
+            </and>
+        </condition>
+        <property name="dist.jlink.dir" value="${dist.dir}/jlink"/>
+        <property name="dist.jlink.output" value="${dist.jlink.dir}/${application.title}"/>
+    </target>
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
+        <property name="platform.java" value="${java.home}/bin/java"/>
+        <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" modsource="${test.src.dir.path}" property="have.tests.test.src.dir.regexp"/>
+        <dirset dir="${basedir}/${test.src.dir}" id="have.tests.test.src.dir.set" includes="*/*">
+            <filename regex="${have.tests.test.src.dir.regexp}"/>
+        </dirset>
+        <union id="have.tests.set">
+            <dirset refid="have.tests.test.src.dir.set"/>
+        </union>
+        <condition property="have.tests">
+            <or>
+                <resourcecount count="0" when="greater">
+                    <union refid="have.tests.set"/>
+                </resourcecount>
+            </or>
+        </condition>
+        <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" modsource="${test.src.dir.path}" property="have.tests.test.src.dir.regexp"/>
+        <dirset dir="${basedir}/${test.src.dir}" id="have.tests.test.src.dir.patchset" includes="*/*">
+            <filename regex="${have.tests.test.src.dir.regexp}"/>
+            <scriptselector language="javascript">
+                            self.setSelected(!new java.io.File(file, "module-info.java").exists());
+                        </scriptselector>
+        </dirset>
+        <union id="have.tests.patchset">
+            <dirset refid="have.tests.test.src.dir.patchset"/>
+        </union>
+        <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" modsource="${src.dir.path}" property="have.sources.src.dir.regexp"/>
+        <dirset dir="${basedir}/${src.dir}" id="have.sources.src.dir.set" includes="*/*">
+            <filename regex="${have.sources.src.dir.regexp}"/>
+        </dirset>
+        <union id="have.sources.set">
+            <dirset refid="have.sources.src.dir.set"/>
+        </union>
+        <condition property="have.sources">
+            <or>
+                <resourcecount count="0" when="greater">
+                    <union refid="have.sources.set"/>
+                </resourcecount>
+            </or>
+        </condition>
+        <condition property="main.class.available">
+            <and>
+                <isset property="main.class"/>
+                <not>
+                    <equals arg1="${main.class}" arg2="" trim="true"/>
+                </not>
+            </and>
+        </condition>
+        <condition property="netbeans.home+have.tests">
+            <and>
+                <isset property="netbeans.home"/>
+                <isset property="have.tests"/>
+            </and>
+        </condition>
+        <condition property="no.javadoc.preview">
+            <and>
+                <isset property="javadoc.preview"/>
+                <isfalse value="${javadoc.preview}"/>
+            </and>
+        </condition>
+        <condition property="do.archive">
+            <or>
+                <not>
+                    <istrue value="${jar.archive.disabled}"/>
+                </not>
+                <istrue value="${not.archive.disabled}"/>
+            </or>
+        </condition>
+        <property name="run.jvmargs" value=""/>
+        <property name="run.jvmargs.ide" value=""/>
+        <property name="javac.compilerargs" value=""/>
+        <property name="work.dir" value="${basedir}"/>
+        <condition property="no.deps">
+            <and>
+                <istrue value="${no.dependencies}"/>
+            </and>
+        </condition>
+        <property name="javac.debug" value="true"/>
+        <property name="javadoc.preview" value="true"/>
+        <property name="application.args" value=""/>
+        <property name="source.encoding" value="${file.encoding}"/>
+        <property name="runtime.encoding" value="${source.encoding}"/>
+        <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
+            <and>
+                <isset property="javadoc.encoding"/>
+                <not>
+                    <equals arg1="${javadoc.encoding}" arg2=""/>
+                </not>
+            </and>
+        </condition>
+        <property name="javadoc.encoding.used" value="${source.encoding}"/>
+        <property name="includes" value="**"/>
+        <property name="excludes" value=""/>
+        <property name="do.depend" value="false"/>
+        <condition property="do.depend.true">
+            <istrue value="${do.depend}"/>
+        </condition>
+        <path id="endorsed.classpath.path" path="${endorsed.classpath}"/>
+        <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
+            <and>
+                <isset property="endorsed.classpath"/>
+                <not>
+                    <equals arg1="${endorsed.classpath}" arg2="" trim="true"/>
+                </not>
+            </and>
+        </condition>
+        <condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
+            <isset property="profile.available"/>
+        </condition>
+        <condition else="false" property="jdkBug6558476">
+            <and>
+                <matches pattern="1\.[56]" string="${java.specification.version}"/>
+                <not>
+                    <os family="unix"/>
+                </not>
+            </and>
+        </condition>
+        <condition else="false" property="javac.fork">
+            <or>
+                <istrue value="${jdkBug6558476}"/>
+                <istrue value="${javac.external.vm}"/>
+            </or>
+        </condition>
+        <condition property="main.class.check.available">
+            <and>
+                <isset property="libs.CopyLibs.classpath"/>
+                <available classname="org.netbeans.modules.java.j2seproject.moduletask.ModuleMainClass" classpath="${libs.CopyLibs.classpath}"/>
+            </and>
+        </condition>
+        <property name="jar.index" value="false"/>
+        <property name="jar.index.metainf" value="${jar.index}"/>
+        <condition property="junit.available">
+            <or>
+                <available classname="org.junit.Test" classpath="${run.test.classpath}"/>
+                <available classname="junit.framework.Test" classpath="${run.test.classpath}"/>
+            </or>
+        </condition>
+        <condition property="testng.available">
+            <available classname="org.testng.annotations.Test" classpath="${run.test.classpath}"/>
+        </condition>
+        <condition property="junit+testng.available">
+            <and>
+                <istrue value="${junit.available}"/>
+                <istrue value="${testng.available}"/>
+            </and>
+        </condition>
+        <condition else="testng" property="testng.mode" value="mixed">
+            <istrue value="${junit+testng.available}"/>
+        </condition>
+        <condition else="" property="testng.debug.mode" value="-mixed">
+            <istrue value="${junit+testng.available}"/>
+        </condition>
+        <property name="java.failonerror" value="true"/>
+        <macrodef name="for-paths" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute name="paths"/>
+            <attribute default="${path.separator}" name="separator"/>
+            <element implicit="yes" name="call"/>
+            <sequential>
+                <local name="entry"/>
+                <local name="tail"/>
+                <local name="moreElements"/>
+                <loadresource property="entry" quiet="true" unless:blank="@{paths}">
+                    <concat>@{paths}</concat>
+                    <filterchain>
+                        <replaceregex pattern="([^@{separator}]*)\Q@{separator}\E.*" replace="\1"/>
+                    </filterchain>
+                </loadresource>
+                <sequential if:set="entry">
+                    <call/>
+                </sequential>
+                <condition else="false" property="moreElements" value="true">
+                    <contains string="@{paths}" substring="@{separator}"/>
+                </condition>
+                <loadresource if:true="${moreElements}" property="tail" quiet="true">
+                    <concat>@{paths}</concat>
+                    <filterchain>
+                        <replaceregex pattern="[^@{separator}]*\Q@{separator}\E(.*)" replace="\1"/>
+                    </filterchain>
+                </loadresource>
+                <j2semodularproject1:for-paths xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" if:true="${moreElements}" paths="${tail}">
+                    <call/>
+                </j2semodularproject1:for-paths>
+            </sequential>
+        </macrodef>
+        <property name="modules.supported.internal" value="true"/>
+        <condition else="${file.separator}" property="file.separator.string" value="\${file.separator}">
+            <equals arg1="${file.separator}" arg2="\"/>
+        </condition>
+    </target>
+    <target name="-post-init">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
+        <fail unless="src.dir">Must set src.dir</fail>
+        <fail unless="test.src.dir">Must set test.src.dir</fail>
+        <fail unless="build.dir">Must set build.dir</fail>
+        <fail unless="dist.dir">Must set dist.dir</fail>
+        <fail unless="build.modules.dir">Must set build.modules.dir</fail>
+        <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
+        <fail unless="build.test.modules.dir">Must set build.test.modules.dir</fail>
+        <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
+        <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
+        <fail message="Java 9 support requires Ant 1.10.0 or higher.">
+            <condition>
+                <not>
+                    <antversion atleast="1.10.0"/>
+                </not>
+            </condition>
+        </fail>
+    </target>
+    <target name="-init-macrodef-property">
+        <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute name="name"/>
+            <attribute name="value"/>
+            <sequential>
+                <property name="@{name}" value="${@{value}}"/>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-ap-cmdline-properties,-init-source-module-properties" name="-init-macrodef-javac">
+        <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${build.modules.dir}" name="destdir"/>
+            <attribute default="${javac.classpath}" name="classpath"/>
+            <attribute default="${javac.modulepath}" name="modulepath"/>
+            <attribute default="${src.dir}/*/${src.dir.path}" name="modulesourcepath"/>
+            <attribute default="${javac.upgrademodulepath}" name="upgrademodulepath"/>
+            <attribute default="${javac.processorpath}" name="processorpath"/>
+            <attribute default="${javac.processormodulepath}" name="processormodulepath"/>
+            <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="${javac.debug}" name="debug"/>
+            <attribute default="${empty.dir}" name="gensrcdir"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <property location="${build.dir}/empty" name="empty.dir"/>
+                <mkdir dir="${empty.dir}"/>
+                <mkdir dir="@{apgeneratedsrcdir}"/>
+                <condition property="processormodulepath.set">
+                    <resourcecount count="0" when="greater">
+                        <path>
+                            <pathelement path="@{processormodulepath}"/>
+                        </path>
+                    </resourcecount>
+                </condition>
+                <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" target="${javac.target}" tempdir="${java.io.tmpdir}">
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                    <modulepath>
+                        <path path="@{modulepath}"/>
+                    </modulepath>
+                    <modulesourcepath>
+                        <path path="@{modulesourcepath}"/>
+                    </modulesourcepath>
+                    <upgrademodulepath>
+                        <path path="@{upgrademodulepath}"/>
+                    </upgrademodulepath>
+                    <compilerarg line="${javac.systemmodulepath.cmd.line.arg}"/>
+                    <compilerarg line="${javac.profile.cmd.line.arg}"/>
+                    <compilerarg line="${javac.compilerargs}"/>
+                    <compilerarg if:set="processormodulepath.set" value="--processor-module-path"/>
+                    <compilerarg if:set="processormodulepath.set" path="@{processormodulepath}"/>
+                    <compilerarg unless:set="processormodulepath.set" value="-processorpath"/>
+                    <compilerarg path="@{processorpath}:${empty.dir}" unless:set="processormodulepath.set"/>
+                    <compilerarg line="${ap.processors.internal}"/>
+                    <compilerarg line="${annotation.processing.processor.options}"/>
+                    <compilerarg value="-s"/>
+                    <compilerarg path="@{apgeneratedsrcdir}"/>
+                    <compilerarg line="${ap.proc.none.internal}"/>
+                    <customize/>
+                </javac>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-javac" name="-init-macrodef-javac-depend">
+        <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${src.dir}" name="srcdir"/>
+            <attribute default="${build.classes.dir}" name="destdir"/>
+            <attribute default="${javac.classpath}" name="classpath"/>
+            <sequential>
+                <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                </depend>
+            </sequential>
+        </macrodef>
+        <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${build.modules.dir}" name="destdir"/>
+            <sequential>
+                <fail unless="javac.includes">Must set javac.includes</fail>
+                <pathconvert pathsep="${line.separator}" property="javac.includes.binary">
+                    <path>
+                        <filelist dir="@{destdir}" files="${javac.includes}"/>
+                    </path>
+                    <globmapper from="*.java" to="*.class"/>
+                </pathconvert>
+                <tempfile deleteonexit="true" property="javac.includesfile.binary"/>
+                <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/>
+                <delete>
+                    <files includesfile="${javac.includesfile.binary}"/>
+                </delete>
+                <delete>
+                    <fileset file="${javac.includesfile.binary}"/>
+                </delete>
+            </sequential>
+        </macrodef>
+    </target>
+    <target if="${junit.available}" name="-init-macrodef-junit-init">
+        <condition else="false" property="nb.junit.batch" value="true">
+            <and>
+                <istrue value="${junit.available}"/>
+                <not>
+                    <isset property="test.method"/>
+                </not>
+            </and>
+        </condition>
+        <condition else="false" property="nb.junit.single" value="true">
+            <and>
+                <istrue value="${junit.available}"/>
+                <isset property="test.method"/>
+            </and>
+        </condition>
+    </target>
+    <target name="-init-test-properties">
+        <property name="test.binaryincludes" value="&lt;nothing&gt;"/>
+        <property name="test.binarytestincludes" value=""/>
+        <property name="test.binaryexcludes" value=""/>
+    </target>
+    <target name="-init-macrodef-junit-prototype">
+        <macrodef name="junit-prototype" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <element name="customizePrototype" optional="true"/>
+            <sequential>
+                <property location="${build.dir}/empty" name="empty.dir"/>
+                <property name="junit.forkmode" value="perTest"/>
+                <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
+                    <syspropertyset>
+                        <propertyref prefix="test-sys-prop."/>
+                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
+                    </syspropertyset>
+                    <classpath>
+                        <path path="${run.test.classpath}"/>
+                    </classpath>
+                    <formatter type="brief" usefile="false"/>
+                    <formatter type="xml"/>
+                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <jvmarg value="-ea"/>
+                    <jvmarg value="--module-path"/>
+                    <jvmarg path="${run.modulepath}${path.separator}${run.test.modulepath}${path.separator}${empty.dir}"/>
+                    <jvmarg line="${run.test.jvmargs}"/>
+                    <customizePrototype/>
+                </junit>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-test-properties,-init-macrodef-junit-prototype" if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}">
+        <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <j2semodularproject1:junit-prototype xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1">
+                    <customizePrototype>
+                        <test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
+                        <customize/>
+                    </customizePrototype>
+                </j2semodularproject1:junit-prototype>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-test-properties,-init-macrodef-junit-prototype" if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}">
+        <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <j2semodularproject1:junit-prototype xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1">
+                    <customizePrototype>
+                        <batchtest todir="${build.test.results.dir}">
+                            <mappedresources>
+                                <union>
+                                    <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="**/@{includes}">
+                                        <filename name="**/@{testincludes}"/>
+                                        <filename regex="${have.tests.test.src.dir.regexp}"/>
+                                    </fileset>
+                                </union>
+                                <regexpmapper from="${have.tests.test.src.dir.regexp}\Q${file.separator}\E(.*)$" to="\3"/>
+                            </mappedresources>
+                            <fileset dir="${build.test.modules.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}">
+                                <filename name="${test.binarytestincludes}"/>
+                            </fileset>
+                        </batchtest>
+                        <customize/>
+                    </customizePrototype>
+                </j2semodularproject1:junit-prototype>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-junit-init,-init-macrodef-junit-single, -init-macrodef-junit-batch" if="${junit.available}" name="-init-macrodef-junit"/>
+    <target if="${testng.available}" name="-init-macrodef-testng">
+        <macrodef name="testng" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}">
+                    <isset property="test.method"/>
+                </condition>
+                <union id="test.set">
+                    <fileset dir="${test.src.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}">
+                        <filename name="@{testincludes}"/>
+                    </fileset>
+                </union>
+                <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
+                <testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="notzed.zcl" testname="TestNG tests" workingDir="${work.dir}">
+                    <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
+                    <propertyset>
+                        <propertyref prefix="test-sys-prop."/>
+                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
+                    </propertyset>
+                    <classpath>
+                        <path path="${run.test.classpath}"/>
+                    </classpath>
+                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <customize/>
+                </testng>
+            </sequential>
+        </macrodef>
+    </target>
+    <target name="-init-macrodef-test-impl">
+        <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <element implicit="true" name="customize" optional="true"/>
+            <sequential>
+                <echo>No tests executed.</echo>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-impl">
+        <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <element implicit="true" name="customize" optional="true"/>
+            <sequential>
+                <j2semodularproject1:junit xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+                    <customize/>
+                </j2semodularproject1:junit>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-testng" if="${testng.available}" name="-init-macrodef-testng-impl">
+        <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <element implicit="true" name="customize" optional="true"/>
+            <sequential>
+                <j2semodularproject1:testng xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+                    <customize/>
+                </j2semodularproject1:testng>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-test-impl,-init-macrodef-junit-impl,-init-macrodef-testng-impl" name="-init-macrodef-test">
+        <macrodef name="test" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <sequential>
+                <j2semodularproject1:test-impl xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+                    <customize>
+                        <jvmarg line="${run.jvmargs}"/>
+                        <jvmarg line="${run.jvmargs.ide}"/>
+                    </customize>
+                </j2semodularproject1:test-impl>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-debug-impl">
+        <macrodef name="test-debug-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <element name="customizeDebuggee" optional="true"/>
+            <sequential>
+                <j2semodularproject1:junit xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+                    <customize>
+                        <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
+                        <customizeDebuggee/>
+                    </customize>
+                </j2semodularproject1:junit>
+            </sequential>
+        </macrodef>
+    </target>
+    <target if="${testng.available}" name="-init-macrodef-testng-debug">
+        <macrodef name="testng-debug" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${main.class}" name="testClass"/>
+            <attribute default="" name="testMethod"/>
+            <element name="customize2" optional="true"/>
+            <sequential>
+                <condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
+                    <isset property="test.method"/>
+                </condition>
+                <condition else="-suitename notzed.zcl -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
+                    <matches pattern=".*\.xml" string="@{testClass}"/>
+                </condition>
+                <delete dir="${build.test.results.dir}" quiet="true"/>
+                <mkdir dir="${build.test.results.dir}"/>
+                <j2semodularproject1:debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="org.testng.TestNG" classpath="${debug.test.classpath}">
+                    <customizeDebuggee>
+                        <customize2/>
+                        <jvmarg value="-ea"/>
+                        <arg line="${testng.debug.mode}"/>
+                        <arg line="-d ${build.test.results.dir}"/>
+                        <arg line="-listener org.testng.reporters.VerboseReporter"/>
+                        <arg line="${testng.cmd.args}"/>
+                    </customizeDebuggee>
+                </j2semodularproject1:debug>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-testng-debug" if="${testng.available}" name="-init-macrodef-testng-debug-impl">
+        <macrodef name="testng-debug-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${main.class}" name="testClass"/>
+            <attribute default="" name="testMethod"/>
+            <element implicit="true" name="customize2" optional="true"/>
+            <sequential>
+                <j2semodularproject1:testng-debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" testClass="@{testClass}" testMethod="@{testMethod}">
+                    <customize2/>
+                </j2semodularproject1:testng-debug>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-junit-debug-impl" if="${junit.available}" name="-init-macrodef-test-debug-junit">
+        <macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <attribute default="${main.class}" name="testClass"/>
+            <attribute default="" name="testMethod"/>
+            <sequential>
+                <j2semodularproject1:test-debug-impl xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+                    <customizeDebuggee>
+                        <jvmarg line="${run.jvmargs}"/>
+                        <jvmarg line="${run.jvmargs.ide}"/>
+                    </customizeDebuggee>
+                </j2semodularproject1:test-debug-impl>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-testng-debug-impl" if="${testng.available}" name="-init-macrodef-test-debug-testng">
+        <macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <attribute default="" name="testmethods"/>
+            <attribute default="${main.class}" name="testClass"/>
+            <attribute default="" name="testMethod"/>
+            <sequential>
+                <j2semodularproject1:testng-debug-impl xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" testClass="@{testClass}" testMethod="@{testMethod}">
+                    <customize2>
+                        <syspropertyset>
+                            <propertyref prefix="test-sys-prop."/>
+                            <mapper from="test-sys-prop.*" to="*" type="glob"/>
+                        </syspropertyset>
+                    </customize2>
+                </j2semodularproject1:testng-debug-impl>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-test-debug-junit,-init-macrodef-test-debug-testng" name="-init-macrodef-test-debug"/>
+    <!--
+                pre NB7.2 profiling section; consider it deprecated
+            -->
+    <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" if="profiler.info.jvmargs.agent" name="profile-init"/>
+    <target if="profiler.info.jvmargs.agent" name="-profile-pre-init">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target if="profiler.info.jvmargs.agent" name="-profile-post-init">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target if="profiler.info.jvmargs.agent" name="-profile-init-macrodef-profile">
+        <macrodef name="resolve">
+            <attribute name="name"/>
+            <attribute name="value"/>
+            <sequential>
+                <property name="@{name}" value="${env.@{value}}"/>
+            </sequential>
+        </macrodef>
+        <macrodef name="profile">
+            <attribute default="${main.class}" name="classname"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <property environment="env"/>
+                <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/>
+                <java classname="@{classname}" dir="${profiler.info.dir}" failonerror="${java.failonerror}" fork="true" jvm="${profiler.info.jvm}">
+                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <jvmarg value="${profiler.info.jvmargs.agent}"/>
+                    <jvmarg line="${profiler.info.jvmargs}"/>
+                    <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
+                    <arg line="${application.args}"/>
+                    <classpath>
+                        <path path="${run.classpath}"/>
+                    </classpath>
+                    <syspropertyset>
+                        <propertyref prefix="run-sys-prop."/>
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
+                    </syspropertyset>
+                    <customize/>
+                </java>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" if="profiler.info.jvmargs.agent" name="-profile-init-check">
+        <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
+        <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
+    </target>
+    <!--
+                end of pre NB7.2 profiling section
+            -->
+    <target depends="-init-debug-args" name="-init-macrodef-nbjpda">
+        <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${main.class}" name="name"/>
+            <attribute default="${debug.modulepath}" name="modulepath"/>
+            <attribute default="${debug.classpath}" name="classpath"/>
+            <attribute default="" name="stopclassname"/>
+            <sequential>
+                <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}">
+                    <modulepath>
+                        <path path="@{modulepath}"/>
+                    </modulepath>
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                </nbjpdastart>
+            </sequential>
+        </macrodef>
+        <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${debug.modules.dir}" name="dir"/>
+            <sequential>
+                <nbjpdareload>
+                    <fileset dir="@{dir}" includes="${fix.classes}">
+                        <include name="*/${fix.includes}*.class"/>
+                    </fileset>
+                </nbjpdareload>
+            </sequential>
+        </macrodef>
+    </target>
+    <target name="-init-debug-args">
+        <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
+            <os family="windows"/>
+        </condition>
+        <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
+            <isset property="debug.transport"/>
+        </condition>
+    </target>
+    <target depends="-init-debug-args" name="-init-macrodef-debug">
+        <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${module.name}" name="modulename"/>
+            <attribute default="${main.class}" name="classname"/>
+            <attribute default="${debug.modulepath}" name="modulepath"/>
+            <attribute default="${debug.classpath}" name="classpath"/>
+            <element name="customizeDebuggee" optional="true"/>
+            <sequential>
+                <j2semodularproject1:java xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="@{classname}" classpath="@{classpath}" modulename="@{modulename}" modulepath="@{modulepath}">
+                    <customize>
+                        <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
+                        <customizeDebuggee/>
+                    </customize>
+                </j2semodularproject1:java>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-source-module-properties" name="-init-macrodef-java">
+        <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${module.name}" name="modulename"/>
+            <attribute default="${main.class}" name="classname"/>
+            <attribute default="${run.modulepath}" name="modulepath"/>
+            <attribute default="${run.upgrademodulepath}" name="upgrademodulepath"/>
+            <attribute default="${run.classpath}" name="classpath"/>
+            <attribute default="jvm" name="jvm"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" module="@{modulename}">
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                    <modulepath>
+                        <path path="@{modulepath}"/>
+                    </modulepath>
+                    <upgrademodulepath>
+                        <path path="@{upgrademodulepath}"/>
+                    </upgrademodulepath>
+                    <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
+                    <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
+                    <jvmarg line="${run.jvmargs}"/>
+                    <jvmarg line="${run.jvmargs.ide}"/>
+                    <syspropertyset>
+                        <propertyref prefix="run-sys-prop."/>
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
+                    </syspropertyset>
+                    <customize/>
+                </java>
+            </sequential>
+        </macrodef>
+    </target>
+    <target name="-init-presetdef-jar">
+        <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifestencoding="UTF-8">
+                <j2semodularproject1:fileset xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
+            </jar>
+        </presetdef>
+    </target>
+    <target name="-init-ap-cmdline-properties">
+        <property name="annotation.processing.enabled" value="true"/>
+        <property name="annotation.processing.processors.list" value=""/>
+        <property name="annotation.processing.processor.options" value=""/>
+        <property name="annotation.processing.run.all.processors" value="true"/>
+        <property name="javac.processorpath" value="${javac.classpath}"/>
+        <property name="javac.test.processorpath" value="${javac.test.classpath}"/>
+    </target>
+    <target depends="-init-ap-cmdline-properties" name="-init-ap-cmdline-supported">
+        <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}">
+            <isfalse value="${annotation.processing.run.all.processors}"/>
+        </condition>
+        <condition else="" property="ap.proc.none.internal" value="-proc:none">
+            <isfalse value="${annotation.processing.enabled}"/>
+        </condition>
+    </target>
+    <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline">
+        <property name="ap.cmd.line.internal" value=""/>
+    </target>
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac-depend,-init-macrodef-test,-init-macrodef-test-debug,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/>
+    <!--
+                ===================
+                COMPILATION SECTION
+                ===================
+            -->
+    <target name="-deps-jar-init" unless="built-jar.properties">
+        <property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
+        <delete file="${built-jar.properties}" quiet="true"/>
+    </target>
+    <target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
+        <echo level="warn" message="Cycle detected: notzed.zcl was already built"/>
+    </target>
+    <target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
+        <mkdir dir="${build.dir}"/>
+        <touch file="${built-jar.properties}" verbose="false"/>
+        <property file="${built-jar.properties}" prefix="already.built.jar."/>
+        <antcall target="-warn-already-built-jar"/>
+        <propertyfile file="${built-jar.properties}">
+            <entry key="${basedir}" value=""/>
+        </propertyfile>
+        <antcall target="-maybe-call-dep">
+            <param name="call.built.properties" value="${built-jar.properties}"/>
+            <param location="${project.notzed_nativez}" name="call.subproject"/>
+            <param location="${project.notzed_nativez}/build.xml" name="call.script"/>
+            <param name="call.target" value="jar"/>
+            <param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
+            <param name="transfer.not.archive.disabled" value="true"/>
+            <param name="transfer.do.jlink" value="false"/>
+        </antcall>
+    </target>
+    <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
+    <target depends="init" name="-check-automatic-build">
+        <available file="${build.modules.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
+    </target>
+    <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
+        <antcall target="clean">
+            <param name="no.dependencies" value="true"/>
+        </antcall>
+    </target>
+    <target name="-pre-pre-compile">
+        <mkdir dir="${build.modules.dir}"/>
+    </target>
+    <target name="-pre-compile">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <scriptdef language="javascript" name="coalesce_keyvalue" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+        <attribute name="property"/>
+        <attribute name="value"/>
+        <attribute name="value-sep"/>
+        <attribute name="entry-sep"/>
+        <attribute name="multi-sep"/>
+        <attribute name="out-sep"/>
+                            
+
+            function coalesce(input, keyValueSeparator, multiSeparator, entrySeparator) {
+                var result = [];
+                var values = {};
+
+                (typeof input === "string" ? input.split(entrySeparator) : input).forEach(function(entry) {
+                    var idx = entry.indexOf(keyValueSeparator);
+                    if (idx &lt; 1) {
+                        result.push(entry);
+                    } else {
+                        var key = entry.substring(0, idx);
+                        var val = entry.substring(idx + 1);
+                        if (!values[key]) {
+                            values[key] = [];
+                        }
+                        values[key].push(val.trim());
+                    }
+                });
+                Object.keys(values).sort().forEach(function(k) {
+                    result.push(k + keyValueSeparator + values[k].join(multiSeparator));
+                });
+                return result.join(" " + entrySeparator);
+            }
+            self.project.setProperty(attributes.get("property"),
+                coalesce(attributes.get("value"), 
+                attributes.get("value-sep"), 
+                attributes.get("entry-sep"),
+                attributes.get("multi-sep")
+            ));
+            
+            
+    
+    </scriptdef>
+    <scriptdef language="javascript" name="modsource_regexp" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+        <attribute name="property"/>
+        <attribute name="filePattern"/>
+        <attribute name="modsource"/>
+                        function expandGroup(grp) {
+            var exp = [];
+            var item = "";
+            var depth = 0;
+
+            for (i = 0; i &lt; grp.length; i++) {
+                var c = grp[i];
+                switch (c) {
+                    case '{':
+                        if (depth++ === 0) {
+                            continue;
+                        }
+                        break;
+                    case '}':
+                        if (--depth === 0) {
+                            exp.push(item);
+                            continue;
+                        }
+                        break;
+                    case ',':
+                        if (depth === 1) {
+                            exp.push(item);
+                            item = "";
+                            continue;
+                        }
+                    default:
+                        break;
+                }
+                item = item + c;
+            }
+            return exp;
+        }
+
+        function pathVariants(spec, res) {
+            res = res || [];
+            var start  = spec.indexOf('{');
+            if (start === -1) {
+                res.push(spec);
+                return res;
+            }
+            var depth = 1;
+            var end;
+            for (end = start + 1; end &lt; spec.length &amp;&amp; depth &gt; 0; end++) {
+                var c = spec[end];
+                switch (c) {
+                    case '{': depth++; break;
+                    case '}': depth--; break;
+                }
+            }
+            var prefix = spec.substring(0, start);
+            var suffix = spec.substring(end);
+            expandGroup(spec.slice(start, end)).forEach(function (item) {
+                pathVariants(prefix + item + suffix, res);
+            })
+            return res;
+        }
+
+        function toRegexp2(spec, filepattern, separator) {
+            var prefixes = [];
+            var suffixes = [];
+            pathVariants(spec).forEach(function(item) {
+                suffixes.push(item);
+            });
+            var tail = "";
+            var separatorString = separator;
+            if (separatorString == "\\") {
+                separatorString = "\\\\";
+            }
+            if (filepattern &amp;&amp; filepattern != tail) {
+                tail = separatorString + filepattern;
+            }
+            return "([^" + separatorString +"]+)\\Q" + separator + "\\E(" + suffixes.join("|") + ")" + tail;
+        }
+                self.project.setProperty(attributes.get("property"), 
+                    toRegexp2(attributes.get("modsource"), attributes.get("filepattern"), self.project.getProperty("file.separator")));
+            
+            
+            
+    
+    </scriptdef>
+    <target if="do.depend.true" name="-compile-depend">
+        <pathconvert property="build.generated.subdirs">
+            <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+                <include name="*"/>
+            </dirset>
+        </pathconvert>
+        <j2semodularproject1:depend xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" srcdir="${src.dir}:${build.generated.subdirs}"/>
+    </target>
+    <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
+        <j2semodularproject1:javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" gensrcdir="${build.generated.sources.dir}"/>
+        <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${src.dir.path}" property="src.dir.path.regexp"/>
+        <echo message="Copying resources from ${src.dir}"/>
+        <copy todir="${build.modules.dir}">
+            <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
+            <regexpmapper from="${src.dir.path.regexp}" to="\1/\3"/>
+        </copy>
+    </target>
+    <target if="has.persistence.xml" name="-copy-persistence-xml">
+        <fail message="XXX: Not supported on MM projects"/>
+        <mkdir dir="${build.classes.dir}/META-INF"/>
+        <copy todir="${build.classes.dir}/META-INF">
+            <fileset dir="${meta.inf.dir}" includes="persistence.xml orm.xml"/>
+        </copy>
+    </target>
+    <target name="-post-compile">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
+    <target name="-pre-compile-single">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-jar" name="-do-compile-single">
+        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
+        <j2semodularproject1:force-recompile xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1"/>
+        <j2semodularproject1:javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}, module-info.java"/>
+    </target>
+    <target name="-post-compile-single">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
+    <!--
+                ====================
+                JAR BUILDING SECTION
+                ====================
+            -->
+    <target depends="init,compile" name="-check-module-main-class">
+        <condition property="do.module.main.class">
+            <and>
+                <available file="${module.dir}/module-info.class"/>
+                <isset property="main.class.check.available"/>
+            </and>
+        </condition>
+    </target>
+    <target depends="init" name="-pre-pre-jar">
+        <dirname file="${dist.jar}" property="dist.jar.dir"/>
+        <mkdir dir="${dist.jar.dir}"/>
+    </target>
+    <target name="-pre-jar">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target name="-pre-single-jar"/>
+    <target depends="-pre-single-jar" if="module.jar.filename" name="-make-single-jar">
+        <jar basedir="${module.dir}" compress="${jar.compress}" destfile="${dist.dir}/${module.jar.filename}" excludes="${dist.archive.excludes}" manifestencoding="UTF-8"/>
+    </target>
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
+        <property location="${build.modules.dir}" name="build.modules.dir.resolved"/>
+        <dirset dir="${build.modules.dir.resolved}" id="do.jar.dirs" includes="*"/>
+        <pathconvert property="do.jar.dir.list" refid="do.jar.dirs">
+            <identitymapper/>
+        </pathconvert>
+        <j2semodularproject1:for-paths xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" paths="${do.jar.dir.list}">
+            <local name="module.jar.filename"/>
+            <local name="module.jar.name.tmp"/>
+            <basename file="${entry}" property="module.jar.name.tmp"/>
+            <property name="module.jar.filename" value="${module.jar.name.tmp}.jar"/>
+            <antcall inheritRefs="true" target="-make-single-jar">
+                <param name="module.jar.filename" value="${module.jar.filename}"/>
+                <param location="${entry}" name="module.dir"/>
+            </antcall>
+        </j2semodularproject1:for-paths>
+        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
+        <property location="${dist.jar}" name="dist.jar.resolved"/>
+        <pathconvert property="run.classpath.with.dist.jar">
+            <path path="${run.classpath}"/>
+            <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
+        </pathconvert>
+        <pathconvert property="run.modulepath.with.dist.jar">
+            <path path="${run.modulepath}"/>
+            <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
+        </pathconvert>
+        <condition else="" property="jar.usage.message.module.path" value=" -modulepath ${run.modulepath.with.dist.jar}">
+            <and>
+                <isset property="modules.supported.internal"/>
+                <length length="0" string="${run.modulepath.with.dist.jar}" when="greater"/>
+            </and>
+        </condition>
+        <condition else="" property="jar.usage.message.class.path" value=" -cp ${run.classpath.with.dist.jar}">
+            <length length="0" string="${run.classpath.with.dist.jar}" when="greater"/>
+        </condition>
+        <condition else=" ${main.class}" property="jar.usage.message.main.class" value=" -m ${module.name}/${main.class}">
+            <isset property="named.module.internal"/>
+        </condition>
+        <condition else="" property="jar.usage.message" value="To run this application from the command line without Ant, try:${line.separator}${platform.java}${jar.usage.message.module.path}${jar.usage.message.class.path}${jar.usage.message.main.class}">
+            <isset property="main.class.available"/>
+        </condition>
+        <condition else="debug" property="jar.usage.level" value="info">
+            <isset property="main.class.available"/>
+        </condition>
+        <echo level="${jar.usage.level}" message="${jar.usage.message}"/>
+    </target>
+    <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-jar" name="-do-jar-without-libraries"/>
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" name="-do-jar-with-libraries"/>
+    <target name="-post-jar">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,compile,-pre-jar,-do-jar-without-libraries,-do-jar-with-libraries,-post-jar" name="-do-jar"/>
+    <target depends="init,compile,-pre-jar,-do-jar,-post-jar,deploy" description="Build JAR." name="jar"/>
+    <!--
+                =================
+                DEPLOY SECTION
+                =================
+            -->
+    <target name="-pre-deploy">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init" name="-check-jlink">
+        <condition property="do.jlink.internal">
+            <and>
+                <istrue value="${do.jlink}"/>
+                <isset property="do.archive"/>
+            </and>
+        </condition>
+    </target>
+    <target depends="init,-do-jar,-post-jar,-pre-deploy,-check-jlink,-main-module-set" if="do.jlink.internal" name="-do-deploy">
+        <delete dir="${dist.jlink.dir}" failonerror="false" quiet="true"/>
+        <property name="jlink.launcher.name" value="${application.title}"/>
+        <pathconvert pathsep="," property="jlink.modulelist.internal">
+            <fileset dir="${dist.dir}" includes="*.jar"/>
+            <mapper>
+                <chainedmapper>
+                    <flattenmapper/>
+                    <globmapper from="*.jar" to="*"/>
+                </chainedmapper>
+            </mapper>
+        </pathconvert>
+        <condition else="${jlink.modulelist.internal}" property="jlink.add.modules" value="${jlink.modulelist.internal},${jlink.additionalmodules}">
+            <and>
+                <isset property="jlink.additionalmodules"/>
+                <length length="0" string="${jlink.additionalmodules}" when="greater"/>
+            </and>
+        </condition>
+        <condition property="jlink.do.strip.internal">
+            <and>
+                <isset property="jlink.strip"/>
+                <istrue value="${jlink.strip}"/>
+            </and>
+        </condition>
+        <condition property="jlink.do.additionalparam.internal">
+            <and>
+                <isset property="jlink.additionalparam"/>
+                <length length="0" string="${jlink.additionalparam}" when="greater"/>
+            </and>
+        </condition>
+        <condition property="jlink.do.launcher.internal">
+            <and>
+                <istrue value="${jlink.launcher}"/>
+                <isset property="module.name"/>
+                <length length="0" string="${module.name}" when="greater"/>
+                <isset property="main.class.available"/>
+            </and>
+        </condition>
+        <property name="platform.jlink" value="${jdk.home}/bin/jlink"/>
+        <property name="jlink.systemmodules.internal" value="${jdk.home}/jmods"/>
+        <exec executable="${platform.jlink}">
+            <arg value="--module-path"/>
+            <arg path="${jlink.systemmodules.internal}:${run.modulepath}:${dist.dir}"/>
+            <arg value="--add-modules"/>
+            <arg value="${jlink.add.modules}"/>
+            <arg if:set="jlink.do.strip.internal" value="--strip-debug"/>
+            <arg if:set="jlink.do.launcher.internal" value="--launcher"/>
+            <arg if:set="jlink.do.launcher.internal" value="${jlink.launcher.name}=${module.name}/${main.class}"/>
+            <arg if:set="jlink.do.additionalparam.internal" line="${jlink.additionalparam}"/>
+            <arg value="--output"/>
+            <arg value="${dist.jlink.output}"/>
+        </exec>
+    </target>
+    <target name="-post-deploy">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="-do-jar,-post-jar,-pre-deploy,-do-deploy,-post-deploy" name="deploy"/>
+    <!--
+                =================
+                EXECUTION SECTION
+                =================
+            -->
+    <target name="-check-main-class">
+        <fail unless="main.class">No main class specified</fail>
+    </target>
+    <target depends="init,compile,-check-main-class,-main-module-check" description="Run a main class." name="run">
+        <property name="main.class.relativepath" refid="main.class.relativepath"/>
+        <pathconvert pathsep="," property="src.dir.list" refid="have.sources.set"/>
+        <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${src.dir.path}" property="run.src.dir.path.regexp"/>
+        <j2semodularproject1:java xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <customize>
+                <arg line="${application.args}"/>
+            </customize>
+        </j2semodularproject1:java>
+    </target>
+    <target name="-main-module-set" unless="module.name">
+        <condition else="${main.class}" property="check.class.name" value="${run.class}">
+            <isset property="run.class"/>
+        </condition>
+        <condition property="run.modules.dir" value="${build.modules.dir}">
+            <not>
+                <isset property="run.modules.dir"/>
+            </not>
+        </condition>
+        <resources id="main.class.relativepath">
+            <mappedresources>
+                <string value="${check.class.name}"/>
+                <unpackagemapper from="*" to="*.class"/>
+            </mappedresources>
+        </resources>
+        <property location="${run.modules.dir}" name="run.modules.dir.location"/>
+        <pathconvert property="module.name">
+            <fileset dir="${run.modules.dir}" includes="**/${toString:main.class.relativepath}"/>
+            <regexpmapper from="\Q${run.modules.dir.location}${file.separator}\E([^${file.separator.string}]+)\Q${file.separator}\E.*\.class" to="\1"/>
+        </pathconvert>
+    </target>
+    <target depends="-main-module-set" name="-main-module-check">
+        <fail message="Could not determine module of the main class and module.name is not set">
+            <condition>
+                <or>
+                    <not>
+                        <isset property="module.name"/>
+                    </not>
+                    <length length="0" string="${module.name}" when="equal"/>
+                </or>
+            </condition>
+        </fail>
+    </target>
+    <target name="-do-not-recompile">
+        <property name="javac.includes.binary" value=""/>
+    </target>
+    <target depends="init,compile-single,-main-module-check" name="run-single">
+        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+        <j2semodularproject1:java xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${run.class}"/>
+    </target>
+    <target depends="init,compile-test-single,-init-test-run-module-properties,-main-module-check" name="run-test-with-main">
+        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+        <j2semodularproject1:java xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${run.class}" classpath="${run.test.classpath}" modulepath="${run.test.modulepath}">
+            <customize>
+                <jvmarg line="${run.test.jvmargs}"/>
+            </customize>
+        </j2semodularproject1:java>
+    </target>
+    <!--
+                =================
+                DEBUGGING SECTION
+                =================
+            -->
+    <target name="-debug-init">
+        <condition else="${main.class}" property="run.class" value="${debug.class}">
+            <isset property="debug.class"/>
+        </condition>
+        <fail message="debug.class or main.class property is not set" unless="run.class"/>
+    </target>
+    <target depends="init,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debugger">
+        <j2semodularproject1:nbjpdastart xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" name="${debug.class}"/>
+    </target>
+    <target depends="init,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debugger-main-test">
+        <j2semodularproject1:nbjpdastart xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classpath="${debug.test.classpath}" name="${debug.class}"/>
+    </target>
+    <target depends="init,compile,-debug-init,-main-module-check" name="-debug-start-debuggee">
+        <j2semodularproject1:debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${run.class}">
+            <customizeDebuggee>
+                <arg line="${application.args}"/>
+            </customizeDebuggee>
+        </j2semodularproject1:debug>
+    </target>
+    <target depends="init,compile,-debug-init,-main-module-check,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
+    <target depends="init,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debugger-stepinto">
+        <j2semodularproject1:nbjpdastart xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" stopclassname="${debug.class}"/>
+    </target>
+    <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
+    <target depends="init,compile-single,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debuggee-single">
+        <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
+        <j2semodularproject1:debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${debug.class}"/>
+    </target>
+    <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
+    <target depends="init,compile-test-single,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debuggee-main-test">
+        <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
+        <j2semodularproject1:debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${debug.class}" classpath="${debug.test.classpath}"/>
+    </target>
+    <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
+    <target depends="init" name="-pre-debug-fix">
+        <fail unless="fix.includes">Must set fix.includes</fail>
+        <property name="javac.includes" value="${fix.includes}.java"/>
+    </target>
+    <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
+        <property location="${build.modules.dir}" name="debug.modules.dir"/>
+        <j2semodularproject1:nbjpdareload xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1"/>
+    </target>
+    <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
+    <!--
+                =================
+                PROFILING SECTION
+                =================
+            -->
+    <!--
+                pre NB7.2 profiler integration
+            -->
+    <target depends="profile-init,compile" description="Profile a project in the IDE." if="profiler.info.jvmargs.agent" name="-profile-pre72">
+        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
+        <nbprofiledirect>
+            <classpath>
+                <path path="${run.classpath}"/>
+            </classpath>
+        </nbprofiledirect>
+        <profile/>
+    </target>
+    <target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="profiler.info.jvmargs.agent" name="-profile-single-pre72">
+        <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
+        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
+        <nbprofiledirect>
+            <classpath>
+                <path path="${run.classpath}"/>
+            </classpath>
+        </nbprofiledirect>
+        <profile classname="${profile.class}"/>
+    </target>
+    <target depends="profile-init,compile-single" if="profiler.info.jvmargs.agent" name="-profile-applet-pre72">
+        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
+        <nbprofiledirect>
+            <classpath>
+                <path path="${run.classpath}"/>
+            </classpath>
+        </nbprofiledirect>
+        <profile classname="sun.applet.AppletViewer">
+            <customize>
+                <arg value="${applet.url}"/>
+            </customize>
+        </profile>
+    </target>
+    <target depends="-init-macrodef-junit,profile-init,compile-test-single" if="profiler.info.jvmargs.agent" name="-profile-test-single-pre72">
+        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
+        <nbprofiledirect>
+            <classpath>
+                <path path="${run.test.classpath}"/>
+            </classpath>
+        </nbprofiledirect>
+        <j2semodularproject1:junit xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="${excludes}" includes="${includes}" testincludes="${profile.class}" testmethods="">
+            <customize>
+                <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
+                <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
+                <jvmarg value="${profiler.info.jvmargs.agent}"/>
+                <jvmarg line="${profiler.info.jvmargs}"/>
+                <classpath>
+                    <path path="${run.test.classpath}"/>
+                </classpath>
+            </customize>
+        </j2semodularproject1:junit>
+    </target>
+    <!--
+                end of pre NB72 profiling section
+            -->
+    <target if="netbeans.home" name="-profile-check">
+        <condition property="profiler.configured">
+            <or>
+                <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-agentpath:"/>
+                <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-javaagent:"/>
+            </or>
+        </condition>
+    </target>
+    <target depends="-profile-check,-profile-pre72" description="Profile a project in the IDE." if="profiler.configured" name="profile" unless="profiler.info.jvmargs.agent">
+        <startprofiler/>
+        <antcall target="run"/>
+    </target>
+    <target depends="-profile-check,-profile-single-pre72" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-single" unless="profiler.info.jvmargs.agent">
+        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+        <startprofiler/>
+        <antcall target="run-single"/>
+    </target>
+    <target depends="-profile-test-single-pre72" description="Profile a selected test in the IDE." name="profile-test-single"/>
+    <target depends="-profile-check" description="Profile a selected test in the IDE." if="profiler.configured" name="profile-test" unless="profiler.info.jvmargs">
+        <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
+        <startprofiler/>
+        <antcall target="test-single"/>
+    </target>
+    <target depends="-profile-check" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-test-with-main">
+        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+        <startprofiler/>
+        <antcall target="run-test-with-main"/>
+    </target>
+    <target depends="-profile-check,-profile-applet-pre72" if="profiler.configured" name="profile-applet" unless="profiler.info.jvmargs.agent">
+        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
+        <startprofiler/>
+        <antcall target="run-applet"/>
+    </target>
+    <!--
+                ===============
+                JAVADOC SECTION
+                ===============
+            -->
+    <target depends="init" if="have.sources" name="-javadoc-build">
+        <mkdir dir="${dist.javadoc.dir}"/>
+        <condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}">
+            <and>
+                <isset property="endorsed.classpath.cmd.line.arg"/>
+                <not>
+                    <equals arg1="${endorsed.classpath.cmd.line.arg}" arg2=""/>
+                </not>
+            </and>
+        </condition>
+        <condition else="" property="bug5101868workaround" value="*.java">
+            <matches pattern="1\.[56](\..*)?" string="${java.version}"/>
+        </condition>
+        <condition else="" property="javadoc.html5.cmd.line.arg" value="-html5">
+            <and>
+                <isset property="javadoc.html5"/>
+                <available file="${jdk.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
+            </and>
+        </condition>
+        <javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
+            <classpath>
+                <path path="${javac.classpath}"/>
+            </classpath>
+            <fileset dir="${src.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
+                <filename name="**/*.java"/>
+            </fileset>
+            <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+                <include name="**/*.java"/>
+                <exclude name="*.java"/>
+            </fileset>
+            <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/>
+            <arg line="${javadoc.html5.cmd.line.arg}"/>
+        </javadoc>
+        <copy todir="${dist.javadoc.dir}">
+            <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
+                <filename name="**/doc-files/**"/>
+            </fileset>
+            <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+                <include name="**/doc-files/**"/>
+            </fileset>
+        </copy>
+    </target>
+    <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
+        <nbbrowse file="${dist.javadoc.dir}/index.html"/>
+    </target>
+    <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
+    <!--
+                =========================
+                TEST COMPILATION SECTION
+                =========================
+            -->
+    <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
+        <mkdir dir="${build.test.modules.dir}"/>
+    </target>
+    <target name="-pre-compile-test">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="-init-source-module-properties" name="-init-test-run-module-properties">
+        <fileset dir="${build.test.modules.dir}" id="run.test.packages.internal" includes="**/*.class"/>
+        <property location="${build.test.modules.dir}" name="build.test.modules.dir.abs.internal"/>
+        <pathconvert pathsep=" " property="run.test.addexports.internal" refid="run.test.packages.internal">
+            <chainedmapper>
+                <filtermapper>
+                    <replacestring from="${build.test.modules.dir.abs.internal}${file.separator}" to=""/>
+                </filtermapper>
+                <regexpmapper from="^([^${file.separator.string}]*)\Q${file.separator}\E(.*)\Q${file.separator}\E.*\.class$$" to="\1${path.separator}\2"/>
+                <filtermapper>
+                    <uniqfilter/>
+                    <replacestring from="${file.separator}" to="."/>
+                </filtermapper>
+                <regexpmapper from="([^${file.separator.string}]+)${path.separator}(.*)" to="--add-exports \1/\2=ALL-UNNAMED"/>
+            </chainedmapper>
+        </pathconvert>
+        <property location="${build.test.modules.dir}" name="build.test.modules.location"/>
+        <pathconvert pathsep="," property="run.test.addmodules.list">
+            <map from="${build.test.modules.location}${file.separator}" to=""/>
+            <dirset dir="${build.test.modules.dir}" includes="*"/>
+            <chainedmapper>
+                <filtermapper>
+                    <uniqfilter/>
+                </filtermapper>
+            </chainedmapper>
+        </pathconvert>
+        <pathconvert pathsep=" " property="run.test.patchmodules.list">
+            <dirset dir="${build.test.modules.dir}" includes="*">
+                <scriptselector language="javascript">
+                            self.setSelected(!new java.io.File(file, "module-info.class").exists());
+                        </scriptselector>
+            </dirset>
+            <chainedmapper>
+                <filtermapper>
+                    <uniqfilter/>
+                </filtermapper>
+                <regexpmapper from=".*\Q${file.separator}\E([^${file.separator.string}]+)$" to="--patch-module \1=\0"/>
+            </chainedmapper>
+        </pathconvert>
+        <j2semodularproject1:coalesce_keyvalue xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" entry-sep="${path.separator}" multi-sep="--patch-module " property="run.test.patchmodules" value="${run.test.patchmodules.list}" value-sep="="/>
+        <condition else="" property="run.test.addmodules.internal" value="--add-modules ${run.test.addmodules.list}">
+            <isset property="run.test.addmodules.list"/>
+        </condition>
+        <pathconvert pathsep=" " property="run.test.addreads.internal">
+            <map from="${build.test.modules.location}" to=""/>
+            <dirset dir="${build.test.modules.dir}" includes="*"/>
+            <chainedmapper>
+                <regexpmapper from="^\Q${build.test.modules.location}${file.separator}\E(.*)" to="\1"/>
+                <regexpmapper from="(.*)" to="--add-reads \1=ALL-UNNAMED"/>
+                <filtermapper>
+                    <uniqfilter/>
+                </filtermapper>
+            </chainedmapper>
+        </pathconvert>
+        <property name="run.test.jvmargs" value="${run.test.addmodules.internal} ${run.test.addreads.internal} ${run.test.addexports.internal} ${run.test.patchmodules}"/>
+    </target>
+    <target depends="-init-source-module-properties" name="-init-test-javac-module-properties">
+        <pathconvert pathsep=" " property="compile.test.patchmodule.internal" refid="have.tests.patchset">
+            <regexpmapper from="(.*\Q${file.separator}\E)([^${file.separator.string}]+)\Q${file.separator}\E(.*)$$" to="--patch-module \2=\1\2${file.separator.string}\3"/>
+        </pathconvert>
+        <pathconvert pathsep=" " property="compile.test.addreads">
+            <union refid="have.tests.set"/>
+            <chainedmapper>
+                <firstmatchmapper>
+                    <regexpmapper from="${have.tests.test.src.dir.regexp}" to="\1"/>
+                </firstmatchmapper>
+                <regexpmapper from="(.*)" to="--add-reads \1=ALL-UNNAMED"/>
+                <filtermapper>
+                    <uniqfilter/>
+                </filtermapper>
+            </chainedmapper>
+        </pathconvert>
+        <j2semodularproject1:coalesce_keyvalue xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" entry-sep="${path.separator}" multi-sep="--patch-module " property="compile.test.patchmodules" value="${compile.test.patchmodule.internal}" value-sep="="/>
+        <property name="javac.test.moduleargs" value="${compile.test.patchmodules} ${compile.test.addreads}"/>
+    </target>
+    <target depends="-init-test-javac-module-properties" name="-init-test-module-properties">
+        <property location="${build.modules.dir}" name="test.module.build.location"/>
+        <property name="test.source.modulepath" value="${test.src.dir}/*/${test.src.dir.path}"/>
+        <property name="test.compile.modulepath" value="${javac.test.modulepath}:${build.modules.dir}"/>
+        <macrodef name="test-javac" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <element implicit="true" name="additionalargs" optional="true"/>
+            <sequential>
+                <j2semodularproject1:javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" apgeneratedsrcdir="${build.test.modules.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.modules.dir}" excludes="@{excludes}" includes="@{includes}" modulepath="${test.compile.modulepath}" modulesourcepath="${test.source.modulepath}" processorpath="${javac.test.processorpath}">
+                    <customize>
+                        <compilerarg line="${javac.test.moduleargs}"/>
+                        <additionalargs/>
+                    </customize>
+                </j2semodularproject1:javac>
+            </sequential>
+        </macrodef>
+    </target>
+    <target if="do.depend.true" name="-compile-test-depend">
+        <j2semodularproject1:depend xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
+    </target>
+    <target depends="init,deps-jar,compile,-init-test-module-properties,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
+        <j2semodularproject1:test-javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1"/>
+        <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${test.src.dir.path}" property="test.src.dir.path.regexp"/>
+        <echo message="Copying resources from ${test.src.dir}"/>
+        <copy todir="${build.test.modules.dir}">
+            <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
+            <regexpmapper from="${test.src.dir.path.regexp}" to="\1/\3"/>
+        </copy>
+    </target>
+    <target name="-post-compile-test">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
+    <target name="-pre-compile-test-single">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-jar,compile,-init-test-module-properties,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
+        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
+        <j2semodularproject1:force-recompile xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" destdir="${build.test.modules.dir}"/>
+        <j2semodularproject1:test-javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" includes="${javac.includes}"/>
+        <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${test.src.dir.path}" property="test.src.dir.path.regexp"/>
+        <echo message="Copying resources from ${test.src.dir}"/>
+        <copy todir="${build.test.modules.dir}">
+            <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
+            <regexpmapper from="${test.src.dir.path.regexp}" to="\1/\3"/>
+        </copy>
+    </target>
+    <target name="-post-compile-test-single">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
+    <!--
+                =======================
+                TEST EXECUTION SECTION
+                =======================
+            -->
+    <target depends="init" if="have.tests" name="-pre-test-run">
+        <mkdir dir="${build.test.results.dir}"/>
+    </target>
+    <target name="-init-test-run">
+        <property name="run.modules.dir" value="${build.test.modules.dir}"/>
+    </target>
+    <target depends="init,compile-test,-init-test-run-module-properties,-pre-test-run" if="have.tests" name="-do-test-run">
+        <j2semodularproject1:test xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" includes="${includes}" testincludes="**/*Test.java"/>
+    </target>
+    <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
+        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
+    </target>
+    <target depends="init" if="have.tests" name="test-report"/>
+    <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
+    <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
+    <target depends="init" if="have.tests" name="-pre-test-run-single">
+        <mkdir dir="${build.test.results.dir}"/>
+    </target>
+    <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
+        <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
+        <j2semodularproject1:test xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" includes="${test.includes}" testincludes="${test.includes}"/>
+    </target>
+    <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
+        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
+    </target>
+    <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
+    <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single-method">
+        <fail unless="test.class">Must select some files in the IDE or set test.class</fail>
+        <fail unless="test.method">Must select some method in the IDE or set test.method</fail>
+        <j2semodularproject1:test xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" includes="${javac.includes}" testincludes="${test.class}" testmethods="${test.method}"/>
+    </target>
+    <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method" if="have.tests" name="-post-test-run-single-method">
+        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
+    </target>
+    <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single,-do-test-run-single-method,-post-test-run-single-method" description="Run single unit test." name="test-single-method"/>
+    <!--
+                =======================
+                TEST DEBUGGING SECTION
+                =======================
+            -->
+    <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test">
+        <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
+        <j2semodularproject1:test-debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" includes="${javac.includes}" testClass="${test.class}" testincludes="${javac.includes}"/>
+    </target>
+    <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test-method">
+        <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
+        <fail unless="test.method">Must select some method in the IDE or set test.method</fail>
+        <j2semodularproject1:test-debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" includes="${javac.includes}" testClass="${test.class}" testMethod="${test.method}" testincludes="${test.class}" testmethods="${test.method}"/>
+    </target>
+    <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
+        <j2semodularproject1:nbjpdastart xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classpath="${debug.test.classpath}" name="${test.class}"/>
+    </target>
+    <target depends="init,compile-test-single,-init-test-run-module-properties,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
+    <target depends="init,compile-test-single,-init-test-run-module-properties,-debug-start-debugger-test,-debug-start-debuggee-test-method" name="debug-test-method"/>
+    <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
+        <property name="debug.modules.dir" value="${build.test.modules.dir}"/>
+        <j2semodularproject1:nbjpdareload xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1"/>
+    </target>
+    <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
+    <!--
+                =========================
+                APPLET EXECUTION SECTION
+                =========================
+            -->
+    <target name="run-applet">
+        <fail message="Applets are no longer supported by JDK 9"/>
+    </target>
+    <!--
+                =========================
+                APPLET DEBUGGING  SECTION
+                =========================
+            -->
+    <target name="-debug-start-debuggee-applet">
+        <fail message="Applets are no longer supported by JDK 9"/>
+    </target>
+    <target name="debug-applet">
+        <fail message="Applets are no longer supported by JDK 9"/>
+    </target>
+    <!--
+                ===============
+                CLEANUP SECTION
+                ===============
+            -->
+    <target name="-deps-clean-init" unless="built-clean.properties">
+        <property location="${build.dir}/built-clean.properties" name="built-clean.properties"/>
+        <delete file="${built-clean.properties}" quiet="true"/>
+    </target>
+    <target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
+        <echo level="warn" message="Cycle detected: notzed.zcl was already built"/>
+    </target>
+    <target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
+        <mkdir dir="${build.dir}"/>
+        <touch file="${built-clean.properties}" verbose="false"/>
+        <property file="${built-clean.properties}" prefix="already.built.clean."/>
+        <antcall target="-warn-already-built-clean"/>
+        <propertyfile file="${built-clean.properties}">
+            <entry key="${basedir}" value=""/>
+        </propertyfile>
+        <antcall target="-maybe-call-dep">
+            <param name="call.built.properties" value="${built-clean.properties}"/>
+            <param location="${project.notzed_nativez}" name="call.subproject"/>
+            <param location="${project.notzed_nativez}/build.xml" name="call.script"/>
+            <param name="call.target" value="clean"/>
+            <param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
+            <param name="transfer.not.archive.disabled" value="true"/>
+            <param name="transfer.do.jlink" value="false"/>
+        </antcall>
+    </target>
+    <target depends="init" name="-do-clean">
+        <delete dir="${build.dir}"/>
+        <delete dir="${dist.jlink.output}"/>
+        <delete dir="${dist.dir}" followsymlinks="false" includeemptydirs="true"/>
+    </target>
+    <target name="-post-clean">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
+    <target name="-check-call-dep">
+        <property file="${call.built.properties}" prefix="already.built."/>
+        <condition property="should.call.dep">
+            <and>
+                <not>
+                    <isset property="already.built.${call.subproject}"/>
+                </not>
+                <available file="${call.script}"/>
+            </and>
+        </condition>
+    </target>
+    <target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep">
+        <ant antfile="${call.script}" inheritall="false" target="${call.target}">
+            <propertyset>
+                <propertyref prefix="transfer."/>
+                <mapper from="transfer.*" to="*" type="glob"/>
+            </propertyset>
+        </ant>
+    </target>
+</project>
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
new file mode 100644 (file)
index 0000000..c2d597c
--- /dev/null
@@ -0,0 +1,8 @@
+build.xml.data.CRC32=508a6882
+build.xml.script.CRC32=b55362bc
+build.xml.stylesheet.CRC32=32069288@1.6.1
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=e7caf820
+nbproject/build-impl.xml.script.CRC32=2c69bf13
+nbproject/build-impl.xml.stylesheet.CRC32=0f0529df@1.6.1
diff --git a/nbproject/project.properties b/nbproject/project.properties
new file mode 100644 (file)
index 0000000..09e9e7c
--- /dev/null
@@ -0,0 +1,98 @@
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=notzed.zcl
+application.vendor=notzed
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+build.modules.dir=${build.dir}/modules
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.modules.dir=${build.dir}/test/modules
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+    ${run.classpath}
+debug.modulepath=\
+    ${run.modulepath}
+debug.test.classpath=\
+    ${run.test.classpath}
+debug.test.modulepath=\
+    ${run.test.modulepath}
+# Files in build.classes.dir which should be excluded from distribution jar
+dist.archive.excludes=
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.javadoc.dir=${dist.dir}/javadoc
+dist.jlink.dir=${dist.dir}/jlink
+dist.jlink.output=${dist.jlink.dir}/notzed.zcl
+endorsed.classpath=
+excludes=
+includes=**
+jar.compress=false
+javac.classpath=
+# Space-separated list of extra javac options
+javac.compilerargs=-Xlint:unchecked
+javac.deprecation=false
+javac.external.vm=false
+javac.modulepath=\
+    ${reference.notzed_nativez.notzed_nativez_jar}
+javac.processormodulepath=
+javac.processorpath=\
+    ${javac.classpath}
+javac.source=11
+javac.target=11
+javac.test.classpath=\
+    ${javac.classpath}
+javac.test.modulepath=\
+    ${javac.modulepath}:\
+    ${build.modules.dir}
+javac.test.processorpath=\
+    ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.html5=false
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+# The jlink additional root modules to resolve
+jlink.additionalmodules=
+# The jlink additional command line parameters
+jlink.additionalparam=
+jlink.launcher=true
+jlink.launcher.name=notzed.zcl
+platform.active=default_platform
+project.notzed_nativez=../nativez
+reference.notzed_nativez.notzed_nativez_jar=${project.notzed_nativez}/dist/notzed.nativez.jar
+run.classpath=
+# Space-separated list of JVM arguments used when running the project.
+# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
+# To set system properties for unit tests define test-sys-prop.name=value:
+run.jvmargs=-Djava.library.path=../nativez/bin/notzed.nativez/linux-amd64/lib:bin/notzed.zcl/linux-amd64/lib
+run.modulepath=\
+    ${javac.modulepath}:\
+    ${build.modules.dir}
+run.test.classpath=\
+    ${javac.test.classpath}
+run.test.modulepath=\
+    ${javac.test.modulepath}:\
+    ${build.test.modules.dir}
+source.encoding=UTF-8
+src.dir=src
+src.dir.path=classes
+test.src.dir=src
+test.src.dir.path=tests
diff --git a/nbproject/project.xml b/nbproject/project.xml
new file mode 100644 (file)
index 0000000..15787d7
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+    <type>org.netbeans.modules.java.j2semodule</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/j2se-modular-project/1">
+            <name>notzed.zcl</name>
+            <source-roots>
+                <root id="src.dir" pathref="src.dir.path"/>
+            </source-roots>
+            <test-roots>
+                <root id="test.src.dir" pathref="test.src.dir.path"/>
+            </test-roots>
+        </data>
+        <references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
+            <reference>
+                <foreign-project>notzed_nativez</foreign-project>
+                <artifact-type>jar</artifact-type>
+                <script>build.xml</script>
+                <target>jar</target>
+                <clean-target>clean</clean-target>
+                <id>notzed.nativez.jar</id>
+            </reference>
+        </references>
+    </configuration>
+</project>
diff --git a/src/notzed.zcl.demo/classes/au/notzed/zcl/tools/clinfo.java b/src/notzed.zcl.demo/classes/au/notzed/zcl/tools/clinfo.java
new file mode 100644 (file)
index 0000000..c92bb15
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2014 notzed
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl.tools;
+
+import static au.notzed.zcl.CL.*;
+import au.notzed.zcl.CLDevice;
+import au.notzed.zcl.CLObject;
+import au.notzed.zcl.CLPlatform;
+import au.notzed.zcl.CLRuntimeException;
+import java.io.PrintStream;
+
+/**
+ * A very basic and incomplete copy of 'clinfo'.
+ */
+public class clinfo {
+
+       static int level = 0;
+       static final String fmt = "%-40s %s\n";
+       static final String fmtprop = " %-39s %s\n";
+       static final int margin = 80;
+
+       static void print(String label, Object value) {
+               System.out.printf(fmt, label, value);
+       }
+
+       abstract static class property {
+
+               int id;
+               String label;
+
+               public property(int id, String label) {
+                       this.id = id;
+                       this.label = label;
+               }
+
+               abstract public void print(PrintStream out, CLObject src);
+
+               public void print(PrintStream out, Object value) {
+                       String s = value.toString();
+                       int pos = 0;
+                       String l = label;
+
+                       while (pos < s.length()) {
+                               int v;
+
+                               if (s.length() - pos > margin) {
+                                       v = s.lastIndexOf(' ', pos + margin);
+                                       if (v < 0)
+                                               v = pos + margin;
+                               } else {
+                                       v = s.length();
+                               }
+                               out.printf(fmtprop, l, s.substring(pos, v));
+                               pos = v;
+                               l = "";
+                       }
+               }
+       }
+
+       static class intprop extends property {
+
+               public intprop(int id, String label) {
+                       super(id, label);
+               }
+
+               @Override
+               public void print(PrintStream out, CLObject src) {
+                       print(out, src.getInfoInt(id));
+               }
+
+       }
+
+       static class longprop extends property {
+
+               public longprop(int id, String label) {
+                       super(id, label);
+               }
+
+               @Override
+               public void print(PrintStream out, CLObject src) {
+                       print(out, src.getInfoLong(id));
+               }
+
+       }
+
+       static class boolprop extends property {
+
+               public boolprop(int id, String label) {
+                       super(id, label);
+               }
+
+               @Override
+               public void print(PrintStream out, CLObject src) {
+                       print(out, src.getInfoInt(id) == 0 ? "No" : "Yes");
+               }
+
+       }
+
+       static class sizetprop extends property {
+
+               public sizetprop(int id, String label) {
+                       super(id, label);
+               }
+
+               @Override
+               public void print(PrintStream out, CLObject src) {
+                       print(out, src.getInfoSizeT(id));
+               }
+
+       }
+
+       static class stringprop extends property {
+
+               public stringprop(int id, String label) {
+                       super(id, label);
+               }
+
+               @Override
+               public void print(PrintStream out, CLObject src) {
+                       print(out, src.getInfoString(id));
+               }
+
+       }
+
+       static property[] platform = {
+               new stringprop(CL_PLATFORM_PROFILE, "Platform Profile"),
+               new stringprop(CL_PLATFORM_VERSION, "Platform Version"),
+               new stringprop(CL_PLATFORM_NAME, "Platform Name"),
+               new stringprop(CL_PLATFORM_VENDOR, "Platform Vendor"),
+               new stringprop(CL_PLATFORM_EXTENSIONS, "Platform Extensions"),};
+
+       static property[] device = {
+               new longprop(CL_DEVICE_TYPE, "Device Type"),
+               //new stringprop(CL_DEVICE_TYPE, "Device ID"),
+               //new stringprop(CL_DEVICE_NAME, "Board Name"),
+               new intprop(CL_DEVICE_MAX_COMPUTE_UNITS, "Max compute units"),
+               new intprop(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, "Max work items dimensions"),
+               //
+               new intprop(CL_DEVICE_MAX_CLOCK_FREQUENCY, "Max clock frequency"),
+               new intprop(CL_DEVICE_ADDRESS_BITS, "Address bits"),
+               new longprop(CL_DEVICE_MAX_MEM_ALLOC_SIZE, "Max memory allocation"),
+               new boolprop(CL_DEVICE_IMAGE_SUPPORT, "Image support"),
+               //
+               new stringprop(CL_DEVICE_NAME, "Name"),
+               new stringprop(CL_DEVICE_VENDOR, "Vendor"),
+               new stringprop(CL_DEVICE_OPENCL_C_VERSION, "Device OpenCL C Version"),
+               new stringprop(CL_DRIVER_VERSION, "Driver Version"),
+               new stringprop(CL_DEVICE_PROFILE, "Profile"),
+               new stringprop(CL_DEVICE_VERSION, "Version"),
+               new stringprop(CL_DEVICE_EXTENSIONS, "Extensions"),
+       };
+
+       static void print(CLObject src, property[] props) {
+               for (property p : props) {
+                       try {
+                               p.print(System.out, src);
+                       } catch (CLRuntimeException ex) {
+                               p.print(System.out, "*unsupported");
+                       }
+               }
+       }
+
+       public static void main(String[] args) {
+               try {
+                       CLPlatform[] platforms = CLPlatform.getPlatforms();
+
+                       print("Number of platforms", platforms.length);
+
+                       for (CLPlatform p : platforms) {
+                               print(p, platform);
+                               System.out.println();
+
+                               CLDevice[] devices = p.getDevices(CL_DEVICE_TYPE_ALL);
+
+                               print("Number of devices", devices.length);
+
+                               for (CLDevice d : devices) {
+                                       print(d, device);
+                                       System.out.println();
+                               }
+                       }
+               } catch (Exception ex) {
+                       ex.printStackTrace();
+               }
+       }
+
+}
diff --git a/src/notzed.zcl.demo/classes/module-info.java b/src/notzed.zcl.demo/classes/module-info.java
new file mode 100644 (file)
index 0000000..8cfc6f5
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2019 Michael Zucchi
+ *
+ * This file is part of zcl <https://www.zedzone.space/software/zcl.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+module notzed.zcl.demo {
+       requires notzed.zcl;
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CL.java b/src/notzed.zcl/classes/au/notzed/zcl/CL.java
new file mode 100644 (file)
index 0000000..50f9ee6
--- /dev/null
@@ -0,0 +1,601 @@
+/**
+ * *****************************************************************************
+ * Copyright (c) 2008 - 2013 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.
+ *
+ * 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.
+ * ****************************************************************************
+ */
+package au.notzed.zcl;
+
+/**
+ * Constants from cl.h.
+ *
+ * Taken from OpenCL version 2.0.
+ */
+public interface CL {
+
+       /**
+        * ***************************************************************************
+        */
+
+       /* Error Codes */
+       public final static int CL_SUCCESS = 0;
+       public final static int CL_DEVICE_NOT_FOUND = -1;
+       public final static int CL_DEVICE_NOT_AVAILABLE = -2;
+       public final static int CL_COMPILER_NOT_AVAILABLE = -3;
+       public final static int CL_MEM_OBJECT_ALLOCATION_FAILURE = -4;
+       public final static int CL_OUT_OF_RESOURCES = -5;
+       public final static int CL_OUT_OF_HOST_MEMORY = -6;
+       public final static int CL_PROFILING_INFO_NOT_AVAILABLE = -7;
+       public final static int CL_MEM_COPY_OVERLAP = -8;
+       public final static int CL_IMAGE_FORMAT_MISMATCH = -9;
+       public final static int CL_IMAGE_FORMAT_NOT_SUPPORTED = -10;
+       public final static int CL_BUILD_PROGRAM_FAILURE = -11;
+       public final static int CL_MAP_FAILURE = -12;
+       public final static int CL_MISALIGNED_SUB_BUFFER_OFFSET = -13;
+       public final static int CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST = -14;
+       public final static int CL_COMPILE_PROGRAM_FAILURE = -15;
+       public final static int CL_LINKER_NOT_AVAILABLE = -16;
+       public final static int CL_LINK_PROGRAM_FAILURE = -17;
+       public final static int CL_DEVICE_PARTITION_FAILED = -18;
+       public final static int CL_KERNEL_ARG_INFO_NOT_AVAILABLE = -19;
+
+       public final static int CL_INVALID_VALUE = -30;
+       public final static int CL_INVALID_DEVICE_TYPE = -31;
+       public final static int CL_INVALID_PLATFORM = -32;
+       public final static int CL_INVALID_DEVICE = -33;
+       public final static int CL_INVALID_CONTEXT = -34;
+       public final static int CL_INVALID_QUEUE_PROPERTIES = -35;
+       public final static int CL_INVALID_COMMAND_QUEUE = -36;
+       public final static int CL_INVALID_HOST_PTR = -37;
+       public final static int CL_INVALID_MEM_OBJECT = -38;
+       public final static int CL_INVALID_IMAGE_FORMAT_DESCRIPTOR = -39;
+       public final static int CL_INVALID_IMAGE_SIZE = -40;
+       public final static int CL_INVALID_SAMPLER = -41;
+       public final static int CL_INVALID_BINARY = -42;
+       public final static int CL_INVALID_BUILD_OPTIONS = -43;
+       public final static int CL_INVALID_PROGRAM = -44;
+       public final static int CL_INVALID_PROGRAM_EXECUTABLE = -45;
+       public final static int CL_INVALID_KERNEL_NAME = -46;
+       public final static int CL_INVALID_KERNEL_DEFINITION = -47;
+       public final static int CL_INVALID_KERNEL = -48;
+       public final static int CL_INVALID_ARG_INDEX = -49;
+       public final static int CL_INVALID_ARG_VALUE = -50;
+       public final static int CL_INVALID_ARG_SIZE = -51;
+       public final static int CL_INVALID_KERNEL_ARGS = -52;
+       public final static int CL_INVALID_WORK_DIMENSION = -53;
+       public final static int CL_INVALID_WORK_GROUP_SIZE = -54;
+       public final static int CL_INVALID_WORK_ITEM_SIZE = -55;
+       public final static int CL_INVALID_GLOBAL_OFFSET = -56;
+       public final static int CL_INVALID_EVENT_WAIT_LIST = -57;
+       public final static int CL_INVALID_EVENT = -58;
+       public final static int CL_INVALID_OPERATION = -59;
+       public final static int CL_INVALID_GL_OBJECT = -60;
+       public final static int CL_INVALID_BUFFER_SIZE = -61;
+       public final static int CL_INVALID_MIP_LEVEL = -62;
+       public final static int CL_INVALID_GLOBAL_WORK_SIZE = -63;
+       public final static int CL_INVALID_PROPERTY = -64;
+       public final static int CL_INVALID_IMAGE_DESCRIPTOR = -65;
+       public final static int CL_INVALID_COMPILER_OPTIONS = -66;
+       public final static int CL_INVALID_LINKER_OPTIONS = -67;
+       public final static int CL_INVALID_DEVICE_PARTITION_COUNT = -68;
+       // Added in 2.0
+       public final static int CL_INVALID_PIPE_SIZE = -69;
+       public final static int CL_INVALID_DEVICE_QUEUE = -70;
+
+       /* OpenCL Version */
+       //public final static int CL_VERSION_1_0 = 1;
+       //public final static int CL_VERSION_1_1 = 1;
+       //public final static int CL_VERSION_1_2 = 1;
+       //public final static int CL_VERSION_2_0 = 1;
+       //public final static int CL_VERSION_2_1 = 1;
+
+       /* cl_bool */
+       public final static boolean CL_FALSE = false;
+       public final static boolean CL_TRUE = true;
+       public final static boolean CL_BLOCKING = true;
+       public final static boolean CL_NON_BLOCKING = false;
+
+       /* cl_platform_info */
+       public final static int CL_PLATFORM_PROFILE = 0x0900;
+       public final static int CL_PLATFORM_VERSION = 0x0901;
+       public final static int CL_PLATFORM_NAME = 0x0902;
+       public final static int CL_PLATFORM_VENDOR = 0x0903;
+       public final static int CL_PLATFORM_EXTENSIONS = 0x0904;
+       // 2.1
+       public final static int CL_PLATFORM_HOST_TIMER_RESOLUTION = 0x0905;
+       
+       /* cl_device_type - bitfield */
+       public final static long CL_DEVICE_TYPE_DEFAULT = (1 << 0);
+       public final static long CL_DEVICE_TYPE_CPU = (1 << 1);
+       public final static long CL_DEVICE_TYPE_GPU = (1 << 2);
+       public final static long CL_DEVICE_TYPE_ACCELERATOR = (1 << 3);
+       public final static long CL_DEVICE_TYPE_CUSTOM = (1 << 4);
+       public final static long CL_DEVICE_TYPE_ALL = 0xFFFFFFFF;
+
+       /* cl_device_info */
+       public final static int CL_DEVICE_TYPE = 0x1000;
+       public final static int CL_DEVICE_VENDOR_ID = 0x1001;
+       public final static int CL_DEVICE_MAX_COMPUTE_UNITS = 0x1002;
+       public final static int CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = 0x1003;
+       public final static int CL_DEVICE_MAX_WORK_GROUP_SIZE = 0x1004;
+       public final static int CL_DEVICE_MAX_WORK_ITEM_SIZES = 0x1005;
+       public final static int CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR = 0x1006;
+       public final static int CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT = 0x1007;
+       public final static int CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT = 0x1008;
+       public final static int CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG = 0x1009;
+       public final static int CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT = 0x100A;
+       public final static int CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE = 0x100B;
+       public final static int CL_DEVICE_MAX_CLOCK_FREQUENCY = 0x100C;
+       public final static int CL_DEVICE_ADDRESS_BITS = 0x100D;
+       public final static int CL_DEVICE_MAX_READ_IMAGE_ARGS = 0x100E;
+       public final static int CL_DEVICE_MAX_WRITE_IMAGE_ARGS = 0x100F;
+       public final static int CL_DEVICE_MAX_MEM_ALLOC_SIZE = 0x1010;
+       public final static int CL_DEVICE_IMAGE2D_MAX_WIDTH = 0x1011;
+       public final static int CL_DEVICE_IMAGE2D_MAX_HEIGHT = 0x1012;
+       public final static int CL_DEVICE_IMAGE3D_MAX_WIDTH = 0x1013;
+       public final static int CL_DEVICE_IMAGE3D_MAX_HEIGHT = 0x1014;
+       public final static int CL_DEVICE_IMAGE3D_MAX_DEPTH = 0x1015;
+       public final static int CL_DEVICE_IMAGE_SUPPORT = 0x1016;
+       public final static int CL_DEVICE_MAX_PARAMETER_SIZE = 0x1017;
+       public final static int CL_DEVICE_MAX_SAMPLERS = 0x1018;
+       public final static int CL_DEVICE_MEM_BASE_ADDR_ALIGN = 0x1019;
+       public final static int CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE = 0x101A;
+       public final static int CL_DEVICE_SINGLE_FP_CONFIG = 0x101B;
+       public final static int CL_DEVICE_GLOBAL_MEM_CACHE_TYPE = 0x101C;
+       public final static int CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE = 0x101D;
+       public final static int CL_DEVICE_GLOBAL_MEM_CACHE_SIZE = 0x101E;
+       public final static int CL_DEVICE_GLOBAL_MEM_SIZE = 0x101F;
+       public final static int CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE = 0x1020;
+       public final static int CL_DEVICE_MAX_CONSTANT_ARGS = 0x1021;
+       public final static int CL_DEVICE_LOCAL_MEM_TYPE = 0x1022;
+       public final static int CL_DEVICE_LOCAL_MEM_SIZE = 0x1023;
+       public final static int CL_DEVICE_ERROR_CORRECTION_SUPPORT = 0x1024;
+       public final static int CL_DEVICE_PROFILING_TIMER_RESOLUTION = 0x1025;
+       public final static int CL_DEVICE_ENDIAN_LITTLE = 0x1026;
+       public final static int CL_DEVICE_AVAILABLE = 0x1027;
+       public final static int CL_DEVICE_COMPILER_AVAILABLE = 0x1028;
+       public final static int CL_DEVICE_EXECUTION_CAPABILITIES = 0x1029;
+       /**
+        * @deprecated in OpenCL 2.0
+        */
+       @Deprecated
+       public final static int CL_DEVICE_QUEUE_PROPERTIES = 0x102A;
+       public final static int CL_DEVICE_QUEUE_ON_HOST_PROPERTIES = 0x102A;
+       public final static int CL_DEVICE_NAME = 0x102B;
+       public final static int CL_DEVICE_VENDOR = 0x102C;
+       public final static int CL_DRIVER_VERSION = 0x102D;
+       public final static int CL_DEVICE_PROFILE = 0x102E;
+       public final static int CL_DEVICE_VERSION = 0x102F;
+       public final static int CL_DEVICE_EXTENSIONS = 0x1030;
+       public final static int CL_DEVICE_PLATFORM = 0x1031;
+       public final static int CL_DEVICE_DOUBLE_FP_CONFIG = 0x1032;
+       /* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG */
+       public final static int CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF = 0x1034;
+       /**
+        * @deprecated in OpenCL 2.0
+        */
+       @Deprecated
+       public final static int CL_DEVICE_HOST_UNIFIED_MEMORY = 0x1035;
+       public final static int CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR = 0x1036;
+       public final static int CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT = 0x1037;
+       public final static int CL_DEVICE_NATIVE_VECTOR_WIDTH_INT = 0x1038;
+       public final static int CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG = 0x1039;
+       public final static int CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT = 0x103A;
+       public final static int CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE = 0x103B;
+       public final static int CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF = 0x103C;
+       public final static int CL_DEVICE_OPENCL_C_VERSION = 0x103D;
+       public final static int CL_DEVICE_LINKER_AVAILABLE = 0x103E;
+       public final static int CL_DEVICE_BUILT_IN_KERNELS = 0x103F;
+       public final static int CL_DEVICE_IMAGE_MAX_BUFFER_SIZE = 0x1040;
+       public final static int CL_DEVICE_IMAGE_MAX_ARRAY_SIZE = 0x1041;
+       public final static int CL_DEVICE_PARENT_DEVICE = 0x1042;
+       public final static int CL_DEVICE_PARTITION_MAX_SUB_DEVICES = 0x1043;
+       public final static int CL_DEVICE_PARTITION_PROPERTIES = 0x1044;
+       public final static int CL_DEVICE_PARTITION_AFFINITY_DOMAIN = 0x1045;
+       public final static int CL_DEVICE_PARTITION_TYPE = 0x1046;
+       public final static int CL_DEVICE_REFERENCE_COUNT = 0x1047;
+       public final static int CL_DEVICE_PREFERRED_INTEROP_USER_SYNC = 0x1048;
+       public final static int CL_DEVICE_PRINTF_BUFFER_SIZE = 0x1049;
+       public final static int CL_DEVICE_IMAGE_PITCH_ALIGNMENT = 0x104A;
+       public final static int CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT = 0x104B;
+       // Added in 2.0
+       public final static int CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS = 0x104C;
+       public final static int CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE = 0x104D;
+       public final static int CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES = 0x104E;
+       public final static int CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE = 0x104F;
+       public final static int CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE = 0x1050;
+       public final static int CL_DEVICE_MAX_ON_DEVICE_QUEUES = 0x1051;
+       public final static int CL_DEVICE_MAX_ON_DEVICE_EVENTS = 0x1052;
+       public final static int CL_DEVICE_SVM_CAPABILITIES = 0x1053;
+       public final static int CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE = 0x1054;
+       public final static int CL_DEVICE_MAX_PIPE_ARGS = 0x1055;
+       public final static int CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS = 0x1056;
+       public final static int CL_DEVICE_PIPE_MAX_PACKET_SIZE = 0x1057;
+       public final static int CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT = 0x1058;
+       public final static int CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT = 0x1059;
+       public final static int CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT = 0x105A;
+       // Added in 2.1
+       public final static int CL_DEVICE_IL_VERSION = 0x105B;
+       public final static int CL_DEVICE_MAX_NUM_SUB_GROUPS = 0x105C;
+       public final static int CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS = 0x105D;
+
+       /* cl_device_fp_config - bitfield */
+       public final static long CL_FP_DENORM = (1 << 0);
+       public final static long CL_FP_INF_NAN = (1 << 1);
+       public final static long CL_FP_ROUND_TO_NEAREST = (1 << 2);
+       public final static long CL_FP_ROUND_TO_ZERO = (1 << 3);
+       public final static long CL_FP_ROUND_TO_INF = (1 << 4);
+       public final static long CL_FP_FMA = (1 << 5);
+       public final static long CL_FP_SOFT_FLOAT = (1 << 6);
+       public final static long CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT = (1 << 7);
+
+       /* cl_device_mem_cache_type */
+       public final static int CL_NONE = 0x0;
+       public final static int CL_READ_ONLY_CACHE = 0x1;
+       public final static int CL_READ_WRITE_CACHE = 0x2;
+
+       /* cl_device_local_mem_type */
+       public final static int CL_LOCAL = 0x1;
+       public final static int CL_GLOBAL = 0x2;
+
+       /* cl_device_exec_capabilities - bitfield */
+       public final static long CL_EXEC_KERNEL = (1 << 0);
+       public final static long CL_EXEC_NATIVE_KERNEL = (1 << 1);
+
+       /* cl_command_queue_properties - bitfield */
+       public final static long CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE = (1 << 0);
+       public final static long CL_QUEUE_PROFILING_ENABLE = (1 << 1);
+       // 2.0
+       public final static long CL_QUEUE_ON_DEVICE = (1 << 2);
+       public final static long CL_QUEUE_ON_DEVICE_DEFAULT = (1 << 3);
+
+       /* cl_context_info  */
+       public final static int CL_CONTEXT_REFERENCE_COUNT = 0x1080;
+       public final static int CL_CONTEXT_DEVICES = 0x1081;
+       public final static int CL_CONTEXT_PROPERTIES = 0x1082;
+       public final static int CL_CONTEXT_NUM_DEVICES = 0x1083;
+
+       /* cl_context_properties */
+       public final static int CL_CONTEXT_PLATFORM = 0x1084;
+       public final static int CL_CONTEXT_INTEROP_USER_SYNC = 0x1085;
+
+       /* cl_device_partition_property */
+       public final static int CL_DEVICE_PARTITION_EQUALLY = 0x1086;
+       public final static int CL_DEVICE_PARTITION_BY_COUNTS = 0x1087;
+       public final static int CL_DEVICE_PARTITION_BY_COUNTS_LIST_END = 0x0;
+       public final static int CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN = 0x1088;
+
+       /* cl_device_affinity_domain */
+       public final static long CL_DEVICE_AFFINITY_DOMAIN_NUMA = (1 << 0);
+       public final static long CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE = (1 << 1);
+       public final static long CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE = (1 << 2);
+       public final static long CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE = (1 << 3);
+       public final static long CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE = (1 << 4);
+       public final static long CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE = (1 << 5);
+
+       /* cl_device_svm_capabilities */
+       // 2.0
+       public final static long CL_DEVICE_SVM_COARSE_GRAIN_BUFFER = (1 << 0);
+       public final static long CL_DEVICE_SVM_FINE_GRAIN_BUFFER = (1 << 1);
+       public final static long CL_DEVICE_SVM_FINE_GRAIN_SYSTEM = (1 << 2);
+       public final static long CL_DEVICE_SVM_ATOMICS = (1 << 3);
+
+       /* cl_command_queue_info */
+       public final static int CL_QUEUE_CONTEXT = 0x1090;
+       public final static int CL_QUEUE_DEVICE = 0x1091;
+       public final static int CL_QUEUE_REFERENCE_COUNT = 0x1092;
+       public final static int CL_QUEUE_PROPERTIES = 0x1093;
+       // 2.0
+       public final static int CL_QUEUE_SIZE = 0x1094;
+       // 2.1
+       public final static int CL_QUEUE_DEVICE_DEFAULT = 0x1095;
+
+       /* cl_mem_flags - bitfield */
+       public final static long CL_MEM_READ_WRITE = (1 << 0);
+       public final static long CL_MEM_WRITE_ONLY = (1 << 1);
+       public final static long CL_MEM_READ_ONLY = (1 << 2);
+       public final static long CL_MEM_USE_HOST_PTR = (1 << 3);
+       public final static long CL_MEM_ALLOC_HOST_PTR = (1 << 4);
+       public final static long CL_MEM_COPY_HOST_PTR = (1 << 5);
+// reserved                                         (1 << 6)    
+       public final static long CL_MEM_HOST_WRITE_ONLY = (1 << 7);
+       public final static long CL_MEM_HOST_READ_ONLY = (1 << 8);
+       public final static long CL_MEM_HOST_NO_ACCESS = (1 << 9);
+       // 2.0
+       /* used by cl_svm_mem_flags only */
+       public final static long CL_MEM_SVM_FINE_GRAIN_BUFFER = (1 << 10);
+       /* used by cl_svm_mem_flags only */
+       public final static long CL_MEM_SVM_ATOMICS = (1 << 11);
+       public final static long CL_MEM_KERNEL_READ_AND_WRITE = (1 << 12);
+
+       /* cl_mem_migration_flags - bitfield */
+       public final static long CL_MIGRATE_MEM_OBJECT_HOST = (1 << 0);
+       public final static long CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED = (1 << 1);
+
+       /* cl_channel_order */
+       public final static int CL_R = 0x10B0;
+       public final static int CL_A = 0x10B1;
+       public final static int CL_RG = 0x10B2;
+       public final static int CL_RA = 0x10B3;
+       public final static int CL_RGB = 0x10B4;
+       public final static int CL_RGBA = 0x10B5;
+       public final static int CL_BGRA = 0x10B6;
+       public final static int CL_ARGB = 0x10B7;
+       public final static int CL_INTENSITY = 0x10B8;
+       public final static int CL_LUMINANCE = 0x10B9;
+       public final static int CL_Rx = 0x10BA;
+       public final static int CL_RGx = 0x10BB;
+       public final static int CL_RGBx = 0x10BC;
+       public final static int CL_DEPTH = 0x10BD;
+       public final static int CL_DEPTH_STENCIL = 0x10BE;
+       // Since 2.0 (or 1.2?)
+       public final static int CL_sRGB = 0x10BF;
+       public final static int CL_sRGBx = 0x10C0;
+       public final static int CL_sRGBA = 0x10C1;
+       public final static int CL_sBGRA = 0x10C2;
+       public final static int CL_ABGR = 0x10C3;
+
+       /* cl_channel_type */
+       public final static int CL_SNORM_INT8 = 0x10D0;
+       public final static int CL_SNORM_INT16 = 0x10D1;
+       public final static int CL_UNORM_INT8 = 0x10D2;
+       public final static int CL_UNORM_INT16 = 0x10D3;
+       public final static int CL_UNORM_SHORT_565 = 0x10D4;
+       public final static int CL_UNORM_SHORT_555 = 0x10D5;
+       public final static int CL_UNORM_INT_101010 = 0x10D6;
+       public final static int CL_SIGNED_INT8 = 0x10D7;
+       public final static int CL_SIGNED_INT16 = 0x10D8;
+       public final static int CL_SIGNED_INT32 = 0x10D9;
+       public final static int CL_UNSIGNED_INT8 = 0x10DA;
+       public final static int CL_UNSIGNED_INT16 = 0x10DB;
+       public final static int CL_UNSIGNED_INT32 = 0x10DC;
+       public final static int CL_HALF_FLOAT = 0x10DD;
+       public final static int CL_FLOAT = 0x10DE;
+       public final static int CL_UNORM_INT24 = 0x10DF;
+       // Since OpenCL 2.1?
+       public final static int CL_UNORM_INT_101010_2 = 0x10E0;
+
+       /* cl_mem_object_type */
+       public final static int CL_MEM_OBJECT_BUFFER = 0x10F0;
+       public final static int CL_MEM_OBJECT_IMAGE2D = 0x10F1;
+       public final static int CL_MEM_OBJECT_IMAGE3D = 0x10F2;
+       public final static int CL_MEM_OBJECT_IMAGE2D_ARRAY = 0x10F3;
+       public final static int CL_MEM_OBJECT_IMAGE1D = 0x10F4;
+       public final static int CL_MEM_OBJECT_IMAGE1D_ARRAY = 0x10F5;
+       public final static int CL_MEM_OBJECT_IMAGE1D_BUFFER = 0x10F6;
+       // 2.0
+       public final static int CL_MEM_OBJECT_PIPE = 0x10F7;
+
+       /* cl_mem_info */
+       public final static int CL_MEM_TYPE = 0x1100;
+       public final static int CL_MEM_FLAGS = 0x1101;
+       public final static int CL_MEM_SIZE = 0x1102;
+       public final static int CL_MEM_HOST_PTR = 0x1103;
+       public final static int CL_MEM_MAP_COUNT = 0x1104;
+       public final static int CL_MEM_REFERENCE_COUNT = 0x1105;
+       public final static int CL_MEM_CONTEXT = 0x1106;
+       public final static int CL_MEM_ASSOCIATED_MEMOBJECT = 0x1107;
+       public final static int CL_MEM_OFFSET = 0x1108;
+       // 2.0
+       public final static int CL_MEM_USES_SVM_POINTER = 0x1109;
+
+       /* cl_image_info */
+       public final static int CL_IMAGE_FORMAT = 0x1110;
+       public final static int CL_IMAGE_ELEMENT_SIZE = 0x1111;
+       public final static int CL_IMAGE_ROW_PITCH = 0x1112;
+       public final static int CL_IMAGE_SLICE_PITCH = 0x1113;
+       public final static int CL_IMAGE_WIDTH = 0x1114;
+       public final static int CL_IMAGE_HEIGHT = 0x1115;
+       public final static int CL_IMAGE_DEPTH = 0x1116;
+       public final static int CL_IMAGE_ARRAY_SIZE = 0x1117;
+       public final static int CL_IMAGE_BUFFER = 0x1118;
+       public final static int CL_IMAGE_NUM_MIP_LEVELS = 0x1119;
+       public final static int CL_IMAGE_NUM_SAMPLES = 0x111A;
+
+       /* cl_pipe_info */
+       public final static int CL_PIPE_PACKET_SIZE = 0x1120;
+       public final static int CL_PIPE_MAX_PACKETS = 0x1121;
+
+       /* cl_addressing_mode */
+       public final static int CL_ADDRESS_NONE = 0x1130;
+       public final static int CL_ADDRESS_CLAMP_TO_EDGE = 0x1131;
+       public final static int CL_ADDRESS_CLAMP = 0x1132;
+       public final static int CL_ADDRESS_REPEAT = 0x1133;
+       public final static int CL_ADDRESS_MIRRORED_REPEAT = 0x1134;
+
+       /* cl_filter_mode */
+       public final static int CL_FILTER_NEAREST = 0x1140;
+       public final static int CL_FILTER_LINEAR = 0x1141;
+
+       /* cl_sampler_info */
+       public final static int CL_SAMPLER_REFERENCE_COUNT = 0x1150;
+       public final static int CL_SAMPLER_CONTEXT = 0x1151;
+       public final static int CL_SAMPLER_NORMALIZED_COORDS = 0x1152;
+       public final static int CL_SAMPLER_ADDRESSING_MODE = 0x1153;
+       public final static int CL_SAMPLER_FILTER_MODE = 0x1154;
+       // 2.0 (or 1.2)
+       public final static int CL_SAMPLER_MIP_FILTER_MODE = 0x1155;
+       public final static int CL_SAMPLER_LOD_MIN = 0x1156;
+       public final static int CL_SAMPLER_LOD_MAX = 0x1157;
+
+       /* cl_map_flags - bitfield */
+       public final static long CL_MAP_READ = (1 << 0);
+       public final static long CL_MAP_WRITE = (1 << 1);
+       public final static long CL_MAP_WRITE_INVALIDATE_REGION = (1 << 2);
+
+       /* cl_program_info */
+       public final static int CL_PROGRAM_REFERENCE_COUNT = 0x1160;
+       public final static int CL_PROGRAM_CONTEXT = 0x1161;
+       public final static int CL_PROGRAM_NUM_DEVICES = 0x1162;
+       public final static int CL_PROGRAM_DEVICES = 0x1163;
+       public final static int CL_PROGRAM_SOURCE = 0x1164;
+       public final static int CL_PROGRAM_BINARY_SIZES = 0x1165;
+       public final static int CL_PROGRAM_BINARIES = 0x1166;
+       public final static int CL_PROGRAM_NUM_KERNELS = 0x1167;
+       public final static int CL_PROGRAM_KERNEL_NAMES = 0x1168;
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_PROGRAM_IL = 0x1169;
+
+       /* cl_program_build_info */
+       public final static int CL_PROGRAM_BUILD_STATUS = 0x1181;
+       public final static int CL_PROGRAM_BUILD_OPTIONS = 0x1182;
+       public final static int CL_PROGRAM_BUILD_LOG = 0x1183;
+       public final static int CL_PROGRAM_BINARY_TYPE = 0x1184;
+       // 2.0 (or 1.2)
+       public final static int CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE = 0x1185;
+
+       /* cl_program_binary_type */
+       public final static int CL_PROGRAM_BINARY_TYPE_NONE = 0x0;
+       public final static int CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT = 0x1;
+       public final static int CL_PROGRAM_BINARY_TYPE_LIBRARY = 0x2;
+       public final static int CL_PROGRAM_BINARY_TYPE_EXECUTABLE = 0x4;
+
+       /* cl_build_status */
+       public final static int CL_BUILD_SUCCESS = 0;
+       public final static int CL_BUILD_NONE = -1;
+       public final static int CL_BUILD_ERROR = -2;
+       public final static int CL_BUILD_IN_PROGRESS = -3;
+
+       /* cl_kernel_info */
+       public final static int CL_KERNEL_FUNCTION_NAME = 0x1190;
+       public final static int CL_KERNEL_NUM_ARGS = 0x1191;
+       public final static int CL_KERNEL_REFERENCE_COUNT = 0x1192;
+       public final static int CL_KERNEL_CONTEXT = 0x1193;
+       public final static int CL_KERNEL_PROGRAM = 0x1194;
+       public final static int CL_KERNEL_ATTRIBUTES = 0x1195;
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_MAX_NUM_SUB_GROUPS = 0x11B9;
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_COMPILE_NUM_SUB_GROUPS = 0x11BA;
+
+       /* cl_kernel_arg_info */
+       public final static int CL_KERNEL_ARG_ADDRESS_QUALIFIER = 0x1196;
+       public final static int CL_KERNEL_ARG_ACCESS_QUALIFIER = 0x1197;
+       public final static int CL_KERNEL_ARG_TYPE_NAME = 0x1198;
+       public final static int CL_KERNEL_ARG_TYPE_QUALIFIER = 0x1199;
+       public final static int CL_KERNEL_ARG_NAME = 0x119A;
+
+       /* cl_kernel_arg_address_qualifier */
+       public final static int CL_KERNEL_ARG_ADDRESS_GLOBAL = 0x119B;
+       public final static int CL_KERNEL_ARG_ADDRESS_LOCAL = 0x119C;
+       public final static int CL_KERNEL_ARG_ADDRESS_CONSTANT = 0x119D;
+       public final static int CL_KERNEL_ARG_ADDRESS_PRIVATE = 0x119E;
+
+       /* cl_kernel_arg_access_qualifier */
+       public final static int CL_KERNEL_ARG_ACCESS_READ_ONLY = 0x11A0;
+       public final static int CL_KERNEL_ARG_ACCESS_WRITE_ONLY = 0x11A1;
+       public final static int CL_KERNEL_ARG_ACCESS_READ_WRITE = 0x11A2;
+       public final static int CL_KERNEL_ARG_ACCESS_NONE = 0x11A3;
+
+       /* cl_kernel_arg_type_qualifer */
+       public final static long CL_KERNEL_ARG_TYPE_NONE = 0;
+       public final static long CL_KERNEL_ARG_TYPE_CONST = (1 << 0);
+       public final static long CL_KERNEL_ARG_TYPE_RESTRICT = (1 << 1);
+       public final static long CL_KERNEL_ARG_TYPE_VOLATILE = (1 << 2);
+       // Since 2.0
+       public final static long CL_KERNEL_ARG_TYPE_PIPE = (1 << 3);
+
+       /* cl_kernel_work_group_info */
+       public final static int CL_KERNEL_WORK_GROUP_SIZE = 0x11B0;
+       public final static int CL_KERNEL_COMPILE_WORK_GROUP_SIZE = 0x11B1;
+       public final static int CL_KERNEL_LOCAL_MEM_SIZE = 0x11B2;
+       public final static int CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE = 0x11B3;
+       public final static int CL_KERNEL_PRIVATE_MEM_SIZE = 0x11B4;
+       public final static int CL_KERNEL_GLOBAL_WORK_SIZE = 0x11B5;
+
+       /* cl_kernel_sub_group_info */
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE = 0x2033;
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE = 0x2034;
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT = 0x11B8;
+
+       /* cl_kernel_exec_info */
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_EXEC_INFO_SVM_PTRS = 0x11B6;
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM = 0x11B7;
+
+       /* cl_event_info  */
+       public final static int CL_EVENT_COMMAND_QUEUE = 0x11D0;
+       public final static int CL_EVENT_COMMAND_TYPE = 0x11D1;
+       public final static int CL_EVENT_REFERENCE_COUNT = 0x11D2;
+       public final static int CL_EVENT_COMMAND_EXECUTION_STATUS = 0x11D3;
+       public final static int CL_EVENT_CONTEXT = 0x11D4;
+
+       /* cl_command_type */
+       public final static int CL_COMMAND_NDRANGE_KERNEL = 0x11F0;
+       public final static int CL_COMMAND_TASK = 0x11F1;
+       public final static int CL_COMMAND_NATIVE_KERNEL = 0x11F2;
+       public final static int CL_COMMAND_READ_BUFFER = 0x11F3;
+       public final static int CL_COMMAND_WRITE_BUFFER = 0x11F4;
+       public final static int CL_COMMAND_COPY_BUFFER = 0x11F5;
+       public final static int CL_COMMAND_READ_IMAGE = 0x11F6;
+       public final static int CL_COMMAND_WRITE_IMAGE = 0x11F7;
+       public final static int CL_COMMAND_COPY_IMAGE = 0x11F8;
+       public final static int CL_COMMAND_COPY_IMAGE_TO_BUFFER = 0x11F9;
+       public final static int CL_COMMAND_COPY_BUFFER_TO_IMAGE = 0x11FA;
+       public final static int CL_COMMAND_MAP_BUFFER = 0x11FB;
+       public final static int CL_COMMAND_MAP_IMAGE = 0x11FC;
+       public final static int CL_COMMAND_UNMAP_MEM_OBJECT = 0x11FD;
+       public final static int CL_COMMAND_MARKER = 0x11FE;
+       public final static int CL_COMMAND_ACQUIRE_GL_OBJECTS = 0x11FF;
+       public final static int CL_COMMAND_RELEASE_GL_OBJECTS = 0x1200;
+       public final static int CL_COMMAND_READ_BUFFER_RECT = 0x1201;
+       public final static int CL_COMMAND_WRITE_BUFFER_RECT = 0x1202;
+       public final static int CL_COMMAND_COPY_BUFFER_RECT = 0x1203;
+       public final static int CL_COMMAND_USER = 0x1204;
+       public final static int CL_COMMAND_BARRIER = 0x1205;
+       public final static int CL_COMMAND_MIGRATE_MEM_OBJECTS = 0x1206;
+       public final static int CL_COMMAND_FILL_BUFFER = 0x1207;
+       public final static int CL_COMMAND_FILL_IMAGE = 0x1208;
+       // 2.0
+       public final static int CL_COMMAND_SVM_FREE = 0x1209;
+       public final static int CL_COMMAND_SVM_MEMCPY = 0x120A;
+       public final static int CL_COMMAND_SVM_MEMFILL = 0x120B;
+       public final static int CL_COMMAND_SVM_MAP = 0x120C;
+       public final static int CL_COMMAND_SVM_UNMAP = 0x120D;
+
+       /* command execution status */
+       public final static int CL_COMPLETE = 0x0;
+       public final static int CL_RUNNING = 0x1;
+       public final static int CL_SUBMITTED = 0x2;
+       public final static int CL_QUEUED = 0x3;
+
+       /* cl_buffer_create_type  */
+       public final static int CL_BUFFER_CREATE_TYPE_REGION = 0x1220;
+
+       /* cl_profiling_info  */
+       public final static int CL_PROFILING_COMMAND_QUEUED = 0x1280;
+       public final static int CL_PROFILING_COMMAND_SUBMIT = 0x1281;
+       public final static int CL_PROFILING_COMMAND_START = 0x1282;
+       public final static int CL_PROFILING_COMMAND_END = 0x1283;
+       public final static int CL_PROFILING_COMMAND_COMPLETE = 0x1284;
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLBuffer.java b/src/notzed.zcl/classes/au/notzed/zcl/CLBuffer.java
new file mode 100644 (file)
index 0000000..731823a
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Interface for memory buffers.
+ * <p>
+ */
+public class CLBuffer extends CLMemory {
+
+       /**
+        * Use USE_HOST_PTR was used then this keeps track of the host ptr reference
+        * to avoid java freeing it.
+        */
+       private final ByteBuffer hostPtr;
+
+       /**
+        * Create an interface for a native pointer of type cl_mem that refers to a
+        * buffer object.
+        *
+        * @param p Native pointer.
+        */
+       public CLBuffer(long p) {
+               super(p);
+               hostPtr = null;
+       }
+
+       public CLBuffer(long p, ByteBuffer hostPtr) {
+               super(p);
+
+               this.hostPtr = hostPtr;
+       }
+
+       static void release(long p) {
+               CLMemory.release(p);
+       }
+
+       @Override
+       int getInfoType() {
+               return TYPE_MEM_OBJECT;
+       }
+
+       @Override
+       public ByteBuffer getHostPtr() {
+               return hostPtr;
+       }
+
+       /**
+        * Parameter to define a region for createSubBuffer().
+        *
+        * @param origin Offset into buffer.
+        * @param size Size of sub-buffer.
+        * @see #createSubBuffer
+        * @return
+        */
+       public static CLBufferInfo REGION(long origin, long size) {
+               return new CLBufferInfo.Region(origin, size);
+       }
+
+       /**
+        * Call clCreateSubBuffer.
+        *
+        * @param flags
+        * @param info Define the properties for the sub-bufer.
+        * @return A newly created buffer.<p>
+        * It must be released when no longer needed.
+        * @see #REGION
+        * @throws CLException
+        * @since OpenCL 1.1
+        */
+       public native CLBuffer createSubBuffer(long flags, CLBufferInfo info) throws CLException;
+
+       /*
+        Functional Interface Constructors.
+        */
+       public CLTask ofRead(byte[] target) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueReadBuffer(CLBuffer.this, true, 0, target.length, target, 0, waiters, events);
+               };
+       }
+
+       public CLTask ofRead(short[] target) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueReadBuffer(CLBuffer.this, true, 0, target.length, target, 0, waiters, events);
+               };
+       }
+
+       public CLTask ofRead(int[] target) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueReadBuffer(CLBuffer.this, true, 0, target.length, target, 0, waiters, events);
+               };
+       }
+
+       public CLTask ofRead(float[] target) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueReadBuffer(CLBuffer.this, true, 0, target.length, target, 0, waiters, events);
+               };
+       }
+
+       public CLTask ofRead(int offset, int length, float[] target, int toff) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueReadBuffer(CLBuffer.this, true, offset, length, target, toff, waiters, events);
+               };
+       }
+
+       public CLTask ofRead(ByteBuffer target, boolean blocking) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueReadBuffer(this, blocking, 0, target.limit() - target.position(), target, waiters, events);
+               };
+       }
+
+       public CLTask ofWrite(byte[] source) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueWriteBuffer(CLBuffer.this, true, 0, source.length, source, 0, waiters, events);
+               };
+       }
+
+       public CLTask ofWrite(short[] source) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueWriteBuffer(CLBuffer.this, true, 0, source.length, source, 0, waiters, events);
+               };
+       }
+
+       public CLTask ofWrite(int[] source) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueWriteBuffer(CLBuffer.this, true, 0, source.length, source, 0, waiters, events);
+               };
+       }
+
+       public CLTask ofWrite(float[] source) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueWriteBuffer(CLBuffer.this, true, 0, source.length, source, 0, waiters, events);
+               };
+       }
+
+       public CLTask ofWrite(ByteBuffer source, boolean blocking) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueWriteBuffer(this, blocking, 0, source.limit() - source.position(), source, waiters, events);
+               };
+       }
+
+       public CLTask ofFill(float... pattern) {
+               long count = getSize() / 4 / pattern.length;
+
+               return (CLCommandQueue q, CLEventList wait, CLEventList event) -> {
+                       q.enqueueFillBuffer(this, pattern, 0, count, wait, event);
+               };
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLBufferInfo.java b/src/notzed.zcl/classes/au/notzed/zcl/CLBufferInfo.java
new file mode 100644 (file)
index 0000000..94ef9ec
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Parameters for Buffer.createSubBuffer()
+ * <p>
+ * Specific types are defined on CLBuffer.
+ * 
+ */
+public abstract class CLBufferInfo {
+
+       static class Region extends CLBufferInfo {
+
+               final long origin;
+               final long size;
+
+               Region(long origin, long size) {
+                       this.origin = origin;
+                       this.size = size;
+               }
+
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLChannelOrder.java b/src/notzed.zcl/classes/au/notzed/zcl/CLChannelOrder.java
new file mode 100644 (file)
index 0000000..5bd6e47
--- /dev/null
@@ -0,0 +1,114 @@
+/**
+ * *****************************************************************************
+ * Copyright (c) 2008 - 2013 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.
+ *
+ * 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.
+ * ****************************************************************************
+ */
+package au.notzed.zcl;
+
+/**
+ * Enum for wrapping the cl_channel_order constants from cl.h.
+ *
+ * This is mostly useful for printing them out.
+ */
+public enum CLChannelOrder {
+
+       CL_R(CL.CL_R),
+       CL_A(CL.CL_A),
+       CL_RG(CL.CL_RG),
+       CL_RA(CL.CL_RA),
+       CL_RGB(CL.CL_RGB),
+       CL_RGBA(CL.CL_RGBA),
+       CL_BGRA(CL.CL_BGRA),
+       CL_ARGB(CL.CL_ARGB),
+       CL_INTENSITY(CL.CL_INTENSITY),
+       CL_LUMINANCE(CL.CL_LUMINANCE),
+       CL_Rx(CL.CL_Rx),
+       CL_RGx(CL.CL_RGx),
+       CL_RGBx(CL.CL_RGBx),
+       CL_DEPTH(CL.CL_DEPTH),
+       CL_DEPTH_STENCIL(CL.CL_DEPTH_STENCIL),
+       CL_sRGB(CL.CL_sRGB),
+       CL_sRGBx(CL.CL_sRGBx),
+       CL_sRGBA(CL.CL_sRGBA),
+       CL_sBGRA(CL.CL_sBGRA),
+       CL_ABGR(CL.CL_ABGR);
+
+       int id;
+
+       private CLChannelOrder(int id) {
+               this.id = id;
+       }
+
+       /**
+        * Converts an OpenCL channel order constant into the corresponding CLChannelOrder enumeration.
+        *
+        * @param id
+        * @return
+        * @throws EnumConstantNotPresentException if id is not a channel order.
+        */
+       static public CLChannelOrder fromC(int id) {
+               switch (id) {
+               case CL.CL_R:
+                       return CL_R;
+               case CL.CL_A:
+                       return CL_A;
+               case CL.CL_RG:
+                       return CL_RG;
+               case CL.CL_RA:
+                       return CL_RA;
+               case CL.CL_RGB:
+                       return CL_RGB;
+               case CL.CL_RGBA:
+                       return CL_RGBA;
+               case CL.CL_BGRA:
+                       return CL_BGRA;
+               case CL.CL_ARGB:
+                       return CL_ARGB;
+               case CL.CL_INTENSITY:
+                       return CL_INTENSITY;
+               case CL.CL_LUMINANCE:
+                       return CL_LUMINANCE;
+               case CL.CL_Rx:
+                       return CL_Rx;
+               case CL.CL_RGx:
+                       return CL_RGx;
+               case CL.CL_RGBx:
+                       return CL_RGBx;
+               case CL.CL_DEPTH:
+                       return CL_DEPTH;
+               case CL.CL_DEPTH_STENCIL:
+                       return CL_DEPTH_STENCIL;
+               case CL.CL_sRGB:
+                       return CL_sRGB;
+               case CL.CL_sRGBx:
+                       return CL_sRGBx;
+               case CL.CL_sRGBA:
+                       return CL_sRGBA;
+               case CL.CL_sBGRA:
+                       return CL_sBGRA;
+               case CL.CL_ABGR:
+                       return CL_ABGR;
+
+               default:
+                       throw new EnumConstantNotPresentException(CLChannelOrder.class, Integer.toString(id));
+               }
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLChannelType.java b/src/notzed.zcl/classes/au/notzed/zcl/CLChannelType.java
new file mode 100644 (file)
index 0000000..4402bdd
--- /dev/null
@@ -0,0 +1,102 @@
+/**
+ * *****************************************************************************
+ * Copyright (c) 2008 - 2012 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.
+ *
+ * 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.
+ * ****************************************************************************
+ */
+package au.notzed.zcl;
+
+/**
+ * Enum for wrapping the cl_channel_type constants from cl.h.
+ *
+ * This is mostly useful for printing them out.
+ */
+public enum CLChannelType {
+
+       CL_SNORM_INT8(CL.CL_SNORM_INT8),
+       CL_SNORM_INT16(CL.CL_SNORM_INT16),
+       CL_UNORM_INT8(CL.CL_UNORM_INT8),
+       CL_UNORM_INT16(CL.CL_UNORM_INT16),
+       CL_UNORM_SHORT_565(CL.CL_UNORM_SHORT_565),
+       CL_UNORM_SHORT_555(CL.CL_UNORM_SHORT_555),
+       CL_UNORM_INT_101010(CL.CL_UNORM_INT_101010),
+       CL_SIGNED_INT8(CL.CL_SIGNED_INT8),
+       CL_SIGNED_INT16(CL.CL_SIGNED_INT16),
+       CL_SIGNED_INT32(CL.CL_SIGNED_INT32),
+       CL_UNSIGNED_INT8(CL.CL_UNSIGNED_INT8),
+       CL_UNSIGNED_INT16(CL.CL_UNSIGNED_INT16),
+       CL_UNSIGNED_INT32(CL.CL_UNSIGNED_INT32),
+       CL_HALF_FLOAT(CL.CL_HALF_FLOAT),
+       CL_FLOAT(CL.CL_FLOAT),
+       CL_UNORM_INT24(CL.CL_UNORM_INT24);
+
+       int id;
+
+       private CLChannelType(int id) {
+               this.id = id;
+       }
+
+       /**
+        * Converts an OpenCL channel type constant into the corresponding CLChannelType enumeration.
+        *
+        * @param id
+        * @return
+        * @throws EnumConstantNotPresentException if id is not a channel type.
+        */
+       static public CLChannelType fromC(int id) {
+               switch (id) {
+               case CL.CL_SNORM_INT8:
+                       return CL_SNORM_INT8;
+               case CL.CL_SNORM_INT16:
+                       return CL_SNORM_INT16;
+               case CL.CL_UNORM_INT8:
+                       return CL_UNORM_INT8;
+               case CL.CL_UNORM_INT16:
+                       return CL_UNORM_INT16;
+               case CL.CL_UNORM_SHORT_565:
+                       return CL_UNORM_SHORT_565;
+               case CL.CL_UNORM_SHORT_555:
+                       return CL_UNORM_SHORT_555;
+               case CL.CL_UNORM_INT_101010:
+                       return CL_UNORM_INT_101010;
+               case CL.CL_SIGNED_INT8:
+                       return CL_SIGNED_INT8;
+               case CL.CL_SIGNED_INT16:
+                       return CL_SIGNED_INT16;
+               case CL.CL_SIGNED_INT32:
+                       return CL_SIGNED_INT32;
+               case CL.CL_UNSIGNED_INT8:
+                       return CL_UNSIGNED_INT8;
+               case CL.CL_UNSIGNED_INT16:
+                       return CL_UNSIGNED_INT16;
+               case CL.CL_UNSIGNED_INT32:
+                       return CL_UNSIGNED_INT32;
+               case CL.CL_HALF_FLOAT:
+                       return CL_HALF_FLOAT;
+               case CL.CL_FLOAT:
+                       return CL_FLOAT;
+               case CL.CL_UNORM_INT24:
+                       return CL_UNORM_INT24;
+
+               default:
+                       throw new EnumConstantNotPresentException(CLChannelOrder.class, Integer.toString(id));
+               }
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java b/src/notzed.zcl/classes/au/notzed/zcl/CLCommandQueue.java
new file mode 100644 (file)
index 0000000..b8eadf5
--- /dev/null
@@ -0,0 +1,1103 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import java.nio.ByteBuffer;
+import static au.notzed.zcl.CL.*;
+import au.notzed.zcl.khr.GLSharing;
+
+/**
+ * Interface for cl_command_queue.
+ * <p>
+ * All of the offer calls will take two CLEventList arguments, a waitlist and an
+ * event list. These equate directly to the the num_events_in_wait_list,
+ * event_wait_list, and event arguments for the native OpenCL library calls.
+ * <ul>
+ * <li>For the waitlist list, all events it currently contains is used as the
+ * event_wait_list in the OpenCL call.
+ * <li>For the event list a local event is created for the OpenCL call. If the
+ * call was successful then the event created by the call is added to the event
+ * list.
+ * </ul>
+ * <p>
+ * For the offer operations which take arrays all offsets and sizes are in
+ * primitive element units and not bytes.
+ */
+public class CLCommandQueue extends CLExtendable {
+
+       /**
+        * Create an interface for a native pointer of type cl_command_queue.
+        *
+        * @param p Native pointer.
+        */
+       public CLCommandQueue(long p) {
+               super(p);
+       }
+
+       private native static void release(long p);
+
+       @Override
+       int getInfoType() {
+               return TYPE_COMMAND_QUEUE;
+       }
+
+       public static CLQueueProperty PROPERTIES(long flags) {
+               return new CLQueueProperty.TagValue(CL.CL_QUEUE_PROPERTIES, flags);
+       }
+
+       /**
+        * A convenience variable for the very common local work-size of 64,1,1
+        */
+       public static final long WORKSIZE_64x1x1[] = {64, 1, 1};
+       /**
+        * A convenience variable for the common local work-size of 1,1,64
+        */
+       public static final long WORKSIZE_1x1x64[] = {1, 1, 64};
+       /**
+        * A convenience variable for the very common local work-size of 8,8,1
+        */
+       public static final long WORKSIZE_8x8x1[] = {8, 8, 1};
+       public static final long WORKSIZE_16x16x1[] = {16, 16, 1};
+       /**
+        * A convenience variable for the very common global offset of 0,0,0
+        */
+       public static final long OFFSET_0x0x0[] = {0, 0, 0};
+
+       /**
+        * Calls clFlush.
+        *
+        * @throws CLException
+        */
+       public native void flush() throws CLException;
+
+       /**
+        * Calls clFinish.
+        *
+        * @throws CLException
+        */
+       public native void finish() throws CLException;
+
+       /**
+        * Calls clEnqueueReadBuffer for a direct Buffer.
+        *
+        * @param mem
+        * @param blocking
+        * @param mem_offset source memory offset in bytes.
+        * @param size memory transfer size in bytes.
+        * @param buffer destination buffer. Must be a direct buffer.
+        * @param wait
+        * @param event
+        * @throws CLException
+        */
+       native public void enqueueReadBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               ByteBuffer buffer,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       /**
+        * Calls clEnqueueReadBuffer for a byte array.
+        *
+        * @param mem
+        * @param blocking ignored, array reads are always blocking.
+        * @param mem_offset source memory offset in bytes.
+        * @param size memory transfer size in bytes.
+        * @param buffer destination array.
+        * @param buf_offset destination buffer offset in bytes.
+        * @param wait
+        * @param event
+        * @throws CLException
+        */
+       native public void enqueueReadBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               byte[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       /**
+        * Calls clEnqueueReadBuffer for a short array.
+        *
+        * @param mem
+        * @param blocking ignored, array reads are always blocking.
+        * @param mem_offset source memory offset in shorts.
+        * @param size memory transfer size in shorts.
+        * @param buffer destination array.
+        * @param buf_offset destination buffer offset in shorts.
+        * @param wait
+        * @param event
+        * @throws CLException
+        */
+       native public void enqueueReadBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               short[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueReadBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               int[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueReadBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               long[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueReadBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               float[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueReadBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               double[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       /**
+        *
+        * @param mem
+        * @param blocking
+        * @param buffer_origin
+        * @param host_origin
+        * @param region
+        * @param buffer_row_pitch
+        * @param buffer_slice_pitch
+        * @param host_row_pitch
+        * @param host_slice_pitch
+        * @param buffer
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.1
+        */
+       public native void enqueueReadBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               ByteBuffer buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueReadBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               byte[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueReadBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               short[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueReadBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               int[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueReadBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               long[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueReadBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               float[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueReadBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               double[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       native public void enqueueWriteBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               ByteBuffer buffer,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueWriteBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               byte[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueWriteBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               short[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueWriteBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               int[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueWriteBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               long[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueWriteBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               float[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       native public void enqueueWriteBuffer(CLBuffer mem, boolean blocking,
+               long mem_offset, long size,
+               double[] buffer, long buf_offset,
+               CLEventList wait,
+               CLEventList event) throws CLException;
+
+       /**
+        *
+        * @param mem
+        * @param blocking
+        * @param buffer_origin
+        * @param host_origin
+        * @param region
+        * @param buffer_row_pitch
+        * @param buffer_slice_pitch
+        * @param host_row_pitch
+        * @param host_slice_pitch
+        * @param buffer
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.1
+        */
+       public native void enqueueWriteBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               ByteBuffer buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueWriteBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               byte[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueWriteBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               short[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueWriteBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               int[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueWriteBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               long[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueWriteBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               float[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       public native void enqueueWriteBufferRect(CLBuffer mem, boolean blocking,
+               long[] buffer_origin, long[] host_origin, long[] region,
+               long buffer_row_pitch, long buffer_slice_pitch, long host_row_pitch, long host_slice_pitch,
+               double[] buffer,
+               CLEventList waiters, CLEventList events) throws CLException, UnsupportedOperationException;
+
+       /**
+        * Calls clEnqueueFillBuffer for byte types.
+        *
+        * @param buffer
+        * @param pattern pattern to fill
+        * @param offset offset in multiples of the pattern size.
+        * @param size number of elements in multiples of the pattern size.
+        * @param waiters
+        * @param events
+        * @since OpenCL 1.2
+        * @throws CLException
+        */
+       public native void enqueueFillBuffer(CLBuffer buffer,
+               byte[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls clEnqueueFillBuffer for short types.
+        *
+        * @param buffer
+        * @param pattern pattern to fill
+        * @param offset offset in multiples of the pattern size.
+        * @param size number of elements in multiples of the pattern size.
+        * @param waiters
+        * @param events
+        * @since OpenCL 1.2
+        * @throws CLException
+        */
+       public native void enqueueFillBuffer(CLBuffer buffer,
+               short[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls clEnqueueFillBuffer for integer types.
+        *
+        * @param buffer
+        * @param pattern pattern to fill
+        * @param offset offset in multiples of the pattern size.
+        * @param size number of elements in multiples of the pattern size.
+        * @param waiters
+        * @param events
+        * @since OpenCL 1.2
+        * @throws CLException
+        */
+       public native void enqueueFillBuffer(CLBuffer buffer,
+               int[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls clEnqueueFillBuffer for long types.
+        *
+        * @param buffer
+        * @param pattern pattern to fill
+        * @param offset offset in multiples of the pattern size.
+        * @param size number of elements in multiples of the pattern size.
+        * @param waiters
+        * @param events
+        * @since OpenCL 1.2
+        * @throws CLException
+        */
+       public native void enqueueFillBuffer(CLBuffer buffer,
+               long[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls clEnqueueFillBuffer for float types.
+        *
+        * @param buffer
+        * @param pattern pattern to fill
+        * @param offset offset in multiples of the pattern size.
+        * @param size number of elements in multiples of the pattern size.
+        * @param waiters
+        * @param events
+        * @since OpenCL 1.2
+        * @throws CLException
+        */
+       public native void enqueueFillBuffer(CLBuffer buffer,
+               float[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls clEnqueueFillBuffer for double types.
+        *
+        * @param buffer
+        * @param pattern pattern to fill
+        * @param offset offset in multiples of the pattern size.
+        * @param size number of elements in multiples of the pattern size.
+        * @param waiters
+        * @param events
+        * @since OpenCL 1.2
+        * @throws CLException
+        */
+       public native void enqueueFillBuffer(CLBuffer buffer,
+               double[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueCopyBuffer(CLBuffer srcmem, CLBuffer dstmem, long srcoffset, long dstoffset, long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * @param srcmem
+        * @param dstmem
+        * @param src_origin
+        * @param dst_origin
+        * @param region
+        * @param src_row_pitch
+        * @param src_slice_pitch
+        * @param dst_row_pitch
+        * @param dst_slice_pitch
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.1
+        */
+       public native void enqueueCopyBufferRect(CLBuffer srcmem, CLBuffer dstmem,
+               long[] src_origin,
+               long[] dst_origin,
+               long[] region,
+               long src_row_pitch,
+               long src_slice_pitch,
+               long dst_row_pitch,
+               long dst_slice_pitch,
+               CLEventList waiters,
+               CLEventList events) throws CLException, UnsupportedOperationException;
+
+       /**
+        *
+        * @param image
+        * @param blocking
+        * @param origin
+        * @param region
+        * @param row_pitch
+        * @param slice_pitch
+        * @param buffer the position is honoured and updated
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueReadImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               ByteBuffer buffer,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        *
+        * @param image
+        * @param blocking ignored, array reads are always blocking.
+        * @param origin
+        * @param region
+        * @param row_pitch in number of array elements
+        * @param slice_pitch in number of array elements
+        * @param buffer
+        * @param buff_offset in number of array elements
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueReadImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               byte[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueReadImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               short[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueReadImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               int[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueReadImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               long[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueReadImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               float[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueReadImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               double[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueWriteImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               ByteBuffer buffer,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueWriteImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               byte[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueWriteImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               short[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueWriteImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               int[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueWriteImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               long[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueWriteImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               float[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueWriteImage(CLImage image, boolean blocking,
+               long[] origin,
+               long[] region,
+               long row_pitch,
+               long slice_pitch,
+               double[] buffer, long buff_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls clEnqueueFillImage for images whose channel data type is
+        * unormalised signed or unsigned integral type.
+        *
+        * @param image
+        * @param colour 4-element RGBA components.
+        * @param origin 3-element origin.
+        * @param region 3-element region.
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @since OpenCL 1.2
+        */
+       public native void enqueueFillImage(CLImage image,
+               int[] colour,
+               long[] origin,
+               long[] region,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls clEnqueueFillImage for images whose channel data type is not an
+        * unormalised signed or unsigned integral type.
+        *
+        * @param image
+        * @param colour 4-element RGBA components.
+        * @param origin 3-element origin.
+        * @param region 3-element region.
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @since OpenCL 1.2
+        */
+       public native void enqueueFillImage(CLImage image,
+               float[] colour,
+               long[] origin,
+               long[] region,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueCopyImage(CLImage src, CLImage dst,
+               long[] src_origin,
+               long[] dst_origin,
+               long[] region,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueCopyImageToBuffer(CLImage src, CLBuffer dst,
+               long[] src_origin,
+               long[] region,
+               long dst_offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueCopyBufferToImage(CLBuffer src, CLImage dst,
+               long src_offset,
+               long[] dst_origin,
+               long[] region,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native ByteBuffer enqueueMapBuffer(CLBuffer buffer, boolean blocking,
+               long flags,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native ByteBuffer enqueueMapImage(CLImage image, boolean blocking,
+               long flags,
+               long[] origin,
+               long[] region,
+               long[] image_row_pitch,
+               long[] image_slice_pitch,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueUnmapMemObject(CLMemory mem, ByteBuffer mapped,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        *
+        * @param mems
+        * @param flags
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @since OpenCL 1.2
+        */
+       public native void enqueueMigrateMemObjects(CLMemory[] mems, long flags,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Call clEnqueueNDRangeKernel.
+        *
+        * @param kernel
+        * @param work_dim
+        * @param global_offset global offset values, must be work_dim elements long
+        * or null.
+        * @param global_size global size values, must be work_dim elements long and
+        * each element an even multiple of the corresponding local_size.
+        * @param local_size must be work_dim elements long or null.
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueNDRangeKernel(CLKernel kernel, int work_dim,
+               long[] global_offset,
+               long[] global_size,
+               long[] local_size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        *
+        * @param kernel
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @deprecated as of OpenCL 2.0
+        */
+       @Deprecated
+       public native void enqueueTask(CLKernel kernel,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Invoke a native kernel.
+        *
+        * @param kernel Kernel to invoke.
+        * @param waiters
+        * @param events
+        * @param args the kernel arguments. Any CLBuffer or CLImage parameters will
+        * be replaced by a ByteBuffer in the kernel.
+        * @throws CLException
+        */
+       public native void enqueueNativeKernel(
+               CLNativeKernel kernel,
+               CLEventList waiters,
+               CLEventList events,
+               Object... args) throws CLException;
+
+       /**
+        * Enqueues a marker point.
+        * <p>
+        * On OpenCL 1.1 this is emulated as <code>clEnqueueWaitForEvents</code>
+        * followed by <code>clEnqueueMarker</code>.
+        *
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueMarkerWithWaitList(
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Enqueues a barrier.
+        * <p>
+        * On OpenCL 1.1 this is emulated as <code>clEnqueueWaitForEvents</code>
+        * followed by <code>clEnqueueBarrier</code> then
+        * <code>clEnqueueMarker</code>.
+        *
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueBarrierWithWaitList(
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Call clEnqueueSVMFree().
+        * <p>
+        * All ByteBuffer's must have been explicitly allocated using
+        * CLContext.clSVMAlloc().
+        *
+        * @param svms
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @since OpenCL 2.0
+        */
+       public native void enqueueSVMFree(
+               ByteBuffer[] svms,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Call clEnqueueSVMMemcopy().
+        * <p>
+        * TODO: is the buffer+offset api ideal here?
+        *
+        * @param blocking
+        * @param dst destination buffer. The bytebuffer position is ignored.
+        * @param dstOffset offset into destination buffer.
+        * @param src source buffer. The bytebuffer position is ignored.
+        * @param srcOffset offset into source buffer.
+        * @param size number of bytes to copy
+        * @param waiters
+        * @param events
+        * @throws CLException
+        * @since OpenCL 2.0
+        */
+       public native void enqueueSVMMemcpy(boolean blocking,
+               ByteBuffer dst,
+               long dstOffset,
+               ByteBuffer src,
+               long srcOffset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Fill target with pattern.
+        *
+        * @param dst
+        * @param pattern pattern.
+        * @param offset offset into dst in terms of numbers of patterns, not bytes.
+        * @param patterns Number of patterns to fill, not bytes.
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueSVMMemFill(
+               ByteBuffer dst,
+               byte[] pattern,
+               long offset,
+               long patterns,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueSVMMemFill(
+               ByteBuffer dst,
+               short[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueSVMMemFill(
+               ByteBuffer dst,
+               int[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueSVMMemFill(
+               ByteBuffer dst,
+               long[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueSVMMemFill(
+               ByteBuffer dst,
+               float[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       public native void enqueueSVMMemFill(
+               ByteBuffer dst,
+               double[] pattern,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls clEnqueueSVNMap().
+        * <p>
+        * CHECKME: I don't know if an offset != 0 is allowed.
+        *
+        * @param blocking
+        * @param flags
+        * @param svm
+        * @param offset
+        * @param size
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueSVMMap(boolean blocking, long flags,
+               ByteBuffer svm,
+               long offset,
+               long size,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Must match a corresponding call to enqueueSVMMap (svm and offset).
+        *
+        * @param svm
+        * @param offset
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueSVMUnmap(
+               ByteBuffer svm,
+               long offset,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        *
+        * @param svms svm base mappings
+        * @param offsets optional offsets for buffers, same length as svms if
+        * supplied
+        * @param sizes optional sizes, otherwise length must match svms.
+        * @param flags
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public native void enqueueSVMMigrateMem(
+               ByteBuffer[] svms,
+               long[] offsets,
+               long[] sizes,
+               long flags,
+               CLEventList waiters,
+               CLEventList events) throws CLException;
+
+       /**
+        * Calls enqueueNDRangeKernel for 1 dimensional work.
+        *
+        * @param kernel
+        * @param offsetx
+        * @param global_sizex
+        * @param local_sizex
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public void enqueue1DKernel(CLKernel kernel, long offsetx, long global_sizex, long local_sizex, CLEventList waiters, CLEventList events) throws CLException {
+               enqueueNDRangeKernel(kernel, 1,
+                       new long[]{offsetx},
+                       new long[]{global_sizex},
+                       new long[]{local_sizex},
+                       waiters, events);
+       }
+
+       /**
+        * Calls enqueueNDRangeKernel for 2 dimensional work.
+        *
+        * @param kernel
+        * @param offsetx
+        * @param offsety
+        * @param global_sizex
+        * @param global_sizey
+        * @param local_sizex
+        * @param local_sizey
+        * @param waiters
+        * @param events
+        * @throws CLException
+        */
+       public void enqueue2DKernel(CLKernel kernel, long offsetx, long offsety, long global_sizex, long global_sizey, long local_sizex, long local_sizey, CLEventList waiters, CLEventList events) throws CLException {
+               enqueueNDRangeKernel(kernel, 2,
+                       new long[]{offsetx, offsety},
+                       new long[]{global_sizex, global_sizey},
+                       new long[]{local_sizex, local_sizey},
+                       waiters, events);
+       }
+
+       public CLContext getContext() {
+               return getInfoAny(CTYPE_CONTEXT, CL_QUEUE_CONTEXT);
+       }
+
+       public CLDevice getDevice() {
+               return getInfoAny(CTYPE_DEVICE, CL_QUEUE_DEVICE);
+       }
+
+       public long getProperties() {
+               return getInfoLong(CL_QUEUE_PROPERTIES);
+       }
+
+       /**
+        * @since OpenCL 2.0
+        * @return
+        */
+       public int getSize() {
+               return getInfoInt(CL_QUEUE_SIZE);
+       }
+
+       @Override
+       protected CLPlatform initPlatform() {
+               return getDevice().platform;
+       }
+
+       protected GLSharing getGLSharing() {
+               return getExtension(CLPlatform.cl_khr_gl_sharing);
+       }
+
+       /*
+        Experimental: Alternative interface to extensions.
+        */
+       public void enqueueAcquireGLObjects(
+               CLMemory[] mem_objects,
+               CLEventList waiters,
+               CLEventList events) {
+               getGLSharing().enqueueAcquireGLObjects(this, mem_objects, waiters, events);
+       }
+
+       public void enqueueReleaseGLObjects(
+               CLMemory[] mem_objects,
+               CLEventList waiters,
+               CLEventList events) {
+               getGLSharing().enqueueReleaseGLObjects(this, mem_objects, waiters, events);
+       }
+
+       /**
+        * Invoke task.queue for this queue with no event lists.
+        *
+        * @param task
+        * @return this
+        * @throws CLException
+        */
+       public CLCommandQueue offer(CLTask task) throws CLException {
+               return offer(task, null, null);
+
+       }
+
+       /**
+        * Invoke task.queue for this queue with only an output event lists.
+        *
+        * @param task
+        * @param event
+        * @return this
+        * @throws CLException
+        */
+       public CLCommandQueue offer(CLTask task, CLEventList event) throws CLException {
+               return offer(task, null, event);
+       }
+
+       /**
+        * Invoke task.queue for this queue with an input and output event lists.
+        *
+        * @param task
+        * @param event
+        * @param wait
+        * @return this
+        * @throws CLException
+        */
+       public CLCommandQueue offer(CLTask task, CLEventList wait, CLEventList event) throws CLException {
+               task.enqueue(this, wait, event);
+               return this;
+       }
+
+       /**
+        * Create a null task.
+        * <p>
+        * This enqueues a marker.
+        *
+        * @return
+        * @deprecated use CLTask.ofNOP() instead
+        */
+       @Deprecated
+       public static CLTask ofNOP() {
+               return (CLCommandQueue q, CLEventList wait, CLEventList event) -> {
+                       q.enqueueMarkerWithWaitList(wait, event);
+               };
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLCommandType.java b/src/notzed.zcl/classes/au/notzed/zcl/CLCommandType.java
new file mode 100644 (file)
index 0000000..976562f
--- /dev/null
@@ -0,0 +1,123 @@
+/**
+ * *****************************************************************************
+ * Copyright (c) 2008 - 2012 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.
+ *
+ * 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.
+ * ****************************************************************************
+ */
+package au.notzed.zcl;
+
+/**
+ * Enum for wrapping the cl_command_type constants from cl.h.
+ *
+ * This is mostly useful for printing them out.
+ */
+public enum CLCommandType {
+
+       CL_COMMAND_NDRANGE_KERNEL(CL.CL_COMMAND_NDRANGE_KERNEL),
+       CL_COMMAND_TASK(CL.CL_COMMAND_TASK),
+       CL_COMMAND_NATIVE_KERNEL(CL.CL_COMMAND_NATIVE_KERNEL),
+       CL_COMMAND_READ_BUFFER(CL.CL_COMMAND_READ_BUFFER),
+       CL_COMMAND_WRITE_BUFFER(CL.CL_COMMAND_WRITE_BUFFER),
+       CL_COMMAND_COPY_BUFFER(CL.CL_COMMAND_COPY_BUFFER),
+       CL_COMMAND_READ_IMAGE(CL.CL_COMMAND_READ_IMAGE),
+       CL_COMMAND_WRITE_IMAGE(CL.CL_COMMAND_WRITE_IMAGE),
+       CL_COMMAND_COPY_IMAGE(CL.CL_COMMAND_COPY_IMAGE),
+       CL_COMMAND_COPY_IMAGE_TO_BUFFER(CL.CL_COMMAND_COPY_IMAGE_TO_BUFFER),
+       CL_COMMAND_COPY_BUFFER_TO_IMAGE(CL.CL_COMMAND_COPY_BUFFER_TO_IMAGE),
+       CL_COMMAND_MAP_BUFFER(CL.CL_COMMAND_MAP_BUFFER),
+       CL_COMMAND_MAP_IMAGE(CL.CL_COMMAND_MAP_IMAGE),
+       CL_COMMAND_UNMAP_MEM_OBJECT(CL.CL_COMMAND_UNMAP_MEM_OBJECT),
+       CL_COMMAND_MARKER(CL.CL_COMMAND_MARKER),
+       CL_COMMAND_ACQUIRE_GL_OBJECTS(CL.CL_COMMAND_ACQUIRE_GL_OBJECTS),
+       CL_COMMAND_RELEASE_GL_OBJECTS(CL.CL_COMMAND_RELEASE_GL_OBJECTS),
+       CL_COMMAND_READ_BUFFER_RECT(CL.CL_COMMAND_READ_BUFFER_RECT),
+       CL_COMMAND_WRITE_BUFFER_RECT(CL.CL_COMMAND_WRITE_BUFFER_RECT),
+       CL_COMMAND_COPY_BUFFER_RECT(CL.CL_COMMAND_COPY_BUFFER_RECT),
+       CL_COMMAND_USER(CL.CL_COMMAND_USER),
+       CL_COMMAND_BARRIER(CL.CL_COMMAND_BARRIER),
+       CL_COMMAND_MIGRATE_MEM_OBJECTS(CL.CL_COMMAND_MIGRATE_MEM_OBJECTS),
+       CL_COMMAND_FILL_BUFFER(CL.CL_COMMAND_FILL_BUFFER),
+       CL_COMMAND_FILL_IMAGE(CL.CL_COMMAND_FILL_IMAGE),
+       // hack for unknown types (e.g. api changes)
+       CL_COMMAND_UNKNOWN(-1);
+
+       int id;
+
+       private CLCommandType(int id) {
+               this.id = id;
+       }
+
+       static public CLCommandType fromC(int id) {
+               switch (id) {
+               case CL.CL_COMMAND_NDRANGE_KERNEL:
+                       return CL_COMMAND_NDRANGE_KERNEL;
+               case CL.CL_COMMAND_TASK:
+                       return CL_COMMAND_TASK;
+               case CL.CL_COMMAND_NATIVE_KERNEL:
+                       return CL_COMMAND_NATIVE_KERNEL;
+               case CL.CL_COMMAND_READ_BUFFER:
+                       return CL_COMMAND_READ_BUFFER;
+               case CL.CL_COMMAND_WRITE_BUFFER:
+                       return CL_COMMAND_WRITE_BUFFER;
+               case CL.CL_COMMAND_COPY_BUFFER:
+                       return CL_COMMAND_COPY_BUFFER;
+               case CL.CL_COMMAND_READ_IMAGE:
+                       return CL_COMMAND_READ_IMAGE;
+               case CL.CL_COMMAND_WRITE_IMAGE:
+                       return CL_COMMAND_WRITE_IMAGE;
+               case CL.CL_COMMAND_COPY_IMAGE:
+                       return CL_COMMAND_COPY_IMAGE;
+               case CL.CL_COMMAND_COPY_IMAGE_TO_BUFFER:
+                       return CL_COMMAND_COPY_IMAGE_TO_BUFFER;
+               case CL.CL_COMMAND_COPY_BUFFER_TO_IMAGE:
+                       return CL_COMMAND_COPY_BUFFER_TO_IMAGE;
+               case CL.CL_COMMAND_MAP_BUFFER:
+                       return CL_COMMAND_MAP_BUFFER;
+               case CL.CL_COMMAND_MAP_IMAGE:
+                       return CL_COMMAND_MAP_IMAGE;
+               case CL.CL_COMMAND_UNMAP_MEM_OBJECT:
+                       return CL_COMMAND_UNMAP_MEM_OBJECT;
+               case CL.CL_COMMAND_MARKER:
+                       return CL_COMMAND_MARKER;
+               case CL.CL_COMMAND_ACQUIRE_GL_OBJECTS:
+                       return CL_COMMAND_ACQUIRE_GL_OBJECTS;
+               case CL.CL_COMMAND_RELEASE_GL_OBJECTS:
+                       return CL_COMMAND_RELEASE_GL_OBJECTS;
+               case CL.CL_COMMAND_READ_BUFFER_RECT:
+                       return CL_COMMAND_READ_BUFFER_RECT;
+               case CL.CL_COMMAND_WRITE_BUFFER_RECT:
+                       return CL_COMMAND_WRITE_BUFFER_RECT;
+               case CL.CL_COMMAND_COPY_BUFFER_RECT:
+                       return CL_COMMAND_COPY_BUFFER_RECT;
+               case CL.CL_COMMAND_USER:
+                       return CL_COMMAND_USER;
+               case CL.CL_COMMAND_BARRIER:
+                       return CL_COMMAND_BARRIER;
+               case CL.CL_COMMAND_MIGRATE_MEM_OBJECTS:
+                       return CL_COMMAND_MIGRATE_MEM_OBJECTS;
+               case CL.CL_COMMAND_FILL_BUFFER:
+                       return CL_COMMAND_FILL_BUFFER;
+               case CL.CL_COMMAND_FILL_IMAGE:
+                       return CL_COMMAND_FILL_IMAGE;
+               default:
+                       return CL_COMMAND_UNKNOWN;
+               }
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java b/src/notzed.zcl/classes/au/notzed/zcl/CLContext.java
new file mode 100644 (file)
index 0000000..08153d2
--- /dev/null
@@ -0,0 +1,458 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import java.nio.ByteBuffer;
+import static au.notzed.zcl.CL.*;
+import au.notzed.zcl.khr.GLEvent;
+import au.notzed.zcl.khr.GLSharing;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+/**
+ * Interface for cl_context
+ */
+public class CLContext extends CLExtendable {
+
+       /**
+        * If a notify callback is supplied to createContext() then this is used to track the reference.
+        */
+       final CLContextNotify notify;
+
+       /**
+        * Creates an interface for a native pointer of type cl_context.
+        *
+        * @param p Native pointer.
+        */
+       public CLContext(long p) {
+               super(p);
+               this.notify = null;
+       }
+
+       CLContext(long p, CLContextNotify notify) {
+               super(p);
+               this.notify = notify;
+       }
+
+       private native static void release(long p);
+
+       @Override
+       public String toString() {
+               StringBuilder sb = new StringBuilder("CLContext[");
+               for (CLDevice d : getDevices()) {
+                       sb.append(d);
+                       sb.append(' ');
+               }
+               sb.append(']');
+
+               return sb.toString();
+       }
+
+       @Override
+       int getInfoType() {
+               return TYPE_CONTEXT;
+       }
+
+       /**
+        * Creates a property representing CL_CONTEXT_PLATFORM.
+        *
+        * @param platform target value.
+        * @return new property
+        */
+       public static CLContextProperty PLATFORM(CLPlatform platform) {
+               return new CLContextProperty.TagValue(CL.CL_CONTEXT_PLATFORM, platform.getP());
+       }
+
+       /**
+        * Creates a property representing CL_CONTEXT_INTEROP_USER_SYNC.
+        *
+        * @param sync
+        * @return new property
+        */
+       public static CLContextProperty INTEROP_USER_SYNC(boolean sync) {
+               return new CLContextProperty.TagValue(CL.CL_CONTEXT_INTEROP_USER_SYNC, sync ? 1 : 0);
+       }
+
+       /**
+        * Calls clCreateContext.
+        *
+        * @param properties
+        * @param devices
+        * @param notify
+        * @return Newly allocated context.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLRuntimeException
+        */
+       public static native CLContext createContext(CLContextProperty[] properties, CLDevice[] devices, CLContextNotify notify) throws CLRuntimeException;
+
+       public static CLContext createContext(CLContextProperty[] properties, CLDevice[] devices) throws CLRuntimeException {
+               return createContext(properties, devices, (String what, ByteBuffer error_info) -> {
+                       System.err.printf("CLContext: '%s'\n", what);
+               });
+       }
+
+       /**
+        * Calls clCreateContextFromType.
+        *
+        * @param properties
+        * @param device_type
+        * @param notify
+        * @return Newly allocated context.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLRuntimeException
+        */
+       public static native CLContext createContextFromType(CLContextProperty[] properties, long device_type, CLContextNotify notify) throws CLRuntimeException;
+
+       /**
+        * Calls clCreateCommandQueue.
+        *
+        * @param dev
+        * @param properties
+        * @return Newly created command queue.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLRuntimeException
+        * @deprecated as of OpenCL 2.0
+        */
+       @Deprecated
+       native public CLCommandQueue createCommandQueue(CLDevice dev, long properties) throws CLRuntimeException;
+
+       /**
+        * Calls clCreateCommandQueueWithProperties.
+        *
+        * @param dev
+        * @param properties
+        * @return
+        * @throws CLRuntimeException
+        * @since OpenCL 2.0
+        */
+       native public CLCommandQueue createCommandQueue(CLDevice dev, CLQueueProperty[] properties) throws CLRuntimeException;
+
+       /**
+        *
+        * @param dev
+        * @param q
+        * @throws CLException
+        * @since OpenCL 2.1
+        */
+       native public void setDefaultDeviceCommandQueue(CLDevice dev, CLCommandQueue q) throws CLException;
+
+       public CLBuffer createBuffer(long flags, long size) throws CLRuntimeException {
+               return createBuffer(flags, size, null);
+       }
+
+       /**
+        * Calls clCreateBuffer.
+        *
+        * @param flags CL_MEM_* flags.
+        * @param size Size in bytes.
+        * @param hostp Optional host memory pointer.
+        * @return Newly allocated buffer.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLRuntimeException
+        */
+       native public CLBuffer createBuffer(long flags, long size, ByteBuffer hostp) throws CLRuntimeException;
+
+       /**
+        * Wraps a full buffer.
+        *
+        * @param flags
+        * @param hostp must not be null. only capacity is honoured.
+        * @return
+        * @throws CLRuntimeException
+        */
+       public CLBuffer createBuffer(long flags, ByteBuffer hostp) throws CLRuntimeException {
+               return createBuffer(flags, hostp.capacity(), hostp);
+       }
+
+       /**
+        * Calls clCreateBuffer with the array as the host pointer.
+        *
+        * @param flags If CL_MEM_COPY_HOST_PTR is set and hostp is non-null then the array is copied to device memory.
+        *
+        * If CL_MEM_COPY_HOST_PTR is not set and hostp is non-null then the size is taken from the array.
+        *
+        * @param hostp an array. Not null.
+        * @return
+        * @throws CLRuntimeException if the clCreateBuffer fails, or with CL_INVALID_VALUE if CL_MEM_USE_HOST_PTR is specified in flags.
+        * @throws NullPointerException if hostp is null.
+        */
+       native public CLBuffer createBuffer(long flags, byte[] hostp) throws CLRuntimeException;
+
+       native public CLBuffer createBuffer(long flags, short[] hostp) throws CLRuntimeException;
+
+       native public CLBuffer createBuffer(long flags, int[] hostp) throws CLRuntimeException;
+
+       native public CLBuffer createBuffer(long flags, float[] hostp) throws CLRuntimeException;
+
+       native public CLBuffer createBuffer(long flags, double[] hostp) throws CLRuntimeException;
+
+       public CLImage createImage(long flags, CLImageFormat fmt, CLImageDesc desc) throws CLRuntimeException, UnsupportedOperationException {
+               return createImage(flags, fmt, desc, (ByteBuffer) null);
+       }
+
+       /**
+        * Calls clCreateImage.
+        *
+        * @param flags CL_MEM_* flags.
+        * @param fmt Image format.
+        * @param desc Image descriptor. For OpenCL 1.2 only CL_MEM_OBJECT_IMAGE2D and CL_MEM_OBJECT_IMAGE3D are allowed.
+        * @param hostp
+        * @return Newly allocated image.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLRuntimeException
+        * @throws UnsupportedOperationException
+        */
+       native public CLImage createImage(long flags, CLImageFormat fmt, CLImageDesc desc, ByteBuffer hostp) throws CLRuntimeException, UnsupportedOperationException;
+
+       native public CLImage createImage(long flags, CLImageFormat fmt, CLImageDesc desc, byte[] hostp) throws CLRuntimeException, UnsupportedOperationException;
+
+       native public CLImage createImage(long flags, CLImageFormat fmt, CLImageDesc desc, short[] hostp) throws CLRuntimeException, UnsupportedOperationException;
+
+       native public CLImage createImage(long flags, CLImageFormat fmt, CLImageDesc desc, int[] hostp) throws CLRuntimeException, UnsupportedOperationException;
+
+       native public CLImage createImage(long flags, CLImageFormat fmt, CLImageDesc desc, float[] hostp) throws CLRuntimeException, UnsupportedOperationException;
+
+       /**
+        * Calls clCreatePipe
+        *
+        * @param flags
+        * @param packetSize
+        * @param maxPackets
+        * @param properties
+        * @return
+        * @throws CLRuntimeException
+        * @throws UnsupportedOperationException
+        * @since OpenCL 2.0
+        */
+       native public CLPipe createPipe(long flags, int packetSize, int maxPackets, CLPipeProperty[] properties) throws CLRuntimeException, UnsupportedOperationException;
+
+       /**
+        * Calls clGetSupportedImageFormats.
+        *
+        * @param flags
+        * @param type
+        * @return List of supported image formats.
+        * @throws CLRuntimeException
+        */
+       native public CLImageFormat[] getSupportedImageFormats(long flags, int type) throws CLRuntimeException;
+
+       /**
+        * Allocate shared virtual memory.
+        * <p>
+        * Memory must be explicity freed using CLContext.SVMFree.
+        *
+        * @param flags
+        * @param size
+        * @param alignment
+        * @return
+        * @throws CLRuntimeException
+        * @since OpenCL 2.0
+        */
+       native public ByteBuffer SVMAlloc(long flags, long size, int alignment) throws CLRuntimeException;
+
+       /**
+        * Free memory allocated by SVMAlloc. It is up to the caller to ensure the memory is not in use.
+        *
+        * @param mem
+        * @throws CLRuntimeException
+        * @since OpenCL 2.0
+        */
+       native public void SVMFree(ByteBuffer mem) throws CLRuntimeException;
+
+       /**
+        * Calls clCreateSampler.
+        *
+        * @param norm Normalised coordinates.
+        * @param addr_mode CL_ADDRESS_
+        *
+        * @param filter_mode CL_FILTER_
+        *
+        * @return Newly created sampler.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLRuntimeException
+        * @deprecated as of OpenCL 2.0
+        */
+       @Deprecated
+       native public CLSampler createSampler(boolean norm, int addr_mode, int filter_mode) throws CLRuntimeException;
+
+       /**
+        * Calls clCreateSamplerWithProperties
+        *
+        * @param props list of propertyes
+        * @return
+        * @throws CLRuntimeException
+        * @since OpenCL 2.0
+        */
+       native public CLSampler createSampler(CLSamplerProperty[] props) throws CLRuntimeException;
+
+       /**
+        * Calls clCreateProgramWithSource.
+        *
+        * @param strings Source strings as byte array blocks.
+        * @return Newly created program.<p>
+        * release() should be called when it is no longer needed or allow for GC cleanup.
+        * @throws CLException
+        */
+       native public CLProgram createProgramWithSource(byte[]... strings) throws CLException;
+
+       public CLProgram createProgramWithSource(String... strings) throws CLException {
+               byte[][] bytes = new byte[strings.length][];
+               for (int i = 0; i < strings.length; i++) {
+                       bytes[i] = strings[i].getBytes(Charset.forName("UTF-8"));
+               }
+
+               return createProgramWithSource(bytes);
+       }
+
+       public CLProgram createProgramWithSource(InputStream is) throws CLException {
+               try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
+                       byte[] buffer = new byte[4096];
+                       int len;
+                       while ((len = is.read(buffer)) > 0) {
+                               bos.write(buffer, 0, len);
+                       }
+                       return createProgramWithSource(new byte[][]{bos.toByteArray()});
+               } catch (IOException ex) {
+                       throw new CLException(CL_BUILD_ERROR);
+               }
+       }
+
+       /**
+        * Calls clCreateProgramWithIL
+        *
+        * @param il
+        * @return
+        * @throws CLException
+        */
+       native public CLProgram createProgramWithIL(byte[] il) throws CLException;
+
+       /**
+        * Calls clCreateProgramWithBinary.
+        *
+        * @param devices
+        * @param binaries
+        * @param status
+        * @return Newly created program.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLException
+        */
+       native public CLProgram createProgramWithBinary(CLDevice[] devices, byte[][] binaries, int[] status) throws CLException;
+
+       /**
+        * Calls clCreateProgramWithBuiltInKernels.
+        *
+        * @param devices
+        * @param names semi-colon separated list of kernel names
+        * @return Newly created program. release() should be called when it is no longer needed.
+        * @throws CLException
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.2
+        */
+       native public CLProgram createProgramWithBuiltInKernels(CLDevice[] devices, String names) throws CLException, UnsupportedOperationException;
+
+       /**
+        * Calls clLinkProgram.
+        *
+        * @param devices
+        * @param options
+        * @param programs
+        * @param notify
+        * @return Newly created program.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLException
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.2
+        */
+       native public CLProgram linkProgram(CLDevice[] devices, String options, CLProgram[] programs, CLNotify<CLProgram> notify) throws CLException, UnsupportedOperationException;
+
+       /**
+        * Calls clCreateUserEvent.
+        *
+        * @return Newly created user event.<p>
+        * release() should be called when it is no longer needed.
+        * @throws CLRuntimeException
+        * @since OpenCL 1.1
+        */
+       native public CLEvent createUserEvent() throws CLRuntimeException;
+
+       /**
+        * gets CL_CONTEXT_NUM_DEVICES.
+        *
+        * @return Number of devices.
+        */
+       public int getNumDevices() {
+               return getInfoInt(CL_CONTEXT_NUM_DEVICES);
+       }
+
+       /**
+        * gets CL_CONTEXT_DEVICES.
+        *
+        * @return List of devices.
+        */
+       public CLDevice[] getDevices() {
+               return getInfoAnyV(CTYPE_DEVICE, CL_CONTEXT_DEVICES);
+       }
+
+       /**
+        * gets CL_CONTEXT_PROPERTIES
+        *
+        * @return List of properties used at create time.
+        */
+       public native CLContextProperty[] getProperties();
+
+       @Override
+       protected CLPlatform initPlatform() {
+               return getDevices()[0].platform;
+       }
+
+       protected GLSharing getGLSharing() {
+               return getExtension(CLPlatform.cl_khr_gl_sharing);
+       }
+
+       protected GLEvent getGLEvent() {
+               return getExtension(CLPlatform.cl_khr_gl_event);
+       }
+
+       /*
+        Experimental: extension interface mechanism
+        */
+       public CLBuffer createFromGLBuffer(
+               long flags,
+               int bufobj) {
+               return getGLSharing().createFromGLBuffer(this, flags, bufobj);
+       }
+
+       public CLImage createFromGLTexture(
+               long flags /* flags */,
+               int target /* target */,
+               int miplevel /* miplevel */,
+               int texture /* texture */) {
+               return getGLSharing().createFromGLTexture(this, flags, target, miplevel, texture);
+       }
+
+       public CLImage createFromGLRenderbuffer(
+               long flags /* flags */,
+               int renderbuffer /* renderbuffer */) {
+               return getGLSharing().createFromGLRenderbuffer(this, flags, renderbuffer);
+       }
+
+       public CLEvent createEventFromGLsync(long glsync) {
+               return getGLEvent().clCreateEventFromGLsync(this, glsync);
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLContextNotify.java b/src/notzed.zcl/classes/au/notzed/zcl/CLContextNotify.java
new file mode 100644 (file)
index 0000000..8c3a304
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Callback for CLContext.createContext*()
+ */
+public interface CLContextNotify {
+
+       public void notify(String what, ByteBuffer error_info);
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLContextProperty.java b/src/notzed.zcl/classes/au/notzed/zcl/CLContextProperty.java
new file mode 100644 (file)
index 0000000..b33cf96
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Properties for CLContext creation.
+ *
+ * The property factory methods for this type are on CLContext.
+ */
+public interface CLContextProperty extends CLProperty {
+
+       public static class TagValue extends CLProperty.TagValue implements CLContextProperty {
+
+               public TagValue(long tag, long value) {
+                       super(tag, value);
+               }
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLDevice.java b/src/notzed.zcl/classes/au/notzed/zcl/CLDevice.java
new file mode 100644 (file)
index 0000000..37dc9fb
--- /dev/null
@@ -0,0 +1,410 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import static au.notzed.zcl.CL.*;
+
+/**
+ * Interface for cl_device_id.
+ */
+public class CLDevice extends CLExtendable {
+
+       /**
+        * Create an interface for a native pointer of type cl_device_id.
+        *
+        * @param p Native pointer.
+        */
+       public CLDevice(long p) {
+               super(p);
+       }
+
+       private native static void release(long p);
+
+       @Override
+       public String toString() {
+               return getName();
+       }
+
+       @Override
+       int getInfoType() {
+               return TYPE_DEVICE;
+       }
+
+       @Override
+       protected CLPlatform initPlatform() {
+               return getPlatform();
+       }
+
+       /**
+        * Gets device view of device and host clock.
+        *
+        * @param times { device_timestamp, host_timestamp }
+        * @since OpenCL 2.1
+        */
+       public native void getDeviceAndHostTimer(long[] times);
+
+       /**
+        * Gets device view of host clock.
+        *
+        * @return host_timestamp.
+        * @since OpenCN 2.1
+        */
+       public native long getHostTimer();
+
+       /**
+        * Create a property representing CL_DEVICE_PARTITION_EQUALLY.
+        *
+        * @param n target value.
+        * @return
+        * @since OpenCL 1.2
+        */
+       public static CLDeviceProperty PARTITION_EQUALLY(int n) {
+               return new CLDeviceProperty.TagValue(CL_DEVICE_PARTITION_EQUALLY, n);
+       }
+
+       /**
+        * Create a property representing CL_DEVICE_PARTITION_BY_COUNTS.
+        *
+        * @param counts Array of counts. Do not include COUNTS_LIST_END.
+        * @return
+        * @since OpenCL 1.2
+        */
+       public static CLDeviceProperty PARTITION_BY_COUNTS(int... counts) {
+               return new CLDeviceProperty.PartitionByCounts(counts);
+       }
+
+       /**
+        * Create a property representing CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN.
+        *
+        * @param domain target value from CL_DEVICE_AFFINITY_DOMAIN* constants.
+        * @return
+        * @since OpenCL 1.2
+        */
+       public static CLDeviceProperty PARTITION_BY_AFFINITY_DOMAIN(int domain) {
+               return new CLDeviceProperty.TagValue(CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN, domain);
+       }
+
+       /**
+        * Call clCreateSubDevices.
+        *
+        * @param properties PARTITION_* properties.
+        * @param num_devices Passed as num_devices to clCreateSubDevices().
+        * @return An array of created devices. The list will reflect the number of devices created by clCreateSubDevices() and may not match num_devices.
+        * @throws CLException
+        * @since OpenCL 1.2
+        */
+       public native CLDevice[] createSubDevices(CLDeviceProperty[] properties, int num_devices) throws CLException, UnsupportedOperationException;
+
+       /**
+        * get CL_DEVICE_TYPE
+        *
+        * @return CL_DEVICE_TYPE_*
+        */
+       public long getType() {
+               return getInfoLong(CL_DEVICE_TYPE);
+       }
+
+       /**
+        * get CL_DEVICE_VENDOR_ID
+        *
+        * @return Unique vendor identifier.
+        */
+       public int getVendorID() {
+               return getInfoInt(CL_DEVICE_VENDOR_ID);
+       }
+
+       /**
+        * get CL_DEVICE_MAX_COMPUTE_UNITS
+        *
+        * @return Maximum compute units.
+        */
+       public int getMaxComputeUnits() {
+               return getInfoInt(CL_DEVICE_MAX_COMPUTE_UNITS);
+       }
+
+       public int getMaxWorkItemDimensions() {
+               return getInfoInt(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS);
+       }
+
+       public long[] getMaxWorkItemSizes() {
+               return getInfoSizeTA(CL_DEVICE_MAX_WORK_ITEM_SIZES);
+       }
+
+       public long getMaxWorkGroupSize() {
+               return getInfoLong(CL_DEVICE_MAX_WORK_GROUP_SIZE);
+       }
+
+       public int getPreferredVectorWidthChar() {
+               return getInfoInt(CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR);
+       }
+
+       public int getPreferredVectorWidthShort() {
+               return getInfoInt(CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT);
+       }
+
+       public int getPreferredVectorWidthInt() {
+               return getInfoInt(CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT);
+       }
+
+       public int getPreferredVectorWidthLong() {
+               return getInfoInt(CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG);
+       }
+
+       public int getPreferredVectorWidthFloat() {
+               return getInfoInt(CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT);
+       }
+
+       public int getPreferredVectorWidthDouble() {
+               return getInfoInt(CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE);
+       }
+
+       public int getPreferredVectorWidthHalf() {
+               return getInfoInt(CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF);
+       }
+
+       public int getNativeVectorWidthChar() {
+               return getInfoInt(CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR);
+       }
+
+       public int getNativeVectorWidthShort() {
+               return getInfoInt(CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT);
+       }
+
+       public int getNativeVectorWidthInt() {
+               return getInfoInt(CL_DEVICE_NATIVE_VECTOR_WIDTH_INT);
+       }
+
+       public int getNativeVectorWidthLong() {
+               return getInfoInt(CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG);
+       }
+
+       public int getNativeVectorWidthFloat() {
+               return getInfoInt(CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT);
+       }
+
+       public int getNativeVectorWidthDouble() {
+               return getInfoInt(CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE);
+       }
+
+       public int getNativeVectorWidthHalf() {
+               return getInfoInt(CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF);
+       }
+
+       public int getMaxClockFrequency() {
+               return getInfoInt(CL_DEVICE_MAX_CLOCK_FREQUENCY);
+       }
+
+       public int getAddressBits() {
+               return getInfoInt(CL_DEVICE_ADDRESS_BITS);
+       }
+
+       public long getMaxMemAllocSize() {
+               return getInfoLong(CL_DEVICE_MAX_MEM_ALLOC_SIZE);
+       }
+
+       public boolean getImageSupport() {
+               return getInfoInt(CL_DEVICE_IMAGE_SUPPORT) != 0;
+       }
+
+       public int getMaxReadImageArgs() {
+               return getInfoInt(CL_DEVICE_MAX_READ_IMAGE_ARGS);
+       }
+
+       public int getMaxWriteImageArgs() {
+               return getInfoInt(CL_DEVICE_MAX_WRITE_IMAGE_ARGS);
+       }
+
+       public long getImage2DMaxWidth() {
+               return getInfoSizeT(CL_DEVICE_IMAGE2D_MAX_WIDTH);
+       }
+
+       public long getImage2DMaxHeight() {
+               return getInfoSizeT(CL_DEVICE_IMAGE2D_MAX_HEIGHT);
+       }
+
+       public long getImage3DMaxWidth() {
+               return getInfoSizeT(CL_DEVICE_IMAGE3D_MAX_WIDTH);
+       }
+
+       public long getImage3DMaxHeight() {
+               return getInfoSizeT(CL_DEVICE_IMAGE3D_MAX_HEIGHT);
+       }
+
+       public long getImage3DMaxDepth() {
+               return getInfoSizeT(CL_DEVICE_IMAGE3D_MAX_DEPTH);
+       }
+
+       public long getImageMaxBufferSize() {
+               return getInfoSizeT(CL_DEVICE_IMAGE_MAX_BUFFER_SIZE);
+       }
+
+       public long getImageMaxArraySize() {
+               return getInfoSizeT(CL_DEVICE_IMAGE_MAX_ARRAY_SIZE);
+       }
+
+       public int getMaxSamplers() {
+               return getInfoInt(CL_DEVICE_MAX_SAMPLERS);
+       }
+
+       public long getMaxParameterSize() {
+               return getInfoSizeT(CL_DEVICE_MAX_PARAMETER_SIZE);
+       }
+
+       public int getMemBaseAddrAlign() {
+               return getInfoInt(CL_DEVICE_MEM_BASE_ADDR_ALIGN);
+       }
+
+       public long getSinglFPConfig() {
+               return getInfoLong(CL_DEVICE_SINGLE_FP_CONFIG);
+       }
+
+       public long getDoubleFPConfig() {
+               return getInfoLong(CL_DEVICE_SINGLE_FP_CONFIG);
+       }
+
+       public int getGlobalMemCacheType() {
+               return getInfoInt(CL_DEVICE_GLOBAL_MEM_CACHE_TYPE);
+       }
+
+       public int getGlobalMemCachelineSize() {
+               return getInfoInt(CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE);
+       }
+
+       public long getGlobalMemCacheSize() {
+               return getInfoLong(CL_DEVICE_GLOBAL_MEM_CACHE_SIZE);
+       }
+
+       public long getGlobalMemSize() {
+               return getInfoLong(CL_DEVICE_GLOBAL_MEM_SIZE);
+       }
+
+       public long getMaxConstantBufferSize() {
+               return getInfoLong(CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE);
+       }
+
+       public int getMaxConstantArgs() {
+               return getInfoInt(CL_DEVICE_MAX_CONSTANT_ARGS);
+       }
+
+       public int getLocalMemType() {
+               return getInfoInt(CL_DEVICE_LOCAL_MEM_TYPE);
+       }
+
+       public long getLocalMemSize() {
+               return getInfoLong(CL_DEVICE_LOCAL_MEM_SIZE);
+       }
+
+       public boolean getErrorCorrectionSupport() {
+               return getInfoInt(CL_DEVICE_ERROR_CORRECTION_SUPPORT) != 0;
+       }
+
+       public boolean getHostUnifiedMemory() {
+               return getInfoInt(CL_DEVICE_HOST_UNIFIED_MEMORY) != 0;
+       }
+
+       public long getProfilingTimerResolution() {
+               return getInfoSizeT(CL_DEVICE_PROFILING_TIMER_RESOLUTION);
+       }
+
+       public boolean getEndianLittle() {
+               return getInfoInt(CL_DEVICE_ENDIAN_LITTLE) != 0;
+       }
+
+       public boolean getAvailable() {
+               return getInfoInt(CL_DEVICE_AVAILABLE) != 0;
+       }
+
+       public boolean getCompilerAvailable() {
+               return getInfoInt(CL_DEVICE_COMPILER_AVAILABLE) != 0;
+       }
+
+       public boolean getLinkerAvailable() {
+               return getInfoInt(CL_DEVICE_LINKER_AVAILABLE) != 0;
+       }
+
+       public long getExecutionCapabilities() {
+               return getInfoLong(CL_DEVICE_EXECUTION_CAPABILITIES);
+       }
+
+       public long getQueueProperties() {
+               return getInfoLong(CL_DEVICE_QUEUE_PROPERTIES);
+       }
+
+       public String getBuiltInKernels() {
+               return getInfoString(CL_DEVICE_BUILT_IN_KERNELS);
+       }
+
+       public CLPlatform getPlatform() {
+               return getInfoAny(CTYPE_PLATFORM, CL_DEVICE_PLATFORM);
+       }
+
+       public String getName() {
+               return getInfoString(CL_DEVICE_NAME);
+       }
+
+       public String getVendor() {
+               return getInfoString(CL_DEVICE_VENDOR);
+       }
+
+       public String getDriverVersion() {
+               return getInfoString(CL_DRIVER_VERSION);
+       }
+
+       public String getProfile() {
+               return getInfoString(CL_DEVICE_PROFILE);
+       }
+
+       public String getVersion() {
+               return getInfoString(CL_DEVICE_VERSION);
+       }
+
+       public String getOpenCLCVersion() {
+               return getInfoString(CL_DEVICE_OPENCL_C_VERSION);
+       }
+
+       public String getDeviceExtensions() {
+               return getInfoString(CL_DEVICE_EXTENSIONS);
+       }
+
+       public long getPrintfBufferSize() {
+               return getInfoSizeT(CL_DEVICE_PRINTF_BUFFER_SIZE);
+       }
+
+       public boolean getPreferredInteropUserSync() {
+               return getInfoInt(CL_DEVICE_PREFERRED_INTEROP_USER_SYNC) != 0;
+       }
+
+       public CLDevice getParentDevice() {
+               return getInfoAny(CTYPE_DEVICE, CL_DEVICE_PARENT_DEVICE);
+       }
+
+       public int getPartitionMaxSubDevices() {
+               return getInfoInt(CL_DEVICE_PARTITION_MAX_SUB_DEVICES);
+       }
+
+       public native CLDeviceProperty[] getPartitionProperties();
+
+       public long getPartitionAffinityDomain() {
+               return getInfoLong(CL_DEVICE_PARTITION_AFFINITY_DOMAIN);
+       }
+
+       public native CLDeviceProperty[] getPartitionType();
+
+       public static CLDevice[] newArray(int n) {
+               return new CLDevice[n];
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLDeviceProperty.java b/src/notzed.zcl/classes/au/notzed/zcl/CLDeviceProperty.java
new file mode 100644 (file)
index 0000000..4d1d0b4
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Properties for CLDevice sub-device creation.
+ *
+ * The property factory methods for this type are on CLDevice.
+ */
+public interface CLDeviceProperty extends CLProperty {
+
+       public static class TagValue extends CLProperty.TagValue implements CLDeviceProperty {
+
+               public TagValue(long tag, long value) {
+                       super(tag, value);
+               }
+       }
+
+       public static class PartitionByCounts implements CLDeviceProperty {
+
+               int[] counts;
+
+               public PartitionByCounts(int[] counts) {
+                       this.counts = counts;
+               }
+
+               @Override
+               public int getSize() {
+                       return counts.length + 2;
+               }
+
+               @Override
+               public int toInt(int[] dst, int o) {
+                       dst[o++] = CL.CL_DEVICE_PARTITION_BY_COUNTS;
+                       for (int c : counts) {
+                               dst[o++] = c;
+                       }
+                       dst[o++] = CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END;
+                       return o;
+               }
+
+               @Override
+               public int toLong(long[] dst, int o) {
+                       dst[o++] = CL.CL_DEVICE_PARTITION_BY_COUNTS;
+                       for (int c : counts) {
+                               dst[o++] = c;
+                       }
+                       dst[o++] = CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END;
+                       return o;
+               }
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLEvent.java b/src/notzed.zcl/classes/au/notzed/zcl/CLEvent.java
new file mode 100644 (file)
index 0000000..f8dcb60
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import static au.notzed.zcl.CL.*;
+
+/**
+ * Interface for cl_event.
+ */
+public class CLEvent extends CLObject {
+
+       /**
+        * Create an interface for a native pointer of type cl_event.
+        *
+        * @param p Native pointer.
+        */
+       public CLEvent(long p) {
+               super(p);
+       }
+
+       private native static void release(long p);
+
+       @Override
+       int getInfoType() {
+               return TYPE_EVENT;
+       }
+
+       /**
+        * Call clSetUserEventStatus(this, status).
+        * <p>
+        * This must only be called on user events.
+        *
+        * @param status
+        * @throws CLRuntimeException
+        * @since OpenCL 1.1
+        */
+       public native void setUserEventStatus(int status) throws CLRuntimeException;
+
+       /**
+        * Call clSetEventCallback(type, notify).
+        *
+        * @param type
+        * @param notify
+        * @throws CLRuntimeException
+        * @since OpenCL 1.1
+        */
+       public native void setEventCallback(int type, CLEventNotify notify) throws CLRuntimeException;
+
+       /**
+        * Get CL_EVENT_COMMAND_QUEUE.
+        * <p>
+        * This will return a new CLCommandQueue for each invocation.
+        *
+        * @return
+        */
+       public CLCommandQueue getCommandQueue() {
+               return getInfoAny(CTYPE_COMMAND_QUEUE, CL_EVENT_COMMAND_QUEUE);
+       }
+
+       /**
+        * Get CL_EVENT_CONTEXT.
+        * <p>
+        * This will return a new CLContext for each invocation.
+        *
+        * @return
+        */
+       public CLContext getContext() {
+               return getInfoAny(CTYPE_CONTEXT, CL_EVENT_CONTEXT);
+       }
+
+       /**
+        * Get CL_EVENT_COMMAND_TYPE.
+        *
+        * @return
+        */
+       public int getCommandType() {
+               return getInfoInt(CL_EVENT_COMMAND_TYPE);
+       }
+
+       /**
+        * Get CL_EVENT_COMMAND_EXECUTION_STATUS.
+        * <p>
+        * Negative values indicate an error taken from the standard OpenCL error definitions.
+        *
+        * @return
+        */
+       public int getCommandExecutionStatus() {
+               return getInfoInt(CL_EVENT_COMMAND_EXECUTION_STATUS);
+       }
+
+       public long getProfilingCommandQueued() {
+               return getInfoLong(TYPE_EVENT_PROFILING, CL_PROFILING_COMMAND_QUEUED);
+       }
+
+       public long getProfilingCommandSubmit() {
+               return getInfoLong(TYPE_EVENT_PROFILING, CL_PROFILING_COMMAND_SUBMIT);
+       }
+
+       public long getProfilingCommandStart() {
+               return getInfoLong(TYPE_EVENT_PROFILING, CL_PROFILING_COMMAND_START);
+       }
+
+       public long getProfilingCommandEnd() {
+               return getInfoLong(TYPE_EVENT_PROFILING, CL_PROFILING_COMMAND_END);
+       }
+
+       public long getProfilingCommandComplete() {
+               return getInfoLong(TYPE_EVENT_PROFILING, CL_PROFILING_COMMAND_COMPLETE);
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLEventList.java b/src/notzed.zcl/classes/au/notzed/zcl/CLEventList.java
new file mode 100644 (file)
index 0000000..96f6c5d
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Manages a list of cl_events.
+ * <p>
+ * This hides some ugly details with the way events work in OpenCL and within
+ * this API binding and provides a much cleaner, efficient, and simple interface.
+ * <p>
+ * See {@link au.notzed.zcl.CLCommandQueue} for more information on usage.
+ * <p>
+ * <h2>Internal Details</h2>
+ * <p>
+ * Internally the CLEventList is maintained as an array of long values which hold
+ * the cl_event pointers. CLEvent objects are only created to access this pointer
+ * from Java or to transfer the event pointers to new event lists.
+ * <p>
+ * The JNI code directly reads from the events list and index in order to build
+ * a list of wait events, and calls the internal add(long) method to append to
+ * the events array.
+ * <p>
+ */
+public class CLEventList {
+
+       /**
+        * C-accessible copy of jevets[i].p
+        */
+       final long[] events;
+       /**
+        * Event references.
+        */
+       final CLEvent[] jevents;
+       int index = 0;
+
+       /**
+        * Creates a new event list.
+        *
+        * @param capacity Sets the event list capacity. This
+        */
+       public CLEventList(int capacity) {
+               this.events = new long[capacity];
+               this.jevents = new CLEvent[capacity];
+       }
+
+       /**
+        * Clears the event list.
+        * <p>
+        * All added events are released and the index counter is reset to 0.
+        */
+       public void reset() {
+               for (int i = 0; i < index; i++) {
+                       jevents[i] = null;
+                       events[i] = 0;
+               }
+               index = 0;
+       }
+
+       /**
+        * Creates an interface to the given event.
+        *
+        * @param index
+        * @return An event interface.
+        */
+       public CLEvent get(int index) {
+               return jevents[index];
+       }
+
+       /**
+        * Add the event to the event list.
+        *
+        * @param event
+        */
+       public void add(CLEvent event) {
+               events[index] = event.getP();
+               jevents[index++] = event;
+       }
+
+       /**
+        * Interface for JNI to add an event after a successful enqueue operation.
+        *
+        * @param eid
+        */
+       private void add(long eid) {
+               add(CLObject.resolve(CLEvent.class, eid));
+       }
+
+       /**
+        * Get the number of active events.
+        *
+        * @return
+        */
+       public int size() {
+               return index;
+       }
+
+       /**
+        * Calls clWaitForEvents with all active events in this list.
+        *
+        * @throws CLException
+        */
+       public native void waitForEvents() throws CLException;
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLEventNotify.java b/src/notzed.zcl/classes/au/notzed/zcl/CLEventNotify.java
new file mode 100644 (file)
index 0000000..1c793a1
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Callback for CLEvent.
+ */
+public interface CLEventNotify {
+
+       /**
+        * Callback target for clSetEventCallback.
+        *
+        * @param event event that caused the notify.
+        * @param status status.
+        */
+       public void notify(CLEvent event, int status);
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLException.java b/src/notzed.zcl/classes/au/notzed/zcl/CLException.java
new file mode 100644 (file)
index 0000000..fccafe9
--- /dev/null
@@ -0,0 +1,183 @@
+/**
+ * *****************************************************************************
+ * Copyright (c) 2008 - 2012 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.
+ *
+ * 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.
+ * ****************************************************************************
+ */
+package au.notzed.zcl;
+
+/**
+ * Exception for OpenCL error values.
+ */
+public class CLException extends Exception {
+
+       int id;
+
+       public CLException(int id) {
+               this.id = id;
+       }
+
+       /**
+        * Get the error code.
+        *
+        * @return OpenCL error code.
+        * @see #codeToError
+        */
+       public int getID() {
+               return id;
+       }
+
+       @Override
+       public String getMessage() {
+               return String.format("Error (%d): '%s'", id, codeToError(id));
+       }
+
+       /**
+        * Convert the error code to a description.
+        *
+        * @param code
+        * @return
+        */
+       public static String codeToError(int code) {
+               switch (code) {
+               case CL.CL_SUCCESS:
+                       return "CL_SUCCESS";
+               case CL.CL_DEVICE_NOT_FOUND:
+                       return "CL_DEVICE_NOT_FOUND";
+               case CL.CL_DEVICE_NOT_AVAILABLE:
+                       return "CL_DEVICE_NOT_AVAILABLE";
+               case CL.CL_COMPILER_NOT_AVAILABLE:
+                       return "CL_COMPILER_NOT_AVAILABLE";
+               case CL.CL_MEM_OBJECT_ALLOCATION_FAILURE:
+                       return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
+               case CL.CL_OUT_OF_RESOURCES:
+                       return "CL_OUT_OF_RESOURCES";
+               case CL.CL_OUT_OF_HOST_MEMORY:
+                       return "CL_OUT_OF_HOST_MEMORY";
+               case CL.CL_PROFILING_INFO_NOT_AVAILABLE:
+                       return "CL_PROFILING_INFO_NOT_AVAILABLE";
+               case CL.CL_MEM_COPY_OVERLAP:
+                       return "CL_MEM_COPY_OVERLAP";
+               case CL.CL_IMAGE_FORMAT_MISMATCH:
+                       return "CL_IMAGE_FORMAT_MISMATCH";
+               case CL.CL_IMAGE_FORMAT_NOT_SUPPORTED:
+                       return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
+               case CL.CL_BUILD_PROGRAM_FAILURE:
+                       return "CL_BUILD_PROGRAM_FAILURE";
+               case CL.CL_MAP_FAILURE:
+                       return "CL_MAP_FAILURE";
+               case CL.CL_MISALIGNED_SUB_BUFFER_OFFSET:
+                       return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
+               case CL.CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST:
+                       return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
+               case CL.CL_COMPILE_PROGRAM_FAILURE:
+                       return "CL_COMPILE_PROGRAM_FAILURE";
+               case CL.CL_LINKER_NOT_AVAILABLE:
+                       return "CL_LINKER_NOT_AVAILABLE";
+               case CL.CL_LINK_PROGRAM_FAILURE:
+                       return "CL_LINK_PROGRAM_FAILURE";
+               case CL.CL_DEVICE_PARTITION_FAILED:
+                       return "CL_DEVICE_PARTITION_FAILED";
+               case CL.CL_KERNEL_ARG_INFO_NOT_AVAILABLE:
+                       return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
+
+               case CL.CL_INVALID_VALUE:
+                       return "CL_INVALID_VALUE";
+               case CL.CL_INVALID_DEVICE_TYPE:
+                       return "CL_INVALID_DEVICE_TYPE";
+               case CL.CL_INVALID_PLATFORM:
+                       return "CL_INVALID_PLATFORM";
+               case CL.CL_INVALID_DEVICE:
+                       return "CL_INVALID_DEVICE";
+               case CL.CL_INVALID_CONTEXT:
+                       return "CL_INVALID_CONTEXT";
+               case CL.CL_INVALID_QUEUE_PROPERTIES:
+                       return "CL_INVALID_QUEUE_PROPERTIES";
+               case CL.CL_INVALID_COMMAND_QUEUE:
+                       return "CL_INVALID_COMMAND_QUEUE";
+               case CL.CL_INVALID_HOST_PTR:
+                       return "CL_INVALID_HOST_PTR";
+               case CL.CL_INVALID_MEM_OBJECT:
+                       return "CL_INVALID_MEM_OBJECT";
+               case CL.CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
+                       return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
+               case CL.CL_INVALID_IMAGE_SIZE:
+                       return "CL_INVALID_IMAGE_SIZE";
+               case CL.CL_INVALID_SAMPLER:
+                       return "CL_INVALID_SAMPLER";
+               case CL.CL_INVALID_BINARY:
+                       return "CL_INVALID_BINARY";
+               case CL.CL_INVALID_BUILD_OPTIONS:
+                       return "CL_INVALID_BUILD_OPTIONS";
+               case CL.CL_INVALID_PROGRAM:
+                       return "CL_INVALID_PROGRAM";
+               case CL.CL_INVALID_PROGRAM_EXECUTABLE:
+                       return "CL_INVALID_PROGRAM_EXECUTABLE";
+               case CL.CL_INVALID_KERNEL_NAME:
+                       return "CL_INVALID_KERNEL_NAME";
+               case CL.CL_INVALID_KERNEL_DEFINITION:
+                       return "CL_INVALID_KERNEL_DEFINITION";
+               case CL.CL_INVALID_KERNEL:
+                       return "CL_INVALID_KERNEL";
+               case CL.CL_INVALID_ARG_INDEX:
+                       return "CL_INVALID_ARG_INDEX";
+               case CL.CL_INVALID_ARG_VALUE:
+                       return "CL_INVALID_ARG_VALUE";
+               case CL.CL_INVALID_ARG_SIZE:
+                       return "CL_INVALID_ARG_SIZE";
+               case CL.CL_INVALID_KERNEL_ARGS:
+                       return "CL_INVALID_KERNEL_ARGS";
+               case CL.CL_INVALID_WORK_DIMENSION:
+                       return "CL_INVALID_WORK_DIMENSION";
+               case CL.CL_INVALID_WORK_GROUP_SIZE:
+                       return "CL_INVALID_WORK_GROUP_SIZE";
+               case CL.CL_INVALID_WORK_ITEM_SIZE:
+                       return "CL_INVALID_WORK_ITEM_SIZE";
+               case CL.CL_INVALID_GLOBAL_OFFSET:
+                       return "CL_INVALID_GLOBAL_OFFSET";
+               case CL.CL_INVALID_EVENT_WAIT_LIST:
+                       return "CL_INVALID_EVENT_WAIT_LIST";
+               case CL.CL_INVALID_EVENT:
+                       return "CL_INVALID_EVENT";
+               case CL.CL_INVALID_OPERATION:
+                       return "CL_INVALID_OPERATION";
+               case CL.CL_INVALID_GL_OBJECT:
+                       return "CL_INVALID_GL_OBJECT";
+               case CL.CL_INVALID_BUFFER_SIZE:
+                       return "CL_INVALID_BUFFER_SIZE";
+               case CL.CL_INVALID_MIP_LEVEL:
+                       return "CL_INVALID_MIP_LEVEL";
+               case CL.CL_INVALID_GLOBAL_WORK_SIZE:
+                       return "CL_INVALID_GLOBAL_WORK_SIZE";
+               case CL.CL_INVALID_PROPERTY:
+                       return "CL_INVALID_PROPERTY";
+               case CL.CL_INVALID_IMAGE_DESCRIPTOR:
+                       return "CL_INVALID_IMAGE_DESCRIPTOR";
+               case CL.CL_INVALID_COMPILER_OPTIONS:
+                       return "CL_INVALID_COMPILER_OPTIONS";
+               case CL.CL_INVALID_LINKER_OPTIONS:
+                       return "CL_INVALID_LINKER_OPTIONS";
+               case CL.CL_INVALID_DEVICE_PARTITION_COUNT:
+                       return "CL_INVALID_DEVICE_PARTITION_COUNT";
+               default:
+                       return "Unknown error";
+               }
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLExtendable.java b/src/notzed.zcl/classes/au/notzed/zcl/CLExtendable.java
new file mode 100644 (file)
index 0000000..f5a45ec
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 notzed
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Extendable object. These keep track of the platform and api revision to be
+ * able to lookup extension pointers efficiently.
+ */
+public abstract class CLExtendable extends CLObject {
+
+       protected final CLPlatform platform;
+       /**
+        * Copy of platform.apiVersion, cached for faster lookup
+        */
+       final int apiVersion;
+
+       public CLExtendable(long p) {
+               super(p);
+
+               platform = initPlatform();
+               apiVersion = platform.apiVersion;
+       }
+
+       /**
+        * Retrieve the platform. This should not cache the lookup. It cannot return
+        * null by definition. This should not be called by any implementing class.
+        *
+        * @return
+        */
+       protected abstract CLPlatform initPlatform();
+
+       public CLPlatform getPlatform() {
+               return platform;
+       }
+
+       public int getAPIVersion() {
+               return apiVersion;
+       }
+
+       /**
+        * Retrieve an extension interface for this object. Used by implementors of
+        * CLExtenable.
+        *
+        * @param <T>
+        * @param id The extension id code on CLPlatform.
+        * @return
+        */
+       protected <T extends CLExtension> T getExtension(int id) {
+               return platform.getExtension(id);
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLExtension.java b/src/notzed.zcl/classes/au/notzed/zcl/CLExtension.java
new file mode 100644 (file)
index 0000000..16e4520
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 notzed
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Experimental code for extension support.
+ * <p>
+ * Extensions need to be per-platform and are backed by a C structure
+ * which holds the function pointers.
+ * <p>
+ * Because some extensions effectively expand the method or property sets
+ * of the basic objects it may make sense for the extension methods to appear
+ * to reside there even if they go through the platform.
+ * <p>
+ * Actually the above is always true otherwise it becomes one huge fuckup to use.
+ */
+public abstract class CLExtension extends CLObject {
+
+       protected CLExtension(long p) {
+               super(p);
+       }
+
+       public abstract String getName();
+
+       @Override
+       int getInfoType() {
+               throw new UnsupportedOperationException();
+       }
+       
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java b/src/notzed.zcl/classes/au/notzed/zcl/CLImage.java
new file mode 100644 (file)
index 0000000..b4117fb
--- /dev/null
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import static au.notzed.zcl.CL.*;
+import java.nio.ByteBuffer;
+
+/**
+ * Interface for cl_image.
+ *
+ * @param <T> Not used, yet?
+ */
+public class CLImage<T> extends CLMemory {
+
+       /**
+        * Create an interface for a native pointer of type cl_mem that refers to an
+        * image object.
+        *
+        * @param p Native pointer.
+        */
+       public CLImage(long p) {
+               super(p);
+       }
+
+       static void release(long p) {
+               CLMemory.release(p);
+       }
+
+       @Override
+       int getInfoType() {
+               return TYPE_IMAGE;
+       }
+
+       public native CLImageFormat getFormat();
+
+       public long getElementSize() {
+               return getInfoSizeT(CL_IMAGE_ELEMENT_SIZE);
+       }
+
+       public long getRowPitch() {
+               return getInfoSizeT(CL_IMAGE_ROW_PITCH);
+       }
+
+       public long getSlicePitch() {
+               return getInfoSizeT(CL_IMAGE_SLICE_PITCH);
+       }
+
+       public long getWidth() {
+               return getInfoSizeT(CL_IMAGE_WIDTH);
+       }
+
+       public long getHeight() {
+               return getInfoSizeT(CL_IMAGE_HEIGHT);
+       }
+
+       public long getDepth() {
+               return getInfoSizeT(CL_IMAGE_DEPTH);
+       }
+
+       public long getArraySize() {
+               return getInfoSizeT(CL_IMAGE_ARRAY_SIZE);
+       }
+
+       public CLBuffer getBuffer() {
+               return getInfoAny(CTYPE_BUFFER, CL_IMAGE_BUFFER);
+       }
+
+       public int getNumMipLevels() {
+               return getInfoInt(CL_IMAGE_NUM_MIP_LEVELS);
+       }
+
+       public int getNumSamples() {
+               return getInfoInt(CL_IMAGE_NUM_SAMPLES);
+       }
+
+       @Override
+       public String toString() {
+               return String.format("[%s: %dx%dx%d  0x%x]", getClass().getSimpleName(), getWidth(), getHeight(), getDepth(), getP());
+       }
+
+       /**
+        * Origin of (0,0,0) for read/write.
+        */
+       public static final long[] ORIGIN = {0, 0, 0};
+
+       public static long[] ORIGIN(long x, long y) {
+               return new long[]{x, y, 0};
+       }
+
+       /**
+        * Whole region of this image { width, height, depth }
+        *
+        * @return
+        */
+       public long[] region() {
+               long height = getHeight();
+               long size = getArraySize();
+
+               if (size == 0) {
+                       size = getDepth();
+               }
+
+               return new long[]{getWidth(), height == 0 ? 1 : height, size == 0 ? 1 : size};
+       }
+
+       /**
+        * 2D region of this image { width, height, 1 }
+        *
+        * @param width
+        * @param height
+        * @return
+        */
+       public long[] region(long width, long height) {
+               return new long[]{width, height, 1};
+       }
+
+       /*
+        Functional Interface Constructors.
+        */
+       /**
+        * Read whole image.
+        *
+        * @param target
+        * @return
+        */
+       public CLTask ofRead(byte[] target) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueReadImage(this, true, ORIGIN, region(), 0, 0, target, 0, waiters, events);
+       }
+
+       public CLTask ofRead(float[] target) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueReadImage(this, true, ORIGIN, region(), 0, 0, target, 0, waiters, events);
+       }
+
+       public CLTask ofWrite(byte[] source) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueWriteImage(this, true, ORIGIN, region(), 0, 0, source, 0, waiters, events);
+       }
+
+       public CLTask ofWrite(float[] source) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueWriteImage(this, true, ORIGIN, region(), 0, 0, source, 0, waiters, events);
+       }
+
+       /**
+        * Read operation from a single whole 2D image within a 2D image array.
+        *
+        * @param index Which image to read.
+        * @param target
+        * @return
+        */
+       public CLTask ofRead(int index, byte[] target) {
+               long[] origin = {0, 0, index};
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueReadImage(this, true, origin, region(getWidth(), getHeight()), 0, 0, target, 0, waiters, events);
+       }
+
+       public CLTask ofRead(int index, float[] target) {
+               long[] origin = {0, 0, index};
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueReadImage(this, true, origin, region(getWidth(), getHeight()), 0, 0, target, 0, waiters, events);
+       }
+
+       /**
+        * Write operation to a single whole 2D image within a 2D image array.
+        *
+        * @param index Which image to read.
+        * @param source
+        * @return
+        */
+       public CLTask ofWrite(int index, byte[] source) {
+               long[] origin = {0, 0, index};
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueWriteImage(this, true, origin, region(getWidth(), getHeight()), 0, 0, source, 0, waiters, events);
+       }
+
+       /**
+        * Read whole image into a direct byte buffer.
+        *
+        * @param target Target memory. position() and capacity() are ignored?
+        * @param blocking
+        * @return
+        */
+       public CLTask ofRead(ByteBuffer target, boolean blocking) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueReadImage(this, true, ORIGIN, region(), 0, 0, target, waiters, events);
+       }
+
+       /**
+        * Read whole 2D image into a direct byte buffer.
+        *
+        * @param target
+        * @param blocking
+        * @param row_pitch Row pitch in bytes.
+        * @return
+        */
+       public CLTask ofRead(ByteBuffer target, boolean blocking, int row_pitch) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueReadImage(this, blocking, ORIGIN, region(getWidth(), getHeight()), row_pitch, 0, target, waiters, events);
+       }
+
+       public CLTask ofWrite(ByteBuffer source, boolean blocking) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueWriteImage(this, true, ORIGIN, region(), 0, 0, source, waiters, events);
+       }
+
+       /**
+        * Write 2D image.
+        *
+        * @param source
+        * @param blocking
+        * @param row_pitch Row pitch in bytes.
+        * @return
+        */
+       public CLTask ofWrite(ByteBuffer source, boolean blocking, int row_pitch) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events)
+                       -> q.enqueueWriteImage(this, blocking, ORIGIN, region(getWidth(), getHeight()), row_pitch, 0, source, waiters, events);
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLImageDesc.java b/src/notzed.zcl/classes/au/notzed/zcl/CLImageDesc.java
new file mode 100644 (file)
index 0000000..aacc985
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Holder for cl_image_desc equivalent.
+ */
+public class CLImageDesc {
+
+       public int imageType;
+       public int imageWidth;
+       public int imageHeight;
+       public int imageDepth;
+       public int imageArraySize;
+       public int imageRowPitch;
+       public int imageSlicePitch;
+       public int numMipLevels;
+       public int numSamples;
+       public CLMemory memObject;
+
+       public CLImageDesc() {
+       }
+
+       public CLImageDesc(int imageType, int imageWidth, int imageHeight, int imageDepth, int imageArraySize, int imageRowPitch, int imageSlicePitch, int numMipLevels, int numSamples, CLMemory memObject) {
+               this.imageType = imageType;
+               this.imageWidth = imageWidth;
+               this.imageHeight = imageHeight;
+               this.imageDepth = imageDepth;
+               this.imageArraySize = imageArraySize;
+               this.imageRowPitch = imageRowPitch;
+               this.imageSlicePitch = imageSlicePitch;
+               this.numMipLevels = numMipLevels;
+               this.numSamples = numSamples;
+               this.memObject = memObject;
+       }
+
+       /**
+        * Create a 2d image descriptor.
+        *
+        * @param w
+        * @param h
+        * @return
+        */
+       public static CLImageDesc create2D(int w, int h) {
+               return new CLImageDesc(CL.CL_MEM_OBJECT_IMAGE2D, w, h, 1, 0, 0, 0, 0, 0, null);
+       }
+
+       /**
+        * Create a 2d image array descriptor.
+        *
+        * @param w
+        * @param h
+        * @param count
+        * @return
+        */
+       public static CLImageDesc create2D(int w, int h, int count) {
+               return new CLImageDesc(CL.CL_MEM_OBJECT_IMAGE2D_ARRAY, w, h, 1, count, 0, 0, 0, 0, null);
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLImageFormat.java b/src/notzed.zcl/classes/au/notzed/zcl/CLImageFormat.java
new file mode 100644 (file)
index 0000000..d870024
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Holder for cl_image_format equivalent.
+ */
+public class CLImageFormat {
+
+       public final int channelOrder;
+       public final int channelDataType;
+
+       public static final CLImageFormat INTENSITY_FLOAT = new CLImageFormat(CL.CL_INTENSITY, CL.CL_FLOAT);
+       public static final CLImageFormat INTENSITY_UNORM_INT8 = new CLImageFormat(CL.CL_INTENSITY, CL.CL_UNORM_INT8);
+       public static final CLImageFormat R_UNSIGNED_INT8 = new CLImageFormat(CL.CL_R, CL.CL_UNSIGNED_INT8);
+       public static final CLImageFormat R_UNORM_INT8 = new CLImageFormat(CL.CL_R, CL.CL_UNORM_INT8);
+       public static final CLImageFormat R_FLOAT = new CLImageFormat(CL.CL_R, CL.CL_FLOAT);
+       public static final CLImageFormat R_HALF_FLOAT = new CLImageFormat(CL.CL_R, CL.CL_HALF_FLOAT);
+       public static final CLImageFormat RG_FLOAT = new CLImageFormat(CLChannelOrder.CL_RG, CLChannelType.CL_FLOAT);
+       public static final CLImageFormat RGBA_FLOAT = new CLImageFormat(CLChannelOrder.CL_RGBA, CLChannelType.CL_FLOAT);
+       public static final CLImageFormat RG_UNORM_INT8 = new CLImageFormat(CL.CL_RG, CL.CL_UNORM_INT8);
+       public static final CLImageFormat RGBA_UNORM_INT8 = new CLImageFormat(CL.CL_RGBA, CL.CL_UNORM_INT8);
+
+       public CLImageFormat(CLChannelOrder order, CLChannelType type) {
+               channelOrder = order.id;
+               channelDataType = type.id;
+       }
+
+       public CLImageFormat(int channelOrder, int channelDataType) {
+               this.channelOrder = channelOrder;
+               this.channelDataType = channelDataType;
+       }
+
+       public CLChannelOrder getChannelOrder() {
+               return CLChannelOrder.fromC(channelOrder);
+       }
+
+       public CLChannelType getChannelDataType() {
+               return CLChannelType.fromC(channelDataType);
+       }
+
+       @Override
+       public int hashCode() {
+               int hash = 3;
+               hash = 59 * hash + this.channelOrder;
+               hash = 59 * hash + this.channelDataType;
+               return hash;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (obj == null) {
+                       return false;
+               }
+               if (getClass() != obj.getClass()) {
+                       return false;
+               }
+               final CLImageFormat other = (CLImageFormat) obj;
+               return this.channelOrder == other.channelOrder
+                               && this.channelDataType == other.channelDataType;
+       }
+
+       @Override
+       public String toString() {
+               return String.format("CLImageFormat: %s,%s",
+                               getChannelOrder(), getChannelDataType());
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLKernel.java b/src/notzed.zcl/classes/au/notzed/zcl/CLKernel.java
new file mode 100644 (file)
index 0000000..899e206
--- /dev/null
@@ -0,0 +1,397 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import java.nio.Buffer;
+import static au.notzed.zcl.CL.*;
+import java.nio.ByteBuffer;
+
+/**
+ * Interface for cl_kernel.
+ * <p>
+ * Note although this has api versioning it does not extend CLExtendable for
+ * efficiency reasons. There is therefore no run-time checking of api.
+ */
+public class CLKernel extends CLObject {
+
+       /**
+        * Create an interface for a native pointer of type cl_kernel.
+        *
+        * @param p Native pointer.
+        */
+       public CLKernel(long p) {
+               super(p);
+       }
+
+       private native static void release(long p);
+
+       @Override
+       int getInfoType() {
+               return TYPE_KERNEL;
+       }
+
+       /**
+        * Calls clCloneKernel.
+        *
+        * @return
+        * @throws CLRuntimeException
+        * @since OpenCL 2.1
+        */
+       public native CLKernel cloneKernel() throws CLRuntimeException;
+
+       /**
+        * Calls clSetKernelArg with the arguments.
+        *
+        * @param index
+        * @param size Size of argument value in bytes.
+        * @param buffer Memory for argument. The buffer position and limits are
+        * ignored. May be null to setArg the size of a local scope parameter.
+        * @param offset Offset in buffer.
+        */
+       public native void setArg(int index, long size, Buffer buffer, long offset);
+
+       /**
+        * Set the size of a parameter that is of a local scope.
+        *
+        * @param index
+        * @param size The size to reserve in bytes.
+        */
+       public void setArgLDS(int index, long size) {
+               setArg(index, size, null, 0);
+       }
+
+       /**
+        * Set an argument to an OpenCL object.
+        *
+        * @param index
+        * @param o
+        */
+       public native void setArg(int index, CLObject o);
+
+       /**
+        * Set a byte-valued argument. Equates to OpenCL types char, unsigned char,
+        * and uchar (and perhaps bool?).
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, byte val);
+
+       /**
+        * Set a short-valued argument. Equates to OpenCL types short, unsigned
+        * short, and ushort.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, short val);
+
+       /**
+        * Set an integer-valued argument. Equates to OpenCL types int, unsigned
+        * int, and uint.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, int val);
+
+       /**
+        * Set a long-valued argument. Equates (somewhat conveniently) to the OpenCL
+        * types long, unsigned long, and ulong.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, long val);
+
+       /**
+        * Set a float-valued argument.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, float val);
+
+       /**
+        * Set a double-valued argument.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, double val);
+
+       /**
+        * Set SVM argument.
+        *
+        * @param index
+        * @param svm MUST have been allocated using CLContext.SVMAlloc().
+        */
+       public native void setArg(int index, ByteBuffer svm);
+
+       /**
+        * Set a multi-element byte argument. This may be used to setArg vector
+        * types.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, byte... val);
+
+       /**
+        * Set a multi-element short argument. This may be used to setArg vector
+        * types.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, short... val);
+
+       /**
+        * Set a multi-element integer argument. This may be used to setArg vector
+        * types.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, int... val);
+
+       /**
+        * Set a multi-element long argument. This may be used to setArg vector
+        * types.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, long... val);
+
+       /**
+        * Set a multi-element float argument. This may be used to setArg vector
+        * types.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, float... val);
+
+       /**
+        * Set a multi-element double argument. This may be used to setArg vector
+        * types.
+        *
+        * @param index
+        * @param val
+        */
+       public native void setArg(int index, double... val);
+
+       /**
+        * Sets a number of arguments.
+        * <p>
+        * This isn't terribly efficient.
+        *
+        * @param index0 Starting index.
+        * @param values
+        */
+       public void setArgs(int index0, Object... values) {
+               for (Object v : values) {
+                       //System.out.printf("%d: %s\n", index0, v.getClass().getName());
+                       if (v instanceof CLObject) {
+                               setArg(index0, (CLObject) v);
+                       } else if (v instanceof Integer) {
+                               setArg(index0, (Integer) v);
+                       } else if (v instanceof Float) {
+                               setArg(index0, (Float) v);
+                       } else if (v instanceof Short) {
+                               setArg(index0, (Short) v);
+                       } else if (v instanceof Byte) {
+                               setArg(index0, (Byte) v);
+                       } else if (byte[].class.isInstance(v)) {
+                               setArg(index0, (int[]) v);
+                       } else if (short[].class.isInstance(v)) {
+                               setArg(index0, (short[]) v);
+                       } else if (int[].class.isInstance(v)) {
+                               setArg(index0, (int[]) v);
+                       } else if (float[].class.isInstance(v)) {
+                               setArg(index0, (float[]) v);
+                       } else if (double[].class.isInstance(v)) {
+                               setArg(index0, (double[]) v);
+                       } else {
+                               throw new CLRuntimeException(CL_INVALID_ARG_VALUE);
+                       }
+                       index0 += 1;
+               }
+       }
+
+       public String getFunctionName() {
+               return getInfoString(CL_KERNEL_FUNCTION_NAME);
+       }
+
+       public int getNumArgs() {
+               return getInfoInt(CL_KERNEL_NUM_ARGS);
+       }
+
+       public CLContext getContext() {
+               return getInfoAny(CTYPE_CONTEXT, CL_KERNEL_CONTEXT);
+       }
+
+       public CLProgram getProgram() {
+               return getInfoAny(CTYPE_PROGRAM, CL_KERNEL_PROGRAM);
+       }
+
+       public String getAttributes() {
+               return getInfoString(CL_KERNEL_ATTRIBUTES);
+       }
+
+       /* cl_kernel_work_group_info */
+       native <T> T getWorkGroupInfoAny(CLDevice dev, int otype, int param_name) throws CLRuntimeException;
+
+       native <T> T getWorkGroupInfoAnyV(CLDevice dev, int otype, int param_name) throws CLRuntimeException;
+
+       /**
+        * gets CL_KERNEL_GLOBAL_WORK_SIZE
+        *
+        * @param device device to use, may be null
+        * @return
+        */
+       public long[] getGlobalWorkSize(CLDevice device) {
+               return getWorkGroupInfoAnyV(device, CTYPE_SIZE_T, CL_KERNEL_GLOBAL_WORK_SIZE);
+       }
+
+       public long getWorkGroupSize(CLDevice device) {
+               return getWorkGroupInfoAny(device, CTYPE_SIZE_T, CL_KERNEL_WORK_GROUP_SIZE);
+       }
+
+       public long[] getCompileWorkGroupSize(CLDevice device) {
+               return getWorkGroupInfoAnyV(device, CTYPE_SIZE_T, CL_KERNEL_COMPILE_WORK_GROUP_SIZE);
+       }
+
+       public long getLocalMemSize(CLDevice device) {
+               return getWorkGroupInfoAny(device, CTYPE_LONG, CL_KERNEL_LOCAL_MEM_SIZE);
+       }
+
+       public long getPreferredWorkGroupSizeMultiple(CLDevice device) {
+               return getWorkGroupInfoAny(device, CTYPE_SIZE_T, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE);
+       }
+
+       public long getPrivateMemSize(CLDevice device) {
+               return getWorkGroupInfoAny(device, CTYPE_SIZE_T, CL_KERNEL_PRIVATE_MEM_SIZE);
+       }
+
+       /* cl_kernel_sub_group_info */
+       // this assumes all size_t's atm.
+       native <T> T getSubGroupInfoAny(CLDevice dev, int otype, int param_name, long[] input) throws CLRuntimeException;
+
+       native <T> T getSubGroupInfoAnyV(CLDevice dev, int otype, int param_name, long[] input) throws CLRuntimeException;
+
+       /**
+        * @since OpenCL 2.1
+        */
+       public long getMaxSubGroupSizeForNDRange(CLDevice device, long[] range) {
+               return getSubGroupInfoAny(device, CTYPE_SIZE_T, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, range);
+       }
+
+       /**
+        * @since OpenCL 2.1
+        */
+       public long getSubGroupCountForNDRange(CLDevice device, long[] range) {
+               return getSubGroupInfoAny(device, CTYPE_SIZE_T, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, range);
+       }
+
+       /**
+        * @since OpenCL 2.1
+        */
+       public long[] getLocalSizeForSubGroupCount(CLDevice device, long count) {
+               return getSubGroupInfoAnyV(device, CTYPE_SIZE_T, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, new long[]{count});
+       }
+
+       public long getMaxNumSubGroups(CLDevice device) {
+               return getSubGroupInfoAny(device, CTYPE_SIZE_T, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, null);
+       }
+
+       /* cl_kernel_exec_info */
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_EXEC_INFO_SVM_PTRS = 0x11B6;
+       /**
+        * @since OpenCL 2.1
+        */
+       public final static int CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM = 0x11B7;
+
+       /* cl_kernel_arg_info */
+       native <T> T getArgInfoAny(int index, int otype, int param_name) throws CLRuntimeException;
+
+       native <T> T getArgInfoAnyV(int index, int otype, int param_name) throws CLRuntimeException;
+
+       /**
+        * gets CL_KERNEL_ARG_ADDRESS_QUALIFIER.
+        *
+        * @param index
+        * @return
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.2
+        */
+       public int getArgAddressQualifier(int index) throws UnsupportedOperationException {
+               return getArgInfoAny(index, CTYPE_INT, CL_KERNEL_ARG_ADDRESS_QUALIFIER);
+       }
+
+       /**
+        * gets CL_KERNEL_ARG_ACCESS_QUALIFIER.
+        *
+        * @param index
+        * @return
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.2
+        */
+       public int getArgAccessQualifier(int index) throws UnsupportedOperationException {
+               return getArgInfoAny(index, CTYPE_INT, CL_KERNEL_ARG_ACCESS_QUALIFIER);
+       }
+
+       /**
+        * gets CL_KERNEL_ARG_TYPE_NAME.
+        *
+        * @param index
+        * @return
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.2
+        */
+       public String getArgTypeName(int index) throws UnsupportedOperationException {
+               return fromInfoString(getArgInfoAnyV(index, CTYPE_BYTE, CL_KERNEL_ARG_TYPE_NAME));
+       }
+
+       /**
+        * gets CL_KERNEL_ARG_TYPE_QUALIFIER.
+        *
+        * @param index
+        * @return
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.2
+        */
+       public long getArgTypeQualifier(int index) throws UnsupportedOperationException {
+               return getArgInfoAny(index, CTYPE_LONG, CL_KERNEL_ARG_TYPE_QUALIFIER);
+       }
+
+       /**
+        * gets CL_KERNEL_ARG_NAME.
+        *
+        * @param index
+        * @return
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.2
+        */
+       public String getArgName(int index) throws UnsupportedOperationException {
+               return fromInfoString(getArgInfoAnyV(index, CTYPE_BYTE, CL_KERNEL_ARG_NAME));
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java b/src/notzed.zcl/classes/au/notzed/zcl/CLMemory.java
new file mode 100644 (file)
index 0000000..c4bd264
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import java.nio.ByteBuffer;
+import static au.notzed.zcl.CL.*;
+import java.nio.ByteOrder;
+
+/**
+ * Interface for cl_mem.
+ * <p>
+ * <h1>Memory Transfers</h1>
+ * <p>
+ * Subclasses of CLMemory define various read, write, and map operations. These
+ * are performed via ByteBuffer objects or primitive arrays.
+ * </p>
+ * <strong>Primtive Arrays</strong>
+ * <p>
+ * Where available the primitive transfers will take the primitive array and an
+ * offset. Offsets are treated as units of the primitive type.
+ * <p>
+ * Due to the Java memory design primitive arrays only allow for synchronous
+ * transfers. This is a trade-off between ease of use, efficiency, and
+ * performance and may change in the future.
+ * </p>
+ * <strong>ByteBuffers</strong>
+ * <p>
+ * All transfer and memory operations support the use of ByteBuffer objects.
+ * These are initialised to the endianness of host (ByteOrder.nativeOrder()).
+ * <p>
+ * ByteBuffer objects allow access to native (malloc) memory from Java and hence
+ * support both synchronous (blocking) asynchronous (nonblocking) memory
+ * transfers.
+ * <p>
+ * When a user-created (i.e. not mapped) ByteBuffer is accepted as an argument
+ * then the position() and limit() of the buffer is honoured at the time the
+ * function is invoked. Note that <em>the position itself is never modified by
+ * zcl</em>. This is to simplify use of the common case and to avoid the need to
+ * track asnchronous operations.
+ * <p>
+ * <em>It is unclear if this api is the correct one as it comes at a small
+ * performance penalty over simply passing the byte offset as with the array
+ * methods. It may change (again) in the future?</em>
+ */
+public abstract class CLMemory extends CLObject {
+
+       CLMemory(long p) {
+               super(p);
+       }
+
+       native static void release(long p);
+
+       /**
+        * Call clSetMemObjectDestructorCallback.
+        *
+        * @param notify
+        * @throws CLException
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.1
+        */
+       public native void setMemObjectDestructorCallback(CLNotify<CLMemory> notify) throws CLException, UnsupportedOperationException;
+
+       @Override
+       int getInfoType() {
+               return TYPE_MEM_OBJECT;
+       }
+
+       public long getType() {
+               return getInfoInt(CL_MEM_TYPE);
+       }
+
+       /**
+        * Get CL_MEM_FLAGS.
+        *
+        * @return
+        */
+       public long getFlags() {
+               return getInfoLong(CL_MEM_FLAGS);
+       }
+
+       /**
+        * Get CL_MEM_SIZE.
+        *
+        * @return
+        */
+       public long getSize() {
+               return getInfoSizeT(CL_MEM_SIZE);
+       }
+
+       /**
+        * Get CL_MEM_HOST_PTR.
+        *
+        * @return
+        */
+       public native ByteBuffer getHostPtr() throws CLRuntimeException;
+
+       /**
+        * Get CL_MEM_CONTEXT.
+        *
+        * @return An interface to the context this memory was created on.
+        */
+       public CLContext getContext() {
+               return getInfoAny(CTYPE_CONTEXT, CL_MEM_CONTEXT);
+       }
+
+       /**
+        * Get CL_MEM_ASSOCIATED_MEMOBJECT for a sub-buffer.
+        *
+        * @return
+        */
+       public CLBuffer getAssociatedMemObject() {
+               return getInfoAny(CTYPE_BUFFER, CL_MEM_ASSOCIATED_MEMOBJECT);
+       }
+
+       /**
+        * Get CL_MEM_OFFSET for a sub-buffer.
+        *
+        * @return
+        */
+       public long getMemOffset() {
+               return getInfoSizeT(CL_MEM_OFFSET);
+       }
+
+       /**
+        * Allocates a buffer suitable for opencl use - sets the byte order.
+        *
+        * @param size
+        * @return
+        */
+       static public ByteBuffer alloc(int size) {
+               return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
+       }
+
+       /**
+        * Copies the array to a direct buffer.
+        *
+        * @param data
+        * @return
+        */
+       public static ByteBuffer alloc(float[] data) {
+               ByteBuffer bb = ByteBuffer.allocateDirect(data.length * 4).order(ByteOrder.nativeOrder());
+               bb.asFloatBuffer().put(data);
+               return bb;
+       }
+
+       /**
+        * Copies the array to a direct buffer.
+        *
+        * @param data
+        * @return
+        */
+       public static ByteBuffer alloc(int[] data) {
+               ByteBuffer bb = ByteBuffer.allocateDirect(data.length * 4).order(ByteOrder.nativeOrder());
+               bb.asIntBuffer().put(data);
+               return bb;
+       }
+
+       /**
+        * Copies the array to a direct buffer.
+        *
+        * @param data
+        * @return
+        */
+       public static ByteBuffer alloc(short[] data) {
+               ByteBuffer bb = ByteBuffer.allocateDirect(data.length * 2).order(ByteOrder.nativeOrder());
+               bb.asShortBuffer().put(data);
+               return bb;
+       }
+
+       /**
+        * Copies the array to a direct buffer.
+        *
+        * @param data
+        * @return
+        */
+       public static ByteBuffer alloc(byte[] data) {
+               if (data != null) {
+                       ByteBuffer bb = ByteBuffer.allocateDirect(data.length).order(ByteOrder.nativeOrder());
+                       bb.put(data).rewind();
+                       return bb;
+               } else {
+                       return null;
+               }
+       }
+
+       public static CLTask ofAcquireGL(CLMemory... mems) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueAcquireGLObjects(mems, waiters, events);
+               };
+       }
+
+       public static CLTask ofReleaseGL(CLMemory... mems) {
+               return (CLCommandQueue q, CLEventList waiters, CLEventList events) -> {
+                       q.enqueueReleaseGLObjects(mems, waiters, events);
+               };
+       }
+
+       /*
+        Experimental: extensions/gl
+        */
+       public CLTask ofAcquireGL() {
+               return ofAcquireGL(this);
+       }
+
+       public CLTask ofReleaseGL() {
+               return ofReleaseGL(this);
+       }
+
+       /*
+       Experimental half stuff
+        */
+       /**
+        * Utility function for converting a buffer from java float to opencl half
+        *
+        * @param dst
+        * @param doff
+        * @param src
+        * @param soff
+        * @param len
+        * @return
+        */
+       public static short[] toHalf(short[] dst, int doff, float[] src, int soff, int len) {
+               for (int e = soff + len; soff < e; soff++, doff++) {
+                       dst[doff] = toHalf(src[soff]);
+               }
+               return dst;
+       }
+
+       public static short[] toHalf(float[] src) {
+               return toHalf(new short[src.length], 0, src, 0, src.length);
+       }
+
+       public static float[] toFloat(float[] dst, int doff, short[] src, int soff, int len) {
+               for (int e = soff + len; soff < e; soff++, doff++) {
+                       dst[doff] = toFloat(src[soff]);
+               }
+               return dst;
+       }
+
+       public static float[] toFloat(short[] src) {
+               return toFloat(new float[src.length], 0, src, 0, src.length);
+       }
+
+       // Taken from stack overflow from wikipedia link
+       // ignores the higher 16 bits
+       public static float toFloat(short hbits) {
+               int mant = hbits & 0x03ff;            // 10 bits mantissa
+               int exp = hbits & 0x7c00;            // 5 bits exponent
+               if (exp == 0x7c00) // NaN/Inf
+               {
+                       exp = 0x3fc00;                    // -> NaN/Inf
+               } else if (exp != 0) // normalized value
+               {
+                       exp += 0x1c000;                   // exp - 15 + 127
+                       if (mant == 0 && exp > 0x1c400) // smooth transition
+                       {
+                               return Float.intBitsToFloat((hbits & 0x8000) << 16
+                                       | exp << 13 | 0x3ff);
+                       }
+               } else if (mant != 0) // && exp==0 -> subnormal
+               {
+                       exp = 0x1c400;                    // make it normal
+                       do {
+                               mant <<= 1;                   // mantissa * 2
+                               exp -= 0x400;                 // decrease exp by 1
+                       } while ((mant & 0x400) == 0); // while not normal
+                       mant &= 0x3ff;                    // discard subnormal bit
+               }                                     // else +/-0 -> +/-0
+               return Float.intBitsToFloat( // combine all parts
+                       (hbits & 0x8000) << 16 // sign  << ( 31 - 15 )
+                       | (exp | mant) << 13);         // value << ( 23 - 10 )
+       }
+
+       // returns all higher 16 bits as 0 for all results
+       public static short toHalf(float fval) {
+               int fbits = Float.floatToIntBits(fval);
+               int sign = fbits >>> 16 & 0x8000;          // sign only
+               int val = (fbits & 0x7fffffff) + 0x1000; // rounded value
+
+               if (val >= 0x47800000) // might be or become NaN/Inf
+               {                                     // avoid Inf due to rounding
+                       if ((fbits & 0x7fffffff) >= 0x47800000) {                                 // is or must become NaN/Inf
+                               if (val < 0x7f800000) // was value but too large
+                               {
+                                       return (short) (sign | 0x7c00);     // make it +/-Inf
+                               }
+                               return (short) (sign | 0x7c00
+                                       | // remains +/-Inf or NaN
+                                       (fbits & 0x007fffff) >>> 13); // keep NaN (and Inf) bits
+                       }
+                       return (short) (sign | 0x7bff);             // unrounded not quite Inf
+               }
+               if (val >= 0x38800000) // remains normalized value
+               {
+                       return (short) (sign | val - 0x38000000 >>> 13); // exp - 127 + 15
+               }
+               if (val < 0x33000000) // too small for subnormal
+               {
+                       return (short) sign;                      // becomes +/-0
+               }
+               val = (fbits & 0x7fffffff) >>> 23;  // tmp exp for subnormal calc
+               return (short) (sign | ((fbits & 0x7fffff | 0x800000) // add subnormal bit
+                       + (0x800000 >>> val - 102) // round depending on cut off
+                       >>> 126 - val));   // div by 2^(1-(exp-127+15)) and >> 13 | exp=0
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLNativeKernel.java b/src/notzed.zcl/classes/au/notzed/zcl/CLNativeKernel.java
new file mode 100644 (file)
index 0000000..9f38101
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Native kernel as passed to CLCommandQueue.enqueueNativeKernel.
+ */
+public interface CLNativeKernel {
+
+       /**
+        * Native kernel entry point.
+        *
+        * @param args arguments, with any CLMemory objects replaced with
+        * ByteBuffer.
+        */
+       public void invoke(Object[] args);
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java b/src/notzed.zcl/classes/au/notzed/zcl/CLNotify.java
new file mode 100644 (file)
index 0000000..94b912c
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Generic notify routine.
+ * @param <T> Type of source object.
+ */
+public interface CLNotify<T> {
+
+       public void notify(T source);
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLObject.java b/src/notzed.zcl/classes/au/notzed/zcl/CLObject.java
new file mode 100644 (file)
index 0000000..284c82a
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2014,2019 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import au.notzed.nativez.NativeZ;
+
+/**
+ * Base class for all OpenCL types which can be represented as objects - i.e.
+ * those that are defined by anonymous pointer types in cl.h.
+ * <p>
+ * Each object has a single memory pointer which is stored in the p field. A
+ * long is used for all platforms for code simplicity. For most objects this is
+ * the only value retained and all get methods defer to the OpenCL runtime.
+ * CLObjects are not guaranteed to map unique instances to a given OpenCL object
+ * although in many cases the API doesn't allow for any other behaviour. Objects
+ * are considered equal if their p value is identical.
+ * <p>
+ * To reduce the code-size, retain(), release(), getInfo() and object-specific
+ * getInfo() variants have been implemented in a polymorphic fashion. The TYPE_*
+ * fields and getType() method are used to implement this mechanism. get()
+ * methods which return CLObjects will normally return a new instance for each
+ * call although each instance will point to the same underlying native
+ * resource.
+ * <p>
+ * Memory management is explicit and objects must be released when no longer
+ * needed.
+ */
+public abstract class CLObject extends NativeZ {
+
+       protected CLObject(long p) {
+               super(p);
+       }
+
+       static {
+               System.loadLibrary("zcl");
+       }
+
+       // These are not really public - for access by extensions
+       public static final int CTYPE_PLATFORM = 0;
+       public static final int CTYPE_DEVICE = 1;
+       public static final int CTYPE_CONTEXT = 2;
+       public static final int CTYPE_COMMAND_QUEUE = 3;
+       public static final int CTYPE_PIPE = 4;
+       public static final int CTYPE_BUFFER = 5;
+       public static final int CTYPE_IMAGE = 6;
+       public static final int CTYPE_SAMPLER = 7;
+       public static final int CTYPE_PROGRAM = 8;
+       public static final int CTYPE_KERNEL = 9;
+       public static final int CTYPE_EVENT = 10;
+       public static final int CTYPE_SIZEOF = 11; // just a count
+
+       /*
+        These type codes are used for getInfoX() queries.
+        Various values in zcl-jni.c must be synchronised with this manually.
+        */
+       public static final int CTYPE_SIZE_T = 16;
+       public static final int CTYPE_BYTE = 17;
+       public static final int CTYPE_SHORT = 18;
+       public static final int CTYPE_INT = 19;
+       public static final int CTYPE_LONG = 20;
+       public static final int CTYPE_FLOAT = 21;
+       public static final int CTYPE_DOUBLE = 22;
+       // Range of primitives
+       protected static final int CTYPE_PRIMITIVE = 16;
+       protected static final int CTYPE_PRIMITIVE_SIZEOF = 23 - 16;
+       //protected static final int CTYPE_ARRAY = 128;
+
+
+       /* Info types */
+       final static int TYPE_PLATFORM = 0;
+       final static int TYPE_DEVICE = 1;
+       final static int TYPE_CONTEXT = 2;
+       final static int TYPE_COMMAND_QUEUE = 3;
+       final static int TYPE_MEM_OBJECT = 4;
+       final static int TYPE_IMAGE = 5;
+       final static int TYPE_PIPE = 6;
+       final static int TYPE_SAMPLER = 7;
+       final static int TYPE_PROGRAM = 8;
+       final static int TYPE_PROGRAM_BUILD = 9;
+       final static int TYPE_KERNEL = 10;
+       final static int TYPE_KERNEL_ARG = 11;
+       final static int TYPE_KERNEL_WORK_GROUP = 12;
+       final static int TYPE_EVENT = 13;
+       final static int TYPE_EVENT_PROFILING = 14;
+       final static int TYPE_KERNEL_SUB_GROUP = 15;
+
+       /**
+        * A generic get info type for GetInfo() qeries that take 5 arguments.
+        *
+        * @param type type code for 'this', or the query that applies to this.
+        * @param param_name name of value being queried.
+        * @param otype output type
+        * @return result, primitive types are boxed.
+        * @throws CLRuntimeException
+        */
+       native <T> T getInfoAny(int type, int otype, int param_name) throws CLRuntimeException;
+
+       <T> T getInfoAny(int otype, int param_name) throws CLRuntimeException {
+               return getInfoAny(getInfoType(), otype, param_name);
+       }
+
+       /**
+        * A generic get info type for GetInfo() qeries that take 5 arguments and
+        * returns an array.
+        *
+        * @param type type code for 'this', or the query that applies to this.
+        * @param param_name name of value being queried.
+        * @param otype output type
+        * @return result array type.
+        * @throws CLRuntimeException
+        */
+       native <T> T getInfoAnyV(int type, int otype, int param_name) throws CLRuntimeException;
+
+       <T> T getInfoAnyV(int otype, int param_name) throws CLRuntimeException {
+               return getInfoAnyV(getInfoType(), otype, param_name);
+       }
+
+       native long getInfoLong(int type, int param_name) throws CLRuntimeException;
+
+       native int getInfoInt(int type, int param_name) throws CLRuntimeException;
+
+       native long getInfoSizeT(int type, int param_name) throws CLRuntimeException;
+
+       /**
+        * Retrieve an int field.
+        *
+        * @param param
+        * @return
+        */
+       public int getInfoInt(int param) {
+               return getInfoInt(getInfoType(), param);
+       }
+
+       /**
+        * Retrieves a long field.
+        *
+        * @param param
+        * @return
+        */
+       public long getInfoLong(int param) {
+               return getInfoLong(getInfoType(), param);
+       }
+
+       /**
+        * Retrieves a size_t field.
+        *
+        * @param param
+        * @return Value of parameter.
+        * @throws CLRuntimeException
+        */
+       public long getInfoSizeT(int param) {
+               return getInfoSizeT(getInfoType(), param);
+       }
+
+       /**
+        * Retrieves an array of size_t fields.
+        *
+        * @param param
+        * @return The parameter value.
+        * @throws CLRuntimeException
+        */
+       public long[] getInfoSizeTA(int param) {
+               return getInfoAnyV(getInfoType(), CTYPE_SIZE_T, param);
+       }
+
+       /**
+        * Strips the trailing NUL from the c-String buffer.
+        *
+        * @param bytea
+        * @return
+        */
+       static String fromInfoString(byte[] bytea) {
+               return new String(bytea, 0, bytea.length - 1);
+       }
+
+       /**
+        * Retrieves a char * field as a UTF8 string.
+        *
+        * @param param
+        * @return
+        */
+       public String getInfoString(int param) {
+               return fromInfoString(getInfoAnyV(getInfoType(), CTYPE_BYTE, param));
+       }
+
+       /**
+        * Returns the type code for this class. Taken from TYPE_*
+        *
+        * @return
+        */
+       abstract int getInfoType();
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLPipe.java b/src/notzed.zcl/classes/au/notzed/zcl/CLPipe.java
new file mode 100644 (file)
index 0000000..dd16778
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import static au.notzed.zcl.CL.*;
+
+/**
+ * Interface for pipes.
+ *
+ * @param <T> Not used - yet?
+ */
+public class CLPipe<T> extends CLMemory {
+
+       /**
+        * Create an interface for a native pointer of type cl_mem that refers to a
+        * pipe object.
+        *
+        * @param p Native pointer.
+        */
+       public CLPipe(long p) {
+               super(p);
+       }
+
+       static void release(long p) {
+               CLMemory.release(p);
+       }
+
+       @Override
+       int getInfoType() {
+               return TYPE_PIPE;
+       }
+
+       public int getPacketSize() {
+               return getInfoInt(CL_PIPE_PACKET_SIZE);
+       }
+
+       public int getMaxPackets() {
+               return getInfoInt(CL_PIPE_MAX_PACKETS);
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLPipeProperty.java b/src/notzed.zcl/classes/au/notzed/zcl/CLPipeProperty.java
new file mode 100644 (file)
index 0000000..c768fb9
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Properties for CLPipe creation.
+ */
+public interface CLPipeProperty extends CLProperty {
+
+       public static class TagValue extends CLProperty.TagValue implements CLPipeProperty {
+
+               public TagValue(long tag, long value) {
+                       super(tag, value);
+               }
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLPlatform.java b/src/notzed.zcl/classes/au/notzed/zcl/CLPlatform.java
new file mode 100644 (file)
index 0000000..04c538a
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import static au.notzed.zcl.CL.*;
+import au.notzed.zcl.khr.GLSharing;
+import java.util.function.ToDoubleFunction;
+
+/**
+ * Interface for cl_platform_id
+ */
+public class CLPlatform extends CLObject {
+
+       // Note that these don't match the typical version flags used by the c preprocessor
+       public final static int VERSION_1_0 = 0x100;
+       public final static int VERSION_1_1 = 0x101;
+       public final static int VERSION_1_2 = 0x102;
+       public final static int VERSION_2_0 = 0x200;
+       public final static int VERSION_2_1 = 0x201;
+
+       final int apiVersion;
+
+       /**
+        * Create an interface for a native pointer of type cl_platform_id.
+        *
+        * @param p Native pointer.
+        */
+       public CLPlatform(long p) {
+               super(p);
+
+               String v = getVersion();
+               try {
+                       int dot = v.indexOf('.', 7);
+                       int space = v.indexOf(' ', dot);
+                       int major = Integer.parseInt(v.substring(7, dot));
+                       int minor = Integer.parseInt(v.substring(dot + 1, space));
+                       apiVersion = (major << 8) | minor;
+               } catch (NullPointerException | NumberFormatException | IndexOutOfBoundsException ex) {
+                       throw new RuntimeException(String.format("Unable to parse version string `%s'", v));
+               }
+       }
+
+       private native static void release(long p);
+
+       @Override
+       public String toString() {
+               return getName();
+       }
+
+       @Override
+       int getInfoType() {
+               return TYPE_PLATFORM;
+       }
+
+       /**
+        * Calls clGetPlatformIDs.
+        *
+        * @return List of all available platforms.
+        * @throws CLRuntimeException
+        */
+       public static native CLPlatform[] getPlatforms() throws CLRuntimeException;
+
+       /**
+        * Calls clGetDeviceIDs.
+        * <p>
+        * All devices of the given type will be listed.
+        *
+        * @param type CL_DEVICE_TYPE_*.
+        * @return List of matching devices in this platform.
+        * @throws CLRuntimeException
+        */
+       public native CLDevice[] getDevices(long type) throws CLRuntimeException;
+
+       /**
+        * Find the 'best' device using supplied statistic.
+        *
+        * @param type CL_DEVICE_TYPE_*.
+        * @param scoreFunc return a higher value for a better score.
+        * @return A device, if found.
+        */
+       public static CLDevice getBestDevice(long type, ToDoubleFunction<CLDevice> scoreFunc) {
+               CLPlatform[] platforms = CLPlatform.getPlatforms();
+               CLDevice best = null;
+               double bestScore = 0;
+
+               for (CLPlatform p : platforms) {
+                       CLDevice[] devs = p.getDevices(type);
+
+                       for (CLDevice d : devs) {
+                               double score = scoreFunc.applyAsDouble(d);
+
+                               if (best == null || score > bestScore) {
+                                       best = d;
+                                       bestScore = score;
+                               }
+                       }
+               }
+
+               return best;
+       }
+
+       /**
+        * Find the 'best' device based on number of compute units. GPUs are assumed
+        * to have 64 FPUs per compute unit.
+        *
+        * @param type CL_DEVICE_TYPE_*.
+        * @return A device, if found.
+        */
+       public static CLDevice getBestDevice(long type) {
+               return getBestDevice(type, (CLDevice d) -> (d.getMaxComputeUnits() * d.getType() == CL_DEVICE_TYPE_GPU ? 64 : 1));
+       }
+
+       /**
+        * Calls clUnloadPlatformCompiler.
+        *
+        * @throws CLRuntimeException
+        */
+       public native void unloadPlatformCompiler() throws CLRuntimeException;
+
+       /**
+        * get CL_PLATFORM_PROFILE.
+        *
+        * @return platform profile
+        */
+       public String getProfile() {
+               return getInfoString(CL_PLATFORM_PROFILE);
+       }
+
+       /**
+        * get CL_PLATFORM_VERSION.
+        *
+        * @return platform version
+        */
+       public String getVersion() {
+               return getInfoString(CL_PLATFORM_VERSION);
+       }
+
+       /**
+        * get CL_PLATFORM_NAME.
+        *
+        * @return platform name
+        */
+       public String getName() {
+               return getInfoString(CL_PLATFORM_NAME);
+       }
+
+       /**
+        * get CL_PLATFORM_VENDOR.
+        *
+        * @return platform vendor
+        */
+       public String getVendor() {
+               return getInfoString(CL_PLATFORM_VENDOR);
+       }
+
+       /**
+        * get CL_PLATFORM_EXTENSIONS
+        *
+        * @return platform extensions
+        */
+       public String getExtensions() {
+               return getInfoString(CL_PLATFORM_EXTENSIONS);
+       }
+
+       /**
+        * GL sharing extension id.
+        */
+       public static final int cl_khr_gl_sharing = 0;
+       /**
+        * GL event extension id
+        */
+       public static final int cl_khr_gl_event = 1;
+
+       /**
+        * Tracks extension per platform.
+        * <p>
+        * Extensions are bound to platforms.
+        */
+       final CLExtension[] extensions = new CLExtension[2];
+
+       native CLExtension createExtension(int extension); // throws something
+
+       public <T extends CLExtension> T getExtension(int id) {
+               synchronized (extensions) {
+                       if (extensions[id] == null) {
+                               extensions[id] = createExtension(id);
+                       }
+                       return (T) extensions[id];
+               }
+       }
+
+       /**
+        * Retrieve an extension by name.
+        *
+        * @param <T>
+        * @param name
+        * @return
+        */
+       public <T extends CLExtension> T getExtension(String name) {
+               switch (name) {
+               case GLSharing.NAME:
+                       return getExtension(cl_khr_gl_sharing);
+               case au.notzed.zcl.khr.GLEvent.NAME:
+                       return getExtension(cl_khr_gl_event);
+               }
+               return null;
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLProgram.java b/src/notzed.zcl/classes/au/notzed/zcl/CLProgram.java
new file mode 100644 (file)
index 0000000..44da93d
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import static au.notzed.zcl.CL.*;
+
+/**
+ * Interface for cl_program.
+ */
+public class CLProgram extends CLObject {
+
+       /**
+        * Create an interface for a native pointer of type cl_program.
+        *
+        * @param p Native pointer.
+        */
+       public CLProgram(long p) {
+               super(p);
+       }
+
+       private native static void release(long p);
+
+       @Override
+       int getInfoType() {
+               return TYPE_PROGRAM;
+       }
+
+       /**
+        * Call clBuildProgram.
+        *
+        * @param devices Target devices.
+        * @param options Build options.
+        * @param notify Notification callback.
+        * @throws CLException
+        */
+       public native void buildProgram(CLDevice[] devices, String options, CLNotify<CLProgram> notify) throws CLException;
+
+       public void buildProgram(CLDevice[] devices, String options) throws CLException {
+               CLNotify<CLProgram> notify = (CLProgram source) -> {
+                       for (CLDevice d : devices) {
+                               int status = source.getBuildStatus(d);
+                               if (status != 0) {
+                                       System.err.printf("Build status: %d\n", status);
+                                       System.err.printf("Build log:\n%s\n.\n\n", source.getBuildLog(d));
+                               }
+                       }
+               };
+
+               try {
+                       buildProgram(devices, options, notify);
+               } catch (CLException ex) {
+                       notify.notify(this);
+                       throw ex;
+               }
+       }
+
+       /**
+        * Call clCompileProgram.
+        *
+        * @param devices
+        * @param options
+        * @param headers List of programs defining headers.
+        * @param header_names List of names from headers. They must contain the
+        * same number of elements.
+        * @param notify
+        * @throws CLException
+        * @throws UnsupportedOperationException
+        * @since OpenCL 1.2
+        */
+       public native void compileProgram(CLDevice[] devices, String options, CLProgram[] headers, String[] header_names, CLNotify<CLProgram> notify) throws CLException, UnsupportedOperationException;
+
+       /**
+        * Call clCreateKernel.
+        *
+        * @param name Name of kernel function.
+        * @return A newly created kernel. Release should be called when it is no
+        * longer needed.
+        * @throws CLRuntimeException
+        */
+       public native CLKernel createKernel(String name) throws CLRuntimeException;
+
+       /**
+        * Call clCreateKernelsInProgram.
+        *
+        * @return Number of kernels created.
+        * @throws CLRuntimeException
+        */
+       public native CLKernel[] createKernelsInProgram() throws CLRuntimeException;
+
+       public CLContext getContext() {
+               return getInfoAny(CTYPE_CONTEXT, CL_PROGRAM_CONTEXT);
+       }
+
+       public int getNumDevices() {
+               return getInfoInt(CL_PROGRAM_NUM_DEVICES);
+       }
+
+       public CLDevice[] getDevices() {
+               return getInfoAnyV(CTYPE_DEVICE, CL_PROGRAM_DEVICES);
+       }
+
+       public String getSource() {
+               return getInfoString(CL_PROGRAM_SOURCE);
+       }
+
+       /* This is unnecessary since getBinaries() is the only thing that needs it
+        public long[] getBinarySizes() {
+        long[] sizes = new long[getNumDevices()];
+
+        getInfoSizeTA(CL_PROGRAM_BINARY_SIZES, sizes);
+
+        return sizes;
+        }*/
+       public native byte[][] getBinaries();
+
+       public int getNumKernels() {
+               return getInfoInt(CL_PROGRAM_NUM_KERNELS);
+       }
+
+       public String getKernelNames() {
+               return getInfoString(CL_PROGRAM_KERNEL_NAMES);
+       }
+
+       /* cl_program_build_info */
+       native <T> T getBuildInfoAny(CLDevice dev, int otype, int param_name) throws CLRuntimeException;
+
+       native <T> T getBuildInfoAnyV(CLDevice dev, int otype, int param_name) throws CLRuntimeException;
+
+       public int getBuildStatus(CLDevice device) {
+               return getBuildInfoAny(device, CTYPE_INT, CL_PROGRAM_BUILD_STATUS);
+       }
+
+       public String getBuildOptions(CLDevice device) {
+               return fromInfoString(getBuildInfoAnyV(device, CTYPE_BYTE, CL_PROGRAM_BUILD_OPTIONS));
+       }
+
+       public String getBuildLog(CLDevice device) {
+               return fromInfoString(getBuildInfoAnyV(device, CTYPE_BYTE, CL_PROGRAM_BUILD_LOG));
+       }
+
+       public int getBinaryType(CLDevice device) {
+               return getBuildInfoAny(device, CTYPE_INT, CL_PROGRAM_BINARY_TYPE);
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLProperty.java b/src/notzed.zcl/classes/au/notzed/zcl/CLProperty.java
new file mode 100644 (file)
index 0000000..ef03c45
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * All property arrays implement this interface.
+ */
+public interface CLProperty {
+
+       public abstract int getSize();
+
+       /**
+        * Encode this property as an integer array.
+        *
+        * @param dst destination
+        * @param o offset
+        * @return updated o (o + getSize())
+        */
+       public abstract int toInt(int dst[], int o);
+
+       /**
+        * Encode this property as a long array.
+        *
+        * @param dst destination
+        * @param o offset
+        * @return updated o (o + getSize())
+        */
+       public abstract int toLong(long dst[], int o);
+
+       /**
+        * A simple tag/value property type.
+        */
+       public static class TagValue implements CLProperty {
+
+               private final long tag;
+               private final long value;
+
+               public TagValue(long tag, long value) {
+                       this.tag = tag;
+                       this.value = value;
+               }
+
+               @Override
+               public int getSize() {
+                       return 2;
+               }
+
+               @Override
+               public int toInt(int[] dst, int o) {
+                       dst[o++] = (int) tag;
+                       dst[o++] = (int) value;
+                       return o;
+               }
+
+               @Override
+               public int toLong(long[] dst, int o) {
+                       dst[o++] = tag;
+                       dst[o++] = value;
+                       return o;
+               }
+
+       }
+
+       /**
+        * Returns the number of intptr_t values to encode the property array.
+        *
+        * @param props
+        * @return
+        */
+       static int getSize(Object[] props) {
+               int size = 0;
+               for (Object p : props) {
+                       size += ((CLProperty) p).getSize();
+               }
+
+               return size + 1;
+       }
+
+       /**
+        * Convert to 32-bit intptr_t array. A terminating 0 is included.
+        *
+        * @param props
+        * @return
+        */
+       public static int[] toInt(Object[] props) {
+               int[] dst = new int[getSize(props)];
+               int o = 0;
+
+               //System.out.printf("CLProperty toInt(props=%d) size=%d\n", props.length, dst.length);
+
+               for (Object p : props) {
+                       o = ((CLProperty) p).toInt(dst, o);
+               }
+               dst[o] = 0;
+
+               return dst;
+       }
+
+       /**
+        * Convert to 64-bit intptr_t array. A terminating 0L is included.
+        *
+        * @param props
+        * @return
+        */
+       public static long[] toLong(Object[] props) {
+               long[] dst = new long[getSize(props)];
+               int o = 0;
+
+               //System.out.printf("CLProperty toLong(props=%d) size=%d\n", props.length, dst.length);
+
+               for (Object p : props) {
+                       o = ((CLProperty) p).toLong(dst, o);
+               }
+               dst[o] = 0;
+
+               return dst;
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLQueueProperty.java b/src/notzed.zcl/classes/au/notzed/zcl/CLQueueProperty.java
new file mode 100644 (file)
index 0000000..37890e9
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Properties for CLCommandQueue creation.
+ */
+public interface CLQueueProperty extends CLProperty {
+
+       public static class TagValue extends CLProperty.TagValue implements CLQueueProperty {
+
+               public TagValue(long tag, long value) {
+                       super(tag, value);
+               }
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLRuntimeException.java b/src/notzed.zcl/classes/au/notzed/zcl/CLRuntimeException.java
new file mode 100644 (file)
index 0000000..1a6a088
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import static au.notzed.zcl.CLException.codeToError;
+
+/**
+ * An exception that is likely to occur from a more serious error such as out of
+ * memory.
+ */
+public class CLRuntimeException extends RuntimeException {
+
+       private final int id;
+
+       /**
+        *
+        * @param id
+        */
+       public CLRuntimeException(int id) {
+               this.id = id;
+       }
+
+       public int getID() {
+               return id;
+       }
+
+       @Override
+       public String getMessage() {
+               return String.format("Error (%d): '%s'", id, codeToError(id));
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLSampler.java b/src/notzed.zcl/classes/au/notzed/zcl/CLSampler.java
new file mode 100644 (file)
index 0000000..1133e15
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import static au.notzed.zcl.CL.*;
+
+/**
+ * Interface for cl_sampler.
+ */
+public class CLSampler extends CLObject {
+
+       /**
+        * Create an interface for a native pointer of type cl_sampler.
+        *
+        * @param p Native pointer.
+        */
+       public CLSampler(long p) {
+               super(p);
+       }
+
+       private native static void release(long p);
+
+       @Override
+       int getInfoType() {
+               return TYPE_SAMPLER;
+       }
+
+       public CLContext getContext() {
+               return getInfoAny(CTYPE_CONTEXT, CL_SAMPLER_CONTEXT);
+       }
+
+       public boolean getNormalisedCoords() {
+               return getInfoInt(CL_SAMPLER_NORMALIZED_COORDS) != 0;
+       }
+
+       public int getAddressingMode() {
+               return getInfoInt(CL_SAMPLER_ADDRESSING_MODE);
+       }
+
+       public int getFilterMode() {
+               return getInfoInt(CL_SAMPLER_FILTER_MODE);
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLSamplerProperty.java b/src/notzed.zcl/classes/au/notzed/zcl/CLSamplerProperty.java
new file mode 100644 (file)
index 0000000..d927789
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2014 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+/**
+ * Properties for CLSampler creation.
+ */
+public interface CLSamplerProperty extends CLProperty {
+
+       public static class TagValue extends CLProperty.TagValue implements CLSamplerProperty {
+
+               public TagValue(long tag, long value) {
+                       super(tag, value);
+               }
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/CLTask.java b/src/notzed.zcl/classes/au/notzed/zcl/CLTask.java
new file mode 100644 (file)
index 0000000..10c2b89
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2015 notzed
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+import java.util.function.BiConsumer;
+import java.util.function.BinaryOperator;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collector;
+
+/**
+ * Tasks are a functional(ish) interface to queueable jobs.
+ * <p>
+ * At its base each CLCommandQueue enqueue interface is wrapped by the target
+ * data type which defines 'of()' methods for the operations instead.
+ * <p>
+ * The goal is to reduce the interface size which simplifying re-use.
+ * <p>
+ * This is an experimental 'zcl' feature.
+ */
+@FunctionalInterface
+public interface CLTask {
+
+       /**
+        * Enqueue the job.
+        * <p>
+        * @param q target queue.
+        * @param wait events to wait for completion before starting, or null.
+        * @param event target for completion event, or null.
+        */
+       public void enqueue(CLCommandQueue q, CLEventList wait, CLEventList event) throws CLException;
+
+       /**
+        * Cascade two steps.
+        *
+        * @param after Task to run after this one.
+        * @return
+        */
+       public default CLTask andThen(CLTask after) {
+               return (q, w, e) -> {
+                       // FIXME: event handling
+                       enqueue(q, w, null);
+                       after.enqueue(q, null, e);
+               };
+       }
+
+       static CLTask NOP = CLCommandQueue::enqueueMarkerWithWaitList;
+       // TODO: flush doesn't do any event stuff, should it?
+       static CLTask FLUSH = (CLCommandQueue q, CLEventList wait, CLEventList event) -> q.flush();
+
+       public static CLTask toTask(List<CLTask> list) {
+               if (list.isEmpty()) {
+                       return ofNOP();
+               } else if (list.size() == 1) {
+                       return list.get(0);
+               }
+
+               CLTask[] a = list.toArray(new CLTask[list.size()]);
+
+               return (q, wait, event) -> {
+                       int i = 0;
+                       a[i++].enqueue(q, wait, null);
+                       while (i < a.length - 1) {
+                               a[i++].enqueue(q, null, null);
+                       }
+                       a[i++].enqueue(q, null, event);
+               };
+       }
+
+       public static CLTask ofNOP() {
+               return NOP;
+       }
+
+       public static CLTask ofFlush() {
+               return FLUSH;
+       }
+
+       public static Collector<CLTask, List<CLTask>, CLTask> toTask() {
+               return new Collector<CLTask, List<CLTask>, CLTask>() {
+                       @Override
+                       public Supplier<List<CLTask>> supplier() {
+                               return () -> new ArrayList<>();
+                       }
+
+                       @Override
+                       public BiConsumer<List<CLTask>, CLTask> accumulator() {
+                               return List::add;
+                       }
+
+                       @Override
+                       public BinaryOperator<List<CLTask>> combiner() {
+                               return (List<CLTask> t, List<CLTask> u) -> {
+                                       t.addAll(u);
+                                       return t;
+                               };
+                       }
+
+                       @Override
+                       public Function<List<CLTask>, CLTask> finisher() {
+                               return CLTask::toTask;
+                       }
+
+                       @Override
+                       public Set<Collector.Characteristics> characteristics() {
+                               return EnumSet.of(Characteristics.CONCURRENT);
+                       }
+               };
+       }
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/khr/GLEvent.java b/src/notzed.zcl/classes/au/notzed/zcl/khr/GLEvent.java
new file mode 100644 (file)
index 0000000..ffa2599
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2015 notzed
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl.khr;
+
+import au.notzed.zcl.CLContext;
+import au.notzed.zcl.CLEvent;
+import au.notzed.zcl.CLExtension;
+
+/**
+ * cl_khr_gl_sharing extension interface.
+ */
+public class GLEvent extends CLExtension {
+
+       public GLEvent(long p) {
+               super(p);
+       }
+
+       private native static void release(long p);
+
+       @Override
+       public String getName() {
+               return NAME;
+       }
+
+       public final static String NAME = "cl_khr_gl_event";
+
+       public static final int CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR = 0x200D;
+
+       public native CLEvent clCreateEventFromGLsync(CLContext ctx, long glsync);
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/khr/GLSharing.java b/src/notzed.zcl/classes/au/notzed/zcl/khr/GLSharing.java
new file mode 100644 (file)
index 0000000..1bb988c
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2015 notzed
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.zcl.khr;
+
+import au.notzed.zcl.CLBuffer;
+import au.notzed.zcl.CLCommandQueue;
+import au.notzed.zcl.CLContext;
+import au.notzed.zcl.CLContextProperty;
+import au.notzed.zcl.CLDevice;
+import au.notzed.zcl.CLEventList;
+import au.notzed.zcl.CLExtension;
+import au.notzed.zcl.CLImage;
+import au.notzed.zcl.CLMemory;
+import au.notzed.zcl.CLObject;
+import au.notzed.zcl.CLRuntimeException;
+
+/**
+ * cl_khr_gl_sharing extension interface.
+ */
+public class GLSharing extends CLExtension {
+
+       public GLSharing(long p) {
+               super(p);
+       }
+
+       private native static void release(long p);
+
+       @Override
+       public String getName() {
+               return NAME;
+       }
+
+       public final static String NAME = "cl_khr_gl_sharing";
+
+       /* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken           */
+       public static final int CL_GL_OBJECT_BUFFER = 0x2000;
+       public static final int CL_GL_OBJECT_TEXTURE2D = 0x2001;
+       public static final int CL_GL_OBJECT_TEXTURE3D = 0x2002;
+       public static final int CL_GL_OBJECT_RENDERBUFFER = 0x2003;
+       public static final int CL_GL_OBJECT_TEXTURE2D_ARRAY = 0x200E;
+       public static final int CL_GL_OBJECT_TEXTURE1D = 0x200F;
+       public static final int CL_GL_OBJECT_TEXTURE1D_ARRAY = 0x2010;
+       public static final int CL_GL_OBJECT_TEXTURE_BUFFER = 0x2011;
+
+       /* cl_gl_texture_info           */
+       public static final int CL_GL_TEXTURE_TARGET = 0x2004;
+       public static final int CL_GL_MIPMAP_LEVEL = 0x2005;
+       public static final int CL_GL_NUM_SAMPLES = 0x2012;
+
+       /* Additional Error Codes  */
+       public static final int CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR = -1000;
+
+       /* cl_gl_context_info  */
+       public static final int CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR = 0x2006;
+       public static final int CL_DEVICES_FOR_GL_CONTEXT_KHR = 0x2007;
+
+       /* Additional cl_context_properties  */
+       public static final int CL_GL_CONTEXT_KHR = 0x2008;
+       public static final int CL_EGL_DISPLAY_KHR = 0x2009;
+       public static final int CL_GLX_DISPLAY_KHR = 0x200A;
+       public static final int CL_WGL_HDC_KHR = 0x200B;
+       public static final int CL_CGL_SHAREGROUP_KHR = 0x200C;
+
+       public static CLContextProperty GL_CONTEXT_KHR(long id) {
+               return new CLContextProperty.TagValue(CL_GL_CONTEXT_KHR, id);
+       }
+
+       public static CLContextProperty EGL_DISPLAY_KHR(long id) {
+               return new CLContextProperty.TagValue(CL_EGL_DISPLAY_KHR, id);
+       }
+
+       public static CLContextProperty GLX_DISPLAY_KHR(long id) {
+               return new CLContextProperty.TagValue(CL_GLX_DISPLAY_KHR, id);
+       }
+
+       public static CLContextProperty WGL_HDC_KHR(long id) {
+               return new CLContextProperty.TagValue(CL_WGL_HDC_KHR, id);
+       }
+
+       public static CLContextProperty CGL_SHAREGROUP_KHR(long id) {
+               return new CLContextProperty.TagValue(CL_CGL_SHAREGROUP_KHR, id);
+       }
+
+       public native CLBuffer createFromGLBuffer(CLContext ctx,
+               long flags,
+               int bufobj);
+
+       public native CLImage createFromGLTexture(CLContext ctx,
+               long flags /* flags */,
+               int target /* target */,
+               int miplevel /* miplevel */,
+               int texture /* texture */);
+
+       public native CLImage createFromGLRenderbuffer(CLContext cl_context /* context */,
+               long flags /* flags */,
+               int renderbuffer /* renderbuffer */);
+
+       public static class GLObjectInfo {
+
+               public int gl_object_type;
+               public int gl_object_name;
+
+               public GLObjectInfo() {
+               }
+
+               public GLObjectInfo(int gl_object_type, int gl_object_name) {
+                       this.gl_object_type = gl_object_type;
+                       this.gl_object_name = gl_object_name;
+               }
+
+       }
+
+       public native GLObjectInfo getGLObjectInfo(CLMemory mem);
+
+       native int getGLTextureInfoInt(CLMemory mem, int param);
+
+       public int getGLTExtureTarget(CLMemory mem) {
+               return getGLTextureInfoInt(mem, CL_GL_TEXTURE_TARGET);
+       }
+
+       public int getGLMIPMAPLevel(CLMemory mem) {
+               return getGLTextureInfoInt(mem, CL_GL_MIPMAP_LEVEL);
+       }
+
+       public native void enqueueAcquireGLObjects(
+               CLCommandQueue queue /* command_queue */,
+               CLMemory[] mem_objects /* mem_objects */,
+               CLEventList waiters,
+               CLEventList events);
+
+       public native void enqueueReleaseGLObjects(
+               CLCommandQueue queue /* command_queue */,
+               CLMemory[] mem_objects /* mem_objects */,
+               CLEventList waiters,
+               CLEventList events);
+
+       native <T> T getGLContextInfoKHRAny(
+               CLContextProperty[] properties /* properties */,
+               int ctype,
+               int param_name) throws CLRuntimeException;
+
+       native <T> T getGLContextInfoKHRAnyV(
+               CLContextProperty[] properties /* properties */,
+               int ctype,
+               int param_name) throws CLRuntimeException;
+
+       public CLDevice getCurrendDeviceForGLConextKHR(CLContextProperty[] properties) throws CLRuntimeException {
+               return getGLContextInfoKHRAny(properties, CLObject.CTYPE_DEVICE, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR);
+       }
+
+       public CLDevice[] getDevicesForGLConextKHR(CLContextProperty[] properties) throws CLRuntimeException {
+               return getGLContextInfoKHRAnyV(properties, CLObject.CTYPE_DEVICE, CL_DEVICES_FOR_GL_CONTEXT_KHR);
+       }
+
+}
diff --git a/src/notzed.zcl/classes/au/notzed/zcl/package-info.java b/src/notzed.zcl/classes/au/notzed/zcl/package-info.java
new file mode 100644 (file)
index 0000000..35fcc94
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2015 notzed
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+/**
+ * Provides a Java binding for OpenCL 2.0 and earlier.
+ */
+package au.notzed.zcl;
diff --git a/src/notzed.zcl/classes/module-info.java b/src/notzed.zcl/classes/module-info.java
new file mode 100644 (file)
index 0000000..e83a880
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2019 Michael Zucchi
+ *
+ * This file is part of zcl <https://www.zedzone.space/software/zcl.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+module notzed.zcl {
+       requires java.logging;
+       requires notzed.nativez;
+       
+       exports au.notzed.zcl;
+       exports au.notzed.zcl.khr;
+       
+       opens au.notzed.zcl to notzed.nativez;
+}
diff --git a/src/notzed.zcl/jni/include/CL/cl.h b/src/notzed.zcl/jni/include/CL/cl.h
new file mode 100644 (file)
index 0000000..101c2c9
--- /dev/null
@@ -0,0 +1,1447 @@
+/*******************************************************************************
+ * Copyright (c) 2008 - 2013, 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.
+ *
+ * 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.
+ ******************************************************************************/
+
+#ifndef __OPENCL_CL_H
+#define __OPENCL_CL_H
+
+#ifdef __APPLE__
+#include <OpenCL/cl_platform.h>
+#else
+#include <CL/cl_platform.h>
+#endif 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************/
+
+typedef struct _cl_platform_id *    cl_platform_id;
+typedef struct _cl_device_id *      cl_device_id;
+typedef struct _cl_context *        cl_context;
+typedef struct _cl_command_queue *  cl_command_queue;
+typedef struct _cl_mem *            cl_mem;
+typedef struct _cl_program *        cl_program;
+typedef struct _cl_kernel *         cl_kernel;
+typedef struct _cl_event *          cl_event;
+typedef struct _cl_sampler *        cl_sampler;
+
+typedef cl_uint             cl_bool;                     /* WARNING!  Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ 
+typedef cl_ulong            cl_bitfield;
+typedef cl_bitfield         cl_device_type;
+typedef cl_uint             cl_platform_info;
+typedef cl_uint             cl_device_info;
+typedef cl_bitfield         cl_device_fp_config;
+typedef cl_uint             cl_device_mem_cache_type;
+typedef cl_uint             cl_device_local_mem_type;
+typedef cl_bitfield         cl_device_exec_capabilities;
+typedef cl_bitfield         cl_device_svm_capabilities;
+typedef cl_bitfield         cl_command_queue_properties;
+typedef intptr_t            cl_device_partition_property;
+typedef cl_bitfield         cl_device_affinity_domain;
+
+typedef intptr_t            cl_context_properties;
+typedef cl_uint             cl_context_info;
+typedef cl_bitfield         cl_queue_properties;
+typedef cl_uint             cl_command_queue_info;
+typedef cl_uint             cl_channel_order;
+typedef cl_uint             cl_channel_type;
+typedef cl_bitfield         cl_mem_flags;
+typedef cl_bitfield         cl_svm_mem_flags;
+typedef cl_uint             cl_mem_object_type;
+typedef cl_uint             cl_mem_info;
+typedef cl_bitfield         cl_mem_migration_flags;
+typedef cl_uint             cl_image_info;
+typedef cl_uint             cl_buffer_create_type;
+typedef cl_uint             cl_addressing_mode;
+typedef cl_uint             cl_filter_mode;
+typedef cl_uint             cl_sampler_info;
+typedef cl_bitfield         cl_map_flags;
+typedef intptr_t            cl_pipe_properties;
+typedef cl_uint             cl_pipe_info;
+typedef cl_uint             cl_program_info;
+typedef cl_uint             cl_program_build_info;
+typedef cl_uint             cl_program_binary_type;
+typedef cl_int              cl_build_status;
+typedef cl_uint             cl_kernel_info;
+typedef cl_uint             cl_kernel_arg_info;
+typedef cl_uint             cl_kernel_arg_address_qualifier;
+typedef cl_uint             cl_kernel_arg_access_qualifier;
+typedef cl_bitfield         cl_kernel_arg_type_qualifier;
+typedef cl_uint             cl_kernel_work_group_info;
+typedef cl_uint             cl_kernel_sub_group_info;
+typedef cl_uint             cl_event_info;
+typedef cl_uint             cl_command_type;
+typedef cl_uint             cl_profiling_info;
+typedef cl_bitfield         cl_sampler_properties;
+typedef cl_uint             cl_kernel_exec_info;
+
+typedef struct _cl_image_format {
+    cl_channel_order        image_channel_order;
+    cl_channel_type         image_channel_data_type;
+} cl_image_format;
+
+typedef struct _cl_image_desc {
+    cl_mem_object_type      image_type;
+    size_t                  image_width;
+    size_t                  image_height;
+    size_t                  image_depth;
+    size_t                  image_array_size;
+    size_t                  image_row_pitch;
+    size_t                  image_slice_pitch;
+    cl_uint                 num_mip_levels;
+    cl_uint                 num_samples;
+#ifdef __GNUC__
+    __extension__   /* Prevents warnings about anonymous union in -pedantic builds */
+#endif
+    union {
+      cl_mem                  buffer;
+      cl_mem                  mem_object;
+    };
+} cl_image_desc;
+
+typedef struct _cl_buffer_region {
+    size_t                  origin;
+    size_t                  size;
+} cl_buffer_region;
+
+
+/******************************************************************************/
+
+/* Error Codes */
+#define CL_SUCCESS                                  0
+#define CL_DEVICE_NOT_FOUND                         -1
+#define CL_DEVICE_NOT_AVAILABLE                     -2
+#define CL_COMPILER_NOT_AVAILABLE                   -3
+#define CL_MEM_OBJECT_ALLOCATION_FAILURE            -4
+#define CL_OUT_OF_RESOURCES                         -5
+#define CL_OUT_OF_HOST_MEMORY                       -6
+#define CL_PROFILING_INFO_NOT_AVAILABLE             -7
+#define CL_MEM_COPY_OVERLAP                         -8
+#define CL_IMAGE_FORMAT_MISMATCH                    -9
+#define CL_IMAGE_FORMAT_NOT_SUPPORTED               -10
+#define CL_BUILD_PROGRAM_FAILURE                    -11
+#define CL_MAP_FAILURE                              -12
+#define CL_MISALIGNED_SUB_BUFFER_OFFSET             -13
+#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14
+#define CL_COMPILE_PROGRAM_FAILURE                  -15
+#define CL_LINKER_NOT_AVAILABLE                     -16
+#define CL_LINK_PROGRAM_FAILURE                     -17
+#define CL_DEVICE_PARTITION_FAILED                  -18
+#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE            -19
+
+#define CL_INVALID_VALUE                            -30
+#define CL_INVALID_DEVICE_TYPE                      -31
+#define CL_INVALID_PLATFORM                         -32
+#define CL_INVALID_DEVICE                           -33
+#define CL_INVALID_CONTEXT                          -34
+#define CL_INVALID_QUEUE_PROPERTIES                 -35
+#define CL_INVALID_COMMAND_QUEUE                    -36
+#define CL_INVALID_HOST_PTR                         -37
+#define CL_INVALID_MEM_OBJECT                       -38
+#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR          -39
+#define CL_INVALID_IMAGE_SIZE                       -40
+#define CL_INVALID_SAMPLER                          -41
+#define CL_INVALID_BINARY                           -42
+#define CL_INVALID_BUILD_OPTIONS                    -43
+#define CL_INVALID_PROGRAM                          -44
+#define CL_INVALID_PROGRAM_EXECUTABLE               -45
+#define CL_INVALID_KERNEL_NAME                      -46
+#define CL_INVALID_KERNEL_DEFINITION                -47
+#define CL_INVALID_KERNEL                           -48
+#define CL_INVALID_ARG_INDEX                        -49
+#define CL_INVALID_ARG_VALUE                        -50
+#define CL_INVALID_ARG_SIZE                         -51
+#define CL_INVALID_KERNEL_ARGS                      -52
+#define CL_INVALID_WORK_DIMENSION                   -53
+#define CL_INVALID_WORK_GROUP_SIZE                  -54
+#define CL_INVALID_WORK_ITEM_SIZE                   -55
+#define CL_INVALID_GLOBAL_OFFSET                    -56
+#define CL_INVALID_EVENT_WAIT_LIST                  -57
+#define CL_INVALID_EVENT                            -58
+#define CL_INVALID_OPERATION                        -59
+#define CL_INVALID_GL_OBJECT                        -60
+#define CL_INVALID_BUFFER_SIZE                      -61
+#define CL_INVALID_MIP_LEVEL                        -62
+#define CL_INVALID_GLOBAL_WORK_SIZE                 -63
+#define CL_INVALID_PROPERTY                         -64
+#define CL_INVALID_IMAGE_DESCRIPTOR                 -65
+#define CL_INVALID_COMPILER_OPTIONS                 -66
+#define CL_INVALID_LINKER_OPTIONS                   -67
+#define CL_INVALID_DEVICE_PARTITION_COUNT           -68
+#define CL_INVALID_PIPE_SIZE                        -69
+#define CL_INVALID_DEVICE_QUEUE                     -70
+
+/* OpenCL Version */
+#define CL_VERSION_1_0                              1
+#define CL_VERSION_1_1                              1
+#define CL_VERSION_1_2                              1
+#define CL_VERSION_2_0                              1
+#define CL_VERSION_2_1                              1
+
+/* cl_bool */
+#define CL_FALSE                                    0
+#define CL_TRUE                                     1
+#define CL_BLOCKING                                 CL_TRUE
+#define CL_NON_BLOCKING                             CL_FALSE
+
+/* cl_platform_info */
+#define CL_PLATFORM_PROFILE                         0x0900
+#define CL_PLATFORM_VERSION                         0x0901
+#define CL_PLATFORM_NAME                            0x0902
+#define CL_PLATFORM_VENDOR                          0x0903
+#define CL_PLATFORM_EXTENSIONS                      0x0904
+#define CL_PLATFORM_HOST_TIMER_RESOLUTION           0x0905
+
+/* cl_device_type - bitfield */
+#define CL_DEVICE_TYPE_DEFAULT                      (1 << 0)
+#define CL_DEVICE_TYPE_CPU                          (1 << 1)
+#define CL_DEVICE_TYPE_GPU                          (1 << 2)
+#define CL_DEVICE_TYPE_ACCELERATOR                  (1 << 3)
+#define CL_DEVICE_TYPE_CUSTOM                       (1 << 4)
+#define CL_DEVICE_TYPE_ALL                          0xFFFFFFFF
+
+/* cl_device_info */
+#define CL_DEVICE_TYPE                                   0x1000
+#define CL_DEVICE_VENDOR_ID                              0x1001
+#define CL_DEVICE_MAX_COMPUTE_UNITS                      0x1002
+#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS               0x1003
+#define CL_DEVICE_MAX_WORK_GROUP_SIZE                    0x1004
+#define CL_DEVICE_MAX_WORK_ITEM_SIZES                    0x1005
+#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR            0x1006
+#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT           0x1007
+#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT             0x1008
+#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG            0x1009
+#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT           0x100A
+#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE          0x100B
+#define CL_DEVICE_MAX_CLOCK_FREQUENCY                    0x100C
+#define CL_DEVICE_ADDRESS_BITS                           0x100D
+#define CL_DEVICE_MAX_READ_IMAGE_ARGS                    0x100E
+#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS                   0x100F
+#define CL_DEVICE_MAX_MEM_ALLOC_SIZE                     0x1010
+#define CL_DEVICE_IMAGE2D_MAX_WIDTH                      0x1011
+#define CL_DEVICE_IMAGE2D_MAX_HEIGHT                     0x1012
+#define CL_DEVICE_IMAGE3D_MAX_WIDTH                      0x1013
+#define CL_DEVICE_IMAGE3D_MAX_HEIGHT                     0x1014
+#define CL_DEVICE_IMAGE3D_MAX_DEPTH                      0x1015
+#define CL_DEVICE_IMAGE_SUPPORT                          0x1016
+#define CL_DEVICE_MAX_PARAMETER_SIZE                     0x1017
+#define CL_DEVICE_MAX_SAMPLERS                           0x1018
+#define CL_DEVICE_MEM_BASE_ADDR_ALIGN                    0x1019
+#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE               0x101A
+#define CL_DEVICE_SINGLE_FP_CONFIG                       0x101B
+#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE                  0x101C
+#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE              0x101D
+#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE                  0x101E
+#define CL_DEVICE_GLOBAL_MEM_SIZE                        0x101F
+#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE               0x1020
+#define CL_DEVICE_MAX_CONSTANT_ARGS                      0x1021
+#define CL_DEVICE_LOCAL_MEM_TYPE                         0x1022
+#define CL_DEVICE_LOCAL_MEM_SIZE                         0x1023
+#define CL_DEVICE_ERROR_CORRECTION_SUPPORT               0x1024
+#define CL_DEVICE_PROFILING_TIMER_RESOLUTION             0x1025
+#define CL_DEVICE_ENDIAN_LITTLE                          0x1026
+#define CL_DEVICE_AVAILABLE                              0x1027
+#define CL_DEVICE_COMPILER_AVAILABLE                     0x1028
+#define CL_DEVICE_EXECUTION_CAPABILITIES                 0x1029
+#define CL_DEVICE_QUEUE_PROPERTIES                       0x102A    /* deprecated */
+#define CL_DEVICE_QUEUE_ON_HOST_PROPERTIES               0x102A
+#define CL_DEVICE_NAME                                   0x102B
+#define CL_DEVICE_VENDOR                                 0x102C
+#define CL_DRIVER_VERSION                                0x102D
+#define CL_DEVICE_PROFILE                                0x102E
+#define CL_DEVICE_VERSION                                0x102F
+#define CL_DEVICE_EXTENSIONS                             0x1030
+#define CL_DEVICE_PLATFORM                               0x1031
+#define CL_DEVICE_DOUBLE_FP_CONFIG                       0x1032
+/* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG */
+#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF            0x1034
+#define CL_DEVICE_HOST_UNIFIED_MEMORY                    0x1035   /* deprecated */
+#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR               0x1036
+#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT              0x1037
+#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT                0x1038
+#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG               0x1039
+#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT              0x103A
+#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE             0x103B
+#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF               0x103C
+#define CL_DEVICE_OPENCL_C_VERSION                       0x103D
+#define CL_DEVICE_LINKER_AVAILABLE                       0x103E
+#define CL_DEVICE_BUILT_IN_KERNELS                       0x103F
+#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE                  0x1040
+#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE                   0x1041
+#define CL_DEVICE_PARENT_DEVICE                          0x1042
+#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES              0x1043
+#define CL_DEVICE_PARTITION_PROPERTIES                   0x1044
+#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN              0x1045
+#define CL_DEVICE_PARTITION_TYPE                         0x1046
+#define CL_DEVICE_REFERENCE_COUNT                        0x1047
+#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC            0x1048
+#define CL_DEVICE_PRINTF_BUFFER_SIZE                     0x1049
+#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT                  0x104A
+#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT           0x104B
+#define CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS              0x104C
+#define CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE               0x104D
+#define CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES             0x104E
+#define CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE         0x104F
+#define CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE               0x1050
+#define CL_DEVICE_MAX_ON_DEVICE_QUEUES                   0x1051
+#define CL_DEVICE_MAX_ON_DEVICE_EVENTS                   0x1052
+#define CL_DEVICE_SVM_CAPABILITIES                       0x1053
+#define CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE   0x1054
+#define CL_DEVICE_MAX_PIPE_ARGS                          0x1055
+#define CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS           0x1056
+#define CL_DEVICE_PIPE_MAX_PACKET_SIZE                   0x1057
+#define CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT    0x1058
+#define CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT      0x1059
+#define CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT       0x105A
+#define CL_DEVICE_IL_VERSION                             0x105B
+#define CL_DEVICE_MAX_NUM_SUB_GROUPS                     0x105C
+#define CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS 0x105D
+
+/* cl_device_fp_config - bitfield */
+#define CL_FP_DENORM                                (1 << 0)
+#define CL_FP_INF_NAN                               (1 << 1)
+#define CL_FP_ROUND_TO_NEAREST                      (1 << 2)
+#define CL_FP_ROUND_TO_ZERO                         (1 << 3)
+#define CL_FP_ROUND_TO_INF                          (1 << 4)
+#define CL_FP_FMA                                   (1 << 5)
+#define CL_FP_SOFT_FLOAT                            (1 << 6)
+#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT         (1 << 7)
+
+/* cl_device_mem_cache_type */
+#define CL_NONE                                     0x0
+#define CL_READ_ONLY_CACHE                          0x1
+#define CL_READ_WRITE_CACHE                         0x2
+
+/* cl_device_local_mem_type */
+#define CL_LOCAL                                    0x1
+#define CL_GLOBAL                                   0x2
+
+/* cl_device_exec_capabilities - bitfield */
+#define CL_EXEC_KERNEL                              (1 << 0)
+#define CL_EXEC_NATIVE_KERNEL                       (1 << 1)
+
+/* cl_command_queue_properties - bitfield */
+#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE      (1 << 0)
+#define CL_QUEUE_PROFILING_ENABLE                   (1 << 1)
+#define CL_QUEUE_ON_DEVICE                          (1 << 2)
+#define CL_QUEUE_ON_DEVICE_DEFAULT                  (1 << 3)
+
+/* cl_context_info  */
+#define CL_CONTEXT_REFERENCE_COUNT                  0x1080
+#define CL_CONTEXT_DEVICES                          0x1081
+#define CL_CONTEXT_PROPERTIES                       0x1082
+#define CL_CONTEXT_NUM_DEVICES                      0x1083
+
+/* cl_context_properties */
+#define CL_CONTEXT_PLATFORM                         0x1084
+#define CL_CONTEXT_INTEROP_USER_SYNC                0x1085
+    
+/* cl_device_partition_property */
+#define CL_DEVICE_PARTITION_EQUALLY                 0x1086
+#define CL_DEVICE_PARTITION_BY_COUNTS               0x1087
+#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END      0x0
+#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN      0x1088
+    
+/* cl_device_affinity_domain */
+#define CL_DEVICE_AFFINITY_DOMAIN_NUMA               (1 << 0)
+#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE           (1 << 1)
+#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE           (1 << 2)
+#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE           (1 << 3)
+#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE           (1 << 4)
+#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5)
+    
+/* cl_device_svm_capabilities */
+#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER           (1 << 0)
+#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER             (1 << 1)
+#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM             (1 << 2)
+#define CL_DEVICE_SVM_ATOMICS                       (1 << 3)
+
+/* cl_command_queue_info */
+#define CL_QUEUE_CONTEXT                            0x1090
+#define CL_QUEUE_DEVICE                             0x1091
+#define CL_QUEUE_REFERENCE_COUNT                    0x1092
+#define CL_QUEUE_PROPERTIES                         0x1093
+#define CL_QUEUE_SIZE                               0x1094
+#define CL_QUEUE_DEVICE_DEFAULT                     0x1095
+
+/* cl_mem_flags and cl_svm_mem_flags - bitfield */
+#define CL_MEM_READ_WRITE                           (1 << 0)
+#define CL_MEM_WRITE_ONLY                           (1 << 1)
+#define CL_MEM_READ_ONLY                            (1 << 2)
+#define CL_MEM_USE_HOST_PTR                         (1 << 3)
+#define CL_MEM_ALLOC_HOST_PTR                       (1 << 4)
+#define CL_MEM_COPY_HOST_PTR                        (1 << 5)
+/* reserved                                         (1 << 6)    */
+#define CL_MEM_HOST_WRITE_ONLY                      (1 << 7)
+#define CL_MEM_HOST_READ_ONLY                       (1 << 8)
+#define CL_MEM_HOST_NO_ACCESS                       (1 << 9)
+#define CL_MEM_SVM_FINE_GRAIN_BUFFER                (1 << 10)   /* used by cl_svm_mem_flags only */
+#define CL_MEM_SVM_ATOMICS                          (1 << 11)   /* used by cl_svm_mem_flags only */
+#define CL_MEM_KERNEL_READ_AND_WRITE                (1 << 12)
+
+/* cl_mem_migration_flags - bitfield */
+#define CL_MIGRATE_MEM_OBJECT_HOST                  (1 << 0)
+#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED     (1 << 1)
+
+/* cl_channel_order */
+#define CL_R                                        0x10B0
+#define CL_A                                        0x10B1
+#define CL_RG                                       0x10B2
+#define CL_RA                                       0x10B3
+#define CL_RGB                                      0x10B4
+#define CL_RGBA                                     0x10B5
+#define CL_BGRA                                     0x10B6
+#define CL_ARGB                                     0x10B7
+#define CL_INTENSITY                                0x10B8
+#define CL_LUMINANCE                                0x10B9
+#define CL_Rx                                       0x10BA
+#define CL_RGx                                      0x10BB
+#define CL_RGBx                                     0x10BC
+#define CL_DEPTH                                    0x10BD
+#define CL_DEPTH_STENCIL                            0x10BE
+#define CL_sRGB                                     0x10BF
+#define CL_sRGBx                                    0x10C0
+#define CL_sRGBA                                    0x10C1
+#define CL_sBGRA                                    0x10C2
+#define CL_ABGR                                     0x10C3
+
+/* cl_channel_type */
+#define CL_SNORM_INT8                               0x10D0
+#define CL_SNORM_INT16                              0x10D1
+#define CL_UNORM_INT8                               0x10D2
+#define CL_UNORM_INT16                              0x10D3
+#define CL_UNORM_SHORT_565                          0x10D4
+#define CL_UNORM_SHORT_555                          0x10D5
+#define CL_UNORM_INT_101010                         0x10D6
+#define CL_SIGNED_INT8                              0x10D7
+#define CL_SIGNED_INT16                             0x10D8
+#define CL_SIGNED_INT32                             0x10D9
+#define CL_UNSIGNED_INT8                            0x10DA
+#define CL_UNSIGNED_INT16                           0x10DB
+#define CL_UNSIGNED_INT32                           0x10DC
+#define CL_HALF_FLOAT                               0x10DD
+#define CL_FLOAT                                    0x10DE
+#define CL_UNORM_INT24                              0x10DF
+#define CL_UNORM_INT_101010_2                       0x10E0
+
+/* cl_mem_object_type */
+#define CL_MEM_OBJECT_BUFFER                        0x10F0
+#define CL_MEM_OBJECT_IMAGE2D                       0x10F1
+#define CL_MEM_OBJECT_IMAGE3D                       0x10F2
+#define CL_MEM_OBJECT_IMAGE2D_ARRAY                 0x10F3
+#define CL_MEM_OBJECT_IMAGE1D                       0x10F4
+#define CL_MEM_OBJECT_IMAGE1D_ARRAY                 0x10F5
+#define CL_MEM_OBJECT_IMAGE1D_BUFFER                0x10F6
+#define CL_MEM_OBJECT_PIPE                          0x10F7
+
+/* cl_mem_info */
+#define CL_MEM_TYPE                                 0x1100
+#define CL_MEM_FLAGS                                0x1101
+#define CL_MEM_SIZE                                 0x1102
+#define CL_MEM_HOST_PTR                             0x1103
+#define CL_MEM_MAP_COUNT                            0x1104
+#define CL_MEM_REFERENCE_COUNT                      0x1105
+#define CL_MEM_CONTEXT                              0x1106
+#define CL_MEM_ASSOCIATED_MEMOBJECT                 0x1107
+#define CL_MEM_OFFSET                               0x1108
+#define CL_MEM_USES_SVM_POINTER                     0x1109
+
+/* cl_image_info */
+#define CL_IMAGE_FORMAT                             0x1110
+#define CL_IMAGE_ELEMENT_SIZE                       0x1111
+#define CL_IMAGE_ROW_PITCH                          0x1112
+#define CL_IMAGE_SLICE_PITCH                        0x1113
+#define CL_IMAGE_WIDTH                              0x1114
+#define CL_IMAGE_HEIGHT                             0x1115
+#define CL_IMAGE_DEPTH                              0x1116
+#define CL_IMAGE_ARRAY_SIZE                         0x1117
+#define CL_IMAGE_BUFFER                             0x1118
+#define CL_IMAGE_NUM_MIP_LEVELS                     0x1119
+#define CL_IMAGE_NUM_SAMPLES                        0x111A
+    
+/* cl_pipe_info */
+#define CL_PIPE_PACKET_SIZE                         0x1120
+#define CL_PIPE_MAX_PACKETS                         0x1121
+
+/* cl_addressing_mode */
+#define CL_ADDRESS_NONE                             0x1130
+#define CL_ADDRESS_CLAMP_TO_EDGE                    0x1131
+#define CL_ADDRESS_CLAMP                            0x1132
+#define CL_ADDRESS_REPEAT                           0x1133
+#define CL_ADDRESS_MIRRORED_REPEAT                  0x1134
+
+/* cl_filter_mode */
+#define CL_FILTER_NEAREST                           0x1140
+#define CL_FILTER_LINEAR                            0x1141
+
+/* cl_sampler_info */
+#define CL_SAMPLER_REFERENCE_COUNT                  0x1150
+#define CL_SAMPLER_CONTEXT                          0x1151
+#define CL_SAMPLER_NORMALIZED_COORDS                0x1152
+#define CL_SAMPLER_ADDRESSING_MODE                  0x1153
+#define CL_SAMPLER_FILTER_MODE                      0x1154
+#define CL_SAMPLER_MIP_FILTER_MODE                  0x1155
+#define CL_SAMPLER_LOD_MIN                          0x1156
+#define CL_SAMPLER_LOD_MAX                          0x1157
+
+/* cl_map_flags - bitfield */
+#define CL_MAP_READ                                 (1 << 0)
+#define CL_MAP_WRITE                                (1 << 1)
+#define CL_MAP_WRITE_INVALIDATE_REGION              (1 << 2)
+
+/* cl_program_info */
+#define CL_PROGRAM_REFERENCE_COUNT                  0x1160
+#define CL_PROGRAM_CONTEXT                          0x1161
+#define CL_PROGRAM_NUM_DEVICES                      0x1162
+#define CL_PROGRAM_DEVICES                          0x1163
+#define CL_PROGRAM_SOURCE                           0x1164
+#define CL_PROGRAM_BINARY_SIZES                     0x1165
+#define CL_PROGRAM_BINARIES                         0x1166
+#define CL_PROGRAM_NUM_KERNELS                      0x1167
+#define CL_PROGRAM_KERNEL_NAMES                     0x1168
+#define CL_PROGRAM_IL                               0x1169
+
+/* cl_program_build_info */
+#define CL_PROGRAM_BUILD_STATUS                     0x1181
+#define CL_PROGRAM_BUILD_OPTIONS                    0x1182
+#define CL_PROGRAM_BUILD_LOG                        0x1183
+#define CL_PROGRAM_BINARY_TYPE                      0x1184
+#define CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE 0x1185
+    
+/* cl_program_binary_type */
+#define CL_PROGRAM_BINARY_TYPE_NONE                 0x0
+#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT      0x1
+#define CL_PROGRAM_BINARY_TYPE_LIBRARY              0x2
+#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE           0x4
+
+/* cl_build_status */
+#define CL_BUILD_SUCCESS                            0
+#define CL_BUILD_NONE                               -1
+#define CL_BUILD_ERROR                              -2
+#define CL_BUILD_IN_PROGRESS                        -3
+
+/* cl_kernel_info */
+#define CL_KERNEL_FUNCTION_NAME                     0x1190
+#define CL_KERNEL_NUM_ARGS                          0x1191
+#define CL_KERNEL_REFERENCE_COUNT                   0x1192
+#define CL_KERNEL_CONTEXT                           0x1193
+#define CL_KERNEL_PROGRAM                           0x1194
+#define CL_KERNEL_ATTRIBUTES                        0x1195
+#define CL_KERNEL_MAX_NUM_SUB_GROUPS                0x11B9
+#define CL_KERNEL_COMPILE_NUM_SUB_GROUPS            0x11BA
+
+/* cl_kernel_arg_info */
+#define CL_KERNEL_ARG_ADDRESS_QUALIFIER             0x1196
+#define CL_KERNEL_ARG_ACCESS_QUALIFIER              0x1197
+#define CL_KERNEL_ARG_TYPE_NAME                     0x1198
+#define CL_KERNEL_ARG_TYPE_QUALIFIER                0x1199
+#define CL_KERNEL_ARG_NAME                          0x119A
+
+/* cl_kernel_arg_address_qualifier */
+#define CL_KERNEL_ARG_ADDRESS_GLOBAL                0x119B
+#define CL_KERNEL_ARG_ADDRESS_LOCAL                 0x119C
+#define CL_KERNEL_ARG_ADDRESS_CONSTANT              0x119D
+#define CL_KERNEL_ARG_ADDRESS_PRIVATE               0x119E
+
+/* cl_kernel_arg_access_qualifier */
+#define CL_KERNEL_ARG_ACCESS_READ_ONLY              0x11A0
+#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY             0x11A1
+#define CL_KERNEL_ARG_ACCESS_READ_WRITE             0x11A2
+#define CL_KERNEL_ARG_ACCESS_NONE                   0x11A3
+    
+/* cl_kernel_arg_type_qualifer */
+#define CL_KERNEL_ARG_TYPE_NONE                     0
+#define CL_KERNEL_ARG_TYPE_CONST                    (1 << 0)
+#define CL_KERNEL_ARG_TYPE_RESTRICT                 (1 << 1)
+#define CL_KERNEL_ARG_TYPE_VOLATILE                 (1 << 2)
+#define CL_KERNEL_ARG_TYPE_PIPE                     (1 << 3)
+
+/* cl_kernel_work_group_info */
+#define CL_KERNEL_WORK_GROUP_SIZE                   0x11B0
+#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE           0x11B1
+#define CL_KERNEL_LOCAL_MEM_SIZE                    0x11B2
+#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3
+#define CL_KERNEL_PRIVATE_MEM_SIZE                  0x11B4
+#define CL_KERNEL_GLOBAL_WORK_SIZE                  0x11B5
+
+/* cl_kernel_sub_group_info */
+#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE    0x2033
+#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE       0x2034
+#define CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT    0x11B8
+    
+/* cl_kernel_exec_info */
+#define CL_KERNEL_EXEC_INFO_SVM_PTRS                0x11B6
+#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM   0x11B7
+
+/* cl_event_info  */
+#define CL_EVENT_COMMAND_QUEUE                      0x11D0
+#define CL_EVENT_COMMAND_TYPE                       0x11D1
+#define CL_EVENT_REFERENCE_COUNT                    0x11D2
+#define CL_EVENT_COMMAND_EXECUTION_STATUS           0x11D3
+#define CL_EVENT_CONTEXT                            0x11D4
+
+/* cl_command_type */
+#define CL_COMMAND_NDRANGE_KERNEL                   0x11F0
+#define CL_COMMAND_TASK                             0x11F1
+#define CL_COMMAND_NATIVE_KERNEL                    0x11F2
+#define CL_COMMAND_READ_BUFFER                      0x11F3
+#define CL_COMMAND_WRITE_BUFFER                     0x11F4
+#define CL_COMMAND_COPY_BUFFER                      0x11F5
+#define CL_COMMAND_READ_IMAGE                       0x11F6
+#define CL_COMMAND_WRITE_IMAGE                      0x11F7
+#define CL_COMMAND_COPY_IMAGE                       0x11F8
+#define CL_COMMAND_COPY_IMAGE_TO_BUFFER             0x11F9
+#define CL_COMMAND_COPY_BUFFER_TO_IMAGE             0x11FA
+#define CL_COMMAND_MAP_BUFFER                       0x11FB
+#define CL_COMMAND_MAP_IMAGE                        0x11FC
+#define CL_COMMAND_UNMAP_MEM_OBJECT                 0x11FD
+#define CL_COMMAND_MARKER                           0x11FE
+#define CL_COMMAND_ACQUIRE_GL_OBJECTS               0x11FF
+#define CL_COMMAND_RELEASE_GL_OBJECTS               0x1200
+#define CL_COMMAND_READ_BUFFER_RECT                 0x1201
+#define CL_COMMAND_WRITE_BUFFER_RECT                0x1202
+#define CL_COMMAND_COPY_BUFFER_RECT                 0x1203
+#define CL_COMMAND_USER                             0x1204
+#define CL_COMMAND_BARRIER                          0x1205
+#define CL_COMMAND_MIGRATE_MEM_OBJECTS              0x1206
+#define CL_COMMAND_FILL_BUFFER                      0x1207
+#define CL_COMMAND_FILL_IMAGE                       0x1208
+#define CL_COMMAND_SVM_FREE                         0x1209
+#define CL_COMMAND_SVM_MEMCPY                       0x120A
+#define CL_COMMAND_SVM_MEMFILL                      0x120B
+#define CL_COMMAND_SVM_MAP                          0x120C
+#define CL_COMMAND_SVM_UNMAP                        0x120D
+
+/* command execution status */
+#define CL_COMPLETE                                 0x0
+#define CL_RUNNING                                  0x1
+#define CL_SUBMITTED                                0x2
+#define CL_QUEUED                                   0x3
+
+/* cl_buffer_create_type  */
+#define CL_BUFFER_CREATE_TYPE_REGION                0x1220
+
+/* cl_profiling_info  */
+#define CL_PROFILING_COMMAND_QUEUED                 0x1280
+#define CL_PROFILING_COMMAND_SUBMIT                 0x1281
+#define CL_PROFILING_COMMAND_START                  0x1282
+#define CL_PROFILING_COMMAND_END                    0x1283
+#define CL_PROFILING_COMMAND_COMPLETE               0x1284
+
+/********************************************************************************************************/
+
+/* Platform API */
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetPlatformIDs(cl_uint          /* num_entries */,
+                 cl_platform_id * /* platforms */,
+                 cl_uint *        /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL 
+clGetPlatformInfo(cl_platform_id   /* platform */, 
+                  cl_platform_info /* param_name */,
+                  size_t           /* param_value_size */, 
+                  void *           /* param_value */,
+                  size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Device APIs */
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetDeviceIDs(cl_platform_id   /* platform */,
+               cl_device_type   /* device_type */, 
+               cl_uint          /* num_entries */, 
+               cl_device_id *   /* devices */, 
+               cl_uint *        /* num_devices */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetDeviceInfo(cl_device_id    /* device */,
+                cl_device_info  /* param_name */, 
+                size_t          /* param_value_size */, 
+                void *          /* param_value */,
+                size_t *        /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clCreateSubDevices(cl_device_id                         /* in_device */,
+                   const cl_device_partition_property * /* properties */,
+                   cl_uint                              /* num_devices */,
+                   cl_device_id *                       /* out_devices */,
+                   cl_uint *                            /* num_devices_ret */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clRetainDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2;
+    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clReleaseDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clSetDefaultDeviceCommandQueue(cl_context           /* context */,
+                               cl_device_id         /* device */,
+                               cl_command_queue     /* command_queue */) CL_API_SUFFIX__VERSION_2_1;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetDeviceAndHostTimer(cl_device_id    /* device */,
+                        cl_ulong*       /* device_timestamp */,
+                        cl_ulong*       /* host_timestamp */) CL_API_SUFFIX__VERSION_2_1;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetHostTimer(cl_device_id /* device */,
+               cl_ulong *   /* host_timestamp */)  CL_API_SUFFIX__VERSION_2_1;
+
+    
+/* Context APIs  */
+extern CL_API_ENTRY cl_context CL_API_CALL
+clCreateContext(const cl_context_properties * /* properties */,
+                cl_uint                 /* num_devices */,
+                const cl_device_id *    /* devices */,
+                void (CL_CALLBACK * /* pfn_notify */)(const char *, const void *, size_t, void *),
+                void *                  /* user_data */,
+                cl_int *                /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_context CL_API_CALL
+clCreateContextFromType(const cl_context_properties * /* properties */,
+                        cl_device_type          /* device_type */,
+                        void (CL_CALLBACK *     /* pfn_notify*/ )(const char *, const void *, size_t, void *),
+                        void *                  /* user_data */,
+                        cl_int *                /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clRetainContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clReleaseContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetContextInfo(cl_context         /* context */, 
+                 cl_context_info    /* param_name */, 
+                 size_t             /* param_value_size */, 
+                 void *             /* param_value */, 
+                 size_t *           /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Command Queue APIs */
+extern CL_API_ENTRY cl_command_queue CL_API_CALL
+clCreateCommandQueueWithProperties(cl_context               /* context */,
+                                   cl_device_id             /* device */,
+                                   const cl_queue_properties *    /* properties */,
+                                   cl_int *                 /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clRetainCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clReleaseCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetCommandQueueInfo(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 */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Memory Object APIs */
+extern CL_API_ENTRY cl_mem CL_API_CALL
+clCreateBuffer(cl_context   /* context */,
+               cl_mem_flags /* flags */,
+               size_t       /* size */,
+               void *       /* host_ptr */,
+               cl_int *     /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_mem CL_API_CALL
+clCreateSubBuffer(cl_mem                   /* buffer */,
+                  cl_mem_flags             /* flags */,
+                  cl_buffer_create_type    /* buffer_create_type */,
+                  const void *             /* buffer_create_info */,
+                  cl_int *                 /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1;
+
+extern CL_API_ENTRY cl_mem CL_API_CALL
+clCreateImage(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 */) CL_API_SUFFIX__VERSION_1_2;
+                        
+extern CL_API_ENTRY cl_mem CL_API_CALL
+clCreatePipe(cl_context                 /* context */,
+             cl_mem_flags               /* flags */,
+             cl_uint                    /* pipe_packet_size */,
+             cl_uint                    /* pipe_max_packets */,
+             const cl_pipe_properties * /* properties */,
+             cl_int *                   /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0;
+    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clRetainMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clReleaseMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetSupportedImageFormats(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 */) CL_API_SUFFIX__VERSION_1_0;
+                                    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetMemObjectInfo(cl_mem           /* memobj */,
+                   cl_mem_info      /* param_name */, 
+                   size_t           /* param_value_size */,
+                   void *           /* param_value */,
+                   size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetImageInfo(cl_mem           /* image */,
+               cl_image_info    /* param_name */, 
+               size_t           /* param_value_size */,
+               void *           /* param_value */,
+               size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetPipeInfo(cl_mem           /* pipe */,
+              cl_pipe_info     /* param_name */,
+              size_t           /* param_value_size */,
+              void *           /* param_value */,
+              size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_2_0;
+    
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clSetMemObjectDestructorCallback(cl_mem /* memobj */,
+                                 void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/),
+                                 void * /*user_data */ )             CL_API_SUFFIX__VERSION_1_1;
+
+/* SVM Allocation APIs */
+extern CL_API_ENTRY void * CL_API_CALL
+clSVMAlloc(cl_context       /* context */,
+           cl_svm_mem_flags /* flags */,
+           size_t           /* size */,
+           cl_uint          /* alignment */) CL_API_SUFFIX__VERSION_2_0;
+
+extern CL_API_ENTRY void CL_API_CALL
+clSVMFree(cl_context        /* context */,
+          void *            /* svm_pointer */) CL_API_SUFFIX__VERSION_2_0;
+    
+/* Sampler APIs */
+extern CL_API_ENTRY cl_sampler CL_API_CALL
+clCreateSamplerWithProperties(cl_context                     /* context */,
+                              const cl_sampler_properties *  /* normalized_coords */,
+                              cl_int *                       /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clRetainSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clReleaseSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetSamplerInfo(cl_sampler         /* sampler */,
+                 cl_sampler_info    /* param_name */,
+                 size_t             /* param_value_size */,
+                 void *             /* param_value */,
+                 size_t *           /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+                            
+/* Program Object APIs  */
+extern CL_API_ENTRY cl_program CL_API_CALL
+clCreateProgramWithSource(cl_context        /* context */,
+                          cl_uint           /* count */,
+                          const char **     /* strings */,
+                          const size_t *    /* lengths */,
+                          cl_int *          /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_program CL_API_CALL
+clCreateProgramWithBinary(cl_context                     /* context */,
+                          cl_uint                        /* num_devices */,
+                          const cl_device_id *           /* device_list */,
+                          const size_t *                 /* lengths */,
+                          const unsigned char **         /* binaries */,
+                          cl_int *                       /* binary_status */,
+                          cl_int *                       /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_program CL_API_CALL
+clCreateProgramWithBuiltInKernels(cl_context            /* context */,
+                                  cl_uint               /* num_devices */,
+                                  const cl_device_id *  /* device_list */,
+                                  const char *          /* kernel_names */,
+                                  cl_int *              /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_program CL_API_CALL
+clCreateProgramWithIL(cl_context    /* context */,
+                     const void*    /* il */,
+                     size_t         /* length */,
+                     cl_int*        /* errcode_ret */) CL_API_SUFFIX__VERSION_2_1;
+
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clRetainProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clReleaseProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clBuildProgram(cl_program           /* program */,
+               cl_uint              /* num_devices */,
+               const cl_device_id * /* device_list */,
+               const char *         /* options */, 
+               void (CL_CALLBACK *  /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
+               void *               /* user_data */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clCompileProgram(cl_program           /* program */,
+                 cl_uint              /* num_devices */,
+                 const cl_device_id * /* device_list */,
+                 const char *         /* options */, 
+                 cl_uint              /* num_input_headers */,
+                 const cl_program *   /* input_headers */,
+                 const char **        /* header_include_names */,
+                 void (CL_CALLBACK *  /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
+                 void *               /* user_data */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_program CL_API_CALL
+clLinkProgram(cl_context           /* context */,
+              cl_uint              /* num_devices */,
+              const cl_device_id * /* device_list */,
+              const char *         /* options */, 
+              cl_uint              /* num_input_programs */,
+              const cl_program *   /* input_programs */,
+              void (CL_CALLBACK *  /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
+              void *               /* user_data */,
+              cl_int *             /* errcode_ret */ ) CL_API_SUFFIX__VERSION_1_2;
+
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clUnloadPlatformCompiler(cl_platform_id /* platform */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetProgramInfo(cl_program         /* program */,
+                 cl_program_info    /* param_name */,
+                 size_t             /* param_value_size */,
+                 void *             /* param_value */,
+                 size_t *           /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetProgramBuildInfo(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 */) CL_API_SUFFIX__VERSION_1_0;
+                            
+/* Kernel Object APIs */
+extern CL_API_ENTRY cl_kernel CL_API_CALL
+clCreateKernel(cl_program      /* program */,
+               const char *    /* kernel_name */,
+               cl_int *        /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clCreateKernelsInProgram(cl_program     /* program */,
+                         cl_uint        /* num_kernels */,
+                         cl_kernel *    /* kernels */,
+                         cl_uint *      /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_kernel CL_API_CALL
+clCloneKernel(cl_kernel     /* source_kernel */,
+              cl_int*       /* errcode_ret */) CL_API_SUFFIX__VERSION_2_1;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clRetainKernel(cl_kernel    /* kernel */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clReleaseKernel(cl_kernel   /* kernel */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clSetKernelArg(cl_kernel    /* kernel */,
+               cl_uint      /* arg_index */,
+               size_t       /* arg_size */,
+               const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clSetKernelArgSVMPointer(cl_kernel    /* kernel */,
+                         cl_uint      /* arg_index */,
+                         const void * /* arg_value */) CL_API_SUFFIX__VERSION_2_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clSetKernelExecInfo(cl_kernel            /* kernel */,
+                    cl_kernel_exec_info  /* param_name */,
+                    size_t               /* param_value_size */,
+                    const void *         /* param_value */) CL_API_SUFFIX__VERSION_2_0;
+    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetKernelInfo(cl_kernel       /* kernel */,
+                cl_kernel_info  /* param_name */,
+                size_t          /* param_value_size */,
+                void *          /* param_value */,
+                size_t *        /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetKernelArgInfo(cl_kernel       /* kernel */,
+                   cl_uint         /* arg_indx */,
+                   cl_kernel_arg_info  /* param_name */,
+                   size_t          /* param_value_size */,
+                   void *          /* param_value */,
+                   size_t *        /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetKernelWorkGroupInfo(cl_kernel                  /* kernel */,
+                         cl_device_id               /* device */,
+                         cl_kernel_work_group_info  /* param_name */,
+                         size_t                     /* param_value_size */,
+                         void *                     /* param_value */,
+                         size_t *                   /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetKernelSubGroupInfo(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 */ ) CL_API_SUFFIX__VERSION_2_1;
+
+
+/* Event Object APIs */
+extern CL_API_ENTRY cl_int CL_API_CALL
+clWaitForEvents(cl_uint             /* num_events */,
+                const cl_event *    /* event_list */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetEventInfo(cl_event         /* event */,
+               cl_event_info    /* param_name */,
+               size_t           /* param_value_size */,
+               void *           /* param_value */,
+               size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+                            
+extern CL_API_ENTRY cl_event CL_API_CALL
+clCreateUserEvent(cl_context    /* context */,
+                  cl_int *      /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1;               
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clRetainEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clReleaseEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clSetUserEventStatus(cl_event   /* event */,
+                     cl_int     /* execution_status */) CL_API_SUFFIX__VERSION_1_1;
+                     
+extern CL_API_ENTRY cl_int CL_API_CALL
+clSetEventCallback( cl_event    /* event */,
+                    cl_int      /* command_exec_callback_type */,
+                    void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *),
+                    void *      /* user_data */) CL_API_SUFFIX__VERSION_1_1;
+
+/* Profiling APIs */
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetEventProfilingInfo(cl_event            /* event */,
+                        cl_profiling_info   /* param_name */,
+                        size_t              /* param_value_size */,
+                        void *              /* param_value */,
+                        size_t *            /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+                                
+/* Flush and Finish APIs */
+extern CL_API_ENTRY cl_int CL_API_CALL
+clFlush(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clFinish(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Enqueued Commands APIs */
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueReadBuffer(cl_command_queue    /* command_queue */,
+                    cl_mem              /* buffer */,
+                    cl_bool             /* blocking_read */,
+                    size_t              /* offset */,
+                    size_t              /* size */, 
+                    void *              /* ptr */,
+                    cl_uint             /* num_events_in_wait_list */,
+                    const cl_event *    /* event_wait_list */,
+                    cl_event *          /* event */) CL_API_SUFFIX__VERSION_1_0;
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueReadBufferRect(cl_command_queue    /* command_queue */,
+                        cl_mem              /* buffer */,
+                        cl_bool             /* blocking_read */,
+                        const size_t *      /* buffer_offset */,
+                        const size_t *      /* host_offset */, 
+                        const size_t *      /* region */,
+                        size_t              /* buffer_row_pitch */,
+                        size_t              /* buffer_slice_pitch */,
+                        size_t              /* host_row_pitch */,
+                        size_t              /* host_slice_pitch */,                        
+                        void *              /* ptr */,
+                        cl_uint             /* num_events_in_wait_list */,
+                        const cl_event *    /* event_wait_list */,
+                        cl_event *          /* event */) CL_API_SUFFIX__VERSION_1_1;
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueWriteBuffer(cl_command_queue   /* command_queue */, 
+                     cl_mem             /* buffer */, 
+                     cl_bool            /* blocking_write */, 
+                     size_t             /* offset */, 
+                     size_t             /* size */, 
+                     const void *       /* ptr */, 
+                     cl_uint            /* num_events_in_wait_list */, 
+                     const cl_event *   /* event_wait_list */, 
+                     cl_event *         /* event */) CL_API_SUFFIX__VERSION_1_0;
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueWriteBufferRect(cl_command_queue    /* command_queue */,
+                         cl_mem              /* buffer */,
+                         cl_bool             /* blocking_write */,
+                         const size_t *      /* buffer_offset */,
+                         const size_t *      /* host_offset */, 
+                         const size_t *      /* region */,
+                         size_t              /* buffer_row_pitch */,
+                         size_t              /* buffer_slice_pitch */,
+                         size_t              /* host_row_pitch */,
+                         size_t              /* host_slice_pitch */,                        
+                         const void *        /* ptr */,
+                         cl_uint             /* num_events_in_wait_list */,
+                         const cl_event *    /* event_wait_list */,
+                         cl_event *          /* event */) CL_API_SUFFIX__VERSION_1_1;
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueFillBuffer(cl_command_queue   /* command_queue */,
+                    cl_mem             /* buffer */, 
+                    const void *       /* pattern */, 
+                    size_t             /* pattern_size */, 
+                    size_t             /* offset */, 
+                    size_t             /* size */, 
+                    cl_uint            /* num_events_in_wait_list */, 
+                    const cl_event *   /* event_wait_list */, 
+                    cl_event *         /* event */) CL_API_SUFFIX__VERSION_1_2;
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueCopyBuffer(cl_command_queue    /* command_queue */, 
+                    cl_mem              /* src_buffer */,
+                    cl_mem              /* dst_buffer */, 
+                    size_t              /* src_offset */,
+                    size_t              /* dst_offset */,
+                    size_t              /* size */, 
+                    cl_uint             /* num_events_in_wait_list */,
+                    const cl_event *    /* event_wait_list */,
+                    cl_event *          /* event */) CL_API_SUFFIX__VERSION_1_0;
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueCopyBufferRect(cl_command_queue    /* command_queue */, 
+                        cl_mem              /* src_buffer */,
+                        cl_mem              /* dst_buffer */, 
+                        const size_t *      /* src_origin */,
+                        const size_t *      /* dst_origin */,
+                        const size_t *      /* region */, 
+                        size_t              /* src_row_pitch */,
+                        size_t              /* src_slice_pitch */,
+                        size_t              /* dst_row_pitch */,
+                        size_t              /* dst_slice_pitch */,
+                        cl_uint             /* num_events_in_wait_list */,
+                        const cl_event *    /* event_wait_list */,
+                        cl_event *          /* event */) CL_API_SUFFIX__VERSION_1_1;
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueReadImage(cl_command_queue     /* command_queue */,
+                   cl_mem               /* image */,
+                   cl_bool              /* blocking_read */, 
+                   const size_t *       /* origin[3] */,
+                   const size_t *       /* region[3] */,
+                   size_t               /* row_pitch */,
+                   size_t               /* slice_pitch */, 
+                   void *               /* ptr */,
+                   cl_uint              /* num_events_in_wait_list */,
+                   const cl_event *     /* event_wait_list */,
+                   cl_event *           /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueWriteImage(cl_command_queue    /* command_queue */,
+                    cl_mem              /* image */,
+                    cl_bool             /* blocking_write */, 
+                    const size_t *      /* origin[3] */,
+                    const size_t *      /* region[3] */,
+                    size_t              /* input_row_pitch */,
+                    size_t              /* input_slice_pitch */, 
+                    const void *        /* ptr */,
+                    cl_uint             /* num_events_in_wait_list */,
+                    const cl_event *    /* event_wait_list */,
+                    cl_event *          /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueFillImage(cl_command_queue   /* command_queue */,
+                   cl_mem             /* image */, 
+                   const void *       /* fill_color */, 
+                   const size_t *     /* origin[3] */, 
+                   const size_t *     /* region[3] */, 
+                   cl_uint            /* num_events_in_wait_list */, 
+                   const cl_event *   /* event_wait_list */, 
+                   cl_event *         /* event */) CL_API_SUFFIX__VERSION_1_2;
+                            
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueCopyImage(cl_command_queue     /* command_queue */,
+                   cl_mem               /* src_image */,
+                   cl_mem               /* dst_image */, 
+                   const size_t *       /* src_origin[3] */,
+                   const size_t *       /* dst_origin[3] */,
+                   const size_t *       /* region[3] */, 
+                   cl_uint              /* num_events_in_wait_list */,
+                   const cl_event *     /* event_wait_list */,
+                   cl_event *           /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueCopyImageToBuffer(cl_command_queue /* command_queue */,
+                           cl_mem           /* src_image */,
+                           cl_mem           /* dst_buffer */, 
+                           const size_t *   /* src_origin[3] */,
+                           const size_t *   /* region[3] */, 
+                           size_t           /* dst_offset */,
+                           cl_uint          /* num_events_in_wait_list */,
+                           const cl_event * /* event_wait_list */,
+                           cl_event *       /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueCopyBufferToImage(cl_command_queue /* command_queue */,
+                           cl_mem           /* src_buffer */,
+                           cl_mem           /* dst_image */, 
+                           size_t           /* src_offset */,
+                           const size_t *   /* dst_origin[3] */,
+                           const size_t *   /* region[3] */, 
+                           cl_uint          /* num_events_in_wait_list */,
+                           const cl_event * /* event_wait_list */,
+                           cl_event *       /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY void * CL_API_CALL
+clEnqueueMapBuffer(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 */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY void * CL_API_CALL
+clEnqueueMapImage(cl_command_queue  /* command_queue */,
+                  cl_mem            /* image */, 
+                  cl_bool           /* blocking_map */, 
+                  cl_map_flags      /* map_flags */, 
+                  const size_t *    /* origin[3] */,
+                  const size_t *    /* region[3] */,
+                  size_t *          /* image_row_pitch */,
+                  size_t *          /* image_slice_pitch */,
+                  cl_uint           /* num_events_in_wait_list */,
+                  const cl_event *  /* event_wait_list */,
+                  cl_event *        /* event */,
+                  cl_int *          /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueUnmapMemObject(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 */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueMigrateMemObjects(cl_command_queue       /* command_queue */,
+                           cl_uint                /* num_mem_objects */,
+                           const cl_mem *         /* mem_objects */,
+                           cl_mem_migration_flags /* flags */,
+                           cl_uint                /* num_events_in_wait_list */,
+                           const cl_event *       /* event_wait_list */,
+                           cl_event *             /* event */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueNDRangeKernel(cl_command_queue /* command_queue */,
+                       cl_kernel        /* kernel */,
+                       cl_uint          /* work_dim */,
+                       const size_t *   /* global_work_offset */,
+                       const size_t *   /* global_work_size */,
+                       const size_t *   /* local_work_size */,
+                       cl_uint          /* num_events_in_wait_list */,
+                       const cl_event * /* event_wait_list */,
+                       cl_event *       /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueNativeKernel(cl_command_queue  /* command_queue */,
+                                         void (CL_CALLBACK * /*user_func*/)(void *), 
+                      void *            /* args */,
+                      size_t            /* cb_args */, 
+                      cl_uint           /* num_mem_objects */,
+                      const cl_mem *    /* mem_list */,
+                      const void **     /* args_mem_loc */,
+                      cl_uint           /* num_events_in_wait_list */,
+                      const cl_event *  /* event_wait_list */,
+                      cl_event *        /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueMarkerWithWaitList(cl_command_queue  /* command_queue */,
+                            cl_uint           /* num_events_in_wait_list */,
+                            const cl_event *  /* event_wait_list */,
+                            cl_event *        /* event */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueBarrierWithWaitList(cl_command_queue  /* command_queue */,
+                             cl_uint           /* num_events_in_wait_list */,
+                             const cl_event *  /* event_wait_list */,
+                             cl_event *        /* event */) CL_API_SUFFIX__VERSION_1_2;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueSVMFree(cl_command_queue  /* command_queue */,
+                 cl_uint           /* num_svm_pointers */,
+                 void *[]          /* svm_pointers[] */,
+                 void (CL_CALLBACK * /*pfn_free_func*/)(cl_command_queue /* queue */,
+                                                        cl_uint          /* num_svm_pointers */,
+                                                        void *[]         /* svm_pointers[] */,
+                                                        void *           /* user_data */),
+                 void *            /* user_data */,
+                 cl_uint           /* num_events_in_wait_list */,
+                 const cl_event *  /* event_wait_list */,
+                 cl_event *        /* event */) CL_API_SUFFIX__VERSION_2_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueSVMMemcpy(cl_command_queue  /* command_queue */,
+                   cl_bool           /* blocking_copy */,
+                   void *            /* dst_ptr */,
+                   const void *      /* src_ptr */,
+                   size_t            /* size */,
+                   cl_uint           /* num_events_in_wait_list */,
+                   const cl_event *  /* event_wait_list */,
+                   cl_event *        /* event */) CL_API_SUFFIX__VERSION_2_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueSVMMemFill(cl_command_queue  /* command_queue */,
+                    void *            /* svm_ptr */,
+                    const void *      /* pattern */,
+                    size_t            /* pattern_size */,
+                    size_t            /* size */,
+                    cl_uint           /* num_events_in_wait_list */,
+                    const cl_event *  /* event_wait_list */,
+                    cl_event *        /* event */) CL_API_SUFFIX__VERSION_2_0;
+    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueSVMMap(cl_command_queue  /* command_queue */,
+                cl_bool           /* blocking_map */,
+                cl_map_flags      /* flags */,
+                void *            /* svm_ptr */,
+                size_t            /* size */,
+                cl_uint           /* num_events_in_wait_list */,
+                const cl_event *  /* event_wait_list */,
+                cl_event *        /* event */) CL_API_SUFFIX__VERSION_2_0;
+    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueSVMUnmap(cl_command_queue  /* command_queue */,
+                  void *            /* svm_ptr */,
+                  cl_uint           /* num_events_in_wait_list */,
+                  const cl_event *  /* event_wait_list */,
+                  cl_event *        /* event */) CL_API_SUFFIX__VERSION_2_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueSVMMigrateMem(cl_command_queue         /* command_queue */,
+                       cl_uint                  /* num_svm_pointers */,
+                       const void **            /* svm_pointers */,
+                       const size_t *           /* sizes */,
+                       cl_mem_migration_flags   /* flags */,
+                       cl_uint                  /* num_events_in_wait_list */,
+                       const cl_event *         /* event_wait_list */,
+                       cl_event *               /* event */) CL_API_SUFFIX__VERSION_2_1;
+
+
+/* Extension function access
+ *
+ * Returns the extension function address for the given function name,
+ * or NULL if a valid function can not be found.  The client must
+ * check to make sure the address is not NULL, before using or 
+ * calling the returned function address.
+ */
+extern CL_API_ENTRY void * CL_API_CALL 
+clGetExtensionFunctionAddressForPlatform(cl_platform_id /* platform */,
+                                         const char *   /* func_name */) CL_API_SUFFIX__VERSION_1_2;
+    
+
+/* Deprecated OpenCL 1.1 APIs */
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL
+clCreateImage2D(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 */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+    
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL
+clCreateImage3D(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 */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+    
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL
+clEnqueueMarker(cl_command_queue    /* command_queue */,
+                cl_event *          /* event */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+    
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL
+clEnqueueWaitForEvents(cl_command_queue /* command_queue */,
+                        cl_uint          /* num_events */,
+                        const cl_event * /* event_list */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+    
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL
+clEnqueueBarrier(cl_command_queue /* command_queue */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL
+clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+    
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL
+clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+    
+/* Deprecated OpenCL 2.0 APIs */
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_command_queue CL_API_CALL
+clCreateCommandQueue(cl_context                     /* context */,
+                     cl_device_id                   /* device */,
+                     cl_command_queue_properties    /* properties */,
+                     cl_int *                       /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED;
+    
+    
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_sampler CL_API_CALL
+clCreateSampler(cl_context          /* context */,
+                cl_bool             /* normalized_coords */,
+                cl_addressing_mode  /* addressing_mode */,
+                cl_filter_mode      /* filter_mode */,
+                cl_int *            /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED;
+    
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int CL_API_CALL
+clEnqueueTask(cl_command_queue  /* command_queue */,
+              cl_kernel         /* kernel */,
+              cl_uint           /* num_events_in_wait_list */,
+              const cl_event *  /* event_wait_list */,
+              cl_event *        /* event */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED;
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __OPENCL_CL_H */
+
diff --git a/src/notzed.zcl/jni/include/CL/cl_d3d10.h b/src/notzed.zcl/jni/include/CL/cl_d3d10.h
new file mode 100644 (file)
index 0000000..aa77d37
--- /dev/null
@@ -0,0 +1,126 @@
+/**********************************************************************************
+ * Copyright (c) 2008-2013 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.
+ *
+ * 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.
+ **********************************************************************************/
+
+/* $Revision: 1.1 $ on $Date: 2015/11/22 04:25:36 $ */
+
+#ifndef __OPENCL_CL_D3D10_H
+#define __OPENCL_CL_D3D10_H
+
+#include <d3d10.h>
+#include <CL/cl.h>
+#include <CL/cl_platform.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************
+ * cl_khr_d3d10_sharing                                                       */
+#define cl_khr_d3d10_sharing 1
+
+typedef cl_uint cl_d3d10_device_source_khr;
+typedef cl_uint cl_d3d10_device_set_khr;
+
+/******************************************************************************/
+
+/* Error Codes */
+#define CL_INVALID_D3D10_DEVICE_KHR                  -1002
+#define CL_INVALID_D3D10_RESOURCE_KHR                -1003
+#define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR       -1004
+#define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR           -1005
+
+/* cl_d3d10_device_source_nv */
+#define CL_D3D10_DEVICE_KHR                          0x4010
+#define CL_D3D10_DXGI_ADAPTER_KHR                    0x4011
+
+/* cl_d3d10_device_set_nv */
+#define CL_PREFERRED_DEVICES_FOR_D3D10_KHR           0x4012
+#define CL_ALL_DEVICES_FOR_D3D10_KHR                 0x4013
+
+/* cl_context_info */
+#define CL_CONTEXT_D3D10_DEVICE_KHR                  0x4014
+#define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C
+
+/* cl_mem_info */
+#define CL_MEM_D3D10_RESOURCE_KHR                    0x4015
+
+/* cl_image_info */
+#define CL_IMAGE_D3D10_SUBRESOURCE_KHR               0x4016
+
+/* cl_command_type */
+#define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR         0x4017
+#define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR         0x4018
+
+/******************************************************************************/
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)(
+    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) CL_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)(
+    cl_context     context,
+    cl_mem_flags   flags,
+    ID3D10Buffer * resource,
+    cl_int *       errcode_ret) CL_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)(
+    cl_context        context,
+    cl_mem_flags      flags,
+    ID3D10Texture2D * resource,
+    UINT              subresource,
+    cl_int *          errcode_ret) CL_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)(
+    cl_context        context,
+    cl_mem_flags      flags,
+    ID3D10Texture3D * resource,
+    UINT              subresource,
+    cl_int *          errcode_ret) CL_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)(
+    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_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)(
+    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_API_SUFFIX__VERSION_1_0;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __OPENCL_CL_D3D10_H */
+
diff --git a/src/notzed.zcl/jni/include/CL/cl_d3d11.h b/src/notzed.zcl/jni/include/CL/cl_d3d11.h
new file mode 100644 (file)
index 0000000..52e47ce
--- /dev/null
@@ -0,0 +1,126 @@
+/**********************************************************************************
+ * Copyright (c) 2008-2013 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.
+ *
+ * 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.
+ **********************************************************************************/
+
+/* $Revision: 1.1 $ on $Date: 2015/11/22 04:25:36 $ */
+
+#ifndef __OPENCL_CL_D3D11_H
+#define __OPENCL_CL_D3D11_H
+
+#include <d3d11.h>
+#include <CL/cl.h>
+#include <CL/cl_platform.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************
+ * cl_khr_d3d11_sharing                                                       */
+#define cl_khr_d3d11_sharing 1
+
+typedef cl_uint cl_d3d11_device_source_khr;
+typedef cl_uint cl_d3d11_device_set_khr;
+
+/******************************************************************************/
+
+/* Error Codes */
+#define CL_INVALID_D3D11_DEVICE_KHR                  -1006
+#define CL_INVALID_D3D11_RESOURCE_KHR                -1007
+#define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR       -1008
+#define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR           -1009
+
+/* cl_d3d11_device_source */
+#define CL_D3D11_DEVICE_KHR                          0x4019
+#define CL_D3D11_DXGI_ADAPTER_KHR                    0x401A
+
+/* cl_d3d11_device_set */
+#define CL_PREFERRED_DEVICES_FOR_D3D11_KHR           0x401B
+#define CL_ALL_DEVICES_FOR_D3D11_KHR                 0x401C
+
+/* cl_context_info */
+#define CL_CONTEXT_D3D11_DEVICE_KHR                  0x401D
+#define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D
+
+/* cl_mem_info */
+#define CL_MEM_D3D11_RESOURCE_KHR                    0x401E
+
+/* cl_image_info */
+#define CL_IMAGE_D3D11_SUBRESOURCE_KHR               0x401F
+
+/* cl_command_type */
+#define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR         0x4020
+#define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR         0x4021
+
+/******************************************************************************/
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)(
+    cl_platform_id             platform,
+    cl_d3d11_device_source_khr d3d_device_source,
+    void *                     d3d_object,
+    cl_d3d11_device_set_khr    d3d_device_set,
+    cl_uint                    num_entries,
+    cl_device_id *             devices,
+    cl_uint *                  num_devices) CL_API_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)(
+    cl_context     context,
+    cl_mem_flags   flags,
+    ID3D11Buffer * resource,
+    cl_int *       errcode_ret) CL_API_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)(
+    cl_context        context,
+    cl_mem_flags      flags,
+    ID3D11Texture2D * resource,
+    UINT              subresource,
+    cl_int *          errcode_ret) CL_API_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)(
+    cl_context        context,
+    cl_mem_flags      flags,
+    ID3D11Texture3D * resource,
+    UINT              subresource,
+    cl_int *          errcode_ret) CL_API_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)(
+    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_API_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)(
+    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_API_SUFFIX__VERSION_1_2;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __OPENCL_CL_D3D11_H */
+
diff --git a/src/notzed.zcl/jni/include/CL/cl_dx9_media_sharing.h b/src/notzed.zcl/jni/include/CL/cl_dx9_media_sharing.h
new file mode 100644 (file)
index 0000000..08d3210
--- /dev/null
@@ -0,0 +1,127 @@
+/**********************************************************************************
+ * Copyright (c) 2008-2013 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.
+ *
+ * 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.
+ **********************************************************************************/
+
+/* $Revision: 1.1 $ on $Date: 2015/11/22 04:25:36 $ */
+
+#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H
+#define __OPENCL_CL_DX9_MEDIA_SHARING_H
+
+#include <CL/cl.h>
+#include <CL/cl_platform.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************
+/* cl_khr_dx9_media_sharing                                                   */
+#define cl_khr_dx9_media_sharing 1
+
+typedef cl_uint             cl_dx9_media_adapter_type_khr;
+typedef cl_uint             cl_dx9_media_adapter_set_khr;
+    
+#if defined(_WIN32)
+#include <d3d9.h>
+typedef struct _cl_dx9_surface_info_khr
+{
+    IDirect3DSurface9 *resource;
+    HANDLE shared_handle;
+} cl_dx9_surface_info_khr;
+#endif
+
+
+/******************************************************************************/
+
+/* Error Codes */
+#define CL_INVALID_DX9_MEDIA_ADAPTER_KHR                -1010
+#define CL_INVALID_DX9_MEDIA_SURFACE_KHR                -1011
+#define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR       -1012
+#define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR           -1013
+
+/* cl_media_adapter_type_khr */
+#define CL_ADAPTER_D3D9_KHR                              0x2020
+#define CL_ADAPTER_D3D9EX_KHR                            0x2021
+#define CL_ADAPTER_DXVA_KHR                              0x2022
+
+/* cl_media_adapter_set_khr */
+#define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR   0x2023
+#define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR         0x2024
+
+/* cl_context_info */
+#define CL_CONTEXT_ADAPTER_D3D9_KHR                      0x2025
+#define CL_CONTEXT_ADAPTER_D3D9EX_KHR                    0x2026
+#define CL_CONTEXT_ADAPTER_DXVA_KHR                      0x2027
+
+/* cl_mem_info */
+#define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR                0x2028
+#define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR                0x2029
+
+/* cl_image_info */
+#define CL_IMAGE_DX9_MEDIA_PLANE_KHR                     0x202A
+
+/* cl_command_type */
+#define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR        0x202B
+#define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR        0x202C
+
+/******************************************************************************/
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)(
+    cl_platform_id                   platform,
+    cl_uint                          num_media_adapters,
+    cl_dx9_media_adapter_type_khr *  media_adapter_type,
+    void *                           media_adapters,
+    cl_dx9_media_adapter_set_khr     media_adapter_set,
+    cl_uint                          num_entries,
+    cl_device_id *                   devices,
+    cl_uint *                        num_devices) CL_API_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)(
+    cl_context                    context,
+    cl_mem_flags                  flags,
+    cl_dx9_media_adapter_type_khr adapter_type,
+    void *                        surface_info,
+    cl_uint                       plane,                                                                          
+    cl_int *                      errcode_ret) CL_API_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)(
+    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_API_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)(
+    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_API_SUFFIX__VERSION_1_2;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __OPENCL_CL_DX9_MEDIA_SHARING_H */
+
diff --git a/src/notzed.zcl/jni/include/CL/cl_egl.h b/src/notzed.zcl/jni/include/CL/cl_egl.h
new file mode 100644 (file)
index 0000000..93e6c9c
--- /dev/null
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2010 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.
+ *
+ * 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.
+ ******************************************************************************/
+
+#ifndef __OPENCL_CL_EGL_H
+#define __OPENCL_CL_EGL_H
+
+#ifdef __APPLE__
+
+#else
+#include <CL/cl.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#endif  
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Command type for events created with clEnqueueAcquireEGLObjectsKHR */
+#define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR  0x202F
+#define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR    0x202D
+#define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR    0x202E
+
+/* Error type for clCreateFromEGLImageKHR */
+#define CL_INVALID_EGL_OBJECT_KHR             -1093
+#define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR      -1092
+
+/* CLeglImageKHR is an opaque handle to an EGLImage */
+typedef void* CLeglImageKHR;
+
+/* CLeglDisplayKHR is an opaque handle to an EGLDisplay */
+typedef void* CLeglDisplayKHR;
+
+/* CLeglSyncKHR is an opaque handle to an EGLSync object */
+typedef void* CLeglSyncKHR;
+
+/* properties passed to clCreateFromEGLImageKHR */
+typedef intptr_t cl_egl_image_properties_khr;
+
+
+#define cl_khr_egl_image 1
+
+extern CL_API_ENTRY cl_mem CL_API_CALL
+clCreateFromEGLImageKHR(cl_context                  /* context */,
+                        CLeglDisplayKHR             /* egldisplay */,
+                        CLeglImageKHR               /* eglimage */,
+                        cl_mem_flags                /* flags */,
+                        const cl_egl_image_properties_khr * /* properties */,
+                        cl_int *                    /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)(
+       cl_context                  context,
+       CLeglDisplayKHR             egldisplay,
+       CLeglImageKHR               eglimage,
+       cl_mem_flags                flags,
+       const cl_egl_image_properties_khr * properties,
+       cl_int *                    errcode_ret);
+
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueAcquireEGLObjectsKHR(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_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)(
+       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);
+
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueReleaseEGLObjectsKHR(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_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)(
+       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);
+
+
+#define cl_khr_egl_event 1
+
+extern CL_API_ENTRY cl_event CL_API_CALL
+clCreateEventFromEGLSyncKHR(cl_context      /* context */,
+                            CLeglSyncKHR    /* sync */,
+                            CLeglDisplayKHR /* display */,
+                            cl_int *        /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)(
+       cl_context      context,
+       CLeglSyncKHR    sync,
+       CLeglDisplayKHR display,
+       cl_int *        errcode_ret);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OPENCL_CL_EGL_H */
diff --git a/src/notzed.zcl/jni/include/CL/cl_ext.h b/src/notzed.zcl/jni/include/CL/cl_ext.h
new file mode 100644 (file)
index 0000000..80d0e8b
--- /dev/null
@@ -0,0 +1,386 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2013 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.
+ *
+ * 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.
+ ******************************************************************************/
+
+/* $Revision: 1.1 $ on $Date: 2015/11/22 04:25:36 $ */
+
+/* cl_ext.h contains OpenCL extensions which don't have external */
+/* (OpenGL, D3D) dependencies.                                   */
+
+#ifndef __CL_EXT_H
+#define __CL_EXT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __APPLE__
+        #include <OpenCL/cl.h>
+    #include <AvailabilityMacros.h>
+#else
+        #include <CL/cl.h>
+#endif
+
+/* cl_khr_fp16 extension - no extension #define since it has no functions  */
+#define CL_DEVICE_HALF_FP_CONFIG                    0x1033
+
+/* Memory object destruction
+ *
+ * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR
+ *
+ * Registers a user callback function that will be called when the memory object is deleted and its resources 
+ * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback 
+ * stack associated with memobj. The registered user callback functions are called in the reverse order in 
+ * which they were registered. The user callback functions are called and then the memory object is deleted 
+ * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be 
+ * notified when the memory referenced by host_ptr, specified when the memory object is created and used as 
+ * the storage bits for the memory object, can be reused or freed.
+ *
+ * The application may not call CL api's with the cl_mem object passed to the pfn_notify.
+ *
+ * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS)
+ * before using.
+ */
+#define cl_APPLE_SetMemObjectDestructor 1
+cl_int  CL_API_ENTRY clSetMemObjectDestructorAPPLE(  cl_mem /* memobj */, 
+                                        void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), 
+                                        void * /*user_data */ )             CL_EXT_SUFFIX__VERSION_1_0;  
+
+
+/* Context Logging Functions
+ *
+ * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext().
+ * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS)
+ * before using.
+ *
+ * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger 
+ */
+#define cl_APPLE_ContextLoggingFunctions 1
+extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE(  const char * /* errstr */, 
+                                            const void * /* private_info */, 
+                                            size_t       /* cb */, 
+                                            void *       /* user_data */ )  CL_EXT_SUFFIX__VERSION_1_0;
+
+/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */
+extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE(   const char * /* errstr */, 
+                                          const void * /* private_info */, 
+                                          size_t       /* cb */, 
+                                          void *       /* user_data */ )    CL_EXT_SUFFIX__VERSION_1_0;
+
+/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */
+extern void CL_API_ENTRY clLogMessagesToStderrAPPLE(   const char * /* errstr */, 
+                                          const void * /* private_info */, 
+                                          size_t       /* cb */, 
+                                          void *       /* user_data */ )    CL_EXT_SUFFIX__VERSION_1_0;
+
+
+/************************ 
+* cl_khr_icd extension *                                                  
+************************/
+#define cl_khr_icd 1
+
+/* cl_platform_info                                                        */
+#define CL_PLATFORM_ICD_SUFFIX_KHR                  0x0920
+
+/* Additional Error Codes                                                  */
+#define CL_PLATFORM_NOT_FOUND_KHR                   -1001
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clIcdGetPlatformIDsKHR(cl_uint          /* num_entries */,
+                       cl_platform_id * /* platforms */,
+                       cl_uint *        /* num_platforms */);
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)(
+    cl_uint          /* num_entries */,
+    cl_platform_id * /* platforms */,
+    cl_uint *        /* num_platforms */);
+
+
+/* Extension: cl_khr_image2D_buffer
+ *
+ * This extension allows a 2D image to be created from a cl_mem buffer without a copy.
+ * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t.
+ * Both the sampler and sampler-less read_image built-in functions are supported for 2D images
+ * and 2D images created from a buffer.  Similarly, the write_image built-ins are also supported
+ * for 2D images created from a buffer.
+ *
+ * When the 2D image from buffer is created, the client must specify the width,
+ * height, image format (i.e. channel order and channel data type) and optionally the row pitch
+ *
+ * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels.
+ * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels.
+ */
+    
+/*************************************
+ * cl_khr_initalize_memory extension *
+ *************************************/
+    
+#define CL_CONTEXT_MEMORY_INITIALIZE_KHR            0x2030
+    
+    
+/**************************************
+ * cl_khr_terminate_context extension *
+ **************************************/
+    
+#define CL_DEVICE_TERMINATE_CAPABILITY_KHR          0x2031
+#define CL_CONTEXT_TERMINATE_KHR                    0x2032
+
+#define cl_khr_terminate_context 1
+extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2;
+    
+    
+/*
+ * Extension: cl_khr_spir
+ *
+ * This extension adds support to create an OpenCL program object from a 
+ * Standard Portable Intermediate Representation (SPIR) instance
+ */
+
+#define CL_DEVICE_SPIR_VERSIONS                     0x40E0
+#define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE         0x40E1
+
+
+/******************************************
+* cl_nv_device_attribute_query extension *
+******************************************/
+/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */
+#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV       0x4000
+#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV       0x4001
+#define CL_DEVICE_REGISTERS_PER_BLOCK_NV            0x4002
+#define CL_DEVICE_WARP_SIZE_NV                      0x4003
+#define CL_DEVICE_GPU_OVERLAP_NV                    0x4004
+#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV            0x4005
+#define CL_DEVICE_INTEGRATED_MEMORY_NV              0x4006
+
+/*********************************
+* cl_amd_device_attribute_query *
+*********************************/
+#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD        0x4036
+
+/*********************************
+* cl_arm_printf extension
+*********************************/
+#define CL_PRINTF_CALLBACK_ARM                      0x40B0
+#define CL_PRINTF_BUFFERSIZE_ARM                    0x40B1
+
+#ifdef CL_VERSION_1_1
+   /***********************************
+    * cl_ext_device_fission extension *
+    ***********************************/
+    #define cl_ext_device_fission   1
+    
+    extern CL_API_ENTRY cl_int CL_API_CALL
+    clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 
+    
+    typedef CL_API_ENTRY cl_int 
+    (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1;
+
+    extern CL_API_ENTRY cl_int CL_API_CALL
+    clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 
+    
+    typedef CL_API_ENTRY cl_int 
+    (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1;
+
+    typedef cl_ulong  cl_device_partition_property_ext;
+    extern CL_API_ENTRY cl_int CL_API_CALL
+    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;
+
+    typedef CL_API_ENTRY cl_int 
+    ( CL_API_CALL * clCreateSubDevicesEXT_fn)(  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;
+
+    /* cl_device_partition_property_ext */
+    #define CL_DEVICE_PARTITION_EQUALLY_EXT             0x4050
+    #define CL_DEVICE_PARTITION_BY_COUNTS_EXT           0x4051
+    #define CL_DEVICE_PARTITION_BY_NAMES_EXT            0x4052
+    #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT  0x4053
+    
+    /* clDeviceGetInfo selectors */
+    #define CL_DEVICE_PARENT_DEVICE_EXT                 0x4054
+    #define CL_DEVICE_PARTITION_TYPES_EXT               0x4055
+    #define CL_DEVICE_AFFINITY_DOMAINS_EXT              0x4056
+    #define CL_DEVICE_REFERENCE_COUNT_EXT               0x4057
+    #define CL_DEVICE_PARTITION_STYLE_EXT               0x4058
+    
+    /* error codes */
+    #define CL_DEVICE_PARTITION_FAILED_EXT              -1057
+    #define CL_INVALID_PARTITION_COUNT_EXT              -1058
+    #define CL_INVALID_PARTITION_NAME_EXT               -1059
+    
+    /* CL_AFFINITY_DOMAINs */
+    #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT             0x1
+    #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT             0x2
+    #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT             0x3
+    #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT             0x4
+    #define CL_AFFINITY_DOMAIN_NUMA_EXT                 0x10
+    #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT     0x100
+    
+    /* cl_device_partition_property_ext list terminators */
+    #define CL_PROPERTIES_LIST_END_EXT                  ((cl_device_partition_property_ext) 0)
+    #define CL_PARTITION_BY_COUNTS_LIST_END_EXT         ((cl_device_partition_property_ext) 0)
+    #define CL_PARTITION_BY_NAMES_LIST_END_EXT          ((cl_device_partition_property_ext) 0 - 1)
+
+/*********************************
+* cl_qcom_ext_host_ptr extension
+*********************************/
+
+#define CL_MEM_EXT_HOST_PTR_QCOM                  (1 << 29)
+
+#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM   0x40A0      
+#define CL_DEVICE_PAGE_SIZE_QCOM                  0x40A1
+#define CL_IMAGE_ROW_ALIGNMENT_QCOM               0x40A2
+#define CL_IMAGE_SLICE_ALIGNMENT_QCOM             0x40A3
+#define CL_MEM_HOST_UNCACHED_QCOM                 0x40A4
+#define CL_MEM_HOST_WRITEBACK_QCOM                0x40A5
+#define CL_MEM_HOST_WRITETHROUGH_QCOM             0x40A6
+#define CL_MEM_HOST_WRITE_COMBINING_QCOM          0x40A7
+
+typedef cl_uint                                   cl_image_pitch_info_qcom;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetDeviceImageInfoQCOM(cl_device_id             device,
+                         size_t                   image_width,
+                         size_t                   image_height,
+                         const cl_image_format   *image_format,
+                         cl_image_pitch_info_qcom param_name,
+                         size_t                   param_value_size,
+                         void                    *param_value,
+                         size_t                  *param_value_size_ret);
+
+typedef struct _cl_mem_ext_host_ptr
+{
+    /* Type of external memory allocation. */
+    /* Legal values will be defined in layered extensions. */
+    cl_uint  allocation_type;
+            
+    /* Host cache policy for this external memory allocation. */
+    cl_uint  host_cache_policy;
+
+} cl_mem_ext_host_ptr;
+
+/*********************************
+* cl_qcom_ion_host_ptr extension
+*********************************/
+
+#define CL_MEM_ION_HOST_PTR_QCOM                  0x40A8
+
+typedef struct _cl_mem_ion_host_ptr
+{
+    /* Type of external memory allocation. */
+    /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */
+    cl_mem_ext_host_ptr  ext_host_ptr;
+
+    /* ION file descriptor */
+    int                  ion_filedesc;
+            
+    /* Host pointer to the ION allocated memory */
+    void*                ion_hostptr;
+
+} cl_mem_ion_host_ptr;
+
+#endif /* CL_VERSION_1_1 */
+
+
+#ifdef CL_VERSION_2_0
+/*********************************
+* cl_khr_sub_groups extension
+*********************************/
+#define cl_khr_sub_groups 1
+
+typedef cl_uint  cl_kernel_sub_group_info;
+
+/* cl_khr_sub_group_info */
+#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR   0x2033
+#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR              0x2034
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetKernelSubGroupInfoKHR(cl_kernel /* in_kernel */,
+                                                  cl_device_id /*in_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*/ ) CL_EXT_SUFFIX__VERSION_2_0;
+                                                  
+typedef CL_API_ENTRY cl_int
+     ( CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel /* in_kernel */,
+                                                     cl_device_id /*in_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*/ ) CL_EXT_SUFFIX__VERSION_2_0;
+#endif /* CL_VERSION_2_0 */
+
+#ifdef CL_VERSION_2_1
+/*********************************
+* cl_khr_priority_hints extension
+*********************************/
+#define cl_khr_priority_hints 1
+
+typedef cl_uint  cl_queue_priority_khr;
+
+/* cl_command_queue_properties */
+#define CL_QUEUE_PRIORITY_KHR 0x1096
+
+/* cl_queue_priority_khr */
+#define CL_QUEUE_PRIORITY_HIGH_KHR (1<<0)
+#define CL_QUEUE_PRIORITY_MED_KHR (1<<1)
+#define CL_QUEUE_PRIORITY_LOW_KHR (1<<2)
+
+#endif /* CL_VERSION_2_1 */
+
+#ifdef CL_VERSION_2_1
+/*********************************
+* cl_khr_throttle_hints extension
+*********************************/
+#define cl_khr_throttle_hints 1
+
+typedef cl_uint  cl_queue_throttle_khr;
+
+/* cl_command_queue_properties */
+#define CL_QUEUE_THROTTLE_KHR 0x1097
+
+/* cl_queue_throttle_khr */
+#define CL_QUEUE_THROTTLE_HIGH_KHR (1<<0)
+#define CL_QUEUE_THROTTLE_MED_KHR (1<<1)
+#define CL_QUEUE_THROTTLE_LOW_KHR (1<<2)
+
+#endif /* CL_VERSION_2_1 */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __CL_EXT_H */
diff --git a/src/notzed.zcl/jni/include/CL/cl_gl.h b/src/notzed.zcl/jni/include/CL/cl_gl.h
new file mode 100644 (file)
index 0000000..0408093
--- /dev/null
@@ -0,0 +1,162 @@
+/**********************************************************************************
+ * Copyright (c) 2008 - 2013 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.
+ *
+ * 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.
+ **********************************************************************************/
+
+#ifndef __OPENCL_CL_GL_H
+#define __OPENCL_CL_GL_H
+
+#ifdef __APPLE__
+#include <OpenCL/cl.h>
+#else
+#include <CL/cl.h>
+#endif 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef cl_uint     cl_gl_object_type;
+typedef cl_uint     cl_gl_texture_info;
+typedef cl_uint     cl_gl_platform_info;
+typedef struct __GLsync *cl_GLsync;
+
+/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken           */
+#define CL_GL_OBJECT_BUFFER                     0x2000
+#define CL_GL_OBJECT_TEXTURE2D                  0x2001
+#define CL_GL_OBJECT_TEXTURE3D                  0x2002
+#define CL_GL_OBJECT_RENDERBUFFER               0x2003
+#define CL_GL_OBJECT_TEXTURE2D_ARRAY            0x200E
+#define CL_GL_OBJECT_TEXTURE1D                  0x200F
+#define CL_GL_OBJECT_TEXTURE1D_ARRAY            0x2010
+#define CL_GL_OBJECT_TEXTURE_BUFFER             0x2011
+
+/* cl_gl_texture_info           */
+#define CL_GL_TEXTURE_TARGET                    0x2004
+#define CL_GL_MIPMAP_LEVEL                      0x2005
+#define CL_GL_NUM_SAMPLES                       0x2012
+
+
+extern CL_API_ENTRY cl_mem CL_API_CALL
+clCreateFromGLBuffer(cl_context     /* context */,
+                     cl_mem_flags   /* flags */,
+                     cl_GLuint      /* bufobj */,
+                     int *          /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_mem CL_API_CALL
+clCreateFromGLTexture(cl_context      /* context */,
+                      cl_mem_flags    /* flags */,
+                      cl_GLenum       /* target */,
+                      cl_GLint        /* miplevel */,
+                      cl_GLuint       /* texture */,
+                      cl_int *        /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2;
+    
+extern CL_API_ENTRY cl_mem CL_API_CALL
+clCreateFromGLRenderbuffer(cl_context   /* context */,
+                           cl_mem_flags /* flags */,
+                           cl_GLuint    /* renderbuffer */,
+                           cl_int *     /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetGLObjectInfo(cl_mem                /* memobj */,
+                  cl_gl_object_type *   /* gl_object_type */,
+                  cl_GLuint *           /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0;
+                  
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetGLTextureInfo(cl_mem               /* memobj */,
+                   cl_gl_texture_info   /* param_name */,
+                   size_t               /* param_value_size */,
+                   void *               /* param_value */,
+                   size_t *             /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueAcquireGLObjects(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_API_SUFFIX__VERSION_1_0;
+
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueReleaseGLObjects(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_API_SUFFIX__VERSION_1_0;
+
+
+/* Deprecated OpenCL 1.1 APIs */
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL
+clCreateFromGLTexture2D(cl_context      /* context */,
+                        cl_mem_flags    /* flags */,
+                        cl_GLenum       /* target */,
+                        cl_GLint        /* miplevel */,
+                        cl_GLuint       /* texture */,
+                        cl_int *        /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+    
+extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL
+clCreateFromGLTexture3D(cl_context      /* context */,
+                        cl_mem_flags    /* flags */,
+                        cl_GLenum       /* target */,
+                        cl_GLint        /* miplevel */,
+                        cl_GLuint       /* texture */,
+                        cl_int *        /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
+    
+/* cl_khr_gl_sharing extension  */
+    
+#define cl_khr_gl_sharing 1
+    
+typedef cl_uint     cl_gl_context_info;
+    
+/* Additional Error Codes  */
+#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR  -1000
+    
+/* cl_gl_context_info  */
+#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR    0x2006
+#define CL_DEVICES_FOR_GL_CONTEXT_KHR           0x2007
+    
+/* Additional cl_context_properties  */
+#define CL_GL_CONTEXT_KHR                       0x2008
+#define CL_EGL_DISPLAY_KHR                      0x2009
+#define CL_GLX_DISPLAY_KHR                      0x200A
+#define CL_WGL_HDC_KHR                          0x200B
+#define CL_CGL_SHAREGROUP_KHR                   0x200C
+    
+extern CL_API_ENTRY cl_int CL_API_CALL
+clGetGLContextInfoKHR(const cl_context_properties * /* properties */,
+                      cl_gl_context_info            /* param_name */,
+                      size_t                        /* param_value_size */,
+                      void *                        /* param_value */,
+                      size_t *                      /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+    
+typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)(
+    const cl_context_properties * properties,
+    cl_gl_context_info            param_name,
+    size_t                        param_value_size,
+    void *                        param_value,
+    size_t *                      param_value_size_ret);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __OPENCL_CL_GL_H */
diff --git a/src/notzed.zcl/jni/include/CL/cl_gl_ext.h b/src/notzed.zcl/jni/include/CL/cl_gl_ext.h
new file mode 100644 (file)
index 0000000..cffbf3e
--- /dev/null
@@ -0,0 +1,69 @@
+/**********************************************************************************
+ * Copyright (c) 2008-2013 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.
+ *
+ * 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.
+ **********************************************************************************/
+
+/* $Revision: 1.1 $ on $Date: 2015/11/22 04:25:36 $ */
+
+/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have           */
+/* OpenGL dependencies.                                                         */
+
+#ifndef __OPENCL_CL_GL_EXT_H
+#define __OPENCL_CL_GL_EXT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __APPLE__
+    #include <OpenCL/cl_gl.h>
+#else
+    #include <CL/cl_gl.h>
+#endif
+
+/*
+ * For each extension, follow this template
+ *  cl_VEN_extname extension  */
+/* #define cl_VEN_extname 1
+ * ... define new types, if any
+ * ... define new tokens, if any
+ * ... define new APIs, if any
+ *
+ *  If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header
+ *  This allows us to avoid having to decide whether to include GL headers or GLES here.
+ */
+
+/* 
+ *  cl_khr_gl_event  extension
+ *  See section 9.9 in the OpenCL 1.1 spec for more information
+ */
+#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR     0x200D
+
+extern CL_API_ENTRY cl_event CL_API_CALL
+clCreateEventFromGLsyncKHR(cl_context           /* context */,
+                           cl_GLsync            /* cl_GLsync */,
+                           cl_int *             /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OPENCL_CL_GL_EXT_H  */
diff --git a/src/notzed.zcl/jni/include/CL/cl_platform.h b/src/notzed.zcl/jni/include/CL/cl_platform.h
new file mode 100644 (file)
index 0000000..b8b5131
--- /dev/null
@@ -0,0 +1,1328 @@
+/**********************************************************************************
+ * Copyright (c) 2008-2013 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.
+ *
+ * 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.
+ **********************************************************************************/
+
+/* $Revision: 1.1 $ on $Date: 2015/11/22 04:25:36 $ */
+
+#ifndef __CL_PLATFORM_H
+#define __CL_PLATFORM_H
+
+#ifdef __APPLE__
+    /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */
+    #include <AvailabilityMacros.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_WIN32)
+    #define CL_API_ENTRY
+    #define CL_API_CALL     __stdcall
+    #define CL_CALLBACK     __stdcall
+#else
+    #define CL_API_ENTRY
+    #define CL_API_CALL
+    #define CL_CALLBACK
+#endif
+
+/*
+ * Deprecation flags refer to the last version of the header in which the
+ * feature was not deprecated.
+ *
+ * E.g. VERSION_1_1_DEPRECATED means the feature is present in 1.1 without
+ * deprecation but is deprecated in versions later than 1.1.
+ */
+
+#ifdef __APPLE__
+    #define CL_EXTENSION_WEAK_LINK       __attribute__((weak_import))
+    #define CL_API_SUFFIX__VERSION_1_0                  AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
+    #define CL_EXT_SUFFIX__VERSION_1_0                  CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
+    #define CL_API_SUFFIX__VERSION_1_1                  AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+    #define GCL_API_SUFFIX__VERSION_1_1                 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+    #define CL_EXT_SUFFIX__VERSION_1_1                  CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+    #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED       CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7
+    
+    #ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER
+        #define CL_API_SUFFIX__VERSION_1_2              AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER
+        #define GCL_API_SUFFIX__VERSION_1_2             AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER
+        #define CL_EXT_SUFFIX__VERSION_1_2              CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER
+        #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+        #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED   CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_8
+    #else
+        #warning  This path should never happen outside of internal operating system development.  AvailabilityMacros do not function correctly here!
+        #define CL_API_SUFFIX__VERSION_1_2              AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+        #define GCL_API_SUFFIX__VERSION_1_2             AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+        #define CL_EXT_SUFFIX__VERSION_1_2              CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+        #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED   CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+    #endif
+#else
+    #define CL_EXTENSION_WEAK_LINK  
+    #define CL_API_SUFFIX__VERSION_1_0
+    #define CL_EXT_SUFFIX__VERSION_1_0
+    #define CL_API_SUFFIX__VERSION_1_1
+    #define CL_EXT_SUFFIX__VERSION_1_1
+    #define CL_API_SUFFIX__VERSION_1_2
+    #define CL_EXT_SUFFIX__VERSION_1_2
+    #define CL_API_SUFFIX__VERSION_2_0
+    #define CL_EXT_SUFFIX__VERSION_2_0
+    #define CL_API_SUFFIX__VERSION_2_1
+    #define CL_EXT_SUFFIX__VERSION_2_1
+    
+    #ifdef __GNUC__
+        #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS
+            #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED
+            #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED    
+        #else
+            #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED __attribute__((deprecated))
+            #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED    
+        #endif
+    
+        #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS
+            #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED    
+            #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED    
+        #else
+            #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated))
+            #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED    
+        #endif
+
+        #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS
+            #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
+            #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
+        #else
+            #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED __attribute__((deprecated))
+            #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
+         #endif
+
+        #ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS
+            #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED
+            #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED
+        #else
+            #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED __attribute__((deprecated))
+            #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED
+        #endif
+    #elif _WIN32
+        #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS
+            #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED
+            #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED    
+        #else
+            #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED 
+            #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED __declspec(deprecated)     
+        #endif
+    
+        #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS
+            #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+            #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED    
+        #else
+            #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED 
+            #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED __declspec(deprecated)     
+        #endif
+    
+        #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS
+            #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
+            #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
+        #else
+            #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
+            #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED __declspec(deprecated)
+        #endif
+
+        #ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS
+            #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED
+            #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED
+        #else
+            #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED 
+            #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED __declspec(deprecated)
+        #endif
+    #else
+        #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED
+        #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED
+    
+        #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
+        #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+    
+        #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
+        #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
+
+        #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED
+        #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED
+    #endif
+#endif
+
+#if (defined (_WIN32) && defined(_MSC_VER))
+
+/* scalar types  */
+typedef signed   __int8         cl_char;
+typedef unsigned __int8         cl_uchar;
+typedef signed   __int16        cl_short;
+typedef unsigned __int16        cl_ushort;
+typedef signed   __int32        cl_int;
+typedef unsigned __int32        cl_uint;
+typedef signed   __int64        cl_long;
+typedef unsigned __int64        cl_ulong;
+
+typedef unsigned __int16        cl_half;
+typedef float                   cl_float;
+typedef double                  cl_double;
+
+/* Macro names and corresponding values defined by OpenCL */
+#define CL_CHAR_BIT         8
+#define CL_SCHAR_MAX        127
+#define CL_SCHAR_MIN        (-127-1)
+#define CL_CHAR_MAX         CL_SCHAR_MAX
+#define CL_CHAR_MIN         CL_SCHAR_MIN
+#define CL_UCHAR_MAX        255
+#define CL_SHRT_MAX         32767
+#define CL_SHRT_MIN         (-32767-1)
+#define CL_USHRT_MAX        65535
+#define CL_INT_MAX          2147483647
+#define CL_INT_MIN          (-2147483647-1)
+#define CL_UINT_MAX         0xffffffffU
+#define CL_LONG_MAX         ((cl_long) 0x7FFFFFFFFFFFFFFFLL)
+#define CL_LONG_MIN         ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL)
+#define CL_ULONG_MAX        ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL)
+
+#define CL_FLT_DIG          6
+#define CL_FLT_MANT_DIG     24
+#define CL_FLT_MAX_10_EXP   +38
+#define CL_FLT_MAX_EXP      +128
+#define CL_FLT_MIN_10_EXP   -37
+#define CL_FLT_MIN_EXP      -125
+#define CL_FLT_RADIX        2
+#define CL_FLT_MAX          340282346638528859811704183484516925440.0f
+#define CL_FLT_MIN          1.175494350822287507969e-38f
+#define CL_FLT_EPSILON      0x1.0p-23f
+
+#define CL_DBL_DIG          15
+#define CL_DBL_MANT_DIG     53
+#define CL_DBL_MAX_10_EXP   +308
+#define CL_DBL_MAX_EXP      +1024
+#define CL_DBL_MIN_10_EXP   -307
+#define CL_DBL_MIN_EXP      -1021
+#define CL_DBL_RADIX        2
+#define CL_DBL_MAX          179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0
+#define CL_DBL_MIN          2.225073858507201383090e-308
+#define CL_DBL_EPSILON      2.220446049250313080847e-16
+
+#define  CL_M_E             2.718281828459045090796
+#define  CL_M_LOG2E         1.442695040888963387005
+#define  CL_M_LOG10E        0.434294481903251816668
+#define  CL_M_LN2           0.693147180559945286227
+#define  CL_M_LN10          2.302585092994045901094
+#define  CL_M_PI            3.141592653589793115998
+#define  CL_M_PI_2          1.570796326794896557999
+#define  CL_M_PI_4          0.785398163397448278999
+#define  CL_M_1_PI          0.318309886183790691216
+#define  CL_M_2_PI          0.636619772367581382433
+#define  CL_M_2_SQRTPI      1.128379167095512558561
+#define  CL_M_SQRT2         1.414213562373095145475
+#define  CL_M_SQRT1_2       0.707106781186547572737
+
+#define  CL_M_E_F           2.71828174591064f
+#define  CL_M_LOG2E_F       1.44269502162933f
+#define  CL_M_LOG10E_F      0.43429449200630f
+#define  CL_M_LN2_F         0.69314718246460f
+#define  CL_M_LN10_F        2.30258512496948f
+#define  CL_M_PI_F          3.14159274101257f
+#define  CL_M_PI_2_F        1.57079637050629f
+#define  CL_M_PI_4_F        0.78539818525314f
+#define  CL_M_1_PI_F        0.31830987334251f
+#define  CL_M_2_PI_F        0.63661974668503f
+#define  CL_M_2_SQRTPI_F    1.12837922573090f
+#define  CL_M_SQRT2_F       1.41421353816986f
+#define  CL_M_SQRT1_2_F     0.70710676908493f
+
+#define CL_NAN              (CL_INFINITY - CL_INFINITY)
+#define CL_HUGE_VALF        ((cl_float) 1e50)
+#define CL_HUGE_VAL         ((cl_double) 1e500)
+#define CL_MAXFLOAT         CL_FLT_MAX
+#define CL_INFINITY         CL_HUGE_VALF
+
+#else
+
+#include <stdint.h>
+
+/* scalar types  */
+typedef int8_t          cl_char;
+typedef uint8_t         cl_uchar;
+typedef int16_t         cl_short    __attribute__((aligned(2)));
+typedef uint16_t        cl_ushort   __attribute__((aligned(2)));
+typedef int32_t         cl_int      __attribute__((aligned(4)));
+typedef uint32_t        cl_uint     __attribute__((aligned(4)));
+typedef int64_t         cl_long     __attribute__((aligned(8)));
+typedef uint64_t        cl_ulong    __attribute__((aligned(8)));
+
+typedef uint16_t        cl_half     __attribute__((aligned(2)));
+typedef float           cl_float    __attribute__((aligned(4)));
+typedef double          cl_double   __attribute__((aligned(8)));
+
+/* Macro names and corresponding values defined by OpenCL */
+#define CL_CHAR_BIT         8
+#define CL_SCHAR_MAX        127
+#define CL_SCHAR_MIN        (-127-1)
+#define CL_CHAR_MAX         CL_SCHAR_MAX
+#define CL_CHAR_MIN         CL_SCHAR_MIN
+#define CL_UCHAR_MAX        255
+#define CL_SHRT_MAX         32767
+#define CL_SHRT_MIN         (-32767-1)
+#define CL_USHRT_MAX        65535
+#define CL_INT_MAX          2147483647
+#define CL_INT_MIN          (-2147483647-1)
+#define CL_UINT_MAX         0xffffffffU
+#define CL_LONG_MAX         ((cl_long) 0x7FFFFFFFFFFFFFFFLL)
+#define CL_LONG_MIN         ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL)
+#define CL_ULONG_MAX        ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL)
+
+#define CL_FLT_DIG          6
+#define CL_FLT_MANT_DIG     24
+#define CL_FLT_MAX_10_EXP   +38
+#define CL_FLT_MAX_EXP      +128
+#define CL_FLT_MIN_10_EXP   -37
+#define CL_FLT_MIN_EXP      -125
+#define CL_FLT_RADIX        2
+#define CL_FLT_MAX          0x1.fffffep127f
+#define CL_FLT_MIN          0x1.0p-126f
+#define CL_FLT_EPSILON      0x1.0p-23f
+
+#define CL_DBL_DIG          15
+#define CL_DBL_MANT_DIG     53
+#define CL_DBL_MAX_10_EXP   +308
+#define CL_DBL_MAX_EXP      +1024
+#define CL_DBL_MIN_10_EXP   -307
+#define CL_DBL_MIN_EXP      -1021
+#define CL_DBL_RADIX        2
+#define CL_DBL_MAX          0x1.fffffffffffffp1023
+#define CL_DBL_MIN          0x1.0p-1022
+#define CL_DBL_EPSILON      0x1.0p-52
+
+#define  CL_M_E             2.718281828459045090796
+#define  CL_M_LOG2E         1.442695040888963387005
+#define  CL_M_LOG10E        0.434294481903251816668
+#define  CL_M_LN2           0.693147180559945286227
+#define  CL_M_LN10          2.302585092994045901094
+#define  CL_M_PI            3.141592653589793115998
+#define  CL_M_PI_2          1.570796326794896557999
+#define  CL_M_PI_4          0.785398163397448278999
+#define  CL_M_1_PI          0.318309886183790691216
+#define  CL_M_2_PI          0.636619772367581382433
+#define  CL_M_2_SQRTPI      1.128379167095512558561
+#define  CL_M_SQRT2         1.414213562373095145475
+#define  CL_M_SQRT1_2       0.707106781186547572737
+
+#define  CL_M_E_F           2.71828174591064f
+#define  CL_M_LOG2E_F       1.44269502162933f
+#define  CL_M_LOG10E_F      0.43429449200630f
+#define  CL_M_LN2_F         0.69314718246460f
+#define  CL_M_LN10_F        2.30258512496948f
+#define  CL_M_PI_F          3.14159274101257f
+#define  CL_M_PI_2_F        1.57079637050629f
+#define  CL_M_PI_4_F        0.78539818525314f
+#define  CL_M_1_PI_F        0.31830987334251f
+#define  CL_M_2_PI_F        0.63661974668503f
+#define  CL_M_2_SQRTPI_F    1.12837922573090f
+#define  CL_M_SQRT2_F       1.41421353816986f
+#define  CL_M_SQRT1_2_F     0.70710676908493f
+
+#if defined( __GNUC__ )
+   #define CL_HUGE_VALF     __builtin_huge_valf()
+   #define CL_HUGE_VAL      __builtin_huge_val()
+   #define CL_NAN           __builtin_nanf( "" )
+#else
+   #define CL_HUGE_VALF     ((cl_float) 1e50)
+   #define CL_HUGE_VAL      ((cl_double) 1e500)
+   float nanf( const char * );
+   #define CL_NAN           nanf( "" )  
+#endif
+#define CL_MAXFLOAT         CL_FLT_MAX
+#define CL_INFINITY         CL_HUGE_VALF
+
+#endif
+
+#include <stddef.h>
+
+/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */
+typedef unsigned int cl_GLuint;
+typedef int          cl_GLint;
+typedef unsigned int cl_GLenum;
+
+/*
+ * Vector types 
+ *
+ *  Note:   OpenCL requires that all types be naturally aligned. 
+ *          This means that vector types must be naturally aligned.
+ *          For example, a vector of four floats must be aligned to
+ *          a 16 byte boundary (calculated as 4 * the natural 4-byte 
+ *          alignment of the float).  The alignment qualifiers here
+ *          will only function properly if your compiler supports them
+ *          and if you don't actively work to defeat them.  For example,
+ *          in order for a cl_float4 to be 16 byte aligned in a struct,
+ *          the start of the struct must itself be 16-byte aligned. 
+ *
+ *          Maintaining proper alignment is the user's responsibility.
+ */
+
+/* Define basic vector types */
+#if defined( __VEC__ )
+   #include <altivec.h>   /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */
+   typedef vector unsigned char     __cl_uchar16;
+   typedef vector signed char       __cl_char16;
+   typedef vector unsigned short    __cl_ushort8;
+   typedef vector signed short      __cl_short8;
+   typedef vector unsigned int      __cl_uint4;
+   typedef vector signed int        __cl_int4;
+   typedef vector float             __cl_float4;
+   #define  __CL_UCHAR16__  1
+   #define  __CL_CHAR16__   1
+   #define  __CL_USHORT8__  1
+   #define  __CL_SHORT8__   1
+   #define  __CL_UINT4__    1
+   #define  __CL_INT4__     1
+   #define  __CL_FLOAT4__   1
+#endif
+
+#if defined( __SSE__ )
+    #if defined( __MINGW64__ )
+        #include <intrin.h>
+    #else
+        #include <xmmintrin.h>
+    #endif
+    #if defined( __GNUC__ )
+        typedef float __cl_float4   __attribute__((vector_size(16)));
+    #else
+        typedef __m128 __cl_float4;
+    #endif
+    #define __CL_FLOAT4__   1
+#endif
+
+#if defined( __SSE2__ )
+    #if defined( __MINGW64__ )
+        #include <intrin.h>
+    #else
+        #include <emmintrin.h>
+    #endif
+    #if defined( __GNUC__ )
+        typedef cl_uchar    __cl_uchar16    __attribute__((vector_size(16)));
+        typedef cl_char     __cl_char16     __attribute__((vector_size(16)));
+        typedef cl_ushort   __cl_ushort8    __attribute__((vector_size(16)));
+        typedef cl_short    __cl_short8     __attribute__((vector_size(16)));
+        typedef cl_uint     __cl_uint4      __attribute__((vector_size(16)));
+        typedef cl_int      __cl_int4       __attribute__((vector_size(16)));
+        typedef cl_ulong    __cl_ulong2     __attribute__((vector_size(16)));
+        typedef cl_long     __cl_long2      __attribute__((vector_size(16)));
+        typedef cl_double   __cl_double2    __attribute__((vector_size(16)));
+    #else
+        typedef __m128i __cl_uchar16;
+        typedef __m128i __cl_char16;
+        typedef __m128i __cl_ushort8;
+        typedef __m128i __cl_short8;
+        typedef __m128i __cl_uint4;
+        typedef __m128i __cl_int4;
+        typedef __m128i __cl_ulong2;
+        typedef __m128i __cl_long2;
+        typedef __m128d __cl_double2;
+    #endif
+    #define __CL_UCHAR16__  1
+    #define __CL_CHAR16__   1
+    #define __CL_USHORT8__  1
+    #define __CL_SHORT8__   1
+    #define __CL_INT4__     1
+    #define __CL_UINT4__    1
+    #define __CL_ULONG2__   1
+    #define __CL_LONG2__    1
+    #define __CL_DOUBLE2__  1
+#endif
+
+#if defined( __MMX__ )
+    #include <mmintrin.h>
+    #if defined( __GNUC__ )
+        typedef cl_uchar    __cl_uchar8     __attribute__((vector_size(8)));
+        typedef cl_char     __cl_char8      __attribute__((vector_size(8)));
+        typedef cl_ushort   __cl_ushort4    __attribute__((vector_size(8)));
+        typedef cl_short    __cl_short4     __attribute__((vector_size(8)));
+        typedef cl_uint     __cl_uint2      __attribute__((vector_size(8)));
+        typedef cl_int      __cl_int2       __attribute__((vector_size(8)));
+        typedef cl_ulong    __cl_ulong1     __attribute__((vector_size(8)));
+        typedef cl_long     __cl_long1      __attribute__((vector_size(8)));
+        typedef cl_float    __cl_float2     __attribute__((vector_size(8)));
+    #else
+        typedef __m64       __cl_uchar8;
+        typedef __m64       __cl_char8;
+        typedef __m64       __cl_ushort4;
+        typedef __m64       __cl_short4;
+        typedef __m64       __cl_uint2;
+        typedef __m64       __cl_int2;
+        typedef __m64       __cl_ulong1;
+        typedef __m64       __cl_long1;
+        typedef __m64       __cl_float2;
+    #endif
+    #define __CL_UCHAR8__   1
+    #define __CL_CHAR8__    1
+    #define __CL_USHORT4__  1
+    #define __CL_SHORT4__   1
+    #define __CL_INT2__     1
+    #define __CL_UINT2__    1
+    #define __CL_ULONG1__   1
+    #define __CL_LONG1__    1
+    #define __CL_FLOAT2__   1
+#endif
+
+#if defined( __AVX__ )
+    #if defined( __MINGW64__ )
+        #include <intrin.h>
+    #else
+        #include <immintrin.h> 
+    #endif
+    #if defined( __GNUC__ )
+        typedef cl_float    __cl_float8     __attribute__((vector_size(32)));
+        typedef cl_double   __cl_double4    __attribute__((vector_size(32)));
+    #else
+        typedef __m256      __cl_float8;
+        typedef __m256d     __cl_double4;
+    #endif
+    #define __CL_FLOAT8__   1
+    #define __CL_DOUBLE4__  1
+#endif
+
+/* Define capabilities for anonymous struct members. */
+#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ )
+#define  __CL_HAS_ANON_STRUCT__ 1
+#define  __CL_ANON_STRUCT__ __extension__
+#elif defined( _WIN32) && (_MSC_VER >= 1500)
+   /* Microsoft Developer Studio 2008 supports anonymous structs, but
+    * complains by default. */
+#define  __CL_HAS_ANON_STRUCT__ 1
+#define  __CL_ANON_STRUCT__
+   /* Disable warning C4201: nonstandard extension used : nameless
+    * struct/union */
+#pragma warning( push )
+#pragma warning( disable : 4201 )
+#else
+#define  __CL_HAS_ANON_STRUCT__ 0
+#define  __CL_ANON_STRUCT__
+#endif
+
+/* Define alignment keys */
+#if defined( __GNUC__ )
+    #define CL_ALIGNED(_x)          __attribute__ ((aligned(_x)))
+#elif defined( _WIN32) && (_MSC_VER)
+    /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements     */
+    /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx                                                 */
+    /* #include <crtdefs.h>                                                                                             */
+    /* #define CL_ALIGNED(_x)          _CRT_ALIGN(_x)                                                                   */
+    #define CL_ALIGNED(_x)
+#else
+   #warning  Need to implement some method to align data here
+   #define  CL_ALIGNED(_x)
+#endif
+
+/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */
+#if __CL_HAS_ANON_STRUCT__
+    /* .xyzw and .s0123...{f|F} are supported */
+    #define CL_HAS_NAMED_VECTOR_FIELDS 1
+    /* .hi and .lo are supported */
+    #define CL_HAS_HI_LO_VECTOR_FIELDS 1
+#endif
+
+/* Define cl_vector types */
+
+/* ---- cl_charn ---- */
+typedef union
+{
+    cl_char  CL_ALIGNED(2) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_char  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_char  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_char  lo, hi; };
+#endif
+#if defined( __CL_CHAR2__) 
+    __cl_char2     v2;
+#endif
+}cl_char2;
+
+typedef union
+{
+    cl_char  CL_ALIGNED(4) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_char  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_char  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_char2 lo, hi; };
+#endif
+#if defined( __CL_CHAR2__) 
+    __cl_char2     v2[2];
+#endif
+#if defined( __CL_CHAR4__) 
+    __cl_char4     v4;
+#endif
+}cl_char4;
+
+/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */
+typedef  cl_char4  cl_char3;
+
+typedef union
+{
+    cl_char   CL_ALIGNED(8) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_char  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_char  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_char4 lo, hi; };
+#endif
+#if defined( __CL_CHAR2__) 
+    __cl_char2     v2[4];
+#endif
+#if defined( __CL_CHAR4__) 
+    __cl_char4     v4[2];
+#endif
+#if defined( __CL_CHAR8__ )
+    __cl_char8     v8;
+#endif
+}cl_char8;
+
+typedef union
+{
+    cl_char  CL_ALIGNED(16) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_char  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_char  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_char8 lo, hi; };
+#endif
+#if defined( __CL_CHAR2__) 
+    __cl_char2     v2[8];
+#endif
+#if defined( __CL_CHAR4__) 
+    __cl_char4     v4[4];
+#endif
+#if defined( __CL_CHAR8__ )
+    __cl_char8     v8[2];
+#endif
+#if defined( __CL_CHAR16__ )
+    __cl_char16    v16;
+#endif
+}cl_char16;
+
+
+/* ---- cl_ucharn ---- */
+typedef union
+{
+    cl_uchar  CL_ALIGNED(2) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_uchar  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_uchar  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_uchar  lo, hi; };
+#endif
+#if defined( __cl_uchar2__) 
+    __cl_uchar2     v2;
+#endif
+}cl_uchar2;
+
+typedef union
+{
+    cl_uchar  CL_ALIGNED(4) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_uchar  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_uchar  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_uchar2 lo, hi; };
+#endif
+#if defined( __CL_UCHAR2__) 
+    __cl_uchar2     v2[2];
+#endif
+#if defined( __CL_UCHAR4__) 
+    __cl_uchar4     v4;
+#endif
+}cl_uchar4;
+
+/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */
+typedef  cl_uchar4  cl_uchar3;
+
+typedef union
+{
+    cl_uchar   CL_ALIGNED(8) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_uchar  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_uchar  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_uchar4 lo, hi; };
+#endif
+#if defined( __CL_UCHAR2__) 
+    __cl_uchar2     v2[4];
+#endif
+#if defined( __CL_UCHAR4__) 
+    __cl_uchar4     v4[2];
+#endif
+#if defined( __CL_UCHAR8__ )
+    __cl_uchar8     v8;
+#endif
+}cl_uchar8;
+
+typedef union
+{
+    cl_uchar  CL_ALIGNED(16) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_uchar  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_uchar  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_uchar8 lo, hi; };
+#endif
+#if defined( __CL_UCHAR2__) 
+    __cl_uchar2     v2[8];
+#endif
+#if defined( __CL_UCHAR4__) 
+    __cl_uchar4     v4[4];
+#endif
+#if defined( __CL_UCHAR8__ )
+    __cl_uchar8     v8[2];
+#endif
+#if defined( __CL_UCHAR16__ )
+    __cl_uchar16    v16;
+#endif
+}cl_uchar16;
+
+
+/* ---- cl_shortn ---- */
+typedef union
+{
+    cl_short  CL_ALIGNED(4) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_short  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_short  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_short  lo, hi; };
+#endif
+#if defined( __CL_SHORT2__) 
+    __cl_short2     v2;
+#endif
+}cl_short2;
+
+typedef union
+{
+    cl_short  CL_ALIGNED(8) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_short  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_short  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_short2 lo, hi; };
+#endif
+#if defined( __CL_SHORT2__) 
+    __cl_short2     v2[2];
+#endif
+#if defined( __CL_SHORT4__) 
+    __cl_short4     v4;
+#endif
+}cl_short4;
+
+/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */
+typedef  cl_short4  cl_short3;
+
+typedef union
+{
+    cl_short   CL_ALIGNED(16) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_short  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_short  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_short4 lo, hi; };
+#endif
+#if defined( __CL_SHORT2__) 
+    __cl_short2     v2[4];
+#endif
+#if defined( __CL_SHORT4__) 
+    __cl_short4     v4[2];
+#endif
+#if defined( __CL_SHORT8__ )
+    __cl_short8     v8;
+#endif
+}cl_short8;
+
+typedef union
+{
+    cl_short  CL_ALIGNED(32) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_short  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_short  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_short8 lo, hi; };
+#endif
+#if defined( __CL_SHORT2__) 
+    __cl_short2     v2[8];
+#endif
+#if defined( __CL_SHORT4__) 
+    __cl_short4     v4[4];
+#endif
+#if defined( __CL_SHORT8__ )
+    __cl_short8     v8[2];
+#endif
+#if defined( __CL_SHORT16__ )
+    __cl_short16    v16;
+#endif
+}cl_short16;
+
+
+/* ---- cl_ushortn ---- */
+typedef union
+{
+    cl_ushort  CL_ALIGNED(4) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_ushort  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_ushort  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_ushort  lo, hi; };
+#endif
+#if defined( __CL_USHORT2__) 
+    __cl_ushort2     v2;
+#endif
+}cl_ushort2;
+
+typedef union
+{
+    cl_ushort  CL_ALIGNED(8) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_ushort  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_ushort  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_ushort2 lo, hi; };
+#endif
+#if defined( __CL_USHORT2__) 
+    __cl_ushort2     v2[2];
+#endif
+#if defined( __CL_USHORT4__) 
+    __cl_ushort4     v4;
+#endif
+}cl_ushort4;
+
+/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */
+typedef  cl_ushort4  cl_ushort3;
+
+typedef union
+{
+    cl_ushort   CL_ALIGNED(16) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_ushort  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_ushort  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_ushort4 lo, hi; };
+#endif
+#if defined( __CL_USHORT2__) 
+    __cl_ushort2     v2[4];
+#endif
+#if defined( __CL_USHORT4__) 
+    __cl_ushort4     v4[2];
+#endif
+#if defined( __CL_USHORT8__ )
+    __cl_ushort8     v8;
+#endif
+}cl_ushort8;
+
+typedef union
+{
+    cl_ushort  CL_ALIGNED(32) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_ushort  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_ushort  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_ushort8 lo, hi; };
+#endif
+#if defined( __CL_USHORT2__) 
+    __cl_ushort2     v2[8];
+#endif
+#if defined( __CL_USHORT4__) 
+    __cl_ushort4     v4[4];
+#endif
+#if defined( __CL_USHORT8__ )
+    __cl_ushort8     v8[2];
+#endif
+#if defined( __CL_USHORT16__ )
+    __cl_ushort16    v16;
+#endif
+}cl_ushort16;
+
+/* ---- cl_intn ---- */
+typedef union
+{
+    cl_int  CL_ALIGNED(8) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_int  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_int  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_int  lo, hi; };
+#endif
+#if defined( __CL_INT2__) 
+    __cl_int2     v2;
+#endif
+}cl_int2;
+
+typedef union
+{
+    cl_int  CL_ALIGNED(16) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_int  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_int  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_int2 lo, hi; };
+#endif
+#if defined( __CL_INT2__) 
+    __cl_int2     v2[2];
+#endif
+#if defined( __CL_INT4__) 
+    __cl_int4     v4;
+#endif
+}cl_int4;
+
+/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */
+typedef  cl_int4  cl_int3;
+
+typedef union
+{
+    cl_int   CL_ALIGNED(32) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_int  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_int  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_int4 lo, hi; };
+#endif
+#if defined( __CL_INT2__) 
+    __cl_int2     v2[4];
+#endif
+#if defined( __CL_INT4__) 
+    __cl_int4     v4[2];
+#endif
+#if defined( __CL_INT8__ )
+    __cl_int8     v8;
+#endif
+}cl_int8;
+
+typedef union
+{
+    cl_int  CL_ALIGNED(64) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_int  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_int  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_int8 lo, hi; };
+#endif
+#if defined( __CL_INT2__) 
+    __cl_int2     v2[8];
+#endif
+#if defined( __CL_INT4__) 
+    __cl_int4     v4[4];
+#endif
+#if defined( __CL_INT8__ )
+    __cl_int8     v8[2];
+#endif
+#if defined( __CL_INT16__ )
+    __cl_int16    v16;
+#endif
+}cl_int16;
+
+
+/* ---- cl_uintn ---- */
+typedef union
+{
+    cl_uint  CL_ALIGNED(8) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_uint  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_uint  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_uint  lo, hi; };
+#endif
+#if defined( __CL_UINT2__) 
+    __cl_uint2     v2;
+#endif
+}cl_uint2;
+
+typedef union
+{
+    cl_uint  CL_ALIGNED(16) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_uint  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_uint  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_uint2 lo, hi; };
+#endif
+#if defined( __CL_UINT2__) 
+    __cl_uint2     v2[2];
+#endif
+#if defined( __CL_UINT4__) 
+    __cl_uint4     v4;
+#endif
+}cl_uint4;
+
+/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */
+typedef  cl_uint4  cl_uint3;
+
+typedef union
+{
+    cl_uint   CL_ALIGNED(32) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_uint  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_uint  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_uint4 lo, hi; };
+#endif
+#if defined( __CL_UINT2__) 
+    __cl_uint2     v2[4];
+#endif
+#if defined( __CL_UINT4__) 
+    __cl_uint4     v4[2];
+#endif
+#if defined( __CL_UINT8__ )
+    __cl_uint8     v8;
+#endif
+}cl_uint8;
+
+typedef union
+{
+    cl_uint  CL_ALIGNED(64) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_uint  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_uint  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_uint8 lo, hi; };
+#endif
+#if defined( __CL_UINT2__) 
+    __cl_uint2     v2[8];
+#endif
+#if defined( __CL_UINT4__) 
+    __cl_uint4     v4[4];
+#endif
+#if defined( __CL_UINT8__ )
+    __cl_uint8     v8[2];
+#endif
+#if defined( __CL_UINT16__ )
+    __cl_uint16    v16;
+#endif
+}cl_uint16;
+
+/* ---- cl_longn ---- */
+typedef union
+{
+    cl_long  CL_ALIGNED(16) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_long  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_long  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_long  lo, hi; };
+#endif
+#if defined( __CL_LONG2__) 
+    __cl_long2     v2;
+#endif
+}cl_long2;
+
+typedef union
+{
+    cl_long  CL_ALIGNED(32) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_long  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_long  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_long2 lo, hi; };
+#endif
+#if defined( __CL_LONG2__) 
+    __cl_long2     v2[2];
+#endif
+#if defined( __CL_LONG4__) 
+    __cl_long4     v4;
+#endif
+}cl_long4;
+
+/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */
+typedef  cl_long4  cl_long3;
+
+typedef union
+{
+    cl_long   CL_ALIGNED(64) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_long  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_long  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_long4 lo, hi; };
+#endif
+#if defined( __CL_LONG2__) 
+    __cl_long2     v2[4];
+#endif
+#if defined( __CL_LONG4__) 
+    __cl_long4     v4[2];
+#endif
+#if defined( __CL_LONG8__ )
+    __cl_long8     v8;
+#endif
+}cl_long8;
+
+typedef union
+{
+    cl_long  CL_ALIGNED(128) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_long  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_long  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_long8 lo, hi; };
+#endif
+#if defined( __CL_LONG2__) 
+    __cl_long2     v2[8];
+#endif
+#if defined( __CL_LONG4__) 
+    __cl_long4     v4[4];
+#endif
+#if defined( __CL_LONG8__ )
+    __cl_long8     v8[2];
+#endif
+#if defined( __CL_LONG16__ )
+    __cl_long16    v16;
+#endif
+}cl_long16;
+
+
+/* ---- cl_ulongn ---- */
+typedef union
+{
+    cl_ulong  CL_ALIGNED(16) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_ulong  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_ulong  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_ulong  lo, hi; };
+#endif
+#if defined( __CL_ULONG2__) 
+    __cl_ulong2     v2;
+#endif
+}cl_ulong2;
+
+typedef union
+{
+    cl_ulong  CL_ALIGNED(32) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_ulong  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_ulong  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_ulong2 lo, hi; };
+#endif
+#if defined( __CL_ULONG2__) 
+    __cl_ulong2     v2[2];
+#endif
+#if defined( __CL_ULONG4__) 
+    __cl_ulong4     v4;
+#endif
+}cl_ulong4;
+
+/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */
+typedef  cl_ulong4  cl_ulong3;
+
+typedef union
+{
+    cl_ulong   CL_ALIGNED(64) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_ulong  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_ulong  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_ulong4 lo, hi; };
+#endif
+#if defined( __CL_ULONG2__) 
+    __cl_ulong2     v2[4];
+#endif
+#if defined( __CL_ULONG4__) 
+    __cl_ulong4     v4[2];
+#endif
+#if defined( __CL_ULONG8__ )
+    __cl_ulong8     v8;
+#endif
+}cl_ulong8;
+
+typedef union
+{
+    cl_ulong  CL_ALIGNED(128) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_ulong  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_ulong  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_ulong8 lo, hi; };
+#endif
+#if defined( __CL_ULONG2__) 
+    __cl_ulong2     v2[8];
+#endif
+#if defined( __CL_ULONG4__) 
+    __cl_ulong4     v4[4];
+#endif
+#if defined( __CL_ULONG8__ )
+    __cl_ulong8     v8[2];
+#endif
+#if defined( __CL_ULONG16__ )
+    __cl_ulong16    v16;
+#endif
+}cl_ulong16;
+
+
+/* --- cl_floatn ---- */
+
+typedef union
+{
+    cl_float  CL_ALIGNED(8) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_float  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_float  s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_float  lo, hi; };
+#endif
+#if defined( __CL_FLOAT2__) 
+    __cl_float2     v2;
+#endif
+}cl_float2;
+
+typedef union
+{
+    cl_float  CL_ALIGNED(16) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_float   x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_float   s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_float2  lo, hi; };
+#endif
+#if defined( __CL_FLOAT2__) 
+    __cl_float2     v2[2];
+#endif
+#if defined( __CL_FLOAT4__) 
+    __cl_float4     v4;
+#endif
+}cl_float4;
+
+/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */
+typedef  cl_float4  cl_float3;
+
+typedef union
+{
+    cl_float   CL_ALIGNED(32) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_float   x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_float   s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_float4  lo, hi; };
+#endif
+#if defined( __CL_FLOAT2__) 
+    __cl_float2     v2[4];
+#endif
+#if defined( __CL_FLOAT4__) 
+    __cl_float4     v4[2];
+#endif
+#if defined( __CL_FLOAT8__ )
+    __cl_float8     v8;
+#endif
+}cl_float8;
+
+typedef union
+{
+    cl_float  CL_ALIGNED(64) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_float  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_float  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_float8 lo, hi; };
+#endif
+#if defined( __CL_FLOAT2__) 
+    __cl_float2     v2[8];
+#endif
+#if defined( __CL_FLOAT4__) 
+    __cl_float4     v4[4];
+#endif
+#if defined( __CL_FLOAT8__ )
+    __cl_float8     v8[2];
+#endif
+#if defined( __CL_FLOAT16__ )
+    __cl_float16    v16;
+#endif
+}cl_float16;
+
+/* --- cl_doublen ---- */
+
+typedef union
+{
+    cl_double  CL_ALIGNED(16) s[2];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_double  x, y; };
+   __CL_ANON_STRUCT__ struct{ cl_double s0, s1; };
+   __CL_ANON_STRUCT__ struct{ cl_double lo, hi; };
+#endif
+#if defined( __CL_DOUBLE2__) 
+    __cl_double2     v2;
+#endif
+}cl_double2;
+
+typedef union
+{
+    cl_double  CL_ALIGNED(32) s[4];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_double  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_double  s0, s1, s2, s3; };
+   __CL_ANON_STRUCT__ struct{ cl_double2 lo, hi; };
+#endif
+#if defined( __CL_DOUBLE2__) 
+    __cl_double2     v2[2];
+#endif
+#if defined( __CL_DOUBLE4__) 
+    __cl_double4     v4;
+#endif
+}cl_double4;
+
+/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */
+typedef  cl_double4  cl_double3;
+
+typedef union
+{
+    cl_double   CL_ALIGNED(64) s[8];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_double  x, y, z, w; };
+   __CL_ANON_STRUCT__ struct{ cl_double  s0, s1, s2, s3, s4, s5, s6, s7; };
+   __CL_ANON_STRUCT__ struct{ cl_double4 lo, hi; };
+#endif
+#if defined( __CL_DOUBLE2__) 
+    __cl_double2     v2[4];
+#endif
+#if defined( __CL_DOUBLE4__) 
+    __cl_double4     v4[2];
+#endif
+#if defined( __CL_DOUBLE8__ )
+    __cl_double8     v8;
+#endif
+}cl_double8;
+
+typedef union
+{
+    cl_double  CL_ALIGNED(128) s[16];
+#if __CL_HAS_ANON_STRUCT__
+   __CL_ANON_STRUCT__ struct{ cl_double  x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; };
+   __CL_ANON_STRUCT__ struct{ cl_double  s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; };
+   __CL_ANON_STRUCT__ struct{ cl_double8 lo, hi; };
+#endif
+#if defined( __CL_DOUBLE2__) 
+    __cl_double2     v2[8];
+#endif
+#if defined( __CL_DOUBLE4__) 
+    __cl_double4     v4[4];
+#endif
+#if defined( __CL_DOUBLE8__ )
+    __cl_double8     v8[2];
+#endif
+#if defined( __CL_DOUBLE16__ )
+    __cl_double16    v16;
+#endif
+}cl_double16;
+
+/* Macro to facilitate debugging 
+ * Usage:
+ *   Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. 
+ *   The first line ends with:   CL_PROGRAM_STRING_DEBUG_INFO \"
+ *   Each line thereafter of OpenCL C source must end with: \n\
+ *   The last line ends in ";
+ *
+ *   Example:
+ *
+ *   const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\
+ *   kernel void foo( int a, float * b )             \n\
+ *   {                                               \n\
+ *      // my comment                                \n\
+ *      *b[ get_global_id(0)] = a;                   \n\
+ *   }                                               \n\
+ *   ";
+ *
+ * This should correctly set up the line, (column) and file information for your source 
+ * string so you can do source level debugging.
+ */
+#define  __CL_STRINGIFY( _x )               # _x
+#define  _CL_STRINGIFY( _x )                __CL_STRINGIFY( _x )
+#define  CL_PROGRAM_STRING_DEBUG_INFO       "#line "  _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" 
+  
+#ifdef __cplusplus
+}
+#endif
+
+#undef __CL_HAS_ANON_STRUCT__
+#undef __CL_ANON_STRUCT__
+#if defined( _WIN32) && (_MSC_VER >= 1500)
+#pragma warning( pop )
+#endif
+
+#endif  /* __CL_PLATFORM_H  */
diff --git a/src/notzed.zcl/jni/include/CL/opencl.h b/src/notzed.zcl/jni/include/CL/opencl.h
new file mode 100644 (file)
index 0000000..5dbb954
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2013 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.
+ *
+ * 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.
+ ******************************************************************************/
+
+/* $Revision: 1.1 $ on $Date: 2015/11/22 04:25:36 $ */
+
+#ifndef __OPENCL_H
+#define __OPENCL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __APPLE__
+
+#include <OpenCL/cl.h>
+#include <OpenCL/cl_gl.h>
+#include <OpenCL/cl_gl_ext.h>
+#include <OpenCL/cl_ext.h>
+
+#else
+
+#include <CL/cl.h>
+#include <CL/cl_gl.h>
+#include <CL/cl_gl_ext.h>
+#include <CL/cl_ext.h>
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __OPENCL_H   */
+
diff --git a/src/notzed.zcl/jni/jni.make b/src/notzed.zcl/jni/jni.make
new file mode 100644 (file)
index 0000000..6ba9d17
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright (C) 2015,2019 Michael Zucchi
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+notzed.zcl_JNI_LIBRARIES=zcl
+
+linux-amd64_zcl_SOURCES = zcl-init-so.c
+linux-amd64_zcl_LDFLAGS = -ldl
+
+windows-amd64_zcl_SOURCES = zcl-init-dll.c
+
+zcl_SOURCES=zcl-jni.c                          \
+       zcl-khr-gl-event.c                      \
+       zcl-khr-gl-sharing.c                    \
+       $($(TARGET)_zcl_SOURCES)
+
+zcl_CPPFLAGS=-Isrc/notzed.zcl/jni/include      \
+       -Wno-deprecated-declarations            \
+       -I$(NATIVEZ_HOME)/include
+
+zcl_LDLIBS=-L$(NATIVEZ_HOME)/lib -lnativez $($(TARGET)_zcl_LDFLAGS)
+
+bin/status/notzed.zcl.classes: bin/include/notzed.zcl/zcl-functions.h
+bin/include/notzed.zcl/zcl-functions.h: src/notzed.zcl/jni/include/CL/cl.h src/notzed.zcl/jni/zcl-generate
+       install -d $(@D)
+       src/notzed.zcl/jni/zcl-generate $< > $@.tmp && mv $@.tmp $@
diff --git a/src/notzed.zcl/jni/zcl-extension.h b/src/notzed.zcl/jni/zcl-extension.h
new file mode 100644 (file)
index 0000000..dc49b67
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2015 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+  Common definitions.
+  Header file for extension handlers.
+ */
+#ifndef ZCL_EXTENSION_H
+#define ZCL_EXTENSION_H
+
+jobject createExtension(JNIEnv *env, void *p, const char *className);
+
+jobject createExtension_cl_khr_gl_sharing(JNIEnv *env, cl_platform_id platform);
+jobject createExtension_cl_khr_gl_event(JNIEnv *env, cl_platform_id platform);
+
+void *getExtensionAddress(cl_platform_id platform, const char *func);
+
+/* Utility functions */
+/* Convert property array to array, result must be freed if not null */
+void *fromPropertyArray(JNIEnv *env, jobjectArray jpropArray);
+
+/* CLObjects */
+jobject toCLObject(JNIEnv *env, int, void *p);
+jobject toCLObjectArray(JNIEnv *env, int ctype, size_t count, void **ptrs);
+int fromObjectArray(JNIEnv *env, jobjectArray jobjects, void **dst, int size);
+jobject toArray(JNIEnv *env, int ctype, size_t size, void *value);
+jobject toObject(JNIEnv *env, int ctype, size_t size, void *value);
+
+/* Exceptions */
+
+#define THROW_ERROR_RET(res, ret) if (res != CL_SUCCESS) { throwCLException(env, res); return ret; }
+#define THROW_ERROR(res) if (res != CL_SUCCESS) { throwCLException(env, res); return; }
+
+#define THROW_RTERROR_RET(res, ret) if (res != CL_SUCCESS) { throwCLRuntimeException(env, res); return ret; }
+#define THROW_RTERROR(res) if (res != CL_SUCCESS) { throwCLRuntimeException(env, res); return; }
+
+#define C2J(x) ((jlong)(uintptr_t)(x))
+#define J2C(x) ((void *)(uintptr_t)(x))
+
+void throwCLException(JNIEnv *env, jint id);
+void throwCLRuntimeException(JNIEnv *env, jint id);
+void throwException(JNIEnv *env, const char *type, const char *msg);
+void throwUnsupportedOperation(JNIEnv *env, const char *fail);
+
+#define THROW_UNSUPPORTED_RET(fn, fail, ret) do { if (!fn) { throwUnsupportedOperation(env, fail); return ret; } } while (0)
+#define THROW_UNSUPPORTED(fn, fail) do { if (!fn) { throwUnsupportedOperation(env, fail); return; } } while (0)
+
+/* Events */
+
+#define EVENTS_MAX 28
+
+struct events_info {
+       cl_int wait_count;
+       cl_event *waitersp;
+       cl_event *eventp;
+
+       cl_event waiters[EVENTS_MAX];
+       cl_event event;
+};
+
+int events_init(JNIEnv *env, struct events_info *einfo, jobject jwaiters, jobject jevents);
+int events_post(JNIEnv *env, struct events_info *einfo, jobject jevents);
+
+/* Entry point for dynamic loader init & submodules, return 0 on success */
+int init_dynamic(JNIEnv *env);
+
+#endif
diff --git a/src/notzed.zcl/jni/zcl-generate b/src/notzed.zcl/jni/zcl-generate
new file mode 100755 (executable)
index 0000000..cfe2b82
--- /dev/null
@@ -0,0 +1,100 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2015 Michael Zucchi
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#
+# Compiles cl.h into function types and useful tables
+#
+# Fortunately cl.h is very strictly formatted so this is a simple task.
+#
+
+# $1 == cl header files
+$cl_h = $ARGV[0];
+
+@fn = ();
+%fnproto = {};
+$fnprefix = {};
+$fnsuffix = {};
+
+open H, "<$cl_h" || die;
+while (<H>) {
+    if (m/^extern (CL_API_ENTRY.*)/) {
+       $start = $1;
+       $proto = "";
+       while (<H>) {
+           chop($_);
+           $proto .= $_." ";
+           last if (m/;/);
+       }
+
+       $proto =~ s@/\*.*?\*/@@g;
+       $proto =~ s@ +@ @g;
+
+       if ($proto =~ m/^(\w+)(\(.*)/) {
+           $f = $1;
+
+           push @fn, $f;
+           $fnprefix{$f} = $start;
+           $fnsuffix{$f} = $2;
+       }
+    }
+}
+
+print "#ifndef _ZCL_FUNCIONS_H\n";
+print "/* Autogenerated by zcl-generate from $cl_h */\n\n";
+print "// Function types\n";
+for $f (@fn) {
+    print "typedef $fnprefix{$f} (*$f"."_fn) $fnsuffix{$f}\n";
+}
+
+print "#define zcl_fn_SIZEOF ".($#fn + 1)."\n";
+
+print "#ifdef ZCL_DL_TABLE\n";
+print "// Entry point names\n";
+print "const char const * zcl_fn[] = {\n";
+for $f (@fn) {
+    print "\t\"$f\",\n";
+}
+print "};\n";
+print "// Entry point addresses\n";
+print "const void *zcl_fp[zcl_fn_SIZEOF];\n";
+print "#else\n";
+print "// Entry point names\n";
+print "extern const char const * zcl_fn[zcl_fn_SIZEOF];\n";
+print "// Entry point addresses\n";
+print "extern const void *zcl_fp[zcl_fn_SIZEOF];\n";
+print "#endif\n";
+
+print "// Invoke Macros\n";
+$i = 0;
+for $f (@fn) {
+    print "#define $f (($f"."_fn)zcl_fp[$i])\n";
+    $i++;
+}
+
+print "// Checking macros\n";
+$i = 0;
+for $f (@fn) {
+    $prefix = $fnprefix{$f};
+    $suffix = $fnsuffix{$f};
+
+    print "#define CHECK_$f() (zcl_fp[$i])\n";
+    print "#define FAIL_$f() do { if (!zcl_check_fn(env, $i)) return; } while (0)\n";
+    print "#define FAIL_".$f."_RET(r) do { if (!zcl_check_fn(env, $i)) return (r); } while (0)\n";
+    $i++;
+}
+
+print "#endif /* _ZCL_FUNCTIONS_H */\n";
diff --git a/src/notzed.zcl/jni/zcl-init-dll.c b/src/notzed.zcl/jni/zcl-init-dll.c
new file mode 100644 (file)
index 0000000..1a9a10e
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+  shared library init for mingwin
+ */
+
+#include <windows.h>
+
+#include <CL/cl.h>
+#include <jni.h>
+
+#include "zcl-extension.h"
+
+#define ZCL_DL_TABLE 1
+#include "zcl-functions.h"
+
+static void *lib_opencl;
+
+int init_dynamic(JNIEnv *env) {
+       lib_opencl = LoadLibrary("OpenCL.dll");
+
+       if (lib_opencl) {
+               for (int i=0;i<zcl_fn_SIZEOF;i++)
+                       zcl_fp[i] = GetProcAddress(lib_opencl, zcl_fn[i]);
+               return 0;
+       }
+
+       return -1;
+}
diff --git a/src/notzed.zcl/jni/zcl-init-so.c b/src/notzed.zcl/jni/zcl-init-so.c
new file mode 100644 (file)
index 0000000..8465a4a
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2015 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+  shared library init
+ */
+
+#include <CL/cl.h>
+#include <dlfcn.h>
+#include <jni.h>
+
+#include "zcl-extension.h"
+
+#define ZCL_DL_TABLE 1
+#include "zcl-functions.h"
+
+static void *lib_opencl;
+
+int init_dynamic(JNIEnv *env) {
+       lib_opencl = dlopen("libOpenCL.so", RTLD_LAZY|RTLD_GLOBAL);
+
+       if (lib_opencl) {
+               for (int i=0;i<zcl_fn_SIZEOF;i++)
+                       zcl_fp[i] = dlsym(lib_opencl, zcl_fn[i]);
+               return 0;
+       }
+
+       return -1;
+}
diff --git a/src/notzed.zcl/jni/zcl-jni.c b/src/notzed.zcl/jni/zcl-jni.c
new file mode 100644 (file)
index 0000000..363f21c
--- /dev/null
@@ -0,0 +1,5072 @@
+/*
+ * Copyright (C) 2014,2015,2019 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include <string.h>
+#include "nativez.h"
+
+#include "au_notzed_zcl_CLBuffer.h"
+#include "au_notzed_zcl_CLCommandQueue.h"
+#include "au_notzed_zcl_CLContext.h"
+#include "au_notzed_zcl_CLDevice.h"
+#include "au_notzed_zcl_CLEvent.h"
+#include "au_notzed_zcl_CLEventList.h"
+#include "au_notzed_zcl_CLImage.h"
+#include "au_notzed_zcl_CLKernel.h"
+#include "au_notzed_zcl_CLMemory.h"
+#include "au_notzed_zcl_CLObject.h"
+#include "au_notzed_zcl_CLPlatform.h"
+#include "au_notzed_zcl_CLProgram.h"
+
+#include <CL/cl.h>
+
+#include "zcl-extension.h"
+#include "zcl-functions.h"
+
+// "real" version isn't what cl.h reports
+#ifdef VERSION_IS_1_0
+#undef CL_VERSION_1_1
+#endif
+
+/**
+ * Primitive array transfers can only be blocking on OpenCL 1.0
+ *
+ * Note however that for simplicity all primtiive array operations are blocking.
+ */
+#ifdef CL_VERSION_1_1
+#define PRIMITIVE_BLOCKING(x) 1 // x
+#else
+#define PRIMITIVE_BLOCKING(x) 1
+#endif
+
+#ifndef CL_VERSION_1_2
+typedef struct _cl_image_desc {
+    cl_mem_object_type      image_type;
+    size_t                  image_width;
+    size_t                  image_height;
+    size_t                  image_depth;
+    size_t                  image_array_size;
+    size_t                  image_row_pitch;
+    size_t                  image_slice_pitch;
+    cl_uint                 num_mip_levels;
+    cl_uint                 num_samples;
+    cl_mem                  buffer;
+} cl_image_desc;
+#endif
+
+/* ********************************************************************** */
+/* Helpers */
+
+#define D(x) //x; fflush(stdout)
+
+typedef void (JNICALL *getArrayRegion_t)(JNIEnv *env, jarray array, jsize start, jsize len, void *buf);
+typedef void (JNICALL *setArrayRegion_t)(JNIEnv *env, jarray array, jsize start, jsize len, const void *buf);
+
+typedef void (JNICALL *getArrayRect_t)(JNIEnv *env, jarray array, jsize start, size_t region[3], jlong row_pitch, jlong slice_pitch, void *buf);
+typedef void (JNICALL *setArrayRect_t)(JNIEnv *env, jarray array, jsize start, size_t region[3], jlong row_pitch, jlong slice_pitch, void *buf);
+
+// read or write
+typedef void (JNICALL *copyRegion_t)(JNIEnv *env, jarray array, jsize start, jsize len, void *buf);
+
+// Read/write functions follow the same pattern, use it to reuse some code
+typedef CL_API_ENTRY cl_int CL_API_CALL
+(*enqueueReadWriteBuffer_t)(cl_command_queue    /* command_queue */,
+                         cl_mem              /* buffer */,
+                         cl_bool             /* blocking_read */,
+                         size_t              /* offset */,
+                         size_t              /* size */, 
+                         void *              /* ptr */,
+                         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
+(*enqueueReadWriteBufferRect_t)(cl_command_queue    /* command_queue */,
+                               cl_mem              /* buffer */,
+                               cl_bool             /* blocking_read */,
+                               const size_t *      /* buffer_offset */,
+                               const size_t *      /* host_offset */, 
+                               const size_t *      /* region */,
+                               size_t              /* buffer_row_pitch */,
+                               size_t              /* buffer_slice_pitch */,
+                               size_t              /* host_row_pitch */,
+                               size_t              /* host_slice_pitch */,                        
+                               void *              /* ptr */,
+                               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
+(*enqueueReadWriteImage_t)(cl_command_queue     /* command_queue */,
+                        cl_mem               /* image */,
+                        cl_bool              /* blocking_read */, 
+                        const size_t *       /* origin[3] */,
+                        const size_t *       /* region[3] */,
+                        size_t               /* row_pitch */,
+                        size_t               /* slice_pitch */, 
+                        void *               /* ptr */,
+                        cl_uint              /* num_events_in_wait_list */,
+                        const cl_event *     /* event_wait_list */,
+                        cl_event *           /* event */);
+
+
+static const char * const names[au_notzed_zcl_CLObject_CTYPE_SIZEOF] = {
+       "CLPlatform",
+       "CLDevice",
+       "CLContext",
+       "CLCommandQueue",
+       "CLPipe",
+       "CLBuffer",
+       "CLImage",
+       "CLSampler",
+       "CLProgram",
+       "CLKernel",
+       "CLEvent"
+};
+
+size_t const ctype_sizes[] = {
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       sizeof(void *),
+       0, // reserves
+       0,
+       0,
+       0,
+       0,
+       sizeof(size_t),
+       1, // byte
+       2, // short
+       4, // int
+       8, // long
+       4, // float
+       8, // double
+};
+
+static JavaVM *vm;
+
+static jclass classid[au_notzed_zcl_CLObject_CTYPE_SIZEOF];
+
+/* special constructor for handling notify */
+static jmethodID CLContext_new_pn;
+/* special constructor for handling buffer */
+static jmethodID CLBuffer_new_jb;
+
+//static jclass CLNative_classid;
+//jfieldID CLNative_p;
+
+//static jclass CLObject_classid;
+
+static jclass CLExtendable_classid;
+jfieldID CLExtendable_apiVersion;
+
+static jclass CLMemory_classid;
+
+static jclass Object_classid;
+static jclass byte_a_classid;  /* byte[] / [B */
+
+//static jclass ByteBuffer_classid;
+//static jmethodID ByteBuffer_order;
+//static jmethodID ByteBuffer_positionI;
+//static jmethodID ByteBuffer_position;
+//static jmethodID ByteBuffer_limit;
+//static jobject nativeOrder; // ByteOrder.nativeOrder()
+
+// for primitive boxing
+static jclass Long_classid;
+static jmethodID Long_valueOf;
+static jclass Integer_classid;
+static jmethodID Integer_valueOf;
+
+static jclass CLProperty_classid;
+static jmethodID CLProperty_toIntPtr; // depends on word size, toLong or toInt
+
+static jclass CLContextProperty_classid;
+
+static jclass CLContextProperty_TagValue_classid;
+static jmethodID CLContextProperty_TagValue_new_jj;
+
+static jclass CLDeviceProperty_classid;
+
+static jclass CLDeviceProperty_TagValue_classid;
+static jmethodID CLDeviceProperty_TagValue_new_jj;
+
+static jclass CLDeviceProperty_PartitionByCounts_classid;
+static jmethodID CLDeviceProperty_PartitionByCounts_new_I;
+
+static jclass CLImageDesc_classid;
+static jfieldID CLImageDesc_imageType;
+static jfieldID CLImageDesc_imageWidth;
+static jfieldID CLImageDesc_imageHeight;
+static jfieldID CLImageDesc_imageDepth;
+static jfieldID CLImageDesc_imageArraySize;
+static jfieldID CLImageDesc_imageRowPitch;
+static jfieldID CLImageDesc_imageSlicePitch;
+static jfieldID CLImageDesc_numMipLevels;
+static jfieldID CLImageDesc_numSamples;
+static jfieldID CLImageDesc_memObject;
+
+static jclass CLImageFormat_classid;
+static jfieldID CLImageFormat_channelOrder;
+static jfieldID CLImageFormat_channelDataType;
+static jmethodID CLImageFormat_new_ii;
+
+static jclass CLBufferInfoRegion_classid;
+static jfieldID CLBufferInfoRegion_origin;
+static jfieldID CLBufferInfoRegion_size;
+
+static jclass CLEventList_classid;
+static jfieldID CLEventList_index;
+static jfieldID CLEventList_events;
+static jmethodID CLEventList_add;
+
+static jclass CLContextNotify_classid;
+static jmethodID CLContextNotify_notify;
+
+static jclass CLEventNotify_classid;
+static jmethodID CLEventNotify_notify;
+
+static jclass CLNotify_classid;
+static jmethodID CLNotify_notify;
+
+static jclass CLNativeKernel_classid;
+static jmethodID CLNativeKernel_invoke;
+
+static const NZRefTable reftable[] = {
+
+       JCLASS(CLExtendable_classid, "au/notzed/zcl/CLExtendable"),
+       JFIELD(CLExtendable_apiVersion, "apiVersion", "I"),
+
+       JCLASS(CLMemory_classid, "au/notzed/zcl/CLMemory"),
+
+       JCLASS(Object_classid, "java/lang/Object"),
+       JCLASS(Long_classid, "java/lang/Long"),
+       JSMETHOD(Long_valueOf, "valueOf", "(J)Ljava/lang/Long;"),
+       JCLASS(Integer_classid, "java/lang/Integer"),
+       JSMETHOD(Integer_valueOf, "valueOf", "(I)Ljava/lang/Integer;"),
+       JCLASS(byte_a_classid, "[B"),
+
+       JCLASS(CLProperty_classid, "au/notzed/zcl/CLProperty"),
+#if UINTPTR_MAX == 0xffffffffU
+       JSMETHOD(CLProperty_toIntPtr, "toInt", "([Ljava/lang/Object;)[I"),
+#else
+       JSMETHOD(CLProperty_toIntPtr, "toLong", "([Ljava/lang/Object;)[J"),
+#endif
+
+       JCLASS(CLContextProperty_classid, "au/notzed/zcl/CLContextProperty"),
+       JCLASS(CLContextProperty_TagValue_classid, "au/notzed/zcl/CLContextProperty$TagValue"),
+       JMETHOD(CLContextProperty_TagValue_new_jj, "<init>", "(JJ)V"),
+
+       JCLASS(CLDeviceProperty_classid, "au/notzed/zcl/CLDeviceProperty"),
+       JCLASS(CLDeviceProperty_TagValue_classid, "au/notzed/zcl/CLDeviceProperty$TagValue"),
+       JMETHOD(CLDeviceProperty_TagValue_new_jj, "<init>", "(JJ)V"),
+       JCLASS(CLDeviceProperty_PartitionByCounts_classid, "au/notzed/zcl/CLDeviceProperty$PartitionByCounts"),
+       JMETHOD(CLDeviceProperty_PartitionByCounts_new_I, "<init>", "([I)V"),
+       
+       JCLASS(CLImageDesc_classid, "au/notzed/zcl/CLImageDesc"),
+       JFIELD(CLImageDesc_imageType, "imageType", "I"),
+       JFIELD(CLImageDesc_imageWidth, "imageWidth", "I"),
+       JFIELD(CLImageDesc_imageHeight, "imageHeight", "I"),
+       JFIELD(CLImageDesc_imageDepth, "imageDepth", "I"),
+       JFIELD(CLImageDesc_imageArraySize, "imageArraySize", "I"),
+       JFIELD(CLImageDesc_imageRowPitch, "imageRowPitch", "I"),
+       JFIELD(CLImageDesc_imageSlicePitch, "imageSlicePitch", "I"),
+       JFIELD(CLImageDesc_numMipLevels, "numMipLevels", "I"),
+       JFIELD(CLImageDesc_numSamples, "numSamples", "I"),
+       JFIELD(CLImageDesc_memObject, "memObject", "Lau/notzed/zcl/CLMemory;"),
+
+       JCLASS(CLImageFormat_classid, "au/notzed/zcl/CLImageFormat"),
+       JMETHOD(CLImageFormat_new_ii, "<init>", "(II)V"),
+       JFIELD(CLImageFormat_channelOrder, "channelOrder", "I"),
+       JFIELD(CLImageFormat_channelDataType, "channelDataType", "I"),
+
+       JCLASS(CLBufferInfoRegion_classid, "au/notzed/zcl/CLBufferInfo$Region"),
+       JFIELD(CLBufferInfoRegion_origin, "origin", "J"),
+       JFIELD(CLBufferInfoRegion_size, "size", "J"),
+
+       JCLASS(CLEventList_classid, "au/notzed/zcl/CLEventList"),
+       JMETHOD(CLEventList_add, "add", "(J)V"),
+       JFIELD(CLEventList_index, "index", "I"),
+       JFIELD(CLEventList_events, "events", "[J"),
+
+       JCLASS(CLContextNotify_classid, "au/notzed/zcl/CLContextNotify"),
+       JMETHOD(CLContextNotify_notify, "notify", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)V"),
+
+       JCLASS(CLEventNotify_classid, "au/notzed/zcl/CLEventNotify"),
+       JMETHOD(CLEventNotify_notify, "notify", "(Lau/notzed/zcl/CLEvent;I)V"),
+
+       JCLASS(CLNotify_classid, "au/notzed/zcl/CLNotify"),
+       JMETHOD(CLNotify_notify, "notify", "(Ljava/lang/Object;)V"),
+
+       JCLASS(CLNativeKernel_classid, "au/notzed/zcl/CLNativeKernel"),
+       JMETHOD(CLNativeKernel_invoke, "invoke", "([Ljava/lang/Object;)V"),
+
+       JEND
+};
+
+static int debug_sync = 0;
+
+/* ********************************************************************** */
+
+jint JNI_OnLoad(JavaVM *vmi, void *reserved) {
+       jclass jc;
+       char name[64];
+       JNIEnv *env;
+
+       D(printf("libclz.so: OnLoad()\n"));
+
+       /* Save VM - required for callbacks from threads */
+       vm = vmi;
+
+       if ((*vmi)->GetEnv(vmi, (void *)&env, JNI_VERSION_1_4) < 0)
+               return 0;
+
+       /* Lookup and save all the class / method / field handles */
+       for (int i=0;i<au_notzed_zcl_CLObject_CTYPE_SIZEOF;i++) {
+               sprintf(name, "au/notzed/zcl/%s", names[i]);
+
+               jc = (*env)->FindClass(env, name);
+               if (jc == NULL) {
+                       fprintf(stderr, "class not found: %s\n", name);
+                       return 0;
+               }
+
+               classid[i] = jc = (*env)->NewGlobalRef(env, jc);
+       }
+
+       CLContext_new_pn = (*env)->GetMethodID(env, classid[au_notzed_zcl_CLObject_CTYPE_CONTEXT], "<init>", "(JLau/notzed/zcl/CLContextNotify;)V");
+       CLBuffer_new_jb = (*env)->GetMethodID(env, classid[au_notzed_zcl_CLObject_CTYPE_BUFFER], "<init>", "(JLjava/nio/ByteBuffer;)V");
+
+       if (nativez_OnLoad(vmi, env)
+           || init_dynamic(env)
+           || nativez_ResolveReferences(env, reftable) != 0)
+               return 0;
+
+       char *s = getenv("ZCL_SYNC");
+       if (s)
+               debug_sync = atoi(s);
+       
+       return JNI_VERSION_1_4;
+}
+
+static int zcl_check_fn(JNIEnv *env, int fid) {
+       int ok = zcl_fp[fid] != NULL;
+
+       if (!ok)
+               throwException(env, "java/lang/UnsupportedOperationException", zcl_fn[fid]);
+       
+       return ok;
+}
+
+void throwCLException(JNIEnv *env, jint id) {
+       jclass jc = (*env)->FindClass(env, "au/notzed/zcl/CLException");
+       jmethodID new_i = (*env)->GetMethodID(env, jc, "<init>", "(I)V");
+       jobject ex = (*env)->NewObject(env, jc, new_i, id);
+
+       (*env)->Throw(env, ex); 
+}
+
+void throwCLRuntimeException(JNIEnv *env, jint id) {
+       jclass jc = (*env)->FindClass(env, "au/notzed/zcl/CLRuntimeException");
+       jmethodID new_i = (*env)->GetMethodID(env, jc, "<init>", "(I)V");
+       jobject ex = (*env)->NewObject(env, jc, new_i, id);
+
+       (*env)->Throw(env, ex); 
+}
+
+void throwException(JNIEnv *env, const char *type, const char *msg) {
+       jclass jc = (*env)->FindClass(env, type);
+
+       if (jc)
+               (*env)->ThrowNew(env, jc, msg);
+}
+
+void throwUnsupportedOperation(JNIEnv *env, const char *fail) {
+       throwException(env, "java/lang/UnsupportedOperationException", fail);
+}
+
+#define GETP(env, o) NativeZ_getP(env, o)
+
+static int check_p(JNIEnv *env, jobject src, void **dst, const char *fail) {
+       if (!src) {
+               throwException(env, "java/lang/NullPointerException", fail);
+               return 1;
+       }
+
+       *dst = GETP(env, src);
+
+       return 0;
+}
+
+#define GET_P(env, jval, val, ret, error) do { if (check_p(env, jval, (void **)&val, error)) return ret; } while (0)
+
+static int check_array_min(JNIEnv *env, jobject src, jsize min, const char *fail) {
+       jsize size;
+
+       if (!src) {
+               throwException(env, "java/lang/NullPointerException", fail);
+               return 1;
+       }
+
+       size = (*env)->GetArrayLength(env, src);
+       if (size < min) {
+               throwException(env, "java/lang/ArrayIndexOutOfBoundsException", fail);
+               return 1;
+       }
+
+       return 0;
+}
+
+#define CHECK_ARRAY_MIN(env, jval, min, ret, error) do { if (check_array_min(env, jval, min, error)) return ret; } while (0)
+
+static int check_null(JNIEnv *env, jobject jo, const char *fail) {
+       if (!jo) {
+               throwException(env, "java/lang/NullPointerException", fail);
+               return 1;
+       }
+       return 0;
+}
+
+#define CHECK_NULL(env, jo, ret, error)  do { if (check_null(env, jo, error)) return ret; } while (0)
+
+int fromObjectArray(JNIEnv *env, jobjectArray jobjects, void **dst, int size) {
+       for (int i=0;i<size;i++) {
+               jobject jo = (*env)->GetObjectArrayElement(env, jobjects, i);
+
+               dst[i] = GETP(env, jo);
+       }
+
+       return 0;
+}
+
+jobject toCLObject(JNIEnv *env, int id, void *p) {
+       if (id < au_notzed_zcl_CLObject_CTYPE_SIZEOF) {
+               return NativeZ_resolve(env, classid[id], p);
+       } else {
+               throwCLRuntimeException(env, CL_INVALID_VALUE);
+               return NULL;
+       }
+}
+
+/* unified object instantiator for CLObject and boxed primitive types */
+jobject toObject(JNIEnv *env, int ctype, size_t size, void *value) {
+       jobject jres = NULL;
+       jvalue jarg;
+       
+       switch (ctype) {
+               //case  au_notzed_zcl_CLObject_CTYPE_BYTE:
+       case  au_notzed_zcl_CLObject_CTYPE_INT:
+               jarg.i = ((cl_int *)value)[0];
+               jres = (*env)->CallStaticObjectMethodA(env, Integer_classid, Integer_valueOf, &jarg);
+               break;
+       case  au_notzed_zcl_CLObject_CTYPE_LONG:
+               jarg.j = ((cl_long *)value)[0];
+               jres = (*env)->CallStaticObjectMethodA(env, Long_classid, Long_valueOf, &jarg);
+               break;
+       case  au_notzed_zcl_CLObject_CTYPE_SIZE_T:
+               jarg.j = ((size_t *)value)[0];
+               jres = (*env)->CallStaticObjectMethodA(env, Long_classid, Long_valueOf, &jarg);
+               break;
+       default:
+               jres = toCLObject(env, ctype, ((void **)value)[0]);
+               break;
+       }
+       
+       return jres;
+}
+
+jobject toCLObjectArray(JNIEnv *env, int ctype, size_t count, void **ptrs) {
+       jobject jvalue = NULL;
+       
+       if (ctype < au_notzed_zcl_CLObject_CTYPE_SIZEOF) {
+               jvalue = (*env)->NewObjectArray(env, count, classid[ctype], NULL);
+               if (jvalue) {
+                       for (int i=0;i<count;i++) {
+                               jobject o = toCLObject(env, ctype, ptrs[i]);
+                               
+                               (*env)->SetObjectArrayElement(env, jvalue, i, o);
+                       }
+               }
+       } else {
+               throwCLRuntimeException(env, CL_INVALID_VALUE);
+       }
+
+       return jvalue;
+}
+
+/* unified array builder based on CTYPE* defines */
+jobject toArray(JNIEnv *env, int ctype, size_t size, void *value) {
+       jobject jvalue = NULL;
+       int count;
+
+       switch (ctype) {
+       case  au_notzed_zcl_CLObject_CTYPE_BYTE:
+               count = size;
+               jvalue = (*env)->NewByteArray(env, count);
+               if (jvalue)
+                       (*env)->SetByteArrayRegion(env, jvalue, 0, count, (jbyte *)value);
+               break;
+       case  au_notzed_zcl_CLObject_CTYPE_INT:
+               count = size / sizeof(cl_int);
+               jvalue = (*env)->NewIntArray(env, count);
+               if (jvalue)
+                       (*env)->SetIntArrayRegion(env, jvalue, 0, count, (jint *)value);
+               break;
+       case  au_notzed_zcl_CLObject_CTYPE_LONG:
+               count = size / sizeof(cl_long);
+               jvalue = (*env)->NewLongArray(env, count);
+               if (jvalue)
+                       (*env)->SetLongArrayRegion(env, jvalue, 0, count, (jlong *)value);
+               break;
+       case  au_notzed_zcl_CLObject_CTYPE_SIZE_T:
+               count = size / sizeof(size_t);
+               jvalue = (*env)->NewLongArray(env, count);
+               if (jvalue) {
+                       if (sizeof(size_t) == sizeof(jlong)) {
+                               (*env)->SetLongArrayRegion(env, jvalue, 0, count, (jlong *)value);
+                       } else {
+                               jlong *tmp = alloca(count * sizeof(*tmp));
+                               size_t *data = value;
+
+                               for (int i=0;i<count;i++)
+                                       tmp[i] = (jlong)data[i];
+               
+                               (*env)->SetLongArrayRegion(env, jvalue, 0, count, (jlong *)tmp);
+                       }
+               }
+               break;
+       default:
+               jvalue = toCLObjectArray(env, ctype, size / sizeof(void *), value);
+               break;
+       }
+       
+       return jvalue;
+}
+
+/* Convert a tag/value property array to a primitive array */
+void *fromPropertyArray(JNIEnv *env, jobjectArray jpropArray) {
+#if UINTPTR_MAX == 0xffffffff
+       jint *res = NULL;
+       
+       if (jpropArray) {
+               jvalue jargs = { .l = jpropArray };
+               jlongArray ptmp = (*env)->CallStaticObjectMethodA(env, CLProperty_classid, CLProperty_toIntPtr, &jargs);
+               
+               if (!(*env)->ExceptionCheck(env)) {
+                       jint plen = (*env)->GetArrayLength(env, ptmp);
+                       res = malloc(sizeof(*res) * plen);
+                       if (res)
+                               (*env)->GetIntArrayRegion(env, ptmp, 0, plen, res);
+                       else
+                               throwException(env, "java/lang/OutOfMemoryError", "Allocating propery list");
+               }
+       }
+       return res;
+#else
+       jlong *res = NULL;
+       
+       if (jpropArray) {
+               jvalue jargs = { .l = jpropArray };
+               jlongArray ptmp = (*env)->CallStaticObjectMethodA(env, CLProperty_classid, CLProperty_toIntPtr, &jargs);
+               
+               if (!(*env)->ExceptionCheck(env)) {
+                       jint plen = (*env)->GetArrayLength(env, ptmp);
+                       res = malloc(sizeof(*res) * plen);
+                       if (res)
+                               (*env)->GetLongArrayRegion(env, ptmp, 0, plen, res);
+                       else
+                               throwException(env, "java/lang/OutOfMemoryError", "Allocating property list");
+               }
+       }
+       return res;
+
+#endif
+}
+
+/**
+ * Convert a jlongArray to a size_t *
+ */
+static void getSizeTA(JNIEnv *env, jlongArray jsrc, size_t *dst, size_t count) {
+       memset(dst, 0, sizeof(*dst) * count);
+       if (jsrc) {
+               if (sizeof(size_t) == sizeof(jlong))
+                       (*env)->GetLongArrayRegion(env, jsrc, 0, count, (jlong *)dst);
+               else {
+                       jlong *jdst = alloca(sizeof(*jdst) * count);
+                       (*env)->GetLongArrayRegion(env, jsrc, 0, count, jdst);
+                       for (int i=0;i<count;i++)
+                               dst[i] = (size_t)jdst[i];
+               }
+       }
+}
+
+static jint getAPIVersion(JNIEnv *env, jobject jo) {
+       return (*env)->GetIntField(env, jo, CLExtendable_apiVersion);
+}
+
+static int checkAPIVersion(JNIEnv *env, jobject jo, jint version) {
+       return getAPIVersion(env, jo) >= version;
+}
+
+/* ********************************************************************** */
+
+/*
+  Some helper code to manage the mess of dealing with CLEventList for
+  waiting and event output.
+
+  The primary task is to copy the CLEventList.events list for the 'waiters'
+  object to a local cl_event array, and after-the-event to invoke
+  CLEventList.add() if an event must be recorded as output.
+
+  See any of the CLCommandQueue.enqueue*() functions for how it's used.
+
+  To avoid the overhead of malloc and the need for alloca() in the callee
+  waiters[] is fixed in size, but that could be changed here.
+ */
+int events_init(JNIEnv *env, struct events_info *einfo, jobject jwaiters, jobject jevents) {
+       if (jwaiters) {
+               int count = (*env)->GetIntField(env, jwaiters, CLEventList_index);
+               jlongArray jwaitlist = (*env)->GetObjectField(env, jwaiters, CLEventList_events);
+
+               if (count > EVENTS_MAX) {
+                       throwException(env, "java/lang/ArrayIndexOutOfBoundsException", "Waiting list exceeds internal limit");
+                       return -1;
+               }
+
+               einfo->wait_count = count;
+               einfo->waitersp = &einfo->waiters[0];
+
+               if (sizeof(cl_event) == sizeof(jlong)) {
+                       (*env)->GetLongArrayRegion(env, jwaitlist, 0, count, (jlong *)&einfo->waiters[0]);
+               } else {
+                       jlong *levents = alloca(count * sizeof(*levents));
+                       (*env)->GetLongArrayRegion(env, jwaitlist, 0, count, levents);
+                       for (int i=0;i<count;i++)
+                               einfo->waiters[i] = (cl_event)(uintptr_t)levents[i];
+               }
+       } else {
+               einfo->wait_count = 0;
+               einfo->waitersp = NULL;
+       }
+
+       if (jevents)
+               einfo->eventp = &einfo->event;
+       else
+               einfo->eventp = NULL;
+
+       return 0;
+}
+
+int events_post(JNIEnv *env, struct events_info *einfo, jobject jevents) {
+       if (jevents) {
+               jvalue arg = { .j = (uintptr_t)einfo->event };
+
+               (*env)->CallVoidMethodA(env, jevents, CLEventList_add, &arg);
+       }
+
+       return 0;
+}
+
+/* ********************************************************************** */
+/* Build/compile/link notify handler */
+
+struct build_notify_info {
+       cl_program prog;
+       jobject jprog;
+       jobject jnotify;
+};
+
+static struct build_notify_info *build_notify_alloc(JNIEnv *env, cl_program prog, jobject jprog, jobject jnotify) {
+       struct build_notify_info *data = malloc(sizeof(*data));
+
+       if (!data) {
+               throwException(env, "java/lang/OutOfMemoryError", "Allocating hook data");
+               return NULL;
+       }
+       
+       data->prog = prog;
+       data->jnotify = (*env)->NewGlobalRef(env, jnotify);
+       data->jprog = jprog ? (*env)->NewGlobalRef(env, jprog) : NULL;
+
+
+       return data;
+}
+
+static void build_notify_hook(cl_program prog, void *data) {
+       struct build_notify_info *info = data;
+       JNIEnv *env;
+
+       D(printf("build notify()\n"));
+
+       if (!(env = nativez_AttachCurrentThreadAsDaemon())) {
+               // NB: can't do anything here
+               fprintf(stderr, "Unable to attach java environment\n");
+               free(data);
+               return;
+       }
+
+       if (!info->jprog) {
+               /* For linking, this is the first time we've seen the program */
+               jvalue arg = { .l = toCLObject(env, au_notzed_zcl_CLObject_CTYPE_PROGRAM, prog) };
+
+               (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify, &arg);
+       } else if (info->prog == prog) {
+               jvalue arg = { .l = info->jprog };
+
+               (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify, &arg);
+       } else {
+               fprintf(stderr, "build_notify_hook given wrong cl_program\n");
+       }
+
+       (*env)->DeleteGlobalRef(env, info->jnotify);
+       if (info->jprog)
+               (*env)->DeleteGlobalRef(env, info->jprog);
+
+       free(info);
+}
+
+/* ********************************************************************** */
+
+/* APIs */
+
+/* ********************************************************************** */
+
+/* CLObject */
+
+/*
+  To cut-down on significant API baggage the getInfo, retain, and
+  release methods are implemented in an object-oriented way using
+  using a manual type specifier.
+
+  Some info queries have target-specific variants.
+ */
+
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLSampler_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       cl_int res;
+       FAIL_clReleaseSampler();
+       res = clReleaseSampler((cl_sampler)jp);
+       if (res != CL_SUCCESS)
+               throwCLRuntimeException(env, res);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLProgram_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       cl_int res;
+       FAIL_clReleaseProgram();
+       res = clReleaseProgram((cl_program)jp);
+       if (res != CL_SUCCESS)
+               throwCLRuntimeException(env, res);
+}
+
+/* */
+
+static int getInfo(JNIEnv *env, void *jid, jint type, jint param, size_t size, void *val, void *size_ret) {
+       switch (type) {
+       case  au_notzed_zcl_CLObject_TYPE_PLATFORM:
+               FAIL_clGetPlatformInfo_RET(-1);
+               return clGetPlatformInfo((cl_platform_id)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_DEVICE:
+               FAIL_clGetDeviceInfo_RET(-1);
+               return clGetDeviceInfo((cl_device_id)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_CONTEXT:
+               FAIL_clGetContextInfo_RET(-1);
+               return clGetContextInfo((cl_context)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_COMMAND_QUEUE:
+               FAIL_clGetCommandQueueInfo_RET(-1);
+               return clGetCommandQueueInfo((cl_command_queue)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_MEM_OBJECT:
+               FAIL_clGetMemObjectInfo_RET(-1);
+               return clGetMemObjectInfo((cl_mem)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_IMAGE:
+               FAIL_clGetImageInfo_RET(-1);
+               return clGetImageInfo((cl_mem)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_PIPE:
+#ifdef CL_VERSION_2_0
+               FAIL_clGetPipeInfo_RET(-1);
+               return clGetPipeInfo((cl_mem)jid, param, size, val, size_ret);
+#else
+               return CL_INVALID_OPERATION;
+#endif
+       case  au_notzed_zcl_CLObject_TYPE_SAMPLER:
+               FAIL_clGetSamplerInfo_RET(-1);
+               return clGetSamplerInfo((cl_sampler)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_PROGRAM:
+               FAIL_clGetProgramInfo_RET(-1);
+               return clGetProgramInfo((cl_program)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_KERNEL:
+               FAIL_clGetKernelInfo_RET(-1);
+               return clGetKernelInfo((cl_kernel)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_EVENT:
+               FAIL_clGetEventInfo_RET(-1);
+               return clGetEventInfo((cl_event)jid, param, size, val, size_ret);
+       case  au_notzed_zcl_CLObject_TYPE_EVENT_PROFILING:
+               FAIL_clGetEventProfilingInfo_RET(-1);
+               return clGetEventProfilingInfo((cl_event)jid, param, size, val, size_ret);
+       default:
+               return CL_INVALID_VALUE;
+       }
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLObject_getInfoAny
+(JNIEnv *env, jobject jid, jint type, int otype, jint param) {
+       void *jp = GETP(env, jid);
+       void *value;
+       size_t size = ctype_sizes[otype];
+       cl_int res;
+
+       value = alloca(size);
+       res = getInfo(env, jp, type, param, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toObject(env, otype, size, value);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_zcl_CLObject_getInfoInt
+(JNIEnv *env, jobject jid, jint type, jint param) {
+       void *jp = GETP(env, jid);
+       cl_int res;
+       jint value;
+
+       res = getInfo(env, jp, type, param, sizeof(value), &value, NULL);
+       THROW_RTERROR_RET(res, 0);
+
+       return value;
+}
+
+JNIEXPORT jlong JNICALL Java_au_notzed_zcl_CLObject_getInfoLong
+(JNIEnv *env, jobject jid, jint type, jint param) {
+       void *jp = GETP(env, jid);
+       cl_int res;
+       jlong value;
+
+       res = getInfo(env, jp, type, param, sizeof(value), &value, NULL);
+       THROW_RTERROR_RET(res, 0);
+
+       return value;
+}
+
+JNIEXPORT jlong JNICALL Java_au_notzed_zcl_CLObject_getInfoSizeT
+(JNIEnv *env, jobject jid, jint type, jint param) {
+       void *jp = GETP(env, jid);
+       cl_int res;
+       size_t value;
+
+       res = getInfo(env, jp, type, param, sizeof(value), &value, NULL);
+       THROW_RTERROR_RET(res, 0);
+
+       return value;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLObject_getInfoAnyV
+(JNIEnv *env, jobject jid, jint type, int otype, jint param) {
+       void *jp = GETP(env, jid);
+       void *value;
+       size_t size;
+       cl_int res;
+
+       res = getInfo(env, jp, type, param, 0, NULL, &size);
+       THROW_RTERROR_RET(res, NULL);
+
+       value = alloca(size);
+
+       res = getInfo(env, jp, type, param, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toArray(env, otype, size, value);
+}
+
+/*
+  Query a property list and convert it to an array.
+
+  Most properties are simple tag+value pairs but not all so this must
+  handle those specifically.
+*/
+static jobjectArray getInfoProperties
+(JNIEnv *env, jobject jsrc, jint type, jint param, jclass array_classid, jclass new_classid, jmethodID new_tagvalue) {
+       void *src = GETP(env, jsrc);
+       intptr_t *props;
+       cl_int res;
+       size_t size;
+       int count, limit;
+       jobjectArray jprops;
+
+       res = getInfo(env, src, type, param, 0, NULL, &size);
+       THROW_RTERROR_RET(res, NULL);
+
+       if (size == 0)
+               return (*env)->NewObjectArray(env, 0, array_classid, NULL);
+
+       props = alloca(size);
+       res = getInfo(env, src, type, param, size, props, &size);
+       THROW_RTERROR_RET(res, NULL);
+
+       limit = size / sizeof(*props);
+       count = 0;
+       for (int i=0;i < limit && props[i];) {
+               intptr_t p = props[i];
+
+               count += 1;
+
+               switch (p) {
+               case CL_DEVICE_PARTITION_BY_COUNTS:
+                       i++;
+                       while (props[i] != CL_DEVICE_PARTITION_BY_COUNTS_LIST_END)
+                               i++;
+                       break;
+               default:
+                       i += 2;
+                       break;
+               }
+       }
+
+       jprops = (*env)->NewObjectArray(env, count, array_classid, NULL);
+       if (!jprops)
+               return NULL;
+
+       for (int i=0, j=0;i<limit && props[i];j++) {
+               intptr_t p = props[i];
+               jobject jo;
+
+               switch (p) {
+               case CL_DEVICE_PARTITION_BY_COUNTS: {
+                       int start, ccount;
+
+                       i++;
+                       start = i;
+
+                       while (props[i] != CL_DEVICE_PARTITION_BY_COUNTS_LIST_END)
+                               i++;
+                       ccount = i-start;
+
+                       jint *counts = alloca(sizeof(jint) * ccount);
+                       jintArray jcounts = (*env)->NewIntArray(env, ccount);
+
+                       for (int k=0;k<ccount;k++)
+                               counts[k] = (jint)props[start+k];
+
+                       (*env)->SetIntArrayRegion(env, jcounts, 0, ccount, counts);
+
+                       jo = (*env)->NewObject(env,
+                                              CLDeviceProperty_PartitionByCounts_classid,
+                                              CLDeviceProperty_PartitionByCounts_new_I,
+                                              jcounts);
+                       break;
+               }
+               default:
+                       jo = (*env)->NewObject(env, new_classid, new_tagvalue,
+                                              (jlong)props[i],
+                                              (jlong)props[i+1]);
+                       i += 2;
+                       break;
+               }
+
+               (*env)->SetObjectArrayElement(env, jprops, j, jo);
+       }
+
+       return jprops;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLObject_retain
+(JNIEnv *env, jobject jid, jint type) {
+       void *jp = GETP(env, jid);
+       cl_int res = CL_INVALID_VALUE;
+
+       switch (type) {
+       case  au_notzed_zcl_CLObject_TYPE_PLATFORM:
+               return;
+       case  au_notzed_zcl_CLObject_TYPE_DEVICE:
+#ifdef CL_VERSION_1_2
+               if (CHECK_clRetainDevice())
+                       res = clRetainDevice((cl_device_id)jp);
+               else
+                       return;
+               break;
+#else
+               return;
+#endif
+       case  au_notzed_zcl_CLObject_TYPE_CONTEXT:
+               FAIL_clRetainContext();
+               res = clRetainContext((cl_context)jp);
+               break;
+       case  au_notzed_zcl_CLObject_TYPE_COMMAND_QUEUE:
+               FAIL_clRetainCommandQueue();
+               res = clRetainCommandQueue((cl_command_queue)jp);
+               break;
+       case  au_notzed_zcl_CLObject_TYPE_MEM_OBJECT:
+       case  au_notzed_zcl_CLObject_TYPE_IMAGE:
+       case  au_notzed_zcl_CLObject_TYPE_PIPE:
+               FAIL_clRetainMemObject();
+               res = clRetainMemObject((cl_mem)jp);
+               break;
+       case  au_notzed_zcl_CLObject_TYPE_SAMPLER:
+               FAIL_clRetainSampler();
+               res = clRetainSampler((cl_sampler)jp);
+               break;
+       case  au_notzed_zcl_CLObject_TYPE_PROGRAM:
+               FAIL_clRetainProgram();
+               res = clRetainProgram((cl_program)jp);
+               break;
+       case  au_notzed_zcl_CLObject_TYPE_KERNEL:
+               FAIL_clRetainKernel();
+               res = clRetainKernel((cl_kernel)jp);
+               break;
+       case  au_notzed_zcl_CLObject_TYPE_KERNEL_WORK_GROUP:
+               break;
+       case  au_notzed_zcl_CLObject_TYPE_EVENT:
+               FAIL_clRetainEvent();
+               res = clRetainEvent((cl_event)jp);
+               break;
+       case  au_notzed_zcl_CLObject_TYPE_EVENT_PROFILING:
+               break;
+       }
+
+       if (res != CL_SUCCESS) {
+               throwCLException(env, res);
+               return;
+       }
+}
+
+/* ********************************************************************** */
+/* CLPlatform */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLPlatform_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       // NOOP
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLPlatform_getPlatforms
+(JNIEnv *env, jclass jc) {
+       FAIL_clGetPlatformIDs_RET(NULL);
+
+       cl_platform_id *platforms;
+       cl_int res;
+       cl_uint count;
+
+       res = clGetPlatformIDs(0, NULL, &count);
+       THROW_RTERROR_RET(res, NULL);
+       
+       platforms = alloca(sizeof(*platforms) * count);
+
+       res = clGetPlatformIDs(count, platforms, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObjectArray(env, au_notzed_zcl_CLObject_CTYPE_PLATFORM, count, (void **)platforms);
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLPlatform_getDevices
+(JNIEnv *env, jobject jplatform, jlong type) {
+       cl_platform_id platform = GETP(env, jplatform);
+       cl_device_id *devices;
+       cl_uint count;
+       cl_int res;
+
+       res = clGetDeviceIDs(platform, type, 0, NULL, &count);
+       if (res == CL_DEVICE_NOT_FOUND)
+               return toCLObjectArray(env, au_notzed_zcl_CLObject_CTYPE_DEVICE, 0, NULL);
+               
+       THROW_RTERROR_RET(res, NULL);
+
+       devices = alloca(sizeof(devices[0]) * count);
+
+       res = clGetDeviceIDs(platform, type, count, devices, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObjectArray(env, au_notzed_zcl_CLObject_CTYPE_DEVICE, count, (void **)devices);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLPlatform_unloadPlatformCompiler
+(JNIEnv *env, jobject jplatform) {
+#ifdef CL_VERSION_1_2
+       if (CHECK_clUnloadPlatformCompiler()) {
+               cl_platform_id platform = GETP(env, jplatform);
+               cl_int res;
+
+               res = clUnloadPlatformCompiler(platform);
+               THROW_RTERROR(res);
+       } else {
+               cl_int res;
+
+               res = clUnloadCompiler();
+               THROW_RTERROR(res);
+       }       
+#else
+       cl_int res;
+
+       res = clUnloadCompiler();
+       THROW_RTERROR(res);
+#endif
+}
+
+/* ********************************************************************** */
+/* CLPlatform - CLExtension(s) */
+#include <CL/cl_gl_ext.h>
+
+jobject createExtension(JNIEnv *env, void *p, const char *className) {
+       jclass jc = (*env)->FindClass(env, className);
+       if (jc == NULL)
+               return NULL;
+
+       return NativeZ_create(env, jc, p);
+}
+
+void *getExtensionAddress(cl_platform_id platform, const char *func) {
+#ifdef CL_VERSION_1_2
+       if (CHECK_clGetExtensionFunctionAddressForPlatform())
+               return clGetExtensionFunctionAddressForPlatform(platform, func);
+#endif
+       if (CHECK_clGetExtensionFunctionAddress())
+               return clGetExtensionFunctionAddress(func);
+       else
+               return NULL;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLPlatform_createExtension
+(JNIEnv *env, jobject jplatform, jint extensionid) {
+       cl_platform_id platform = GETP(env, jplatform);
+
+       switch (extensionid) {
+       case au_notzed_zcl_CLPlatform_cl_khr_gl_sharing:
+               return createExtension_cl_khr_gl_sharing(env, platform);
+       case au_notzed_zcl_CLPlatform_cl_khr_gl_event:
+               return createExtension_cl_khr_gl_event(env, platform);
+       }
+
+       // throws unknownextension?
+       throwUnsupportedOperation(env, "Unknown extension number");
+       return NULL;
+}
+
+/* ********************************************************************** */
+/* CLDevice */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLDevice_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       // NOOP
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLDevice_getDeviceAndHostTimer
+(JNIEnv *env, jobject jdevice, jlongArray jdst) {
+#ifdef CL_VERSION_2_1
+       if (checkAPIVersion(env, jdevice, au_notzed_zcl_CLPlatform_VERSION_2_1)) {
+               FAIL_clGetDeviceAndHostTimer();
+       
+               cl_device_id device = GETP(env, jdevice);
+               cl_int res;
+               cl_ulong ts[2];
+
+               res = clGetDeviceAndHostTimer(device, &ts[0], &ts[1]);
+               THROW_RTERROR(res);
+
+               (*env)->SetLongArrayRegion(env, jdst, 0, 2, (jlong *)ts);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.1");
+}
+
+JNIEXPORT jlong JNICALL Java_au_notzed_zcl_CLDevice_getHostTimer
+(JNIEnv *env, jobject jdevice) {
+#ifdef CL_VERSION_2_1
+       if (checkAPIVersion(env, jdevice, au_notzed_zcl_CLPlatform_VERSION_2_1)) {
+               FAIL_clGetHostTimer_RET(0);
+       
+               cl_device_id device = GETP(env, jdevice);
+               cl_int res;
+               cl_ulong ts;
+
+               res = clGetHostTimer(device, &ts);
+               THROW_RTERROR_RET(res, 0);
+
+               return ts;
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.1");
+       return 0;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLDevice_createSubDevices
+(JNIEnv *env, jobject jdevice, jobjectArray jprops, jint count) {
+#ifdef CL_VERSION_1_2
+       FAIL_clCreateSubDevices_RET(NULL);
+
+       cl_device_id device = GETP(env, jdevice);
+       cl_int res;
+       cl_device_partition_property *props = fromPropertyArray(env, jprops);
+       cl_device_id *devices;
+       cl_uint dcount;
+
+       if ((*env)->ExceptionCheck(env)) return NULL;
+
+       devices = alloca(sizeof(*devices) * count);
+
+       res = clCreateSubDevices(device, props, count, devices, &dcount);
+       free(props);
+       
+       THROW_ERROR_RET(res, NULL);
+
+       return toCLObjectArray(env, au_notzed_zcl_CLObject_CTYPE_DEVICE, dcount, (void **)devices);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+       return NULL;
+#endif
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLDevice_getPartitionProperties
+(JNIEnv *env, jobject jcontext) {
+#ifdef CL_VERSION_1_2
+       return getInfoProperties(env, jcontext, au_notzed_zcl_CLObject_TYPE_DEVICE, CL_DEVICE_PARTITION_PROPERTIES,
+                                CLDeviceProperty_classid,
+                                CLDeviceProperty_TagValue_classid, CLDeviceProperty_TagValue_new_jj);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+       return NULL;
+#endif
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLDevice_getPartitionType
+(JNIEnv *env, jobject jcontext) {
+#ifdef CL_VERSION_1_2
+       return getInfoProperties(env, jcontext, au_notzed_zcl_CLObject_TYPE_DEVICE, CL_DEVICE_PARTITION_TYPE,
+                                CLDeviceProperty_classid,
+                                CLDeviceProperty_TagValue_classid, CLDeviceProperty_TagValue_new_jj);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+       return NULL;
+#endif
+}
+
+/* ********************************************************************** */
+/* CLContext */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLContext_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       cl_int res;
+       
+       FAIL_clReleaseContext();
+       if ((res = clReleaseContext((cl_context)jp)) != CL_SUCCESS)
+               throwCLRuntimeException(env, res);
+}
+
+/**
+ * Bounces the context notify callback to java
+ */
+static void context_notify_hook(const char *error_info, const void *private_info, size_t private_size, void *data) {
+       JNIEnv *env;
+       jobject jnotify = data;
+       jobject jerror_info;
+       jobject jprivate_info = NULL;
+
+       D(printf("context notify: %s\n", error_info));
+
+       if (!(env = nativez_AttachCurrentThreadAsDaemon())) {
+               fprintf(stderr, "Unable to attach java environment\n");
+               return;
+       }
+
+       jnotify = (*env)->NewLocalRef(env, jnotify);
+       if (!jnotify) {
+               fprintf(stderr, "cl_context notify called after object death\n");
+               return;
+       }
+
+       jerror_info = (*env)->NewStringUTF(env, error_info);
+
+       if (private_info && private_size)
+               jprivate_info = nativez_NewDirectBuffer(env, (void *)private_info, private_size);
+
+       (*env)->CallVoidMethod(env, jnotify, CLContextNotify_notify, jerror_info, jprivate_info);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createContext
+(JNIEnv *env, jclass jc, jobjectArray jprops, jobjectArray jdevices, jobject jnotify) {
+       FAIL_clCreateContext_RET(NULL);
+
+       cl_context_properties *props = fromPropertyArray(env, jprops);
+       cl_device_id *devices;
+       cl_int res;
+       cl_context ret;
+       int dlen;
+       void (CL_CALLBACK* notify)(const char *, const void *, size_t, void *);
+       void *data;
+
+       if ((*env)->ExceptionCheck(env)) return NULL;
+
+       if (jdevices) {
+               dlen = (*env)->GetArrayLength(env, jdevices);
+               devices = alloca(dlen * sizeof(*devices));
+               fromObjectArray(env, jdevices, (void **)devices, dlen);
+       } else {
+               devices = NULL;
+               dlen = 0;
+       }
+
+       if (jnotify) {
+               // Note: solid reference is handled by constructor
+               notify = context_notify_hook;
+               data = (*env)->NewWeakGlobalRef(env, jnotify);
+       } else {
+               notify = NULL;
+               data = NULL;
+       }
+
+       ret = clCreateContext(props, dlen, devices, notify, data, &res);
+       free(props);
+       THROW_RTERROR_RET(res, NULL);
+
+       return NativeZ_register(env, (*env)->NewObject(env, classid[au_notzed_zcl_CLObject_CTYPE_CONTEXT], CLContext_new_pn, C2J(ret), jnotify));
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createContextFromType
+(JNIEnv *env, jclass jc, jobjectArray jprops, jlong type, jobject jnotify) {
+       FAIL_clCreateContextFromType_RET(NULL);
+
+       cl_context_properties *props = fromPropertyArray(env, jprops);
+       cl_int res;
+       cl_context ret;
+       void (CL_CALLBACK * notify)(const char *, const void *, size_t, void *);
+       void *data;
+
+       if ((*env)->ExceptionCheck(env)) return NULL;
+
+       if (jnotify) {
+               // Note: solid reference is handled by constructor
+               notify = context_notify_hook;
+               data = (*env)->NewWeakGlobalRef(env, jnotify);
+       } else {
+               notify = NULL;
+               data = NULL;
+       }
+
+       ret = clCreateContextFromType(props, type, notify, data, &res);
+       free(props);
+       THROW_RTERROR_RET(res, NULL);
+
+       return NativeZ_register(env, (*env)->NewObject(env, classid[au_notzed_zcl_CLObject_CTYPE_CONTEXT], CLContext_new_pn, C2J(ret), jnotify));
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createCommandQueue__Lau_notzed_zcl_CLDevice_2J
+(JNIEnv *env, jobject jcontext, jobject jdevice, jlong properties) {
+       FAIL_clCreateCommandQueue_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       cl_device_id device = GETP(env, jdevice);
+       cl_int res;
+       cl_command_queue ret;
+
+       ret = clCreateCommandQueue(context,
+                                  device,
+                                  properties,
+                                  &res);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_COMMAND_QUEUE, ret);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createCommandQueue__Lau_notzed_zcl_CLDevice_2_3Lau_notzed_zcl_CLQueueProperty_2
+(JNIEnv *env, jobject jcontext, jobject jdevice, jobjectArray jprops) {
+#ifdef CL_VERSION_2_0
+       if (getAPIVersion(env, jcontext) < au_notzed_zcl_CLPlatform_VERSION_2_0) {
+               cl_command_queue_properties properties = 0;
+
+               printf("Warning: Calling OpenCL 2.0 CreateCommandQueueWithProperties, using fallback\n");
+               fflush(stdout);
+
+               if (jprops) {
+                       cl_queue_properties *props = fromPropertyArray(env, jprops);
+                       
+                       if ((*env)->ExceptionCheck(env))
+                               return NULL;
+                       
+                       for (int i=0;props[i] != 0;i+=2) {
+                               if (CL_QUEUE_PROPERTIES == props[i]) {
+                                       properties = props[i+1];
+                                       break;
+                               }
+                       }
+                       free(props);
+               }
+               return Java_au_notzed_zcl_CLContext_createCommandQueue__Lau_notzed_zcl_CLDevice_2J(env, jcontext, jdevice, properties);
+       }
+
+       FAIL_clCreateCommandQueueWithProperties_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       cl_device_id device = GETP(env, jdevice);
+       cl_int res;
+       cl_command_queue ret;
+       cl_queue_properties *props = fromPropertyArray(env, jprops);
+
+       if ((*env)->ExceptionCheck(env)) return NULL;
+
+       ret = clCreateCommandQueueWithProperties(context,
+                                                device,
+                                                props,
+                                                &res);
+       free(props);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_COMMAND_QUEUE, ret);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+       return NULL;
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLContext_setDefaultDeviceCommandQueue
+(JNIEnv *env, jobject jcontext, jobject jdevice, jobject jqueue)
+{
+#ifdef CL_VERSION_2_1
+       if (checkAPIVersion(env, jcontext, au_notzed_zcl_CLPlatform_VERSION_2_1)) {
+               FAIL_clSetDefaultDeviceCommandQueue();
+
+               cl_context context = GETP(env, jcontext);
+               cl_device_id device = GETP(env, jdevice);
+               cl_command_queue queue = GETP(env, jqueue);
+               cl_int res;
+
+               res = clSetDefaultDeviceCommandQueue(context, device, queue);
+               THROW_ERROR(res);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.1");
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createBuffer__JJLjava_nio_ByteBuffer_2
+(JNIEnv *env, jobject jcontext, jlong flags, jlong size, jobject jhost_ptr) {
+       FAIL_clCreateBuffer_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       cl_int res;
+       cl_mem ret;
+       void *host_ptr = NULL;
+
+       D(printf("createBuffer(%08lx, %ld, %p)\n", flags, size, jhost_ptr));
+       
+       if (jhost_ptr) {
+               jlong jhost_size;
+
+               // TODO: an aligned allocator may be necessary
+               
+               host_ptr = (*env)->GetDirectBufferAddress(env, jhost_ptr);
+               jhost_size = (*env)->GetDirectBufferCapacity(env, jhost_ptr);
+               if (jhost_size < size) {
+                       throwCLException(env, CL_INVALID_HOST_PTR);
+                       return NULL;
+               }
+       }
+
+       ret = clCreateBuffer(context,
+                            flags,
+                            size,
+                            host_ptr,
+                            &res);
+
+       THROW_RTERROR_RET(res, NULL);
+
+       if (jhost_ptr && (flags & CL_MEM_USE_HOST_PTR)) {
+               jvalue args[] = {
+                       { .j = (uintptr_t)ret },
+                       { .l = jhost_ptr }
+               };
+
+               return NativeZ_register(env, (*env)->NewObjectA(env, classid[au_notzed_zcl_CLObject_CTYPE_BUFFER], CLBuffer_new_jb, args));
+       } else
+               return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_BUFFER, ret);
+}
+
+/* The convenience is worth it */
+
+static jobject
+createBufferPrimitive(JNIEnv *env, jobject jcontext, jlong flags, jarray jhost_ptr, int elshift) {
+       FAIL_clCreateBuffer_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       cl_int res;
+       cl_mem ret;
+       void *host_ptr;
+
+       // No way to implement this with java arrays currently
+       if (flags & CL_MEM_USE_HOST_PTR) {
+               throwCLException(env, CL_INVALID_VALUE);
+               return NULL;
+       }
+
+       if (!jhost_ptr) {
+               throwException(env, "java/lang/NullPointerException", "null array");
+               return NULL;
+       }
+
+       jsize size = (*env)->GetArrayLength(env, jhost_ptr);
+
+       host_ptr = (*env)->GetPrimitiveArrayCritical(env, jhost_ptr, NULL);
+
+       ret = clCreateBuffer(context,
+                            flags,
+                            size << elshift,
+                            host_ptr,
+                            &res);
+
+       (*env)->ReleasePrimitiveArrayCritical(env, jhost_ptr, host_ptr, 0);
+
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_BUFFER, ret);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createBuffer__J_3B
+(JNIEnv *env, jobject jcontext, jlong flags, jbyteArray jhost_ptr) {
+       return createBufferPrimitive(env, jcontext, flags, jhost_ptr, 0);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createBuffer__J_3S
+(JNIEnv *env, jobject jcontext, jlong flags, jbyteArray jhost_ptr) {
+       return createBufferPrimitive(env, jcontext, flags, jhost_ptr, 1);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createBuffer__J_3I
+(JNIEnv *env, jobject jcontext, jlong flags, jbyteArray jhost_ptr) {
+       return createBufferPrimitive(env, jcontext, flags, jhost_ptr, 2);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createBuffer__J_3F
+(JNIEnv *env, jobject jcontext, jlong flags, jfloatArray jhost_ptr) {
+       return createBufferPrimitive(env, jcontext, flags, jhost_ptr, 2);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createBuffer__J_3D
+(JNIEnv *env, jobject jcontext, jlong flags, jfloatArray jhost_ptr) {
+       return createBufferPrimitive(env, jcontext, flags, jhost_ptr, 2);
+}
+
+/* ********************************************************************** */
+
+// fmt = unmarshall(jfmt)
+// returns size of 1 element in bytes
+static size_t marshal_image_format(JNIEnv *env, cl_image_format *fmt, jobject jfmt) {
+       size_t nc, ds;
+       
+       fmt->image_channel_order = (*env)->GetIntField(env, jfmt, CLImageFormat_channelOrder);
+       fmt->image_channel_data_type = (*env)->GetIntField(env, jfmt, CLImageFormat_channelDataType);
+
+       switch (fmt->image_channel_order) {
+       case CL_R:
+       case CL_A:
+       case CL_INTENSITY:
+       case CL_LUMINANCE:
+       case CL_DEPTH:
+       case CL_DEPTH_STENCIL: // ???
+               nc = 1;
+               break;
+       case CL_RG:
+       case CL_RA:
+       case CL_Rx:
+               nc = 2;
+               break;
+       case CL_RGB:
+       case CL_RGx:
+       case CL_sRGB: // ??
+               nc = 3;
+               break;
+       case CL_RGBA:
+       case CL_BGRA:
+       case CL_ARGB:
+       case CL_RGBx:
+       case CL_sRGBx:
+       case CL_sRGBA:
+       case CL_sBGRA:
+       case CL_ABGR:
+       default:
+               nc = 4;
+               break;
+       }
+
+       switch (fmt->image_channel_data_type) {
+       case CL_SNORM_INT8:
+       case CL_UNORM_INT8:
+       case CL_SIGNED_INT8:
+       case CL_UNSIGNED_INT8:
+               ds = 1;
+               break;
+       case CL_SNORM_INT16:
+       case CL_UNORM_INT16:
+       case CL_UNORM_SHORT_565:
+       case CL_UNORM_SHORT_555:
+       case CL_UNORM_INT_101010:               
+       case CL_SIGNED_INT16:
+       case CL_UNSIGNED_INT16:
+       case CL_HALF_FLOAT:
+               ds = 2;
+               break;
+       case CL_UNORM_INT24:
+               ds = 3;
+               break;
+       case CL_SIGNED_INT32:
+       case CL_UNSIGNED_INT32:
+       case CL_FLOAT:
+       case CL_UNORM_INT_101010_2: // ??
+       default:
+               ds = 4;
+               break;
+       }
+
+       return nc * ds;
+}
+
+static size_t get_row_pitch(cl_image_desc *desc, size_t elsize) {
+       return desc->image_row_pitch != 0
+               ? desc->image_row_pitch
+               : elsize * desc->image_width;
+}
+
+static size_t get_slice_pitch(cl_image_desc *desc, size_t elsize) {
+       return desc->image_slice_pitch != 0
+               ? desc->image_slice_pitch
+               : desc->image_height * get_row_pitch(desc, elsize);
+}
+
+static size_t get_transfer_size(size_t region[3], size_t row_pitch, size_t slice_pitch, size_t elsize) {
+       if (slice_pitch == 0) {
+               if (row_pitch != 0)
+                       row_pitch = region[0] * elsize;
+               slice_pitch = row_pitch * region[1];
+       }
+       return slice_pitch * region[2];
+}
+
+// desc = unmarshall(jdesc)
+// returns required bytes
+static size_t marshal_image_desc(JNIEnv *env, cl_image_desc *desc, jobject jdesc, size_t elsize) {
+       desc->image_type = (*env)->GetIntField(env, jdesc, CLImageDesc_imageType);
+       desc->image_width = (*env)->GetIntField(env, jdesc, CLImageDesc_imageWidth);
+       desc->image_height = (*env)->GetIntField(env, jdesc, CLImageDesc_imageHeight);
+       desc->image_depth = (*env)->GetIntField(env, jdesc, CLImageDesc_imageDepth);
+       desc->image_array_size = (*env)->GetIntField(env, jdesc, CLImageDesc_imageArraySize);
+       desc->image_row_pitch = (*env)->GetIntField(env, jdesc, CLImageDesc_imageRowPitch);
+       desc->image_slice_pitch = (*env)->GetIntField(env, jdesc, CLImageDesc_imageSlicePitch);
+       desc->num_mip_levels = (*env)->GetIntField(env, jdesc, CLImageDesc_numMipLevels);
+       desc->num_samples = (*env)->GetIntField(env, jdesc, CLImageDesc_numSamples);
+       jobject jmemObject = (*env)->GetObjectField(env, jdesc, CLImageDesc_memObject);
+       desc->mem_object = jmemObject ? GETP(env, jmemObject) : NULL;
+
+       switch (desc->image_type) {
+       case CL_MEM_OBJECT_IMAGE2D:
+               return get_row_pitch(desc, elsize) * desc->image_height;
+       case CL_MEM_OBJECT_IMAGE3D:
+               return get_slice_pitch(desc, elsize) * desc->image_depth;
+#ifdef CL_VERSION_1_2
+       case CL_MEM_OBJECT_IMAGE1D:
+       case CL_MEM_OBJECT_IMAGE1D_BUFFER:
+               return get_row_pitch(desc, elsize);
+       case CL_MEM_OBJECT_IMAGE1D_ARRAY:
+       case CL_MEM_OBJECT_IMAGE2D_ARRAY:
+               return get_slice_pitch(desc, elsize) * desc->image_array_size;
+#endif
+       default:
+               return ~0;
+       }
+}
+
+static jobject createImage(JNIEnv *env, cl_context context, jlong flags, cl_image_format *fmt, cl_image_desc *desc, void *host_ptr) {
+
+       int res = 0;
+       cl_mem ret;
+
+#ifdef CL_VERSION_1_2
+       if (CHECK_clCreateImage()) {
+               ret = clCreateImage(context, flags, fmt, desc, host_ptr, &res);
+       } else {
+               switch (desc->image_type) {
+               case CL_MEM_OBJECT_IMAGE2D:
+                       FAIL_clCreateImage2D_RET(NULL);
+                       D(printf("createImage2D(%dx%d stride=%d host=%p)\n", desc->image_width, desc->image_height, desc->image_row_pitch, host_ptr));
+                       ret = clCreateImage2D(context, flags, fmt, desc->image_width, desc->image_height, desc->image_row_pitch, host_ptr, &res);
+                       break;
+               case CL_MEM_OBJECT_IMAGE3D:
+                       FAIL_clCreateImage3D_RET(NULL);
+                       ret = clCreateImage3D(context, flags, fmt, desc->image_width, desc->image_height, desc->image_depth,
+                                             desc->image_row_pitch, desc->image_slice_pitch, host_ptr, &res);
+                       break;
+               default:
+                       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+                       return NULL;
+               }
+       }
+#else
+       switch (desc->image_type) {
+       case CL_MEM_OBJECT_IMAGE2D:
+               FAIL_clCreateImage2D_RET(NULL);
+               D(printf("createImage2D(%dx%d stride=%d host=%p)\n", desc->image_width, desc->image_height, desc->image_row_pitch, host_ptr));
+               ret = clCreateImage2D(context, flags, fmt, desc->image_width, desc->image_height, desc->image_row_pitch, host_ptr, &res);
+               break;
+       case CL_MEM_OBJECT_IMAGE3D:
+               FAIL_clCreateImage3D_RET(NULL);
+               ret = clCreateImage3D(context, flags, fmt, desc->image_width, desc->image_height, desc->image_depth,
+                                     desc->image_row_pitch, desc->image_slice_pitch, host_ptr, &res);
+               break;
+       default:
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+               return NULL;
+       }
+#endif
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_IMAGE, ret);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createImage__JLau_notzed_zcl_CLImageFormat_2Lau_notzed_zcl_CLImageDesc_2Ljava_nio_ByteBuffer_2
+(JNIEnv *env, jobject jcontext, jlong flags, jobject jfmt, jobject jdesc, jobject jhost_ptr) {
+       cl_context context = GETP(env, jcontext);
+       cl_image_format fmt = { 0 };
+       cl_image_desc desc = { 0 };
+       void *host_ptr = NULL;
+       size_t required, elsize;
+
+       elsize = marshal_image_format(env, &fmt, jfmt);
+       required = marshal_image_desc(env, &desc, jdesc, elsize);
+       
+       if (jhost_ptr) {
+               jsize jhost_size = (*env)->GetDirectBufferCapacity(env, jhost_ptr);
+
+               if (jhost_size < required) {
+                       throwCLException(env, CL_INVALID_HOST_PTR);
+                       return NULL;
+               }
+
+               host_ptr = (*env)->GetDirectBufferAddress(env, jhost_ptr);
+       }
+
+       return createImage(env, context, flags, &fmt, &desc, host_ptr);
+}
+
+static jobject createImagePrimitive
+(JNIEnv *env, jobject jcontext, jlong flags, jobject jfmt, jobject jdesc, jarray jhost_ptr, int elshift) {
+       cl_context context = GETP(env, jcontext);
+       cl_image_format fmt = { 0 };
+       cl_image_desc desc = { 0 };
+       jobject ret;
+       void *host_ptr = NULL;
+       size_t required, elsize;
+
+       // No way to implement this with java arrays currently
+       if (flags & CL_MEM_USE_HOST_PTR) {
+               throwCLException(env, CL_INVALID_VALUE);
+               return NULL;
+       }
+
+       if (!jhost_ptr) {
+               throwException(env, "java/lang/NullPointerException", "null array");
+               return NULL;
+       }
+
+       elsize = marshal_image_format(env, &fmt, jfmt);
+       required = marshal_image_desc(env, &desc, jdesc, elsize);
+
+       jsize size = (*env)->GetArrayLength(env, jhost_ptr) << elshift;
+
+       if (size < required) {
+               throwCLException(env, CL_INVALID_HOST_PTR);
+               return NULL;
+       }
+
+       host_ptr = (*env)->GetPrimitiveArrayCritical(env, jhost_ptr, NULL);
+
+       ret = createImage(env, context, flags, &fmt, &desc, host_ptr);
+
+       (*env)->ReleasePrimitiveArrayCritical(env, jhost_ptr, host_ptr, 0);
+
+       return ret;
+}
+
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createImage__JLau_notzed_zcl_CLImageFormat_2Lau_notzed_zcl_CLImageDesc_2_3B
+(JNIEnv *env, jobject jcontext, jlong flags, jobject jfmt, jobject jdesc, jbyteArray jhost_ptr) {
+       return createImagePrimitive(env, jcontext, flags, jfmt, jdesc, jhost_ptr, 0);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createImage__JLau_notzed_zcl_CLImageFormat_2Lau_notzed_zcl_CLImageDesc_2_3S
+(JNIEnv *env, jobject jcontext, jlong flags, jobject jfmt, jobject jdesc, jbyteArray jhost_ptr) {
+       return createImagePrimitive(env, jcontext, flags, jfmt, jdesc, jhost_ptr, 1);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createImage__JLau_notzed_zcl_CLImageFormat_2Lau_notzed_zcl_CLImageDesc_2_3I
+(JNIEnv *env, jobject jcontext, jlong flags, jobject jfmt, jobject jdesc, jbyteArray jhost_ptr) {
+       return createImagePrimitive(env, jcontext, flags, jfmt, jdesc, jhost_ptr, 2);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createImage__JLau_notzed_zcl_CLImageFormat_2Lau_notzed_zcl_CLImageDesc_2_3F
+(JNIEnv *env, jobject jcontext, jlong flags, jobject jfmt, jobject jdesc, jbyteArray jhost_ptr) {
+       return createImagePrimitive(env, jcontext, flags, jfmt, jdesc, jhost_ptr, 2);
+}
+
+/* ********************************************************************** */
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createPipe
+(JNIEnv *env, jobject jcontext, jlong flags, jint packetSize, jint maxPackets, jobjectArray jprops) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jcontext, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clCreatePipe_RET(NULL);
+
+               cl_context context = GETP(env, jcontext);
+               cl_int res;
+               cl_mem ret;
+               cl_pipe_properties *props = fromPropertyArray(env, jprops);
+
+               if ((*env)->ExceptionCheck(env)) return NULL;
+
+               ret = clCreatePipe(context,
+                                  flags,
+                                  packetSize,
+                                  maxPackets,
+                                  props,
+                                  &res);
+               free(props);
+               THROW_RTERROR_RET(res, NULL);
+
+               return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_PIPE, ret);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+       return NULL;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLContext_getSupportedImageFormats
+(JNIEnv *env, jobject jcontext, jlong flags, jint type) {
+       FAIL_clGetSupportedImageFormats_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       cl_uint count;
+       cl_image_format *formats;
+       jobjectArray jformats;
+       cl_int res;
+
+       res = clGetSupportedImageFormats(context,
+                                        flags,
+                                        type,
+                                        0, NULL, &count);
+       THROW_RTERROR_RET(res, NULL);
+
+       formats = alloca(sizeof(*formats) * count);
+       res = clGetSupportedImageFormats(context,
+                                        flags,
+                                        type,
+                                        count, formats, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       jformats = (*env)->NewObjectArray(env, count, CLImageFormat_classid, NULL);
+       if (!jformats)
+               return NULL;
+
+       for (int i=0;i<count;i++) {
+               jobject o = (*env)->NewObject(env, CLImageFormat_classid, CLImageFormat_new_ii,
+                                             formats[i].image_channel_order,
+                                             formats[i].image_channel_data_type);
+               (*env)->SetObjectArrayElement(env, jformats, i, o);
+       }
+
+       return jformats;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_SVMAlloc
+(JNIEnv *env, jobject jcontext, jlong flags, jlong size, jint alignment) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jcontext, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clSVMAlloc_RET(NULL);
+
+               cl_context context = GETP(env, jcontext);
+               void *svm;
+
+               svm = clSVMAlloc(context, flags, size, alignment);
+               if (!svm) {
+                       // This isn't necessarily correct but there's no other return code
+                       // and it's a bunch of work to look up what it might be.
+                       throwCLRuntimeException(env, CL_OUT_OF_RESOURCES);
+                       return NULL;
+               }
+               
+               return nativez_NewDirectBuffer(env, svm, size);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+       return NULL;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLContext_SVMFree
+(JNIEnv *env, jobject jcontext, jobject jsvm) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jcontext, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clSVMFree();
+
+               cl_context context = GETP(env, jcontext);
+
+               // NULL is ok & ignored
+               if (jsvm) {
+                       void *svm = (*env)->GetDirectBufferAddress(env, jsvm);
+                       
+                       clSVMFree(context, svm);
+               }
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+}
+
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createSampler__ZII
+(JNIEnv *env, jobject jcontext, jboolean norm, jint addr_mode, jint filter_mode) {
+       FAIL_clCreateSampler_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       cl_sampler ret;
+       cl_int res;
+
+       ret = clCreateSampler(context, norm, addr_mode, filter_mode, &res);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_SAMPLER, ret);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createSampler___3Lau_notzed_zcl_CLSamplerProperty_2
+(JNIEnv *env, jobject jcontext, jobjectArray jprops) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jcontext, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clCreateSamplerWithProperties_RET(NULL);
+
+               cl_context context = GETP(env, jcontext);
+               cl_sampler ret;
+               cl_int res;
+               cl_sampler_properties *props = fromPropertyArray(env, jprops);
+
+               if ((*env)->ExceptionCheck(env)) return NULL;
+
+               ret = clCreateSamplerWithProperties(context, props, &res);
+               free(props);
+               THROW_RTERROR_RET(res, NULL);
+
+               return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_SAMPLER, ret);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+       return NULL;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createProgramWithSource
+(JNIEnv *env, jobject jcontext, jobjectArray jstrings) {
+       FAIL_clCreateProgramWithSource_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       int count;
+       const char **strings;
+       size_t *lengths;
+       cl_int res;
+       cl_program ret;
+
+       count = (*env)->GetArrayLength(env, jstrings);
+       strings = alloca(sizeof(*strings) * count);
+       lengths = alloca(sizeof(*lengths) * count);
+       for (int i=0;i<count;i++) {
+               jobject jo = (*env)->GetObjectArrayElement(env, jstrings, i);
+
+               lengths[i] = (*env)->GetArrayLength(env, jo);
+               strings[i] = (*env)->GetPrimitiveArrayCritical(env, jo, NULL);
+       }
+
+       ret = clCreateProgramWithSource(context,
+                                       count,
+                                       strings,
+                                       lengths,
+                                       &res);
+       for (int i=0;i<count;i++) {
+               jobject jo = (*env)->GetObjectArrayElement(env, jstrings, i);
+
+               (*env)->ReleasePrimitiveArrayCritical(env, jo, (void *)strings[i], 0);
+       }
+
+       THROW_ERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_PROGRAM, ret);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createProgramWithIL
+(JNIEnv *env, jobject jcontext, jbyteArray jil) {
+#ifdef CL_VERSION_2_1
+       if (checkAPIVersion(env, jcontext, au_notzed_zcl_CLPlatform_VERSION_2_1)) {
+               FAIL_clCreateProgramWithIL_RET(NULL);
+       
+               cl_context context = GETP(env, jcontext);
+               void *il;
+               size_t length;
+               cl_int res;
+               cl_program ret;
+
+               length = (*env)->GetArrayLength(env, jil);
+               il = (*env)->GetPrimitiveArrayCritical(env, jil, NULL);
+
+               ret = clCreateProgramWithIL(context,
+                                           il,
+                                           length,
+                                           &res);
+       
+               (*env)->ReleasePrimitiveArrayCritical(env, jil, il, 0);
+               THROW_ERROR_RET(res, NULL);
+
+               return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_PROGRAM, ret);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.1");
+       return NULL;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createProgramWithBinary
+(JNIEnv *env, jobject jcontext, jobjectArray jdevices, jobjectArray jbinaries, jintArray jstatus) {
+       FAIL_clCreateProgramWithBinary_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       int dlen, blen, slen;
+       cl_device_id *devices;
+       size_t *lengths;
+       const unsigned char **binaries;
+       cl_int *status;
+       cl_int res;
+       cl_program ret;
+
+       if (!jdevices) {
+               throwException(env, "java/lang/NullPointerException", "device_list must not be null");
+               return NULL;
+       }
+
+       if (!jbinaries) {
+               throwException(env, "java/lang/NullPointerException", "binaries must not be null");
+               return NULL;
+       }
+
+       dlen = (*env)->GetArrayLength(env, jdevices);
+       blen = (*env)->GetArrayLength(env, jbinaries);
+       slen = jstatus ? (*env)->GetArrayLength(env, jbinaries) : 0;
+
+       if (slen > 0 && slen != blen) {
+               throwException(env, "java/lang/ArrayIndexOutOfBoundsException", "binary_status.length != binaries.length");
+               return NULL;
+       }
+
+       devices = alloca(dlen * sizeof(*devices));
+       fromObjectArray(env, jdevices, (void **)devices, dlen);
+
+       binaries = alloca(blen * sizeof(*binaries));
+       lengths = alloca(blen * sizeof(*lengths));
+       status = alloca(blen * sizeof(*status));
+
+       for (int i=0;i<blen;i++) {
+               jobject jo = (*env)->GetObjectArrayElement(env, jbinaries, i);
+
+               lengths[i] = (*env)->GetArrayLength(env, jo);
+               binaries[i] = (*env)->GetPrimitiveArrayCritical(env, jo, NULL);
+       }
+
+       ret = clCreateProgramWithBinary(context,
+                                       dlen,
+                                       devices,
+                                       lengths,
+                                       binaries,
+                                       status,
+                                       &res);
+
+       for (int i=0;i<blen;i++) {
+               jobject jo = (*env)->GetObjectArrayElement(env, jbinaries, i);
+
+               (*env)->ReleasePrimitiveArrayCritical(env, jo, (void *)binaries[i], 0);
+       }
+       THROW_ERROR_RET(res, NULL);
+
+       if (jstatus)
+               (*env)->SetIntArrayRegion(env, jstatus, 0, blen, status);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_PROGRAM, ret);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createProgramWithBuiltInKernels
+(JNIEnv *env, jobject jcontext, jobjectArray jdevices, jstring jnames) {
+#ifdef CL_VERSION_1_2
+       FAIL_clCreateProgramWithBuiltInKernels_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       int dlen;
+       cl_device_id *devices;
+       const char *names;
+       cl_int res;
+       cl_program ret;
+
+       if (!jdevices) {
+               throwException(env, "java/lang/NullPointerException", "device_list must not be null");
+               return NULL;
+       }
+
+       dlen = (*env)->GetArrayLength(env, jdevices);
+       devices = alloca(dlen * sizeof(*devices));
+       fromObjectArray(env, jdevices, (void **)devices, dlen);
+
+       names = (*env)->GetStringUTFChars(env, jnames, NULL);
+       if (!names)
+               return NULL;
+
+       ret = clCreateProgramWithBuiltInKernels(context,
+                                               dlen,
+                                               devices,
+                                               names,
+                                               &res);
+       (*env)->ReleaseStringUTFChars(env, jnames, names);
+
+       THROW_ERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_PROGRAM, ret);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+       return NULL;
+#endif
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_linkProgram
+(JNIEnv *env, jobject jcontext, jobjectArray jdevices, jstring joptions, jobjectArray jprograms, jobject jnotify) {
+#ifdef CL_VERSION_1_2
+       FAIL_clLinkProgram_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       int dlen = 0, plen;
+       cl_device_id *devices = NULL;
+       cl_program *programs;
+       const char *options;
+       cl_int res;
+       cl_program ret = NULL;
+       void (CL_CALLBACK *notify)(cl_program /* program */, void * /* user_data */) = NULL;
+       struct build_notify_info *data = NULL;
+
+       if (!jprograms) {
+               throwException(env, "java/lang/NullPointerException", "device_list must not be null");
+               return NULL;
+       }
+
+       plen = (*env)->GetArrayLength(env, jprograms);
+       programs = alloca(plen * sizeof(*programs));
+       fromObjectArray(env, jprograms, (void **)programs, plen);
+
+       if (jdevices) {
+               dlen = (*env)->GetArrayLength(env, jdevices);
+               devices = alloca(dlen * sizeof(*devices));
+               fromObjectArray(env, jdevices, (void **)devices, dlen);
+       }
+
+       options = (*env)->GetStringUTFChars(env, joptions, NULL);
+
+       if (jnotify) {
+               // Note: build_notify_hook deletes the global ref
+               notify = build_notify_hook;
+               data = build_notify_alloc(env, NULL, NULL, jnotify);    
+               if (!data) {
+                       res = CL_OUT_OF_HOST_MEMORY;
+                       goto fail;
+               }
+       }
+
+       ret = clLinkProgram(context,
+                           dlen,
+                           devices,
+                           options,
+                           plen,
+                           programs,
+                           notify,
+                           data,
+                           &res);
+
+ fail:
+       (*env)->ReleaseStringUTFChars(env, joptions, options);
+
+       THROW_ERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_PROGRAM, ret);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+       return NULL;
+#endif
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLContext_createUserEvent
+(JNIEnv *env, jobject jcontext) {
+#ifdef CL_VERSION_1_1
+       FAIL_clCreateUserEvent_RET(NULL);
+
+       cl_context context = GETP(env, jcontext);
+       cl_event ret;
+       cl_int res;
+
+       ret = clCreateUserEvent(context, &res);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_EVENT, ret);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.1");
+       return NULL;
+#endif
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLContext_getProperties
+(JNIEnv *env, jobject jcontext) {
+       return getInfoProperties(env, jcontext, au_notzed_zcl_CLObject_TYPE_CONTEXT, CL_CONTEXT_PROPERTIES,
+                                CLContextProperty_classid,
+                                CLContextProperty_TagValue_classid, CLContextProperty_TagValue_new_jj);
+}
+
+/* ********************************************************************** */
+/* CLMemory */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLMemory_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       cl_int res;
+
+       FAIL_clReleaseMemObject();
+       res = clReleaseMemObject((cl_mem)jp);
+       if (res != CL_SUCCESS)
+               throwCLRuntimeException(env, res);
+}
+
+#ifdef CL_VERSION_1_1
+struct destroy_notify_info {
+       cl_mem mem;
+       jobject jnotify;
+       jobject jmem;
+};
+
+static void destroy_notify_hook(cl_mem mem, void *data) {
+       struct destroy_notify_info *info = data;
+       JNIEnv *env;
+
+       D(printf("destroy notify()\n"));
+
+       if (!(env = nativez_AttachCurrentThreadAsDaemon())) {
+               // NB: can't do anything here
+               fprintf(stderr, "Unable to attach java environment\n");
+               free(data);
+               return;
+       }
+
+       if (info->mem == mem) {
+               jvalue arg = { .l = info->jmem };
+
+               (*env)->CallVoidMethodA(env, info->jnotify, CLNotify_notify, &arg);
+       } else
+               fprintf(stderr, "destroy_notify_hook given wrong cl_mem\n");
+
+       (*env)->DeleteGlobalRef(env, info->jnotify);
+       (*env)->DeleteGlobalRef(env, info->jmem);
+
+       free(info);
+}
+#endif
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLMemory_setMemObjectDestructorCallback
+(JNIEnv *env, jobject jmem, jobject jnotify) {
+#ifdef CL_VERSION_1_1
+       FAIL_clSetMemObjectDestructorCallback();
+
+       cl_mem mem = GETP(env, jmem);
+       struct destroy_notify_info *info;
+
+       if (!jnotify)
+               return;
+
+       info = malloc(sizeof(*info));
+       if (!info)
+               return;
+
+       info->mem = mem;
+       info->jnotify = (*env)->NewGlobalRef(env, jnotify);
+       info->jmem = (*env)->NewGlobalRef(env, jmem);
+
+       THROW_RTERROR(clSetMemObjectDestructorCallback(mem, destroy_notify_hook, info));
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.1");
+#endif
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLMemory_getHostPtr
+(JNIEnv *env, jobject jmem) {
+       FAIL_clGetMemObjectInfo_RET(NULL);
+
+       cl_mem mem = GETP(env, jmem);
+       cl_int res;
+       void *host_ptr;
+       size_t host_size;
+
+       res = clGetMemObjectInfo(mem, CL_MEM_HOST_PTR, sizeof(host_ptr), &host_ptr, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       res = clGetMemObjectInfo(mem, CL_MEM_SIZE, sizeof(host_size), &host_size, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return nativez_NewDirectBuffer(env, host_ptr, host_size);
+}
+
+/* ********************************************************************** */
+/* CLBuffer */
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLBuffer_createSubBuffer
+(JNIEnv *env, jobject jmem, jlong flags, jobject jinfo) {
+#ifdef CL_VERSION_1_1
+       FAIL_clCreateSubBuffer_RET(NULL);
+
+       cl_mem mem = GETP(env, jmem);
+       cl_mem ret;
+       cl_int res;
+       cl_buffer_create_type type;
+       union {
+               cl_buffer_region region;
+       } info;
+
+       if ((*env)->IsInstanceOf(env, jinfo, CLBufferInfoRegion_classid)) {
+               type = CL_BUFFER_CREATE_TYPE_REGION;
+               info.region.origin = (size_t)(*env)->GetLongField(env, jinfo, CLBufferInfoRegion_origin);
+               info.region.size = (size_t)(*env)->GetLongField(env, jinfo, CLBufferInfoRegion_size);
+       } else {
+               throwCLException(env, CL_INVALID_VALUE);
+               return NULL;
+       }
+
+       ret = clCreateSubBuffer(mem,
+                               flags,
+                               type,
+                               &info,
+                               &res);
+
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_BUFFER, ret);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.1");
+       return NULL;
+#endif
+}
+
+/* ********************************************************************** */
+/* CLProgram */
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLProgram_getBuildInfoAny
+(JNIEnv *env, jobject jprogram, jobject jdevice, jint ctype, jint param) {
+       FAIL_clGetProgramBuildInfo_RET(NULL);
+
+       cl_program program = GETP(env, jprogram);
+       cl_device_id device = GETP(env, jdevice);
+       void *value;
+       size_t size = ctype_sizes[ctype];
+       cl_int res;
+
+       value = alloca(size);
+       res = clGetProgramBuildInfo(program, device, param, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+       
+       return toObject(env, ctype, size, value);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLProgram_getBuildInfoAnyV
+(JNIEnv *env, jobject jprogram, jobject jdevice, jint ctype, jint param) {
+       FAIL_clGetProgramBuildInfo_RET(NULL);
+
+       cl_program program = GETP(env, jprogram);
+       cl_device_id device = GETP(env, jdevice);
+       void *value;
+       size_t size = 0;
+       cl_int res;
+
+       res = clGetProgramBuildInfo(program, device, param, 0, NULL, &size);
+       THROW_RTERROR_RET(res, NULL);
+       
+       value = alloca(size);
+
+       res = clGetProgramBuildInfo(program, device, param, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toArray(env, ctype, size, value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLProgram_buildProgram
+(JNIEnv *env, jobject jprogram, jobjectArray jdevices, jstring joptions, jobject jnotify) {
+       FAIL_clBuildProgram();
+
+       cl_program program = GETP(env, jprogram);
+       cl_device_id *devices = NULL;
+       int devcount = 0;
+       const char *options = NULL;
+       cl_int res;
+       void (CL_CALLBACK *notify)(cl_program /* program */, void * /* user_data */) = NULL;
+       struct build_notify_info *data = NULL;
+
+       if (jdevices) {
+               devcount = (*env)->GetArrayLength(env, jdevices);
+               devices = alloca(sizeof(*devices) * devcount);
+               fromObjectArray(env, jdevices, (void **)devices, devcount);
+       }
+
+       if (joptions) {
+               options = (*env)->GetStringUTFChars(env, joptions, NULL);
+       }
+
+       if (jnotify) {
+               // Note: build_notify_hook deletes the global ref
+               notify = build_notify_hook;
+               data = build_notify_alloc(env, program, jprogram, jnotify);
+               if (!data) {
+                       res = CL_OUT_OF_HOST_MEMORY;
+                       goto fail;
+               }
+       }
+
+       res = clBuildProgram(program, devcount, devices, options, notify, data);
+ fail:
+       if (options)
+               (*env)->ReleaseStringUTFChars(env, joptions, options);
+
+       THROW_ERROR(res);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLProgram_compileProgram
+(JNIEnv *env, jobject jprogram, jobjectArray jdevices, jstring joptions, jobjectArray jheaders, jobjectArray jheadernames, jobject jnotify) {
+#ifdef CL_VERSION_1_2
+       FAIL_clCompileProgram();
+
+       cl_program program = GETP(env, jprogram);
+       cl_device_id *devices = NULL;
+       int devcount = 0;
+       cl_int res;
+       const char *options = NULL;
+       void (CL_CALLBACK *notify)(cl_program /* program */, void * /* user_data */) = NULL;
+       struct build_notify_info *data = NULL;
+       int hlen = 0;
+       cl_program *headers = NULL;
+       const char **names = NULL;
+
+       if (jdevices) {
+               devcount = (*env)->GetArrayLength(env, jdevices);
+               devices = alloca(sizeof(*devices) * devcount);
+               fromObjectArray(env, jdevices, (void **)devices, devcount);
+       }
+
+       if (joptions) {
+               options = (*env)->GetStringUTFChars(env, joptions, NULL);
+       }
+
+       if (jheaders) {
+               hlen = (*env)->GetArrayLength(env, jheaders);
+
+               if (hlen != (*env)->GetArrayLength(env, jheadernames)) {
+                       res = CL_INVALID_VALUE;
+                       goto fail;
+               }
+
+               headers = alloca(sizeof(*headers) * hlen);
+               names = alloca(sizeof(*names) * hlen);
+
+               for (int i=0;i<hlen;i++) {
+                       jobject jheader = (*env)->GetObjectArrayElement(env, jheaders, i);
+                       jobject jname = (*env)->GetObjectArrayElement(env, jheadernames, i);
+
+                       headers[i] = GETP(env, jheader);
+                       names[i] = (*env)->GetStringUTFChars(env, jname, NULL);
+               }
+       }
+
+       if (jnotify) {
+               // Note: build_notify_hook deletes the global ref
+               notify = build_notify_hook;
+               data = build_notify_alloc(env, program, jprogram, jnotify);
+               if (!data) {
+                       res = CL_OUT_OF_HOST_MEMORY;
+                       goto fail;
+               }
+       }
+
+       res = clCompileProgram(program, devcount, devices, options, hlen, headers, names, notify, data);
+ fail:
+       if (options)
+               (*env)->ReleaseStringUTFChars(env, joptions, options);
+
+       if (names) {
+               for (int i=0;i<hlen;i++) {
+                       jobject jname = (*env)->GetObjectArrayElement(env, jheadernames, i);
+
+                       (*env)->ReleaseStringUTFChars(env, jname, names[i]);
+               }
+       }
+
+       THROW_ERROR(res);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+#endif
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLProgram_createKernel
+(JNIEnv *env, jobject jprogram, jstring jname) {
+       FAIL_clCreateKernel_RET(NULL);
+
+       cl_program program = GETP(env, jprogram);
+       const char *name;
+       cl_kernel ret;
+       cl_int res;
+
+       name = (*env)->GetStringUTFChars(env, jname, NULL);
+
+       ret = clCreateKernel(program, name, &res);
+
+       (*env)->ReleaseStringUTFChars(env, jname, name);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_KERNEL, ret);
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLProgram_createKernelsInProgram
+(JNIEnv *env, jobject jprogram) {
+       FAIL_clCreateKernelsInProgram_RET(NULL);
+
+       cl_program program = GETP(env, jprogram);
+       cl_int res;
+       cl_uint kcount;
+       cl_kernel *kernels;
+
+       res = clCreateKernelsInProgram(program, 0, NULL, &kcount);
+       THROW_RTERROR_RET(res, NULL);
+
+       kernels = alloca(sizeof(*kernels) * kcount);
+
+       res = clCreateKernelsInProgram(program, kcount, kernels, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObjectArray(env, au_notzed_zcl_CLObject_CTYPE_KERNEL, kcount, (void **)kernels);
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_zcl_CLProgram_getBinaries
+(JNIEnv *env, jobject jprogram) {
+       FAIL_clGetProgramInfo_RET(NULL);
+
+       cl_program program = GETP(env, jprogram);
+       cl_uint count;
+       size_t *sizes;
+       unsigned char **binaries;
+       cl_int res;
+       jobjectArray ret;
+
+       res = clGetProgramInfo(program, CL_PROGRAM_NUM_DEVICES, sizeof(count), &count, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       sizes = alloca(sizeof(*sizes) * count);
+       res = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, sizeof(*sizes) * count, sizes, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       binaries = alloca(sizeof(*binaries) * count);
+       memset(binaries, 0, sizeof(*binaries) * count);
+       for (int i=0;i<count;i++) {
+               binaries[i] = malloc(sizes[i]);
+               if (!binaries[i]) {
+                       res = CL_OUT_OF_HOST_MEMORY;
+                       goto fail;
+               }
+       }
+       res = clGetProgramInfo(program, CL_PROGRAM_BINARIES, sizeof(*binaries) * count, binaries, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       ret = (*env)->NewObjectArray(env, count, byte_a_classid, NULL);
+       if (!ret)
+               goto fail;
+
+       for (int i=0;i<count;i++) {
+               jbyteArray jo = (*env)->NewByteArray(env, sizes[i]);
+
+               if (!jo)
+                       goto fail;
+
+               (*env)->SetByteArrayRegion(env, jo, 0, sizes[i], (const jbyte *)binaries[i]);
+               (*env)->SetObjectArrayElement(env, ret, i, jo);
+       }
+       for (int i=0;i<count;i++) {
+               free(binaries[i]);
+       }
+
+       return ret;
+ fail:
+       for (int i=0;i<count;i++) {
+               if (binaries[i])
+                       free(binaries[i]);
+       }
+
+       throwCLRuntimeException(env, res);
+
+       return NULL;
+}
+
+/* ********************************************************************** */
+/* CLKernel */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       cl_int res;
+       FAIL_clReleaseKernel();
+       res = clReleaseKernel((cl_kernel)jp);
+       if (res != CL_SUCCESS)
+               throwCLRuntimeException(env, res);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLKernel_getWorkGroupInfoAny
+(JNIEnv *env, jobject jkernel, jobject jdevice, jint ctype, jint param) {
+       FAIL_clGetKernelWorkGroupInfo_RET(NULL);
+
+       cl_kernel kernel = GETP(env, jkernel);
+       cl_device_id device = GETP(env, jdevice);
+       void *value;
+       size_t size = ctype_sizes[ctype];
+       cl_int res;
+
+       value = alloca(size);
+       res = clGetKernelWorkGroupInfo(kernel, device, param, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toObject(env, ctype, size, value);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLKernel_getWorkGroupInfoAnyV
+(JNIEnv *env, jobject jkernel, jobject jdevice, jint ctype, jint param) {
+       FAIL_clGetKernelWorkGroupInfo_RET(NULL);
+
+       cl_kernel kernel = GETP(env, jkernel);
+       cl_device_id device = GETP(env, jdevice);
+       void *value;
+       size_t size = ctype_sizes[ctype];
+       cl_int res;
+
+       res = clGetKernelWorkGroupInfo(kernel, device, param, 0, NULL, &size);
+       THROW_RTERROR_RET(res, NULL);
+       
+       value = alloca(size);
+
+       res = clGetKernelWorkGroupInfo(kernel, device, param, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toArray(env, ctype, size, value);
+}
+
+static void getInputSizeTA(JNIEnv *env, jlongArray jinput, void **input, size_t *input_size) {
+       if (jinput) {
+               int ilen = (*env)->GetArrayLength(env, jinput);
+
+               *input_size = sizeof(*input) * ilen;
+               *input = alloca(sizeof(*input) * ilen);
+               getSizeTA(env, jinput, *input, ilen);
+       } else {
+               *input = NULL;
+               *input_size = 0;
+       }
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLKernel_getSubGroupInfoAny
+(JNIEnv *env, jobject jkernel, jobject jdevice, jint ctype, jint param, jlongArray jinput) {
+       FAIL_clGetKernelSubGroupInfo_RET(NULL);
+
+       cl_kernel kernel = GETP(env, jkernel);
+       cl_device_id device = GETP(env, jdevice);
+       void *value;
+       size_t size = ctype_sizes[ctype];
+       cl_int res;
+       void *input;
+       size_t input_size;
+
+       getInputSizeTA(env, jinput, &input, &input_size);
+
+       value = alloca(size);
+       res = clGetKernelSubGroupInfo(kernel, device, param, input_size, input, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toObject(env, ctype, size, value);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLKernel_getSubGroupInfoAnyV
+(JNIEnv *env, jobject jkernel, jobject jdevice, jint ctype, jint param, jlongArray jinput) {
+       FAIL_clGetKernelSubGroupInfo_RET(NULL);
+
+       cl_kernel kernel = GETP(env, jkernel);
+       cl_device_id device = GETP(env, jdevice);
+       void *value;
+       size_t size = ctype_sizes[ctype];
+       cl_int res;
+       void *input;
+       size_t input_size;
+
+       getInputSizeTA(env, jinput, &input, &input_size);
+
+       res = clGetKernelSubGroupInfo(kernel, device, param, input_size, input, 0, NULL, &size);
+       THROW_RTERROR_RET(res, NULL);
+       
+       value = alloca(size);
+
+       res = clGetKernelSubGroupInfo(kernel, device, param, input_size, input, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toArray(env, ctype, size, value);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLKernel_getArgInfoAny
+(JNIEnv *env, jobject jkernel, jint index, jint ctype, jint param) {
+       FAIL_clGetKernelArgInfo_RET(NULL);
+
+       cl_kernel kernel = GETP(env, jkernel);
+       void *value;
+       size_t size = ctype_sizes[ctype];
+       cl_int res;
+
+       value = alloca(size);
+       res = clGetKernelArgInfo(kernel, index, param, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toObject(env, ctype, size, value);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLKernel_getArgInfoAnyV
+(JNIEnv *env, jobject jkernel, jint index, jint ctype, jint param) {
+       FAIL_clGetKernelArgInfo_RET(NULL);
+
+       cl_kernel kernel = GETP(env, jkernel);
+       void *value;
+       size_t size = ctype_sizes[ctype];
+       cl_int res;
+
+       res = clGetKernelArgInfo(kernel, index, param, 0, NULL, &size);
+       THROW_RTERROR_RET(res, NULL);
+       
+       value = alloca(size);
+
+       res = clGetKernelArgInfo(kernel, index, param, size, value, NULL);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toArray(env, ctype, size, value);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLKernel_cloneKernel
+(JNIEnv *env, jobject jkernel) {
+       // Note: no runtime version check, see CLKernel.java
+#ifdef CL_VERSION_2_1
+       FAIL_clCloneKernel_RET(NULL);
+
+       cl_kernel kernel = GETP(env, jkernel);
+       cl_int res;
+       cl_kernel ret;
+
+       ret = clCloneKernel(kernel, &res);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_KERNEL, ret);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.1");
+       
+       return NULL;
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__IJLjava_nio_Buffer_2J
+(JNIEnv *env, jobject jkernel, jint index, jlong size, jobject jbuffer, jlong offset) {
+       FAIL_clSetKernelArg();
+
+       cl_kernel kernel = GETP(env, jkernel);
+       cl_int res;
+
+       if (jbuffer) {
+               void *buffer = (*env)->GetDirectBufferAddress(env, jbuffer);
+               jlong bsize = (*env)->GetDirectBufferCapacity(env, jbuffer);
+
+               if (offset + size > bsize) {
+                       throwCLException(env, CL_INVALID_VALUE);
+                       return; 
+               }
+
+               res = clSetKernelArg(kernel, index, size, buffer+offset);
+       } else {
+               res = clSetKernelArg(kernel, index, size, NULL);
+       }
+       THROW_ERROR(res);
+}
+
+static void zclSetKernelArg(JNIEnv *env, cl_kernel kernel, jint index, size_t size, void *valuep) {
+       FAIL_clSetKernelArg();
+       THROW_ERROR(clSetKernelArg(kernel, index, size, valuep));
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__ILau_notzed_zcl_CLObject_2
+(JNIEnv *env, jobject jkernel, jint index, jobject jvalue) {
+       cl_kernel kernel = GETP(env, jkernel);
+       void *value = jvalue ? GETP(env, jvalue) : NULL;
+
+       zclSetKernelArg(env, kernel, index, sizeof(value), &value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__IB
+(JNIEnv *env, jobject jkernel, jint index, jbyte value) {
+       cl_kernel kernel = GETP(env, jkernel);
+       zclSetKernelArg(env, kernel, index, sizeof(value), &value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__IS
+(JNIEnv *env, jobject jkernel, jint index, jshort value) {
+       cl_kernel kernel = GETP(env, jkernel);
+       zclSetKernelArg(env, kernel, index, sizeof(value), &value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__II
+(JNIEnv *env, jobject jkernel, jint index, jint value) {
+       cl_kernel kernel = GETP(env, jkernel);
+       zclSetKernelArg(env, kernel, index, sizeof(value), &value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__IJ
+(JNIEnv *env, jobject jkernel, jint index, jlong value) {
+       cl_kernel kernel = GETP(env, jkernel);
+       zclSetKernelArg(env, kernel, index, sizeof(value), &value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__IF
+(JNIEnv *env, jobject jkernel, jint index, jfloat value) {
+       cl_kernel kernel = GETP(env, jkernel);
+       zclSetKernelArg(env, kernel, index, sizeof(value), &value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__ID
+(JNIEnv *env, jobject jkernel, jint index, jdouble value) {
+       cl_kernel kernel = GETP(env, jkernel);
+       zclSetKernelArg(env, kernel, index, sizeof(value), &value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__ILjava_nio_ByteBuffer_2
+(JNIEnv *env, jobject jkernel, jint index, jobject jsvm) {
+#ifdef CL_VERSION_2_0
+       // Note: no runtime version check, see CLKernel.java
+       FAIL_clSetKernelArgSVMPointer();
+
+       cl_kernel kernel = GETP(env, jkernel);
+       void *svm = jsvm ? (*env)->GetDirectBufferAddress(env, jsvm) : NULL;
+
+       THROW_ERROR(clSetKernelArgSVMPointer(kernel, index, svm));
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__I_3B
+(JNIEnv *env, jobject jkernel, jint index, jbyteArray jvalue) {
+       cl_kernel kernel = GETP(env, jkernel);
+       jsize count = (*env)->GetArrayLength(env, jvalue);
+       jbyte *value = alloca(count * sizeof(*value));
+
+       (*env)->GetByteArrayRegion(env, jvalue, 0, count, value);
+       zclSetKernelArg(env, kernel, index, sizeof(*value) * count, value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__I_3S
+(JNIEnv *env, jobject jkernel, jint index, jshortArray jvalue) {
+       cl_kernel kernel = GETP(env, jkernel);
+       jsize count = (*env)->GetArrayLength(env, jvalue);
+       jshort *value = alloca(count * sizeof(*value));
+
+       (*env)->GetShortArrayRegion(env, jvalue, 0, count, value);
+       zclSetKernelArg(env, kernel, index, sizeof(*value) * count, value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__I_3I
+(JNIEnv *env, jobject jkernel, jint index, jintArray jvalue) {
+       cl_kernel kernel = GETP(env, jkernel);
+       jsize count = (*env)->GetArrayLength(env, jvalue);
+       jint *value = alloca(count * sizeof(*value));
+
+       (*env)->GetIntArrayRegion(env, jvalue, 0, count, value);
+       zclSetKernelArg(env, kernel, index, sizeof(*value) * count, value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__I_3J
+(JNIEnv *env, jobject jkernel, jint index, jlongArray jvalue) {
+       cl_kernel kernel = GETP(env, jkernel);
+       jsize count = (*env)->GetArrayLength(env, jvalue);
+       jlong *value = alloca(count * sizeof(*value));
+
+       (*env)->GetLongArrayRegion(env, jvalue, 0, count, value);
+       zclSetKernelArg(env, kernel, index, sizeof(*value) * count, value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__I_3F
+(JNIEnv *env, jobject jkernel, jint index, jfloatArray jvalue) {
+       cl_kernel kernel = GETP(env, jkernel);
+       jsize count = (*env)->GetArrayLength(env, jvalue);
+       jfloat *value = alloca(count * sizeof(*value));
+
+       (*env)->GetFloatArrayRegion(env, jvalue, 0, count, value);      
+       zclSetKernelArg(env, kernel, index, sizeof(*value) * count, value);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLKernel_setArg__I_3D
+(JNIEnv *env, jobject jkernel, jint index, jfloatArray jvalue) {
+       cl_kernel kernel = GETP(env, jkernel);
+       jsize count = (*env)->GetArrayLength(env, jvalue);
+       jdouble *value = alloca(count * sizeof(*value));
+
+       (*env)->GetDoubleArrayRegion(env, jvalue, 0, count, value);
+       zclSetKernelArg(env, kernel, index, sizeof(*value) * count, value);
+}
+
+/* ********************************************************************** */
+/* CLEvent */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLEvent_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       cl_int res;
+       FAIL_clReleaseEvent();
+       res = clReleaseEvent((cl_event)jp);
+       if (res != CL_SUCCESS)
+               throwCLRuntimeException(env, res);
+}
+
+#ifdef CL_VERSION_1_1
+struct event_notify_info {
+       cl_event event;
+       jobject jnotify;
+       jobject jevent;
+};
+
+static void event_notify_hook(cl_event event, cl_int status, void *data) {
+       struct event_notify_info *info = data;
+       JNIEnv *env;
+
+       D(printf("event notify()\n"));
+
+       if (!(env = nativez_AttachCurrentThreadAsDaemon())) {
+               // NB: can't do anything here
+               fprintf(stderr, "Unable to attach java environment\n");
+               free(data);
+               return;
+       }
+
+       if (info->event == event)
+               (*env)->CallVoidMethod(env, info->jnotify, CLEventNotify_notify, info->jevent, status);
+       else
+               fprintf(stderr, "destroy_notify_hook given wrong cl_mem\n");
+
+       (*env)->DeleteGlobalRef(env, info->jnotify);
+       (*env)->DeleteGlobalRef(env, info->jevent);
+
+       free(info);
+}
+#endif
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLEvent_setUserEventStatus
+(JNIEnv *env, jobject jevent, jint status) {
+#ifdef CL_VERSION_1_1
+       FAIL_clSetUserEventStatus();
+
+       cl_event event = GETP(env, jevent);
+       THROW_RTERROR(clSetUserEventStatus(event, status));
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.1");
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLEvent_setEventCallback
+(JNIEnv *env, jobject jevent, jint type, jobject jnotify) {
+#ifdef CL_VERSION_1_1
+       FAIL_clSetEventCallback();
+
+       cl_event event = GETP(env, jevent);
+       struct event_notify_info *info;
+
+       if (!jnotify)
+               return;
+
+       info = malloc(sizeof(*info));
+       if (!info)
+               return;
+
+       info->event = event;
+       info->jnotify = (*env)->NewGlobalRef(env, jnotify);
+       info->jevent = (*env)->NewGlobalRef(env, jevent);
+
+       THROW_RTERROR(clSetEventCallback(event, type, event_notify_hook, info));
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.1");
+#endif
+}
+
+/* ********************************************************************** */
+/* CLEventList */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLEventList_waitForEvents
+(JNIEnv *env, jobject jevent) {
+       FAIL_clWaitForEvents();
+
+       jint count = (*env)->GetIntField(env, jevent, CLEventList_index);
+       jlongArray jevents = (*env)->GetObjectField(env, jevent, CLEventList_events);
+       cl_event *events = alloca(sizeof(*events) * count);
+       cl_int res;
+
+       if (sizeof(cl_event) == sizeof(jlong)) {
+               (*env)->GetLongArrayRegion(env, jevents, 0, count, (jlong *)events);
+       } else {
+               jlong *levents = alloca(count * sizeof(*levents));
+               (*env)->GetLongArrayRegion(env, jevents, 0, count, levents);
+               for (int i=0;i<count;i++)
+                       events[i] = (cl_event)(uintptr_t)levents[i];
+       }
+
+       res = clWaitForEvents(count, (cl_event *)events);
+       THROW_ERROR(res);
+}
+
+/* ********************************************************************** */
+/* CLCommandQueue */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       cl_int res;
+       
+       FAIL_clReleaseCommandQueue();
+       res = clReleaseCommandQueue((cl_command_queue)jp);
+       if (res != CL_SUCCESS)
+               throwCLRuntimeException(env, res);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_flush
+(JNIEnv *env, jobject jqueue) {
+       FAIL_clFlush();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       THROW_ERROR(clFlush(queue));
+}
+       
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_finish
+(JNIEnv *env, jobject jqueue) {
+       FAIL_clFinish();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       THROW_ERROR(clFinish(queue));
+}
+
+/* ********************************************************************** */
+
+static void enqueueBuffer
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize, jobject jbuffer, jobject jwaiters, jobject jevents, enqueueReadWriteBuffer_t op, const char *ex, const char *what) {
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem mem;
+       void *buffer = (*env)->GetDirectBufferAddress(env, jbuffer);
+       jint position = nativez_BufferPosition(env, jbuffer);
+       jint limit = nativez_BufferLimit(env, jbuffer);
+       struct events_info einfo;
+       cl_int res;
+
+       if (memsize > limit - position) {
+               throwException(env, ex, what);
+               return;
+       }
+
+       GET_P(env, jmem, mem,, "mem must not be null");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = (*op)(queue,
+                   mem,
+                   blocking,
+                   memoffset,
+                   memsize,
+                   buffer + position,
+                   einfo.wait_count,
+                   einfo.waitersp,
+                   einfo.eventp);
+       
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+
+JNIEXPORT void JNICALL
+Java_au_notzed_zcl_CLCommandQueue_enqueueReadBuffer__Lau_notzed_zcl_CLBuffer_2ZJJLjava_nio_ByteBuffer_2Lau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize, jobject jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBuffer(env, jqueue, jmem, blocking, memoffset, memsize, jbuffer, jwaiters, jevents, clEnqueueReadBuffer,
+                     "java/nio/BufferOverflowException", "target buffer too small");
+}
+
+JNIEXPORT void JNICALL
+Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBuffer__Lau_notzed_zcl_CLBuffer_2ZJJLjava_nio_ByteBuffer_2Lau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize, jobject jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBuffer(env, jqueue, jmem, blocking, memoffset, memsize, jbuffer, jwaiters, jevents, (enqueueReadWriteBuffer_t)clEnqueueWriteBuffer,
+                     "java/nio/BufferUnderflowException", "source buffer too small");
+}
+
+/* ********************************************************************** */
+
+static void enqueueBufferRect
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jbyteArray jbuffer, jobject jwaiters, jobject jevents,
+ enqueueReadWriteBufferRect_t op) {
+#ifdef CL_VERSION_1_1
+       if (!op) {
+               throwException(env, "java/lang/UnsupportedOperationException", "Buffer read/write");
+               return;
+       }
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem mem;
+       void *buffer = (*env)->GetDirectBufferAddress(env, jbuffer);
+       jlong bsize = (*env)->GetDirectBufferCapacity(env, jbuffer);
+       struct events_info einfo;
+       cl_int res;
+       size_t buf_origin[3];
+       size_t host_origin[3];
+       size_t region[3];
+
+       CHECK_ARRAY_MIN(env, jbuf_origin, 3,, "buf origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jhost_origin, 3,, "host origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       getSizeTA(env, jbuf_origin, buf_origin, 3);
+       getSizeTA(env, jhost_origin, host_origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       size_t stride = (host_row_pitch == 0 ? region[0] : host_row_pitch);
+       size_t slice = (host_slice_pitch == 0 ? region[1] * stride : host_slice_pitch);
+
+       if (host_origin[0] + host_origin[1] * stride + host_origin[2] * slice
+           + region[0] + (region[1]-1) * stride + (region[2]-1) * slice
+           > bsize) {
+               throwException(env, "java/lang/ArrayIndexOutOfBoundsException", "Target buffer over/overflow");
+               return;
+       }
+
+       GET_P(env, jmem, mem,, "mem must not be null");
+       
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+       
+       res = (*op)(queue,
+                   mem,
+                   blocking,
+                   buf_origin,
+                   host_origin,
+                   region,
+                   buf_row_pitch,
+                   buf_slice_pitch,
+                   host_row_pitch,
+                   host_slice_pitch,
+                   buffer,
+                   einfo.wait_count,
+                   einfo.waitersp,
+                   einfo.eventp);
+
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.1");
+#endif
+}
+
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJLjava_nio_ByteBuffer_2Lau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jobject jbuffer,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferRect(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                         buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                         jbuffer, jwaiters, jevents,
+                         clEnqueueReadBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJLjava_nio_ByteBuffer_2Lau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jobject jbuffer,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferRect(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                         buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                         jbuffer, jwaiters, jevents,
+                         (enqueueReadWriteBufferRect_t)clEnqueueWriteBufferRect);
+}
+
+/* ********************************************************************** */
+
+static void enqueueFillBuffer
+(JNIEnv *env, jobject jqueue,
+ jobject jbuffer, jobject jpattern, jlong offset, jlong size,
+ jobject jwaiters, jobject jevents, getArrayRegion_t getArray, int elsize) {
+#ifdef CL_VERSION_1_2
+       FAIL_clEnqueueFillBuffer();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem buffer;
+       void *pattern;
+       size_t pattern_size;
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jbuffer, buffer,, "buffer must not be null");
+       CHECK_NULL(env, jpattern,, "pattern must not be null");
+
+       pattern_size = (*env)->GetArrayLength(env, jpattern);
+       // complex double16 is maximum possible size?
+       if (pattern_size * elsize > 16*16) {
+               throwCLException(env, CL_INVALID_VALUE);
+               return;
+       }
+       pattern = alloca(pattern_size * elsize);
+       getArray(env, jpattern, 0, pattern_size, pattern);
+
+       D(printf("enqueue fill buffer( off=%d size=%d patternsize=%d\n",
+                (int)(offset * pattern_size * elsize),
+                (int)(size * pattern_size * elsize),
+                (int)(pattern_size * elsize)));
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = clEnqueueFillBuffer(queue,
+                                 buffer,
+                                 pattern,
+                                 pattern_size * elsize,
+                                 offset * pattern_size * elsize,
+                                 size * pattern_size * elsize,
+                                 einfo.wait_count,
+                                 einfo.waitersp,
+                                 einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);      
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueFillBuffer__Lau_notzed_zcl_CLBuffer_2_3BJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue,
+ jobject jbuffer, jbyteArray jpattern, jlong offset, jlong size,
+ jobject jwaiters, jobject jevents) {
+       enqueueFillBuffer(env, jqueue, jbuffer, jpattern, offset, size, jwaiters, jevents, (getArrayRegion_t)(*env)->GetByteArrayRegion, 1);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueFillBuffer__Lau_notzed_zcl_CLBuffer_2_3SJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue,
+ jobject jbuffer, jshortArray jpattern, jlong offset, jlong size,
+ jobject jwaiters, jobject jevents) {
+       enqueueFillBuffer(env, jqueue, jbuffer, jpattern, offset, size, jwaiters, jevents, (getArrayRegion_t)(*env)->GetByteArrayRegion, 2);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueFillBuffer__Lau_notzed_zcl_CLBuffer_2_3IJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue,
+ jobject jbuffer, jintArray jpattern, jlong offset, jlong size,
+ jobject jwaiters, jobject jevents) {
+       enqueueFillBuffer(env, jqueue, jbuffer, jpattern, offset, size, jwaiters, jevents, (getArrayRegion_t)(*env)->GetIntArrayRegion, sizeof(cl_int));
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueFillBuffer__Lau_notzed_zcl_CLBuffer_2_3JJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue,
+ jobject jbuffer, jlongArray jpattern, jlong offset, jlong size,
+ jobject jwaiters, jobject jevents) {
+       enqueueFillBuffer(env, jqueue, jbuffer, jpattern, offset, size, jwaiters, jevents, (getArrayRegion_t)(*env)->GetLongArrayRegion, sizeof(cl_long));
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueFillBuffer__Lau_notzed_zcl_CLBuffer_2_3FJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue,
+ jobject jbuffer, jfloatArray jpattern, jlong offset, jlong size,
+ jobject jwaiters, jobject jevents) {
+       enqueueFillBuffer(env, jqueue, jbuffer, jpattern, offset, size, jwaiters, jevents, (getArrayRegion_t)(*env)->GetFloatArrayRegion, sizeof(cl_float));
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueFillBuffer__Lau_notzed_zcl_CLBuffer_2_3DJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue,
+ jobject jbuffer, jdoubleArray jpattern, jlong offset, jlong size,
+ jobject jwaiters, jobject jevents) {
+       enqueueFillBuffer(env, jqueue, jbuffer, jpattern, offset, size, jwaiters, jevents, (getArrayRegion_t)(*env)->GetDoubleArrayRegion, sizeof(cl_double));
+}
+
+/* ********************************************************************** */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueCopyBuffer
+(JNIEnv *env, jobject jqueue, jobject jsrc, jobject jdst, jlong srcoff, jlong dstoff, jlong size,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueCopyBuffer();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem src;
+       cl_mem dst;
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jsrc, src,, "src must not be null");
+       GET_P(env, jdst, dst,, "dst must not be null");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = clEnqueueCopyBuffer(queue,
+                                 src,
+                                 dst,
+                                 srcoff,
+                                 dstoff,
+                                 size,
+                                 einfo.wait_count,
+                                 einfo.waitersp,
+                                 einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);      
+}
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueCopyBufferRect
+(JNIEnv *env, jobject jqueue, jobject jsrc, jobject jdst, jlongArray jsrc_origin, jlongArray jdst_origin, jlongArray jregion,
+ jlong src_row_pitch, jlong src_slice_pitch, jlong dst_row_pitch, jlong dst_slice_pitch,
+ jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_1_1
+       FAIL_clEnqueueCopyBufferRect();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem src;
+       cl_mem dst;
+       size_t src_origin[3];
+       size_t dst_origin[3];
+       size_t region[3];
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jsrc, src,, "src must not be null");
+       GET_P(env, jdst, dst,, "dst must not be null");
+
+       CHECK_ARRAY_MIN(env, jsrc_origin, 3,, "src origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jdst_origin, 3,, "dst origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       getSizeTA(env, jsrc_origin, src_origin, 3);
+       getSizeTA(env, jdst_origin, dst_origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+#if 0
+       printf("CopyBufferRect[ src={ %d, %d, %d }/stride=%d slice=%d dstt={ %d, %d, %d }/stride=%d slice=%d region={ %d, %d, %d }\n",
+              (int)src_origin[0], (int)src_origin[1], (int)src_origin[2], (int)src_row_pitch, (int)src_slice_pitch,
+              (int)dst_origin[0], (int)dst_origin[1], (int)dst_origin[2], (int)dst_row_pitch, (int)dst_slice_pitch,
+              (int)region[0], (int)region[1], (int)region[2]);
+       fflush(stdout);
+#endif
+
+       res = clEnqueueCopyBufferRect(queue,
+                                     src,
+                                     dst,
+                                     src_origin,
+                                     dst_origin,
+                                     region,
+                                     src_row_pitch,
+                                     src_slice_pitch,
+                                     dst_row_pitch,
+                                     dst_slice_pitch,
+                                     einfo.wait_count,
+                                     einfo.waitersp,
+                                     einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);      
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.1");
+#endif
+}
+
+/* ********************************************************************** */
+
+/* Common driver for image read/write from/to byte buffer */
+static void enqueueImageBuffer
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jarray jbuffer,
+ jobject jwaiters, jobject jevents,
+ enqueueReadWriteImage_t op) {
+       if (!op) {
+               throwException(env, "java/lang/UnsupportedOperationException", "Image read/write");
+               return;
+       }
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem image;
+       void *buffer = (*env)->GetDirectBufferAddress(env, jbuffer);
+       jint position = nativez_BufferPosition(env, jbuffer);
+       jint limit = nativez_BufferLimit(env, jbuffer);
+       size_t origin[3];
+       size_t region[3];
+       size_t elsize, tsize;
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jimage, image,, "image must not be null");
+
+       CHECK_ARRAY_MIN(env, jorigin, 3,, "origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       getSizeTA(env, jorigin, origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       // Needed to check transfer size
+       clGetImageInfo(image, CL_IMAGE_ELEMENT_SIZE, sizeof(elsize), &elsize, NULL);
+
+       // Calculate what OpenCL will actually transfer based on parameters.
+       tsize = get_transfer_size(region, row_pitch, slice_pitch, elsize);
+
+       if (tsize > limit - position) {
+               // FIXME: overflow exception for read
+               throwException(env, "java/nio/BufferUnderflowExcetion", "source buffer too small");
+               return;
+       }
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = op(queue,
+                image,
+                blocking,
+                origin,
+                region,
+                row_pitch,
+                slice_pitch,
+                buffer + position,
+                einfo.wait_count,
+                einfo.waitersp,
+                einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL
+Java_au_notzed_zcl_CLCommandQueue_enqueueReadImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJLjava_nio_ByteBuffer_2Lau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jobject jbuffer,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueReadImage();
+       enqueueImageBuffer(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch, jbuffer,
+                          jwaiters, jevents, clEnqueueReadImage);
+}
+JNIEXPORT void JNICALL
+Java_au_notzed_zcl_CLCommandQueue_enqueueWriteImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJLjava_nio_ByteBuffer_2Lau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jobject jbuffer,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueWriteImage();
+
+       // Cast is for a harmless const warning
+       enqueueImageBuffer(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch, jbuffer,
+                          jwaiters, jevents,
+                          (enqueueReadWriteImage_t)clEnqueueWriteImage);
+}
+
+static void enqueueFillImage
+(JNIEnv *env, jobject jqueue,
+ jobject jimage, void *colour, jlongArray jorigin, jlongArray jregion,
+ jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_1_2
+       FAIL_clEnqueueFillImage();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem image;
+       size_t origin[3];
+       size_t region[3];
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jimage, image,, "image must not be null");
+
+       CHECK_ARRAY_MIN(env, jorigin, 3,, "origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       getSizeTA(env, jorigin, origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       D(printf("enqueue fill image( [ %d,%d,%d] [%d,%d,%d] )\n",
+                (int)origin[0], (int)origin[1], (int)origin[2],
+                (int)region[0], (int)region[1], (int)region[2]));
+       
+       res = clEnqueueFillImage(queue,
+                                image,
+                                colour,
+                                origin,
+                                region,
+                                einfo.wait_count,
+                                einfo.waitersp,
+                                einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);      
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueFillImage__Lau_notzed_zcl_CLImage_2_3I_3J_3JLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jintArray jcolour, jlongArray jorigin, jlongArray jregion,
+ jobject jwaiters, jobject jevents) {
+       jint colour[4];
+
+       CHECK_ARRAY_MIN(env, jcolour, 4,, "colour must be 4-elements long");
+       (*env)->GetIntArrayRegion(env, jcolour, 0, 4, colour);
+
+       enqueueFillImage(env, jqueue, jimage, colour, jorigin, jregion, jwaiters, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueFillImage__Lau_notzed_zcl_CLImage_2_3F_3J_3JLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jfloatArray jcolour, jlongArray jorigin, jlongArray jregion,
+ jobject jwaiters, jobject jevents) {
+       jfloat colour[4];
+
+       CHECK_ARRAY_MIN(env, jcolour, 4,, "colour must be 4-elements long");
+       (*env)->GetFloatArrayRegion(env, jcolour, 0, 4, colour);
+
+       enqueueFillImage(env, jqueue, jimage, colour, jorigin, jregion, jwaiters, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueCopyImage
+(JNIEnv *env, jobject jqueue, jobject jsrc, jobject jdst, jlongArray jsrc_origin, jlongArray jdst_origin, jlongArray jregion,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueCopyImage();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem src;
+       cl_mem dst;
+       size_t src_origin[3];
+       size_t dst_origin[3];
+       size_t region[3];
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jsrc, src,, "src must not be null");
+       GET_P(env, jdst, dst,, "dst must not be null");
+
+       CHECK_ARRAY_MIN(env, jsrc_origin, 3,, "src origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jdst_origin, 3,, "dst origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       getSizeTA(env, jsrc_origin, src_origin, 3);
+       getSizeTA(env, jdst_origin, dst_origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       res = clEnqueueCopyImage(queue,
+                                src,
+                                dst,
+                                src_origin,
+                                dst_origin,
+                                region,
+                                einfo.wait_count,
+                                einfo.waitersp,
+                                einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueCopyImageToBuffer
+(JNIEnv *env, jobject jqueue,
+ jobject jsrc, jobject jdst,
+ jlongArray jsrc_origin, jlongArray jregion, jlong dst_offset,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueCopyImageToBuffer();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem src;
+       cl_mem dst;
+       size_t src_origin[3];
+       size_t region[3];
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jsrc, src,, "src must not be null");
+       GET_P(env, jdst, dst,, "dst must not be null");
+
+       CHECK_ARRAY_MIN(env, jsrc_origin, 3,, "src origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       getSizeTA(env, jsrc_origin, src_origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       res = clEnqueueCopyImageToBuffer(queue,
+                                        src,
+                                        dst,
+                                        src_origin,
+                                        region,
+                                        dst_offset,
+                                        einfo.wait_count,
+                                        einfo.waitersp,
+                                        einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueCopyBufferToImage
+(JNIEnv *env, jobject jqueue,
+ jobject jsrc, jobject jdst,
+ jlong src_offset, jlongArray jdst_origin, jlongArray jregion,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueCopyBufferToImage();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem src;
+       cl_mem dst;
+       size_t dst_origin[3];
+       size_t region[3];
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jsrc, src,, "src must not be null");
+       GET_P(env, jdst, dst,, "dst must not be null");
+
+       CHECK_ARRAY_MIN(env, jdst_origin, 3,, "dst origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       getSizeTA(env, jdst_origin, dst_origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       res = clEnqueueCopyBufferToImage(queue,
+                                        src,
+                                        dst,
+                                        src_offset,
+                                        dst_origin,
+                                        region,
+                                        einfo.wait_count,
+                                        einfo.waitersp,
+                                        einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueMapBuffer
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong flags, jlong offset, jlong size, jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueMapBuffer_RET(NULL);
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem mem;
+       struct events_info einfo;
+       cl_int res;
+       void *ret;
+
+       GET_P(env, jmem, mem, NULL, "mem must not be null");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return NULL;
+
+       ret = clEnqueueMapBuffer(queue,
+                                mem,
+                                blocking,
+                                flags,
+                                offset,
+                                size,
+                                einfo.wait_count,
+                                einfo.waitersp,
+                                einfo.eventp,
+                                &res);
+       THROW_ERROR_RET(res, NULL);
+
+       events_post(env, &einfo, jevents);
+
+       return nativez_NewDirectBuffer(env, ret, size);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueMapImage
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlong flags,
+ jlongArray jorigin, jlongArray jregion, jlongArray jrow_pitch, jlongArray jslice_pitch,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueMapImage_RET(NULL);
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem image;
+       struct events_info einfo;
+       size_t origin[3];
+       size_t region[3];
+       size_t row_pitch;
+       size_t slice_pitch;
+       cl_int res;
+       void *ret;
+
+       GET_P(env, jimage, image, NULL, "image must not be null");
+
+       CHECK_ARRAY_MIN(env, jorigin, 3, NULL, "origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3, NULL, "region must be 3-elements long");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return NULL;
+
+       getSizeTA(env, jorigin, origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       ret = clEnqueueMapImage(queue,
+                               image,
+                               blocking,
+                               flags,
+                               origin,
+                               region,
+                               &row_pitch,
+                               &slice_pitch,
+                               einfo.wait_count,
+                               einfo.waitersp,
+                               einfo.eventp,
+                               &res);
+       THROW_ERROR_RET(res, NULL);
+
+       if (jrow_pitch) {
+               jlong value = (jlong)row_pitch;
+               (*env)->SetLongArrayRegion(env, jrow_pitch, 0, 1, &value);
+       }
+       if (jslice_pitch) {
+               jlong value = (jlong)slice_pitch;
+               (*env)->SetLongArrayRegion(env, jslice_pitch, 0, 1, &value);
+       }
+
+       events_post(env, &einfo, jevents);
+
+       // TODO: check these, not sure how it works.
+
+       jlong size;
+
+       size = slice_pitch * region[2] + row_pitch * region[1] + region[0];
+
+       return nativez_NewDirectBuffer(env, ret, size);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueUnmapMemObject
+(JNIEnv *env, jobject jqueue, jobject jmem, jobject jbuffer, jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueUnmapMemObject();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem mem;
+       void *buffer = (*env)->GetDirectBufferAddress(env, jbuffer);
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jmem, mem,, "mem must not be null");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = clEnqueueUnmapMemObject(queue, mem, buffer,
+                                     einfo.wait_count,
+                                     einfo.waitersp,
+                                     einfo.eventp);
+       THROW_ERROR(res);
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueMigrateMemObjects
+(JNIEnv *env, jobject jqueue, jobjectArray jmems, jlong flags, jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_1_2
+       FAIL_clEnqueueMigrateMemObjects();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       jsize mlen = (*env)->GetArrayLength(env, jmems);
+       cl_mem *mems = alloca(mlen * sizeof(*mems));
+       struct events_info einfo;
+       cl_int res;
+
+       if (fromObjectArray(env, jmems, (void **)mems, mlen))
+               return;
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = clEnqueueMigrateMemObjects(queue,
+                                        mlen,
+                                        mems,
+                                        flags,
+                                        einfo.wait_count,
+                                        einfo.waitersp,
+                                        einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.2");
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueNDRangeKernel
+(JNIEnv *env, jobject jqueue, jobject jkernel, jint dim,
+ jlongArray jgwo, jlongArray jgws, jlongArray jlws,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueNDRangeKernel();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_kernel kernel;
+       struct events_info einfo;
+       cl_int res;
+       size_t gwo[3];
+       size_t gws[3];
+       size_t lws[3];
+
+       if (dim > 3 || dim < 1) {
+               throwCLException(env, CL_INVALID_WORK_DIMENSION);
+               return;
+       }
+
+       GET_P(env, jkernel, kernel,, "kernel must not be null");
+
+       if (!jgws) {
+               throwException(env, "java/lang/NullPointerException", "global_size must not be null");
+               return;
+       }
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       getSizeTA(env, jgwo, gwo, dim);
+       getSizeTA(env, jgws, gws, dim);
+       getSizeTA(env, jlws, lws, dim);
+
+       D(printf("enqueue( dim=%d off=%d,%d,%d  gws=%d,%d,%d  lws=%d,%d,%d (%p)\n",
+                dim,
+                (int)gwo[0], (int)gwo[1], (int)gwo[2],
+                (int)gws[0], (int)gws[1], (int)gws[2],
+                (int)lws[0], (int)lws[1], (int)lws[2], jlws));
+
+       res = clEnqueueNDRangeKernel(queue,
+                                    kernel,
+                                    dim,
+                                    jgwo ? gwo : NULL,
+                                    gws,
+                                    jlws ? lws : NULL,
+                                    einfo.wait_count,
+                                    einfo.waitersp,
+                                    einfo.eventp);
+       THROW_ERROR(res);
+
+       if (debug_sync) {
+               char kname[64];
+               size_t size_ret;
+               
+               clGetKernelInfo(kernel, CL_KERNEL_FUNCTION_NAME, 64, kname, &size_ret);
+               (printf("zcl:enqueue('%s' dim=%d off=%d,%d,%d  gws=%d,%d,%d  lws=%d,%d,%d (%p)\n",
+                       kname,
+                       dim,
+                       (int)gwo[0], (int)gwo[1], (int)gwo[2],
+                       (int)gws[0], (int)gws[1], (int)gws[2],
+                       (int)lws[0], (int)lws[1], (int)lws[2], jlws));
+               fflush(stdout);
+               
+               clFlush(queue);
+               clFinish(queue);
+       }
+       
+       
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueTask
+(JNIEnv *env, jobject jqueue, jobject jkernel,
+ jobject jwaiters, jobject jevents) {
+       FAIL_clEnqueueTask();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_kernel kernel;
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jkernel, kernel,, "kernel must not be null");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = clEnqueueTask(queue,
+                           kernel,
+                           einfo.wait_count,
+                           einfo.waitersp,
+                           einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+/**
+ * This interrogates the argument array and provides the appropriate arguments
+ * for the clEnqueueNativeKernel call.
+ *
+ * The first argument to the JNI hook is native_kernel_info which is used
+ * to re-map the data back to Java objects.
+ */
+
+struct native_kernel_info {
+       // Original kernel / args from caller (for reference)
+       jobject jkernel;
+       jobjectArray jargs;
+
+       // Actual arguments passed to clEnqueueNativeKernel
+       // args[0] points to 'this'
+       // arguments follow
+       jobject *args;
+       int argslen;
+
+       cl_mem *mems;
+       const void **memsloc;
+       int memslen;
+};
+
+static void native_kernel_free(JNIEnv *env, struct native_kernel_info *info) {
+       (*env)->DeleteGlobalRef(env, info->jargs);
+       (*env)->DeleteGlobalRef(env, info->jkernel);
+       free(info->args);
+       free(info->mems);
+       free(info->memsloc);
+
+       free(info);
+}
+
+static void native_kernel_hook(void *data) {
+       JNIEnv *env;
+       jobject *args = data;
+       struct native_kernel_info *info = (void *)args[0];
+       jobjectArray kargs;
+       int argslen = info->argslen-1;
+
+       if (!(env = nativez_AttachCurrentThreadAsDaemon())) {
+               // NB: can't do anything here
+               fprintf(stderr, "Unable to attach java environment\n");
+               free(data);
+               return;
+       }
+       
+       kargs = (*env)->NewObjectArray(env, argslen, Object_classid, NULL);
+
+       for (int i=0;i<argslen;i++) {
+               jobject jo = (*env)->GetObjectArrayElement(env, info->jargs, i);
+
+               if ((*env)->IsInstanceOf(env, jo, CLMemory_classid)) {
+                       cl_mem mem = GETP(env, jo);
+                       size_t memsize;
+
+                       clGetMemObjectInfo(mem, CL_MEM_SIZE, sizeof(memsize), &memsize, NULL);
+
+                       jo = nativez_NewDirectBuffer(env, args[i+1], memsize);
+               }
+
+               (*env)->SetObjectArrayElement(env, kargs, i, jo);
+       }
+
+       jvalue arg = { .l = kargs };
+       (*env)->CallVoidMethodA(env, info->jkernel, CLNativeKernel_invoke, &arg);
+
+       native_kernel_free(env, info);
+}
+
+JNIEXPORT void Java_au_notzed_zcl_CLCommandQueue_enqueueNativeKernel
+(JNIEnv *env, jobject jqueue, jobject jkernel,  jobject jwaiters, jobject jevents, jobjectArray jargs) {
+       FAIL_clEnqueueNativeKernel();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       int argslen = (*env)->GetArrayLength(env, jargs);
+       struct native_kernel_info *info;
+       struct events_info einfo;
+       cl_int res;
+
+       // TODO: check if it could use more checks
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       info = malloc(sizeof(*info));
+
+       info->jargs = (*env)->NewGlobalRef(env, jargs);
+       info->jkernel = (*env)->NewGlobalRef(env, jkernel);
+
+       info->args = malloc(sizeof(*info->args) * (argslen+1));
+       info->argslen = argslen + 1;
+       info->mems = malloc(sizeof(*info->mems) * (argslen));
+       info->memsloc = malloc(sizeof(*info->memsloc) * (argslen));
+       info->memslen = 0;
+
+       info->args[0] = (jobject)info;
+
+       for (int i=0;i<argslen;i++) {
+               jobject jo = (*env)->GetObjectArrayElement(env, jargs, i);
+
+               if ((*env)->IsInstanceOf(env, jo, CLMemory_classid)) {
+                       info->mems[info->memslen] = GETP(env, jo);
+                       info->memsloc[info->memslen] = &info->args[i+1];
+                       info->memslen++;
+                       info->args[i+1] = NULL;
+               } else {
+                       info->args[i+1] = jo;
+               }
+       }
+
+       res = clEnqueueNativeKernel(queue,
+                                   native_kernel_hook,
+                                   info->args,
+                                   sizeof(*info->args) * info->argslen,
+                                   info->memslen,
+                                   info->mems,
+                                   info->memsloc,
+                                   einfo.wait_count,
+                                   einfo.waitersp,
+                                   einfo.eventp);
+       if (res != CL_SUCCESS) {
+               native_kernel_free(env, info);
+               throwCLException(env, res);
+               return;
+       }
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueMarkerWithWaitList
+(JNIEnv *env, jobject jqueue, jobject jwaiters, jobject jevents) {
+       /* As this emulates the 1.2 interface always, must fallback */
+#ifdef CL_VERSION_1_2
+       if (CHECK_clEnqueueMarkerWithWaitList()) {
+               cl_command_queue queue = GETP(env, jqueue);
+               struct events_info einfo;
+               cl_int res;
+
+               if (events_init(env, &einfo, jwaiters, jevents))
+                       return;
+
+               res = clEnqueueMarkerWithWaitList(queue,
+                                                 einfo.wait_count,
+                                                 einfo.waitersp,
+                                                 einfo.eventp);
+               THROW_ERROR(res);
+
+               events_post(env, &einfo, jevents);
+       } else {
+               FAIL_clEnqueueWaitForEvents();
+               FAIL_clEnqueueMarker();
+
+               cl_command_queue queue = GETP(env, jqueue);
+               struct events_info einfo;
+               cl_int res;
+
+               if (events_init(env, &einfo, jwaiters, jevents))
+                       return;
+
+               res = clEnqueueWaitForEvents(queue,
+                                            einfo.wait_count,
+                                            einfo.waitersp);
+               THROW_ERROR(res);
+
+               res = clEnqueueMarker(queue,
+                                     einfo.eventp);
+               THROW_ERROR(res);
+
+               events_post(env, &einfo, jevents);
+       }
+#else
+       cl_command_queue queue = GETP(env, jqueue);
+       struct events_info einfo;
+       cl_int res;
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = clEnqueueWaitForEvents(queue,
+                                    einfo.wait_count,
+                                    einfo.waitersp);
+       THROW_ERROR(res);
+
+       res = clEnqueueMarker(queue,
+                             einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueBarrierWithWaitList
+(JNIEnv *env, jobject jqueue, jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_1_2
+       if (checkAPIVersion(env, jqueue, au_notzed_zcl_CLPlatform_VERSION_1_2)) {
+               cl_command_queue queue = GETP(env, jqueue);
+               struct events_info einfo;
+               cl_int res;
+
+               if (events_init(env, &einfo, jwaiters, jevents))
+                       return;
+
+               res = clEnqueueBarrierWithWaitList(queue,
+                                                  einfo.wait_count,
+                                                  einfo.waitersp,
+                                                  einfo.eventp);
+               THROW_ERROR(res);
+               
+               events_post(env, &einfo, jevents);
+               return;
+       }
+#endif
+       FAIL_clEnqueueWaitForEvents();
+       FAIL_clEnqueueBarrier();
+       FAIL_clEnqueueMarker();
+
+       cl_command_queue queue = GETP(env, jqueue);
+       struct events_info einfo;
+       cl_int res;
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       res = clEnqueueWaitForEvents(queue,
+                                    einfo.wait_count,
+                                    einfo.waitersp);
+       THROW_ERROR(res);
+
+       res = clEnqueueBarrier(queue);
+       THROW_ERROR(res);
+
+       res = clEnqueueMarker(queue,
+                             einfo.eventp);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMFree
+(JNIEnv *env, jobject jqueue, jobjectArray jptrs, jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jqueue, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clEnqueueSVMFree();
+
+               cl_command_queue queue = GETP(env, jqueue);
+               struct events_info einfo;
+               cl_int res;
+               void **ptrs;
+               size_t size;
+       
+               if (events_init(env, &einfo, jwaiters, jevents))
+                       return;
+       
+               size = (*env)->GetArrayLength(env, jptrs);
+               ptrs = alloca(sizeof(*ptrs) * size);
+               for (int i=0;i<size;i++) {
+                       jobject jo = (*env)->GetObjectArrayElement(env, jptrs, i);
+                       
+                       ptrs[i] = (*env)->GetDirectBufferAddress(env, jo);
+               }
+       
+               res = clEnqueueSVMFree(queue,
+                                      size,
+                                      ptrs,
+                                      NULL, // free_func
+                                      NULL, // user_data
+                                      einfo.wait_count,
+                                      einfo.waitersp,
+                                      einfo.eventp);
+               THROW_ERROR(res);
+       
+               events_post(env, &einfo, jevents);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMemcpy
+(JNIEnv *env, jobject jqueue, jboolean blocking, jobject jdst, jlong doffset, jobject jsrc, jlong soffset, jlong size, jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jqueue, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clEnqueueSVMMemcpy();
+
+               cl_command_queue queue = GETP(env, jqueue);
+               void *dst, *src;
+               struct events_info einfo;
+               cl_int res;
+       
+               CHECK_NULL(env, jdst,, "dst must not be null");
+               CHECK_NULL(env, jsrc,, "src must not be null");
+               
+               dst = (*env)->GetDirectBufferAddress(env, jdst);
+               src = (*env)->GetDirectBufferAddress(env, jsrc);
+       
+               res = clEnqueueSVMMemcpy(queue,
+                                        blocking,
+                                        dst + doffset,
+                                        src + soffset,
+                                        size,
+                                        einfo.wait_count,
+                                        einfo.waitersp,
+                                        einfo.eventp);                          
+               THROW_ERROR(res);
+       
+               events_post(env, &einfo, jevents);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+}
+
+static void enqueueSVMMemFill
+(JNIEnv *env, jobject jqueue,
+ jobject jbuffer, jobject jpattern, jlong offset, jlong size,
+ jobject jwaiters, jobject jevents, getArrayRegion_t getArray, int elsize) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jqueue, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clEnqueueSVMMemFill();
+
+               cl_command_queue queue = GETP(env, jqueue);
+               void *buffer;
+               void *pattern;
+               size_t pattern_size;
+               struct events_info einfo;
+               cl_int res;
+
+               CHECK_NULL(env, jbuffer,, "pattern must not be null");
+               CHECK_NULL(env, jpattern,, "pattern must not be null");
+       
+               buffer = (*env)->GetDirectBufferAddress(env, jbuffer);
+       
+               pattern_size = (*env)->GetArrayLength(env, jpattern);
+               // complex double16 is maximum possible size?
+               if (pattern_size * elsize > 16*16) {
+                       throwCLException(env, CL_INVALID_VALUE);
+                       return;
+               }
+               pattern = alloca(pattern_size * elsize);
+               getArray(env, jpattern, 0, pattern_size, pattern);
+       
+               D(printf("enqueue svm memfill( off=%d size=%d patternsize=%d\n",
+                        (int)(offset * pattern_size * elsize),
+                        (int)(size * pattern_size * elsize),
+                        (int)(pattern_size * elsize)));
+       
+               if (events_init(env, &einfo, jwaiters, jevents))
+                       return;
+       
+               res = clEnqueueSVMMemFill(queue,
+                                         buffer + offset * pattern_size * elsize,
+                                         pattern,
+                                         pattern_size * elsize,
+                                         size * pattern_size * elsize,
+                                         einfo.wait_count,
+                                         einfo.waitersp,
+                                         einfo.eventp);
+               THROW_ERROR(res);
+       
+               events_post(env, &einfo, jevents);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMemFill__Ljava_nio_ByteBuffer_2_3BJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jdst, jbyteArray jpattern, jlong offset, jlong size, jobject jwaiters, jobject jevents) {
+       enqueueSVMMemFill(env, jqueue, jdst, jpattern, offset, size, jwaiters, jevents,  (getArrayRegion_t)(*env)->GetByteArrayRegion, 1);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMemFill__Ljava_nio_ByteBuffer_2_3SJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jdst, jshortArray jpattern, jlong offset, jlong size, jobject jwaiters, jobject jevents) {
+       enqueueSVMMemFill(env, jqueue, jdst, jpattern, offset, size, jwaiters, jevents,  (getArrayRegion_t)(*env)->GetShortArrayRegion, 2);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMemFill__Ljava_nio_ByteBuffer_2_3IJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jdst, jintArray jpattern, jlong offset, jlong size, jobject jwaiters, jobject jevents) {
+       enqueueSVMMemFill(env, jqueue, jdst, jpattern, offset, size, jwaiters, jevents,  (getArrayRegion_t)(*env)->GetIntArrayRegion, 4);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMemFill__Ljava_nio_ByteBuffer_2_3JJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jdst, jlongArray jpattern, jlong offset, jlong size, jobject jwaiters, jobject jevents) {
+       enqueueSVMMemFill(env, jqueue, jdst, jpattern, offset, size, jwaiters, jevents,  (getArrayRegion_t)(*env)->GetLongArrayRegion, 8);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMemFill__Ljava_nio_ByteBuffer_2_3FJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jdst, jfloatArray jpattern, jlong offset, jlong size, jobject jwaiters, jobject jevents) {
+       enqueueSVMMemFill(env, jqueue, jdst, jpattern, offset, size, jwaiters, jevents,  (getArrayRegion_t)(*env)->GetFloatArrayRegion, 4);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMemFill__Ljava_nio_ByteBuffer_2_3DJJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jdst, jdoubleArray jpattern, jlong offset, jlong size, jobject jwaiters, jobject jevents) {
+       enqueueSVMMemFill(env, jqueue, jdst, jpattern, offset, size, jwaiters, jevents,  (getArrayRegion_t)(*env)->GetDoubleArrayRegion, 8);
+}
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMap
+(JNIEnv *env, jobject jqueue, jboolean blocking, jlong flags, jobject jsvm, jlong offset, jlong size, jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jqueue, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clEnqueueSVMMap();
+
+               cl_command_queue queue = GETP(env, jqueue);
+               void *svm;
+               struct events_info einfo;
+               cl_int res;
+
+               CHECK_NULL(env, jsvm,, "svm pointer must not be null");
+               
+               svm = (*env)->GetDirectBufferAddress(env, jsvm);
+       
+               if (events_init(env, &einfo, jwaiters, jevents))
+                       return;
+       
+               res = clEnqueueSVMMap(queue,
+                                     blocking,
+                                     flags,
+                                     svm + offset,
+                                     size,
+                                     einfo.wait_count,
+                                     einfo.waitersp,
+                                     einfo.eventp);
+               THROW_ERROR(res);
+       
+               events_post(env, &einfo, jevents);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMUnmap
+(JNIEnv *env, jobject jqueue, jobject jsvm, jlong offset, jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_2_0
+       if (checkAPIVersion(env, jqueue, au_notzed_zcl_CLPlatform_VERSION_2_0)) {
+               FAIL_clEnqueueSVMUnmap();
+
+               cl_command_queue queue = GETP(env, jqueue);
+               void *svm;
+               struct events_info einfo;
+               cl_int res;
+
+               CHECK_NULL(env, jsvm,, "svm pointer must not be null");
+       
+               svm = (*env)->GetDirectBufferAddress(env, jsvm);
+
+               if (events_init(env, &einfo, jwaiters, jevents))
+                       return;
+       
+               res = clEnqueueSVMUnmap(queue,
+                                       svm + offset,
+                                       einfo.wait_count,
+                                       einfo.waitersp,
+                                       einfo.eventp);
+               THROW_ERROR(res);
+       
+               events_post(env, &einfo, jevents);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.0");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueSVMMigrateMem
+(JNIEnv *env, jobject jqueue, jobjectArray jmems, jlongArray joffsets, jlongArray jsizes, jlong flags, jobject jwaiters, jobject jevents) {
+#ifdef CL_VERSION_2_1
+       if (checkAPIVersion(env, jqueue, au_notzed_zcl_CLPlatform_VERSION_2_1)) {
+               FAIL_clEnqueueSVMMigrateMem();
+
+               cl_command_queue queue = GETP(env, jqueue);
+               jsize mlen = (*env)->GetArrayLength(env, jmems);
+               void **mems = alloca(mlen * sizeof(*mems));
+               struct events_info einfo;
+               cl_int res;
+               size_t *sizes = NULL;
+               
+               if (fromObjectArray(env, jmems, (void **)mems, mlen))
+                       return;
+
+               if (joffsets) {
+                       size_t *offsets = alloca(sizeof(size_t) * mlen);
+               
+                       getSizeTA(env, joffsets, offsets, mlen);
+                       for (int i=0;i<mlen;i++)
+                               mems[i] += offsets[i];
+               }
+
+               if (jsizes) {
+                       sizes = alloca(sizeof(size_t) * mlen);
+                       getSizeTA(env, jsizes, sizes, mlen);
+               }
+       
+               if (events_init(env, &einfo, jwaiters, jevents))
+                       return;
+
+               res = clEnqueueSVMMigrateMem(queue,
+                                            mlen,
+                                            (const void **)mems,
+                                            sizes,
+                                            flags,
+                                            einfo.wait_count,
+                                            einfo.waitersp,
+                                            einfo.eventp);
+               THROW_ERROR(res);
+
+               events_post(env, &einfo, jevents);
+       } else
+#endif
+               throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 2.1");
+}
+
+/* ********************************************************************** */
+
+/* CLImage */
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_CLImage_getFormat
+(JNIEnv *env, jobject jid) {
+       FAIL_clGetImageInfo_RET(NULL);
+
+       void *jp = GETP(env, jid);
+       cl_int res;
+       cl_image_format value;
+
+       res = clGetImageInfo((cl_mem)jp, CL_IMAGE_FORMAT, sizeof(value), &value, NULL);
+       if (res != CL_SUCCESS) {
+               throwCLRuntimeException(env, res);
+               return NULL;
+       }
+
+       return (*env)->NewObject(env, CLImageFormat_classid, CLImageFormat_new_ii,
+                                value.image_channel_order,
+                                value.image_channel_data_type);
+}
+
+
+/* ********************************************************************** */
+/* Primitive array Buffer read/writes */
+
+/*
+  For simplicity reasons only blocking operations are implemented.
+ */
+
+static void enqueueBufferPrimitive
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jarray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents,
+ int elshift,
+ enqueueReadWriteBuffer_t op) {
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem mem;
+       void *buffer;
+       jsize bsize = (*env)->GetArrayLength(env, jbuffer);
+       struct events_info einfo;
+       cl_int res;
+
+       //blocking = PRIMITIVE_BLOCKING(blocking);
+       blocking = CL_TRUE;
+
+       //memoffset <<= elshift;
+       //memsize <<= elshift;
+       //bufoffset <<= elshift;
+       //bsize <<= elshift;
+
+       if (memsize > bsize - bufoffset) {
+               throwException(env, "java/lang/ArrayIndexOutOfBoundsException", "target array too small");
+               return;
+       }
+
+       GET_P(env, jmem, mem,, "mem must not be null");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       buffer = (*env)->GetPrimitiveArrayCritical(env, jbuffer, NULL);
+
+       res = op(queue,
+                mem,
+                blocking,
+                (memoffset << elshift),
+                (memsize << elshift),
+                buffer + (bufoffset << elshift),
+                einfo.wait_count,
+                einfo.waitersp,
+                einfo.eventp);
+
+       (*env)->ReleasePrimitiveArrayCritical(env, jbuffer, buffer, 0);
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3BJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jbyteArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 0,
+                              clEnqueueReadBuffer);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3SJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jshortArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 1,
+                              clEnqueueReadBuffer);
+
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3IJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jintArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 2,
+                              clEnqueueReadBuffer);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3JJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jlongArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 3,
+                              clEnqueueReadBuffer);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3FJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jfloatArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 2,
+                              clEnqueueReadBuffer);
+
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3DJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jdoubleArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 3,
+                              clEnqueueReadBuffer);
+}
+
+/* * * * */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3BJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jbyteArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 0,
+                              (enqueueReadWriteBuffer_t)clEnqueueWriteBuffer);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3SJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jshortArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 1,
+                              (enqueueReadWriteBuffer_t)clEnqueueWriteBuffer);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3IJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jintArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 2,
+                              (enqueueReadWriteBuffer_t)clEnqueueWriteBuffer);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3JJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jlongArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 3,
+                              (enqueueReadWriteBuffer_t)clEnqueueWriteBuffer);
+
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3FJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jfloatArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 2,
+                              (enqueueReadWriteBuffer_t)clEnqueueWriteBuffer);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBuffer__Lau_notzed_zcl_CLBuffer_2ZJJ_3DJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking, jlong memoffset, jlong memsize,
+ jdoubleArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueBufferPrimitive(env, jqueue, jmem, blocking, memoffset, memsize,
+                              jbuffer, bufoffset,
+                              jwaiters, jevents, 3,
+                              (enqueueReadWriteBuffer_t)clEnqueueWriteBuffer);
+
+}
+
+/* ********************************************************************** */
+
+/* 2D/3D Buffer primitive array read/write operations */
+
+/*
+  For simplicity reasons only blocking operations are implemented.
+ */
+
+static void enqueueBufferRectPrimitive
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jbyteArray jbuffer, jobject jwaiters, jobject jevents, int elshift,
+ enqueueReadWriteBufferRect_t op) {
+#ifdef CL_VERSION_1_1
+       if (!op) {
+               throwException(env, "java/lang/UnsupportedOperationException", "Buffer read/write");
+               return;
+       }
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem mem;
+       void *buffer;
+       jsize bsize = (*env)->GetArrayLength(env, jbuffer);
+       struct events_info einfo;
+       cl_int res;
+       size_t buf_origin[3];
+       size_t host_origin[3];
+       size_t region[3];
+
+       blocking = CL_TRUE;
+
+       CHECK_ARRAY_MIN(env, jbuf_origin, 3,, "buf origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jhost_origin, 3,, "host origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       getSizeTA(env, jbuf_origin, buf_origin, 3);
+       getSizeTA(env, jhost_origin, host_origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       buf_origin[0] <<= elshift;
+       host_origin[0] <<= elshift;
+       region[0] <<= elshift;
+       buf_row_pitch <<= elshift;
+       buf_slice_pitch <<= elshift;
+       host_row_pitch <<= elshift;
+       host_slice_pitch <<= elshift;
+
+       size_t stride = (host_row_pitch == 0 ? region[0] : host_row_pitch);
+       size_t slice = (host_slice_pitch == 0 ? region[1] * stride : host_slice_pitch);
+
+#if 0
+       printf("*BufferRect[ dev={ %d, %d, %d }/stride=%d slice=%d host={ %d, %d, %d }/stride=%d slice=%d region={ %d, %d, %d }   bsize=%d dstride=%d dslice=%d  dorigin=%d  dsize=%d\n",
+              (int)buf_origin[0], (int)buf_origin[1], (int)buf_origin[2], (int)buf_row_pitch, (int)buf_slice_pitch,
+              (int)host_origin[0], (int)host_origin[1], (int)host_origin[2], (int)host_row_pitch, (int)host_slice_pitch,
+              (int)region[0], (int)region[1], (int)region[2],
+              (int)(bsize << elshift),
+              (int)stride, (int)slice,
+              (int)(host_origin[0] + host_origin[1] * stride + host_origin[2] * slice),
+              (int)(region[0] + (region[1]-1) * stride + (region[2]-1) * slice));
+       fflush(stdout);
+#endif
+
+       if (host_origin[0] + host_origin[1] * stride + host_origin[2] * slice
+           + region[0] + (region[1]-1) * stride + (region[2]-1) * slice
+           > bsize << elshift) {
+               throwException(env, "java/lang/ArrayIndexOutOfBoundsException", "Target buffer overflow");
+               return;
+       }
+
+       GET_P(env, jmem, mem,, "mem must not be null");
+       
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+       
+       buffer = (*env)->GetPrimitiveArrayCritical(env, jbuffer, NULL);
+       res = (*op)(queue,
+                   mem,
+                   blocking,
+                   buf_origin,
+                   host_origin,
+                   region,
+                   buf_row_pitch,
+                   buf_slice_pitch,
+                   host_row_pitch,
+                   host_slice_pitch,
+                   buffer,
+                   einfo.wait_count,
+                   einfo.waitersp,
+                   einfo.eventp);
+       (*env)->ReleasePrimitiveArrayCritical(env, jbuffer, buffer, 0);
+       
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+#else
+       throwException(env, "java/lang/UnsupportedOperationException", "Requires OpenCL 1.1");
+#endif
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3BLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jbyteArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 0,
+                                  clEnqueueReadBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3SLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jshortArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 1,
+                                  clEnqueueReadBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3ILau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jintArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 2,
+                                  clEnqueueReadBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3JLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jlongArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 3,
+                                  clEnqueueReadBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3FLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jfloatArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 2,
+                                  clEnqueueReadBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3DLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jdoubleArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 3,
+                                  clEnqueueReadBufferRect);
+}
+
+/* * * * */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3BLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jbyteArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 0,
+                                  (enqueueReadWriteBufferRect_t)clEnqueueWriteBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3SLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jshortArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 1,
+                                  (enqueueReadWriteBufferRect_t)clEnqueueWriteBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3ILau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jintArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 2,
+                                  (enqueueReadWriteBufferRect_t)clEnqueueWriteBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3JLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jlongArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 3,
+                                  (enqueueReadWriteBufferRect_t)clEnqueueWriteBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3FLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jfloatArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 2,
+                                  (enqueueReadWriteBufferRect_t)clEnqueueWriteBufferRect);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteBufferRect__Lau_notzed_zcl_CLBuffer_2Z_3J_3J_3JJJJJ_3DLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jmem, jboolean blocking,
+ jlongArray jbuf_origin, jlongArray jhost_origin, jlongArray jregion,
+ jlong buf_row_pitch, jlong buf_slice_pitch, jlong host_row_pitch, jlong host_slice_pitch,
+ jbyteArray jbuffer, jobject jwaiters, jobject jevents) {
+       enqueueBufferRectPrimitive(env, jqueue, jmem, blocking, jbuf_origin, jhost_origin, jregion,
+                                  buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch,
+                                  jbuffer, jwaiters, jevents, 3,
+                                  (enqueueReadWriteBufferRect_t)clEnqueueWriteBufferRect);
+}
+
+/* ********************************************************************** */
+/* Primitive array Image read/writes */
+
+static void enqueueImagePrimitive
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jarray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents,
+ int elshift,
+ enqueueReadWriteImage_t op) {
+       if (!op) {
+               throwException(env, "java/lang/UnsupportedOperationException", "Image read/write");
+               return;
+       }
+
+       cl_command_queue queue = GETP(env, jqueue);
+       cl_mem image;
+       void *buffer;
+       size_t origin[3];
+       size_t region[3];
+       size_t elsize, tsize;
+       struct events_info einfo;
+       cl_int res;
+
+       GET_P(env, jimage, image,, "image must not be null");
+
+       CHECK_ARRAY_MIN(env, jorigin, 3,, "origin must be 3-elements long");
+       CHECK_ARRAY_MIN(env, jregion, 3,, "region must be 3-elements long");
+
+       getSizeTA(env, jorigin, origin, 3);
+       getSizeTA(env, jregion, region, 3);
+
+       // Needed to check transfer size
+       clGetImageInfo(image, CL_IMAGE_ELEMENT_SIZE, sizeof(elsize), &elsize, NULL);
+       
+       //blocking = PRIMITIVE_BLOCKING(blocking);
+       blocking = CL_TRUE;
+
+       // Map to java primitive type.
+       bufoffset <<= elshift;
+       row_pitch <<= elshift;
+       slice_pitch <<= elshift;
+
+       tsize = get_transfer_size(region, row_pitch, slice_pitch, elsize);
+
+       CHECK_ARRAY_MIN(env, jbuffer, tsize >> elshift,, "array too small");
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       buffer = (*env)->GetPrimitiveArrayCritical(env, jbuffer, NULL);
+
+       res = op(queue,
+                image,
+                blocking,
+                origin,
+                region,
+                row_pitch,
+                slice_pitch,
+                buffer + bufoffset,
+                einfo.wait_count,
+                einfo.waitersp,
+                einfo.eventp);
+               
+       (*env)->ReleasePrimitiveArrayCritical(env, jbuffer, buffer, 0);
+
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3BJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jbyteArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 0,
+                             clEnqueueReadImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3SJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jshortArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 1,
+                             clEnqueueReadImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3IJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jintArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 2,
+                             clEnqueueReadImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3JJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jlongArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 3,
+                             clEnqueueReadImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3FJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jfloatArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 2,
+                             clEnqueueReadImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueReadImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3DJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jdoubleArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 3,
+                             clEnqueueReadImage);
+}
+
+/* * * * */
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3BJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jbyteArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 0,
+                             (enqueueReadWriteImage_t)clEnqueueWriteImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3SJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jshortArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 1,
+                             (enqueueReadWriteImage_t)clEnqueueWriteImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3IJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jintArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 2,
+                             (enqueueReadWriteImage_t)clEnqueueWriteImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3JJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jlongArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 3,
+                             (enqueueReadWriteImage_t)clEnqueueWriteImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3FJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jfloatArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 2,
+                             (enqueueReadWriteImage_t)clEnqueueWriteImage);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_CLCommandQueue_enqueueWriteImage__Lau_notzed_zcl_CLImage_2Z_3J_3JJJ_3DJLau_notzed_zcl_CLEventList_2Lau_notzed_zcl_CLEventList_2
+(JNIEnv *env, jobject jqueue, jobject jimage, jboolean blocking, jlongArray jorigin, jlongArray jregion,
+ jlong row_pitch, jlong slice_pitch,
+ jdoubleArray jbuffer, jlong bufoffset,
+ jobject jwaiters, jobject jevents) {
+       enqueueImagePrimitive(env, jqueue, jimage, blocking, jorigin, jregion, row_pitch, slice_pitch,
+                             jbuffer, bufoffset, jwaiters, jevents, 3,
+                             (enqueueReadWriteImage_t)clEnqueueWriteImage);
+}
diff --git a/src/notzed.zcl/jni/zcl-khr-gl-event.c b/src/notzed.zcl/jni/zcl-khr-gl-event.c
new file mode 100644 (file)
index 0000000..7795209
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2015 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+  Binding handler for gl event extension.
+ */
+
+#include "au_notzed_zcl_khr_GLEvent.h"
+#include "au_notzed_zcl_CLObject.h"
+
+#include <CL/cl_gl_ext.h>
+
+#include "zcl-extension.h"
+
+#include "nativez.h"
+
+extern jfieldID CLNative_p;
+#define GETP(env, o) NativeZ_getP(env, o)
+
+#ifndef CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR
+jobject createExtension_cl_khr_gl_event(JNIEnv *env, cl_platform_id platform) {
+       // throw new?
+       fprintf(stderr, "extension cl_khr_gl_event unavailable at build time\n");
+       fflush(stderr);
+       return NULL;
+}
+#else
+struct ext_cl_khr_gl_event {
+       cl_event (*clCreateEventFromGLsyncKHR)(cl_context, cl_GLsync, cl_int *);
+};
+
+jobject createExtension_cl_khr_gl_event(JNIEnv *env, cl_platform_id platform) {
+       struct ext_cl_khr_gl_event *p;
+
+       p = malloc(sizeof(*p));
+
+       p->clCreateEventFromGLsyncKHR = getExtensionAddress(platform, "clCreateEventFromGLsyncKHR");
+       // FIXME: check they are there
+
+       jobject jo = createExtension(env, p, "au/notzed/zcl/khr/GLEvent");
+
+       if (!jo)
+               free(p);
+
+       return jo;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_khr_GLEvent_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       free((void *)jp);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_khr_GLEvent_clCreateEventFromGLsync
+(JNIEnv *env, jobject jext, jobject jcontext, jlong glsync) {
+       struct ext_cl_khr_gl_event *ext = GETP(env, jext);
+       cl_context context = GETP(env, jcontext);
+       cl_int res = 0;
+       cl_event mo;
+
+       THROW_UNSUPPORTED_RET(ext->clCreateEventFromGLsyncKHR, "clCreateEventFromGLsyncKHR", NULL);
+
+       printf("createEventFromGLsync(%ld)\n", (long int)glsync);
+       fflush(stdout);
+       
+       mo = ext->clCreateEventFromGLsyncKHR(context, (cl_GLsync)(intptr_t)glsync, &res);
+
+       printf("mo = %p, res = %d\n", mo, res);
+       fflush(stdout);
+       
+       THROW_ERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_EVENT, mo);
+}
+
+#endif // have extension
diff --git a/src/notzed.zcl/jni/zcl-khr-gl-sharing.c b/src/notzed.zcl/jni/zcl-khr-gl-sharing.c
new file mode 100644 (file)
index 0000000..cb8b548
--- /dev/null
@@ -0,0 +1,278 @@
+/*
+ * Copyright (C) 2015 Michael Zucchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+  Binding handler for gl sharing extension.
+
+  This is just proof of concept/expriments and not complete.
+ */
+
+#include "au_notzed_zcl_khr_GLSharing.h"
+#include "au_notzed_zcl_CLObject.h"
+
+#include <CL/cl_gl_ext.h>
+
+#include "zcl-extension.h"
+#include "nativez.h"
+
+extern jfieldID CLNative_p;
+#define GETP(env, o) NativeZ_getP(env, o)
+extern size_t const ctype_sizes[];
+
+#ifdef cl_khr_gl_sharing
+struct ext_cl_khr_gl_sharing {
+       cl_mem (*clCreateFromGLBuffer)(cl_context, cl_mem_flags, cl_GLuint, int *);
+       cl_mem (*clCreateFromGLTexture)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int *);
+       cl_mem (*clCreateFromGLRenderbuffer)(cl_context   /* context */,
+                                            cl_mem_flags /* flags */,
+                                            cl_GLuint    /* renderbuffer */,
+                                            cl_int *     /* errcode_ret */);   
+       cl_int (*clEnqueueAcquireGLObjects)(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 (*clEnqueueReleaseGLObjects)(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 */);
+       clGetGLContextInfoKHR_fn clGetGLContextInfoKHR;
+       cl_int (*clGetGLObjectInfo)(cl_mem, cl_gl_object_type *, cl_GLuint *);
+       cl_int (*clGetGLTextureInfo)(cl_mem, cl_gl_texture_info, size_t, void *, size_t *);
+};
+
+static jclass GLObjectInfo_classid;
+static jmethodID GLObjectInfo_new_ii;
+
+jobject createExtension_cl_khr_gl_sharing(JNIEnv *env, cl_platform_id platform) {
+       struct ext_cl_khr_gl_sharing *p;
+
+       if (!GLObjectInfo_classid) {
+               jclass jc;
+               jc = (*env)->FindClass(env, "au/notzed/zcl/khr/GLSharing$GLObjectInfo");
+               if (jc == NULL)
+                       return NULL;
+
+               GLObjectInfo_classid = jc = (*env)->NewGlobalRef(env, jc);
+               GLObjectInfo_new_ii = (*env)->GetMethodID(env, jc, "<init>", "(II)V");
+       }
+
+       //cl_khr_gl_sharing
+
+       p = malloc(sizeof(*p));
+
+       p->clCreateFromGLBuffer = getExtensionAddress(platform, "clCreateFromGLBuffer");
+       p->clCreateFromGLTexture = getExtensionAddress(platform, "clCreateFromGLTexture");
+       p->clCreateFromGLRenderbuffer = getExtensionAddress(platform, "clCreateFromGLRenderbuffer");
+       p->clEnqueueAcquireGLObjects = getExtensionAddress(platform, "clEnqueueAcquireGLObjects");
+       p->clEnqueueReleaseGLObjects = getExtensionAddress(platform, "clEnqueueReleaseGLObjects");
+       p->clGetGLContextInfoKHR = getExtensionAddress(platform, "clGetGLContextInfoKHR");
+       p->clGetGLObjectInfo = getExtensionAddress(platform, "clGetGLObjectInfo");
+       p->clGetGLTextureInfo = getExtensionAddress(platform, "clGetGLTextureInfo");
+       // FIXME: check they are there
+
+       jobject jo = createExtension(env, p, "au/notzed/zcl/khr/GLSharing");
+
+       if (!jo)
+               free(p);
+       
+       return jo;
+}
+#else
+jobject createExtension_cl_khr_gl_sharing(JNIEnv *env, cl_platform_id platform) {
+       // throw new?
+       return NULL;
+}
+#endif
+
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_khr_GLSharing_release
+(JNIEnv *env, jclass jc, jlong jp) {
+       free((void *)jp);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_khr_GLSharing_createFromGLBuffer
+(JNIEnv *env, jobject jext, jobject jcontext, jlong flags, jint bufobj) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_context context = GETP(env, jcontext);
+       cl_int res;
+       cl_mem mo;
+
+       mo = ext->clCreateFromGLBuffer(context, flags, bufobj, &res);
+       THROW_ERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_BUFFER, mo);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_khr_GLSharing_createFromGLTexture
+(JNIEnv *env, jobject jext, jobject jcontext, jlong flags, jint target, jint miplevel, jint texture) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_context context = GETP(env, jcontext);
+       cl_int res;
+       cl_mem mo;
+
+       mo = ext->clCreateFromGLTexture(context, flags, target, miplevel, texture, &res);
+       THROW_ERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_IMAGE, mo);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_khr_GLSharing_createFromGLRenderbuffer
+(JNIEnv *env, jobject jext, jobject jcontext, jlong flags, jint renderbuffer) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_context context = GETP(env, jcontext);
+       cl_int res;
+       cl_mem mo;
+
+       mo = ext->clCreateFromGLRenderbuffer(context, flags, renderbuffer, &res);
+       THROW_ERROR_RET(res, NULL);
+
+       return toCLObject(env, au_notzed_zcl_CLObject_CTYPE_IMAGE, mo);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_khr_GLSharing_getGLObjectInfo
+(JNIEnv *env, jobject jext, jobject jmem) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_mem mem = GETP(env, jmem);
+       cl_gl_object_type type;
+       cl_GLuint name;
+       cl_int res;
+       
+       res = ext->clGetGLObjectInfo(mem, &type, &name);
+       THROW_ERROR_RET(res, NULL);
+
+       jvalue args[] = {
+               { .i = type },
+               { .i = name }
+       };
+       
+       return (*env)->NewObjectA(env, GLObjectInfo_classid, GLObjectInfo_new_ii, args);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_zcl_khr_GLSharing_getGLTextureInfoInt
+(JNIEnv *env, jobject jext, jobject jmem, jint param) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_mem mem = GETP(env, jmem);
+       cl_int res;
+       cl_GLuint value;
+
+       res = ext->clGetGLTextureInfo(mem, param, sizeof(value), &value, NULL);
+       THROW_ERROR_RET(res, 0);
+
+       return value;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_khr_GLSharing_enqueueAcquireGLObjects
+(JNIEnv *env, jobject jext, jobject jqueue, jobjectArray jmemlist, jobject jwaiters, jobject jevents) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_command_queue queue = GETP(env, jqueue);
+       struct events_info einfo;
+       cl_int res;
+       cl_mem *memlist;
+       cl_uint mlen;
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       if (jmemlist) {
+               mlen = (*env)->GetArrayLength(env, jmemlist);
+               memlist = alloca(mlen * sizeof(*memlist));
+               fromObjectArray(env, jmemlist, (void **)memlist, mlen);
+       } else {
+               memlist = NULL;
+               mlen = 0;
+       }
+       
+       res = ext->clEnqueueAcquireGLObjects(queue,
+                                            mlen, memlist,
+                                            einfo.wait_count,
+                                            einfo.waitersp,
+                                            einfo.eventp);
+
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_zcl_khr_GLSharing_enqueueReleaseGLObjects
+(JNIEnv *env, jobject jext, jobject jqueue, jobjectArray jmemlist, jobject jwaiters, jobject jevents) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_command_queue queue = GETP(env, jqueue);
+       struct events_info einfo;
+       cl_int res;
+       cl_mem *memlist;
+       cl_uint mlen;
+
+       if (events_init(env, &einfo, jwaiters, jevents))
+               return;
+
+       if (jmemlist) {
+               mlen = (*env)->GetArrayLength(env, jmemlist);
+               memlist = alloca(mlen * sizeof(*memlist));
+               fromObjectArray(env, jmemlist, (void **)memlist, mlen);
+       } else {
+               memlist = NULL;
+               mlen = 0;
+       }
+       
+       res = ext->clEnqueueReleaseGLObjects(queue,
+                                            mlen, memlist,
+                                            einfo.wait_count,
+                                            einfo.waitersp,
+                                            einfo.eventp);
+
+       THROW_ERROR(res);
+
+       events_post(env, &einfo, jevents);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_khr_GLSharing_getGLContextInfoKHRAny
+(JNIEnv *env, jobject jext, jobjectArray jprops, jint ctype, jint param) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_context_properties *props = fromPropertyArray(env, jprops);
+       size_t size = ctype_sizes[ctype];
+       void *value = alloca(size);
+       cl_int res;
+
+       if ((*env)->ExceptionCheck(env)) return NULL;
+
+       value = alloca(size);
+       res = ext->clGetGLContextInfoKHR(props, param, size, value, NULL);
+       free(props);
+       THROW_RTERROR_RET(res, NULL);
+
+       return toObject(env, ctype, size, value);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_zcl_khr_GLSharing_getGLContextInfoKHRAnyV
+(JNIEnv *env, jobject jext, jobjectArray jprops, jint ctype, jint param) {
+       struct ext_cl_khr_gl_sharing *ext = GETP(env, jext);
+       cl_context_properties *props = fromPropertyArray(env, jprops);
+       size_t size = ctype_sizes[ctype] * 32;
+       void *value = alloca(size);
+       cl_int res;
+
+       res = ext->clGetGLContextInfoKHR(props, param, size, value, &size);
+       free(props);
+       THROW_RTERROR_RET(res, NULL);
+       
+       return toArray(env, ctype, size, value);
+}
diff --git a/src/notzed.zcl/legal/LICENSE b/src/notzed.zcl/legal/LICENSE
new file mode 100644 (file)
index 0000000..94a9ed0
--- /dev/null
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.