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

How to use / install JavaCL

Prequisites

OpenCL implementation

There are now quite a few OpenCL implementations out there (and they're all working fine with JavaCL) :

  • MacOS X 10.6 Snow Leopard comes with OpenCL pre-installed (won't work on earlier MacOS X versions)
  • [Accelerated Parallel Processing (APP) SDK (formerly ATI Stream)] for ATI cards and/or any SSE2-enabled CPUs on all flavours of Linux and Windows (even works on Atom / AMD CPUs !) Note that ATI Stream's CPU implementation only supports images in version 2.4 (before, it will just crash your app !)

Also note that you don't need to install Catalyst drivers or build anything from the APPSDK package : simply untar the package, set up your LD_LIBRARY_PATH and sudo-untar the ICD registration package.

Optional : OpenGL bindings

If you want to share data between OpenCL and OpenGL, you'll need an OpenGL library such as JOGL or LWJGL.

Lightweight Java Game Library (LWJGL)

The excellent Lightweight Java Game Library (LWJGL) is a premier choice for OpenGL and OpenAL cross-platform programming in Java, providing a fast close-to-metal API.

It can be installed in many various ways, including Maven.

Jogamp JOGL

After a long radio silence, fresh forces are injected again into JOGL (now hosted at jogamp.org), with even alternative OpenCL bindings.

As the jogamp OpenGL bindings are still a bit uneasy to install, here's a simplified install procedure to get the latest version of JOGL :

  • Download the NativeLibs4Java-assembled JOGL package for your architecture + operating system :
  • Extract the zip and put its content in your Java Runtime Environment "lib/ext" directory
    • On Linux, this is a path like one of these :
/usr/lib/jvm/java-6-sun/jre/lib/ext/
/usr/lib/jvm/java-6-openjdk/jre/lib/ext/
  So you might install JOGL like this (download included, shown here for i586 architecture) :
cd /usr/lib/jvm/java-6-openjdk/jre/lib/ext/
sudo wget https://nativelibs4java.sourceforge.net/thirdparty/jogl/jogl-linux-i586-latest.zip
sudo unzip jogl-linux*.zip
sudo rm jogl-linux*.zip
* On Windows, this looks like :
C:\Program Files\Java\jre-1.6.0\lib\ext
* On MacOS X this is :
~/Library/Java/Extensions
(the `~` is your user home directory ; you can create these directories if they don't exist, but make sure to do it in a Terminal, as there might be translations in the Finder, for instance `~/Library` being visible as `Bibliothèque` in French)

Use JavaCL in a project

With Maven

The JavaCL plugin can be used with Maven, simply edit your pom.xml as follows :

<project>
  ...
  <repositories>
    ...
    <repository>
      <id>nativelibs4java</id>
      <name>nativelibs4java Maven2 Repository</name>
      <url>https://nativelibs4java.sourceforge.net/maven</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>com.nativelibs4java</groupId>
      <artifactId>javacl</artifactId>
      <version>1.0.0-RC1</version>
    </dependency>
  </dependencies>
  ...
</project>

With sbt (simple-build-tool)

Add these two lines to your project file :

import sbt._
class MyProject(info: ProjectInfo) extends DefaultProject(info)
{
  val nativelibs4javaRepo = "NativeLibs4Java Repository" at "https://nativelibs4java.sourceforge.net/maven/"
  val javacl = "com.nativelibs4java" % "javacl" % "1.0.0-RC1"
}

Raw download

If you're not using Maven, Gradle, sbt or any other build manager, you can proceed to the downloads section and add javacl-x.x.x-shaded.jar to your classpath manually :

Compile some code :

javac -cp javacl-x.x.x-shaded.jar MyTest.java

Run the code (replace the semi-colon ';' by ':' on Unix systems) :

java -cp javacl-x.x.x-shaded.jar;. MyTest

Install / Build from sources

Please read the [Build] page.