opencl can be used to speed up data processing,and jocl is a java binding to opencl。To use it,the first step is to build it。
Take a look at http://www.jocl.org/documentation/documentation.html firstly。
Then install one of opencl implementation, Say nvidia. https://developer.nvidia.com/opencl
Go to https://github.com/gpu/JOCL for instructions to build jocl.
git clone https://github.com/gpu/JOCL.git
git clone https://github.com/gpu/JOCLCommon.git
Download cmake, and take below steps to build JOCL_2_0_1-windows-x86_64.dll
locaed at E:\JOCLRoot\JOCL\nativeLibraries
Start cmake-gui,
Set the directory containing the sources of the JOCL project, e.g. C:\JOCLRoot\JOCL
Set the directory for the build files: e.g. C:\JOCLRoot\JOCL.build
Press "Configure" (and select the appropriate compiler)
Press "Generate"
Download maven, and build jocl-2.0.3-SNAPSHOT.jar
mvn clean install
set PATH=%PATH%;C:\Program Files\Java\jdk-13.0.1\bin
set PATH=%PATH%;C:\Program Files (x86)\apache-maven-3.6.3\bin
set JAVA_HOME=C:\Program Files\Java\jdk-13.0.
If there is an error:
[ERROR] Failure executing javac, but could not parse the error:
错误: 不再支持源选项 6。请使用 7 或更高版本。
错误: 不再支持目标选项 6。请使用 7 或更高版本。
modify jocl pom.xml from 1.6 to 13 assuming java13 is used
<plugin>
< groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>13</source>
<target>13</target>
</configuration>
< /plugin>
That is all. 3 parts are needed to call opencl from java.
- The nvidia driver,
- jocl*.jar
- JOCL*.dll
Build and run joclsamples
Go to https://github.com/gpu/JOCLSamples, and clone it
mvn clean install
需要用-cp指明jocl.jar和jocl-samples.jar的路径
java -cp "E:\\JOCLRoot\\JOCLSamples\\jocl-2.0.2.jar;E:\\JOCLRoot\\JOCLSamples\\target\\jocl-samples-0.0.1-SNAPSHOT.jar" org.jocl.samples.JOCLSample