jocl.org

Code samples


The following table contains some code samples demonstrating the application of JOCL.

Scala versions of some of these samples have been provided by Piotr Tarsa, and you can find them in the list of Scala samples below.

JOCLSample.java
A small sample demonstrating the basic application of JOCL. The sample just compiles the inlined source code for a kernel that multiplies two arrays, and compares the result which is computed by this kernel to a reference that is computed with plain Java.
JOCLSample_1_1.java
A small sample demonstrating some of the new functions that have been added with OpenCL 1.1.
JOCLSample_1_2_KernelArgs.java
A small sample demonstrating some of the new functions that have been added with OpenCL 1.2, namely the possibility to obtain information about kernel arguments.
JOCLDeviceQuery.java
Queries and prints information about all available devices.
JOCLReduction.java
reduction.cl
A sample showing how to perform a simple reduction, using a kernel that is based on the OpenCL case study at http://developer.amd.com/resources/documentation-articles/articles-whitepapers/opencl-optimization-case-study-simple-reductions/.
HistogramAMD.java

The source file for the histogram kernel from the AMD sample: Histogram_Kernels.cl
A direct port of the "Histogram" sample from the AMD ATI Stream SDK.
HistogramNVIDIA.java

The source file for the 256-bin histogram kernel from the NVIDIA sample: Histogram256.cl
A direct port of the "oclHistogram" sample from the NVIDIA GPU computing SDK.
JOCLEventSample.java
A sample demonstrating basic event handling, and how to obtain profiling information for a command queue.
JOCLMultiDeviceSample.java
A very basic sample showing how to use multiple devices of one platform simultaneously.
JOCLSimpleGL3.java

The source file for the simple GL kernel from the NVIDIA sample: simpleGL.cl
This sample uses the kernel from NVIDIAs "oclSimpleGL" application to demonstrate basic JOCL/JOGL interoperability.


This sample has been created for JOGL 2.0. Earlier versions of JOGL did not support the functions necessary for creating an OpenCL context that allows buffer sharing between JOCL and JOGL.

Note that the buffer sharing could not be tested on MacOS until now.

The latest version of JOGL may be downloaded from the JOGL home page.
JOCLSimpleLWJGL.java

The source file for the simple GL kernel from the NVIDIA sample: simpleGL.cl
This sample uses the kernel from NVIDIAs "oclSimpleGL" application to demonstrate basic JOCL/LWJGL interoperability.


This sample has been created for LWJGL 2.6. Earlier versions of LWJGL did not support the functions necessary for creating an OpenCL context that allows buffer sharing between JOCL and JOGL.

The latest version of LWJGL may be downloaded from the LWJGL home page.
JOCLSimpleMandelbrot.java

The kernel source file: SimpleMandelbrot.cl
A program that uses a very simple kernel for computing a Mandelbrot fractal, which is then stored in a BufferedImage that is displayed with Swing.

JOCLMandelbrot.java

The kernel source files:
QuadFloat.cl
QuadFloatMandelbrot.cl
A program that computes the Mandelbrot set and stores the pixels in a BufferedImage which is displayed with Swing. This program uses an OpenCL kernel that performs the computation with "Quad-Float" values, which are high-precision floating point values that are represented as a float4. Additionally, this sample will distribute the workload among all available devices for a single platform (although this could not be tested until now).

The Quad-Float functions are summarized in a separate source file, so these may also be used in other applications. These functions have been created by porting parts of the Quad-Double package from http://crd.lbl.gov/~dhbailey/mpdist/index.html to the float4 type of OpenCL.


JOCLSimpleConvolution.java

The kernel source file: SimpleConvolution.cl
The sample input image: lena512color.png
A program that performs a convolution of an image. The JOCL part is implemented as a java.awt.image.BufferedImageOp, and may thus be used easily as a replacement for the java.awt.image.ConvolveOp. The program allows selecting different convolution kernels and compares the speed of the JOCL and the plain Java implementation.


JOCLSimpleImage.java

The sample input image: lena512color.png
A simple example demonstrating image handling between JOCL and Swing. It shows an animation of a rotating image, which is rotated using an OpenCL kernel involving some basic image operations.




The following table contains Scala versions of some of the samples.

These samples have been translated to Scala by Piotr Tarsa

JOCLSample.scala
A small sample demonstrating the basic application of JOCL. The sample just compiles the inlined source code for a kernel that multiplies two arrays, and compares the result which is computed by this kernel to a reference that is computed with plain Java.
JOCLSample_1_1.scala
A small sample demonstrating some of the new functions that have been added with OpenCL 1.1.
JOCLSample_1_2_KernelArgs.scala
A small sample demonstrating some of the new functions that have been added with OpenCL 1.2, namely the possibility to obtain information about kernel arguments.
JOCLDeviceQuery.scala
Queries and prints information about all available devices.
JOCLReduction.scala
reduction.cl
A sample showing how to perform a simple reduction, using a kernel that is based on the OpenCL case study at http://developer.amd.com/resources/documentation-articles/articles-whitepapers/opencl-optimization-case-study-simple-reductions/.
HistogramAMD.scala

The source file for the histogram kernel from the AMD sample: Histogram_Kernels.cl
A direct port of the "Histogram" sample from the AMD ATI Stream SDK.
HistogramNVIDIA.scala

The source file for the 256-bin histogram kernel from the NVIDIA sample: Histogram256.cl
A direct port of the "oclHistogram" sample from the NVIDIA GPU computing SDK.
JOCLEventSample.scala
A sample demonstrating basic event handling, and how to obtain profiling information for a command queue.
JOCLMultiDeviceSample.scala
A very basic sample showing how to use multiple devices of one platform simultaneously.