Skip to content
Olivier Chafik edited this page Nov 10, 2022 · 5 revisions

Frequently Asked Questions

What is JavaCL / ScalaCL / OpenCL4Java ?

JavaCL is an API that wraps the [OpenCL] library to make it available to the Java platform (https://www.khronos.org/opencl/ OpenCL is the first open, royalty-free standard for cross-platform, parallel programming of modern processors and GPUs).

With JavaCL, Java programs can execute tasks directly on graphic cards and benefit from their massive parallel horsepower.

JavaCL comprises the following parts :

  • a low-level API that matches 1 to 1 the C OpenCL API : OpenCL4Java. Its direct use is deprecated
  • a nice Object-Oriented API that retains all the power of the OpenCL API without most of the C head-scratching : JavaCL Core
  • demos
  • basic utilities (parallel reduction, experimental matrix implementation for UJMP
  • an experimental Scala DSL (Domain-Specific Language) : ScalaCL

What does it look like ?

  • JavaCL :
CLContext context = JavaCL.createBestContext();
CLProgram program = context.createProgram(myKernelSource).build();
CLKernel kernel = program.createKernel(
   	"myKernel", 
    	new float[] { u, v },
    	context.createIntBuffer(Usage.Input, inputBuffer, true),
    	context.createFloatBuffer(Usage.Output, resultsBuffer, false)
);
...

See the complete example...

import scalacl._
import scala.math._
val a = (1000 to 100000).cl

val f = a.filter(v => (v % 2) != 0)
val r = f.zip(f.map(_ * 2f)).zipWithIndex.map(t => {
    val ((a, b) i) = t
    (exp(a).toFloat + b + i, a)
  })

Learn More...

cl_device_id[] ids = new cl_device_id[nDevs];
OpenCLLibrary.INSTANCE.clGetDeviceIDs(null, CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_CPU, nDevs, ids, pCount));
...

How do I get started ?

Please see the "Quick Start" section on the project's homepage.

= My old 1.0-beta code broke with 1.0-RC and later !

Please read [MigratingFromJNAToBridJ].

JavaCL Crashes on Linux (including demos)

Please read [TroubleShootingJavaCLOnLinux] for a workaround.

I get a weird InvalidCommandQueue exception, why ?

Command queues can become invalid after some errors that can go unnoticed by default. To see all errors, please set the environment variable CL_LOG_ERRORS to stdout :

  • On Windows : set CL_LOG_ERRORS=stdout
  • On Unix / Linux / Mac OS X : export CL_LOG_ERRORS=stdout

See this thread on macresearch.org or that thread on khronos.org for more details.

Which platforms does JavaCL support ?

Short answer is "all of them". Please read details here...

Beware though that on Linux you'll have to alter your environment settings to avoid crashes. Please read details here...

How do I build JavaCL / ScalaCL / OpenCL4Java ?

Please read the [Build] page.

How do I run JavaCL Demos ?

You can launch the Particles and HardwareReport JavaCL Demos from the Java Web Start links from the front page.

If you've built JavaCL from the sources, you can also launch the demos directly in command line :

  • Install JOGL properly as described on the [Build] page
  • Go to libraries/OpenCL/Demos/target
  • Launch your demo (read "What demos are available ?" on this page and pick the right demo class) :
java -cp javacl-demos-1.0-SNAPSHOT-shaded.jar com.nativelibs4java.opencl.demos.hardware.HardwareReport

(in Maveneese, "shaded" means "with all dependencies included" so there's only one JAR to put in the classpath, JOGL issues left apart)

What demos are available ?

JavaCL's most notable demos are :

  • Particles Demo : shows a particles system animated in real time
  • Interactive Image Transform Demo : lets you edit image transformation kernels and run them on the fly (with examples provided)
  • Hardware Report : displays information about the available OpenCL implementations detected on your setup, with details on each device.

For more details, please visit [SamplesAndDemos].

How do I write and call OpenCL kernels from Java ?

Please read [CallingOpenCLKernelsFromJava] and look at the demos source code.

Does JavaCL support OpenCL type XXX for kernel arguments ?

JavaCL supports all OpenCL types, please see [UnderstandOpenCLKernelArguments] for type mapping details.

Can I include headers / source files from OpenCL kernels ?

Sure ! You can even include files that are in the Java classpath.

Please read [IncludesInKernels] for more details.

How do I use buffers / images in JavaCL ?

Please read [ReadFromAndWriteToBuffersAndImages]

My question is not here... How can I get some help ?

JavaCL has a user group / mailing-list : you can search in its archive to find similar past questions or post a new message, we'll try to help the best we can.

How can I contribute ?

Here are some ways to contribute to JavaCL :

  • Join the user group / mailing-list and help newbies
  • Download the source code and make it evolve / help fix bugs (for a list of pending bugs, please go to the Issues page
  • Make remarks / suggestions / create content for the project's documentation (including this page)
  • Create new demos
  • Contribute hardware (weird platforms, weird graphic cards) to the project
  • Contribute money to JavaCL's author : Support This Project (Olivier Chafik is also the author of JNAerator)