-
Notifications
You must be signed in to change notification settings - Fork 19
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
- 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)
);
...
- ScalaCL :
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)
})
- OpenCL4Java : [wrappings] auto-JNAerated by https://jnaerator.googlecode.com/ JNAerator (they use https://jna.dev.java.net/ JNA to make the glue with native code)
cl_device_id[] ids = new cl_device_id[nDevs];
OpenCLLibrary.INSTANCE.clGetDeviceIDs(null, CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_CPU, nDevs, ids, pCount));
...
Please see the "Quick Start" section on the project's homepage.
Please read [MigratingFromJNAToBridJ].
Please read [TroubleShootingJavaCLOnLinux] for a workaround.
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.
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...
Please read the [Build] page.
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)
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].
Please read [CallingOpenCLKernelsFromJava] and look at the demos source code.
JavaCL supports all OpenCL types, please see [UnderstandOpenCLKernelArguments] for type mapping details.
Sure ! You can even include files that are in the Java classpath.
Please read [IncludesInKernels] for more details.
Please read [ReadFromAndWriteToBuffersAndImages]
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.
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 : (Olivier Chafik is also the author of JNAerator)