├── .gitignore ├── .settings ├── org.eclipse.jdt.core.prefs └── org.maven.ide.eclipse.prefs ├── .travis.yml ├── Blas ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.maven.ide.eclipse.prefs ├── javacl-blas-bridj.iml ├── javacl-blas.iml ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── nativelibs4java │ │ └── opencl │ │ └── blas │ │ ├── CLDefaultMatrix2D.java │ │ ├── CLEvents.java │ │ ├── CLKernels.java │ │ ├── CLMatrix2D.java │ │ ├── CLMatrixUtils.java │ │ └── ujmp │ │ ├── CLDenseDoubleMatrix2D.java │ │ ├── CLDenseDoubleMatrix2DFactory.java │ │ ├── CLDenseFloatMatrix2D.java │ │ ├── CLDenseFloatMatrix2DFactory.java │ │ ├── CLDenseMatrix2DImpl.java │ │ ├── CLMatrixBenchmark.java │ │ ├── CLWrappedMatrix2D.java │ │ ├── DirectNIODenseDoubleMatrix2D.java │ │ ├── DirectNIODenseDoubleMatrix2DFactory.java │ │ ├── MatrixUtils.java │ │ └── package-info.java │ └── test │ └── java │ └── com │ └── nativelibs4java │ └── opencl │ └── blas │ ├── CLMatrixUtilsTest.java │ └── ujmp │ ├── PerformanceTest.java │ └── UJMPOpenCLTest.java ├── CHANGELOG.md ├── Contributions └── Kazo Csaba │ ├── BinaryKernelTest - issue 30.java │ ├── CreateBinaryProgram - issue 30.README │ └── CreateBinaryProgram - issue 30.diff ├── Core ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.maven.ide.eclipse.prefs ├── javacl-core-bridj.iml ├── javacl-core.iml ├── nb-configuration.xml ├── nbactions.xml ├── pom.xml └── src │ ├── main │ ├── Header.vm │ ├── java │ │ └── com │ │ │ └── ochafik │ │ │ └── util │ │ │ └── string │ │ │ └── StringUtils.java │ ├── javadoc │ │ └── overview.html │ ├── jnlp │ │ ├── HardwareReport.jnlp │ │ ├── InteractiveImageTransformDemo.jnlp │ │ ├── JavaCL.jnlp │ │ ├── MandelbrotDemo.jnlp │ │ ├── OpenCL4Java.jnlp │ │ ├── ParticlesDemo.jnlp │ │ └── ScalaCL.jnlp │ └── velocity │ │ └── com │ │ └── nativelibs4java │ │ └── opencl │ │ ├── ByteOrderHack.java │ │ ├── CLAbstractEntity.java │ │ ├── CLAbstractUserProgram.java │ │ ├── CLBuffer.java │ │ ├── CLBuildException.java │ │ ├── CLContext.java │ │ ├── CLDevice.java │ │ ├── CLEvent.java │ │ ├── CLException.java │ │ ├── CLImage.java │ │ ├── CLImage2D.java │ │ ├── CLImage3D.java │ │ ├── CLImageFormat.java │ │ ├── CLInfoGetter.java │ │ ├── CLKernel.java │ │ ├── CLMem.java │ │ ├── CLPlatform.java │ │ ├── CLProgram.java │ │ ├── CLQueue.java │ │ ├── CLSampler.java │ │ ├── CLUserEvent.java │ │ ├── ImageIOUtils.java │ │ ├── InfoName.java │ │ ├── JavaCL.java │ │ ├── LocalSize.java │ │ ├── PlatformUtils.java │ │ ├── ReusablePointer.java │ │ ├── ReusablePointers.java │ │ └── package-info.java │ └── test │ ├── java │ └── com │ │ └── nativelibs4java │ │ ├── opencl │ │ ├── AbstractCommon.java │ │ ├── BinaryKernelTest.java │ │ ├── BufferReadTest.java │ │ ├── BufferTest.java │ │ ├── ByteOrderHackTest.java │ │ ├── CLPlatformTest.java │ │ ├── CLTestUtils.java │ │ ├── DeviceTest.java │ │ ├── EventTest.java │ │ ├── ImageTest.java │ │ ├── InfoGettersTest.java │ │ ├── JOGLTest.java │ │ ├── KernelTest.java │ │ ├── OpenCL4JavaBasicTest.java │ │ ├── OpenCL4JavaBenchmarkTest.java │ │ ├── OverheadTest.java │ │ ├── StressTest.java │ │ └── SweatTest.java │ │ └── test │ │ └── BenchmarkUtils.java │ └── resources │ └── com │ └── nativelibs4java │ └── opencl │ └── BufferReadTest.c ├── Demos ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.maven.ide.eclipse.prefs ├── javacl-demos-bridj.iml ├── javacl-demos.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── nativelibs4java │ │ │ └── opencl │ │ │ └── demos │ │ │ ├── SetupUtils.java │ │ │ ├── hardware │ │ │ └── HardwareReport.java │ │ │ ├── mandelbrot │ │ │ └── MandelbrotDemo.java │ │ │ ├── random │ │ │ └── ParallelRandomDemo.java │ │ │ ├── sobelfilter │ │ │ └── SobelFilterDemo.java │ │ │ └── vectoradd │ │ │ └── VectorAdd.java │ └── opencl │ │ └── com │ │ └── nativelibs4java │ │ └── opencl │ │ └── demos │ │ ├── mandelbrot │ │ └── Mandelbrot.cl │ │ └── sobelfilter │ │ └── SimpleSobel.cl │ └── test │ └── java │ └── com │ └── nativelibs4java │ └── opencl │ └── demos │ ├── SetupUtilsTest.java │ └── TestReport.java ├── Generator ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.maven.ide.eclipse.prefs ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── nativelibs4java │ └── opencl │ └── generator │ └── JavaCLGenerator.java ├── InteractiveImageDemo ├── .gitignore ├── javacl-interactive-image-demo-bridj.iml ├── javacl-interactive-image-demo.iml ├── pom.xml ├── project │ ├── build.properties │ └── build │ │ └── InteractiveImageDemoProject.scala └── src │ └── main │ ├── java │ └── com │ │ └── nativelibs4java │ │ └── opencl │ │ └── demos │ │ └── interactiveimage │ │ ├── InteractiveImageDemo.java │ │ └── Utils.java │ └── resources │ ├── examples │ ├── Blur.cl │ ├── Convolution.cl │ ├── DesaturateColors.cl │ ├── DummySample.cl │ ├── Identity.cl │ ├── LuminanceThreshold.cl │ ├── NaiveDenoising.cl │ ├── QueryFormat.cl │ ├── RichardsonLucyDeconvolution.cl │ └── SobelFilter.cl │ └── images │ ├── lena.jpg │ └── mandrill.jpg ├── JavaCL ├── .gitignore ├── javacl-bridj.iml ├── javacl.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── nativelibs4java │ │ │ └── opencl │ │ │ ├── OSGiBundleActivator.java │ │ │ └── util │ │ │ ├── Fun1.java │ │ │ ├── Fun2.java │ │ │ ├── LinearAlgebraUtils.java │ │ │ ├── OpenCLType.java │ │ │ ├── ParallelMath.java │ │ │ ├── ParallelRandom.java │ │ │ ├── Primitive.java │ │ │ ├── ReductionUtils.java │ │ │ ├── Transformer.java │ │ │ ├── fft │ │ │ ├── AbstractDFT.java │ │ │ ├── AbstractFFTPow2.java │ │ │ ├── DoubleDFT.java │ │ │ ├── DoubleFFTPow2.java │ │ │ ├── FloatDFT.java │ │ │ ├── FloatFFTPow2.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ ├── opencl │ │ └── com │ │ │ └── nativelibs4java │ │ │ └── opencl │ │ │ └── util │ │ │ ├── LinearAlgebraKernels.c │ │ │ ├── XORShiftRandom.c │ │ │ └── fft │ │ │ ├── DoubleDFTProgram.cl │ │ │ ├── DoubleFFTProgram.cl │ │ │ ├── FloatDFTProgram.cl │ │ │ └── FloatFFTProgram.cl │ └── resources │ │ └── com │ │ └── nativelibs4java │ │ └── opencl │ │ └── util │ │ └── Reduction.c │ └── test │ ├── java │ └── com │ │ └── nativelibs4java │ │ └── opencl │ │ ├── generator │ │ └── GeneratorTest.java │ │ └── util │ │ ├── DiscreteFourierTransformTest.java │ │ ├── ParallelRandomTest.java │ │ └── ReductionTest.java │ └── opencl │ └── com │ └── nativelibs4java │ └── opencl │ └── generator │ └── Structs.c ├── LICENSE ├── LICENSE.header ├── LibCL ├── .gitignore ├── libcl-bridj.iml ├── libcl.iml ├── pom.xml └── src │ └── main │ └── resources │ └── LibCL │ ├── Bits.cl │ ├── Gaussian7x7.cl │ ├── ImageConvert.cl │ ├── ImageConvolution.cl │ ├── RichardsonLucyImageDeconvolution.cl │ ├── SobelOperator.cl │ ├── hsla2rgba.cl │ ├── rgba2hsla.cl │ ├── stdlib.h │ ├── strstr.c │ ├── strtod.c │ └── strtof.c ├── MavenPlugin ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── nativelibs4java │ └── opencl │ └── generator │ └── JavaCLGeneratorMojo.java ├── NumericalBenchmark ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── fft │ │ └── FFTBench.java │ └── scala │ └── fft │ └── FFTScala.scala ├── OpenCL4Java ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.maven.ide.eclipse.prefs ├── opencl4java-bridj.iml ├── opencl4java.iml ├── pom.xml ├── regenerate.cmd └── src │ └── main │ ├── headers │ ├── 1.0 │ │ └── CL │ │ │ ├── cl.h │ │ │ ├── cl_gl.h │ │ │ └── cl_platform.h │ ├── 1.1 │ │ └── CL │ │ │ ├── cl.h │ │ │ ├── cl_ext.h │ │ │ ├── cl_gl.h │ │ │ ├── cl_gl_ext.h │ │ │ ├── cl_platform.h │ │ │ └── opencl.h │ └── 1.2 │ │ └── CL │ │ ├── cl.h │ │ ├── cl_apple.h │ │ ├── cl_ext.h │ │ ├── cl_gl.h │ │ ├── cl_gl_ext.h │ │ ├── cl_platform.h │ │ └── opencl.h │ ├── java │ └── com │ │ └── nativelibs4java │ │ └── opencl │ │ ├── library │ │ ├── IOpenCLLibrary.java │ │ ├── OpenCLLibrary.java │ │ ├── OpenGLContextUtils.java │ │ ├── cl_buffer_region.java │ │ ├── cl_image_desc.java │ │ ├── cl_image_format.java │ │ └── package-info.java │ │ └── proxy │ │ ├── AbstractOpenCLImplementation.java │ │ ├── PointerUtils.java │ │ └── ProxiedOpenCLImplementation.java │ └── jnaerator │ ├── OpenCL.MacOSX.jnaerator │ ├── OpenCL.OtherPlatforms.jnaerator │ ├── OpenCL.Win32ATIStream.jnaerator │ ├── OpenCL.base.jnaerator │ ├── config-1.1.jnaerator │ ├── config-1.2.jnaerator │ └── config.jnaerator ├── OpenGLDemos ├── .gitignore ├── javacl-opengl-demos-bridj.iml ├── javacl-opengl-demos.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── nativelibs4java │ │ └── opencl │ │ └── demos │ │ ├── JavaCLSettingsPanel.form │ │ ├── JavaCLSettingsPanel.java │ │ └── particles │ │ └── ParticlesDemo.java │ └── opencl │ └── com │ └── nativelibs4java │ └── opencl │ └── demos │ └── particles │ ├── HSVtoRGB.c │ └── ParticlesDemoProgram.c ├── Proxy ├── pom.xml └── src │ └── main │ └── cpp │ └── proxy │ ├── API.c │ ├── API.h │ ├── Common.h │ ├── GNUmakefile │ ├── Library.c │ ├── Make.sh │ ├── Proxy.c │ ├── Proxy.h │ └── build.sh ├── README.md ├── ScalaCL.svg ├── Tutorials ├── .gitignore ├── DFT │ ├── .gitignore │ ├── javacl-dft-tutorial.iml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── tutorial │ │ │ ├── DFT.java │ │ │ └── DFT2.java │ │ └── opencl │ │ └── tutorial │ │ ├── DiscreteFourierTransformProgram.c │ │ └── DiscreteFourierTransformProgram.cl ├── Simple │ ├── .gitignore │ ├── javacl-simple-tutorial.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── resources │ │ ├── META-INF │ │ └── maven │ │ │ └── archetype-metadata.xml │ │ └── archetype-resources │ │ ├── .gitignore │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ ├── JavaCLTutorial1.java │ │ ├── JavaCLTutorial2.java │ │ └── JavaCLTutorial3.java │ │ └── opencl │ │ └── TutorialKernels.cl ├── javacl-tutorials-root.iml └── pom.xml ├── buildWebStartArtifacts.sh ├── getJOGL ├── opencl4java-root-bridj.iml ├── opencl4java-root.iml ├── pom.xml ├── runComp └── runComp.cmd /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | Tests 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:48:24 CET 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Sat Jan 30 11:48:04 CET 2010 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | - openjdk6 6 | 7 | cache: 8 | directories: 9 | - $HOME/.m2 10 | 11 | env: 12 | - MAVEN_OPTS=-Xmx512m CL_LOG_ERRORS=stdout 13 | 14 | before_install: 15 | - sudo apt-get update -qq 16 | - sudo apt-get install -qq fglrx=2:8.960-0ubuntu1 opencl-headers 17 | -------------------------------------------------------------------------------- /Blas/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Blas/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /Blas/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Blas 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.maven.ide.eclipse.maven2Builder 15 | 16 | 17 | 18 | 19 | org.eclipse.iam.jdt.core.mavenIncrementalBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.maven.ide.eclipse.maven2Nature 26 | org.eclipse.iam.jdt.core.mavenNature 27 | org.eclipse.jdt.core.javanature 28 | 29 | 30 | -------------------------------------------------------------------------------- /Blas/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:48:19 CET 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /Blas/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:46:13 CET 2010 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /Blas/javacl-blas-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Blas/javacl-blas.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Blas/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.nativelibs4java 5 | javacl-blas 6 | JavaCL BLAS / BridJ 7 | http://code.google.com/p/javacl/ 8 | jar 9 | 10 | 11 | com.nativelibs4java 12 | javacl-parent 13 | 1.0-SNAPSHOT 14 | .. 15 | 16 | 17 | 18 | 19 | 20 | com.nativelibs4java 21 | javacl 22 | 23 | 24 | 25 | org.ujmp 26 | ujmp-core 27 | 0.2.4 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | com.nativelibs4java 36 | maven-javacl-plugin 37 | 38 | 39 | 40 | 41 | 42 | 43 | nativelibs4java-legacy 44 | NativeLibs4Java Legacy Repository 45 | http://nativelibs4java.sourceforge.net/maven/ 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Blas/src/main/java/com/nativelibs4java/opencl/blas/CLMatrix2D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.nativelibs4java.opencl.blas; 6 | 7 | import com.nativelibs4java.opencl.CLBuffer; 8 | import com.nativelibs4java.opencl.CLContext; 9 | import com.nativelibs4java.opencl.CLQueue; 10 | import com.nativelibs4java.opencl.util.Primitive; 11 | import org.bridj.Pointer; 12 | 13 | /** 14 | * 15 | * @author ochafik 16 | */ 17 | public interface CLMatrix2D { 18 | 19 | Primitive getPrimitive(); 20 | Class getPrimitiveClass(); 21 | CLEvents getEvents(); 22 | CLBuffer getBuffer(); 23 | CLContext getContext(); 24 | CLQueue getQueue(); 25 | long getRowCount(); 26 | long getColumnCount(); 27 | long getStride(); 28 | int getBlockSize(); 29 | CLMatrix2D blankClone(); 30 | CLMatrix2D blankMatrix(long rows, long columns); 31 | CLKernels getKernels(); 32 | 33 | void write(Pointer b); 34 | void read(Pointer b); 35 | Pointer read(); 36 | } 37 | -------------------------------------------------------------------------------- /Blas/src/main/java/com/nativelibs4java/opencl/blas/ujmp/CLDenseDoubleMatrix2DFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl.blas.ujmp; 7 | 8 | import com.nativelibs4java.opencl.CLPlatform; 9 | import com.nativelibs4java.opencl.CLPlatform.DeviceFeature; 10 | import com.nativelibs4java.opencl.JavaCL; 11 | import com.nativelibs4java.opencl.blas.CLDefaultMatrix2D; 12 | import com.nativelibs4java.opencl.blas.CLKernels; 13 | import com.nativelibs4java.opencl.util.LinearAlgebraUtils; 14 | import com.nativelibs4java.opencl.util.Primitive; 15 | import org.ujmp.core.doublematrix.DenseDoubleMatrix2D; 16 | import org.ujmp.core.doublematrix.factory.AbstractDoubleMatrix2DFactory; 17 | import org.ujmp.core.exceptions.MatrixException; 18 | 19 | /** 20 | * 21 | * @author ochafik 22 | */ 23 | public class CLDenseDoubleMatrix2DFactory extends AbstractDoubleMatrix2DFactory { 24 | final int blockSize; 25 | public CLDenseDoubleMatrix2DFactory(int blockSize) { 26 | this.blockSize = blockSize; 27 | } 28 | public CLDenseDoubleMatrix2DFactory() { 29 | this(CLDefaultMatrix2D.DEFAULT_BLOCK_SIZE); 30 | } 31 | public CLDenseDoubleMatrix2D dense(long rows, long columns) 32 | throws MatrixException { 33 | return new CLDenseDoubleMatrix2D(rows, columns, CLKernels.getInstance(), blockSize); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Blas/src/main/java/com/nativelibs4java/opencl/blas/ujmp/CLDenseFloatMatrix2DFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl.blas.ujmp; 7 | 8 | import com.nativelibs4java.opencl.blas.CLDefaultMatrix2D; 9 | import com.nativelibs4java.opencl.blas.CLKernels; 10 | import org.ujmp.core.floatmatrix.DenseFloatMatrix2D; 11 | import org.ujmp.core.floatmatrix.factory.AbstractFloatMatrix2DFactory; 12 | import org.ujmp.core.exceptions.MatrixException; 13 | 14 | /** 15 | * 16 | * @author ochafik 17 | */ 18 | public class CLDenseFloatMatrix2DFactory extends AbstractFloatMatrix2DFactory { 19 | final int blockSize; 20 | public CLDenseFloatMatrix2DFactory(int blockSize) { 21 | this.blockSize = blockSize; 22 | } 23 | public CLDenseFloatMatrix2DFactory() { 24 | this(CLDefaultMatrix2D.DEFAULT_BLOCK_SIZE); 25 | } 26 | public CLDenseFloatMatrix2D dense(long rows, long columns) 27 | throws MatrixException { 28 | return new CLDenseFloatMatrix2D(rows, columns, CLKernels.getInstance(), blockSize); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Blas/src/main/java/com/nativelibs4java/opencl/blas/ujmp/CLMatrixBenchmark.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl.blas.ujmp; 7 | 8 | import com.nativelibs4java.opencl.blas.CLDefaultMatrix2D; 9 | import com.nativelibs4java.opencl.blas.CLKernels; 10 | import com.nativelibs4java.opencl.blas.CLMatrixUtils; 11 | import org.bridj.Pointer; 12 | import static org.bridj.Pointer.*; 13 | 14 | import org.ujmp.core.Matrix; 15 | import org.ujmp.core.benchmark.AbstractMatrix2DBenchmark; 16 | import org.ujmp.core.doublematrix.DoubleMatrix2D; 17 | import org.ujmp.core.exceptions.MatrixException; 18 | 19 | /** 20 | * 21 | * @author ochafik 22 | */ 23 | public class CLMatrixBenchmark extends AbstractMatrix2DBenchmark { 24 | 25 | @Override 26 | public DoubleMatrix2D createMatrix(long... size) throws MatrixException { 27 | return new CLDenseDoubleMatrix2D(size); 28 | } 29 | 30 | @Override 31 | public DoubleMatrix2D createMatrix(Matrix source) throws MatrixException { 32 | if (source instanceof CLDenseDoubleMatrix2D) 33 | return (DoubleMatrix2D)((CLDenseDoubleMatrix2D)source).copy(); 34 | else { 35 | DoubleMatrix2D dsource = (DoubleMatrix2D)source; 36 | long rows = dsource.getRowCount(), columns = dsource.getColumnCount(); 37 | CLDenseDoubleMatrix2D copy = new CLDenseDoubleMatrix2D(rows, columns); 38 | long stride = copy.getStride(); 39 | Pointer b = allocateDoubles(rows * stride).order(CLKernels.getInstance().getContext().getKernelsDefaultByteOrder()); 40 | for (long i = 0; i < rows; i++) { 41 | long offset = i * stride; 42 | for (long j = 0; j < columns; j++) { 43 | b.set(offset + i, dsource.getDouble(i, j)); 44 | } 45 | } 46 | copy.write(b); 47 | return copy; 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Blas/src/main/java/com/nativelibs4java/opencl/blas/ujmp/DirectNIODenseDoubleMatrix2D.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl.blas.ujmp; 7 | 8 | import com.nativelibs4java.opencl.blas.CLKernels; 9 | import org.ujmp.core.doublematrix.stub.AbstractDenseDoubleMatrix2D; 10 | import org.ujmp.core.interfaces.Wrapper; 11 | 12 | import org.bridj.Pointer; 13 | import static org.bridj.Pointer.*; 14 | 15 | /** 16 | * 17 | * @author ochafik 18 | */ 19 | public class DirectNIODenseDoubleMatrix2D extends AbstractDenseDoubleMatrix2D { 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = 8936390922363132043L; 25 | final Pointer data; 26 | final long rows, columns; 27 | 28 | public DirectNIODenseDoubleMatrix2D(Pointer data, long rows, long columns) { 29 | this.rows = rows; 30 | this.columns = columns; 31 | this.data = data; 32 | } 33 | 34 | public DirectNIODenseDoubleMatrix2D(long rows, long columns) { 35 | this(allocateDoubles(rows * columns).order(CLKernels.getInstance().getContext().getKernelsDefaultByteOrder()), rows, columns); 36 | } 37 | 38 | public DirectNIODenseDoubleMatrix2D(long[] size) { 39 | this(size[0], size[1]); 40 | if (size.length != 2) 41 | throw new IllegalArgumentException("Size is not 2D !"); 42 | } 43 | 44 | 45 | public Pointer getData() { 46 | return data; 47 | } 48 | 49 | public Pointer getReadableData() { 50 | return getData(); 51 | } 52 | 53 | 54 | public Pointer getWritableData() { 55 | return getData(); 56 | } 57 | 58 | public long[] getSize() { 59 | return new long[] { rows, columns }; 60 | } 61 | 62 | public double getDouble(long row, long column) { 63 | return data.getDoubleAtOffset((row * columns + column) << 3); 64 | } 65 | 66 | @Override 67 | public void setDouble(double value, long row, long column) { 68 | data.setDoubleAtOffset((row * columns + column) << 3, value); 69 | } 70 | 71 | @Override 72 | public double getDouble(int row, int column) { 73 | return getDouble((long)row, column); 74 | } 75 | 76 | @Override 77 | public void setDouble(double value, int row, int column) { 78 | setDouble(value, (long)row, column); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Blas/src/main/java/com/nativelibs4java/opencl/blas/ujmp/DirectNIODenseDoubleMatrix2DFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl.blas.ujmp; 7 | 8 | import org.ujmp.core.doublematrix.DenseDoubleMatrix2D; 9 | import org.ujmp.core.doublematrix.factory.AbstractDoubleMatrix2DFactory; 10 | import org.ujmp.core.exceptions.MatrixException; 11 | 12 | /** 13 | * 14 | * @author ochafik 15 | */ 16 | public class DirectNIODenseDoubleMatrix2DFactory extends 17 | AbstractDoubleMatrix2DFactory { 18 | private static final long serialVersionUID = 4390694808314618187L; 19 | 20 | 21 | public DenseDoubleMatrix2D dense(long rows, long columns) 22 | throws MatrixException { 23 | return new DirectNIODenseDoubleMatrix2D(rows, columns); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Blas/src/main/java/com/nativelibs4java/opencl/blas/ujmp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JavaCL - Java API and utilities for OpenCL 3 | * http://javacl.googlecode.com/ 4 | * 5 | * Copyright (c) 2009-2015, Olivier Chafik (http://ochafik.com/) 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * * Neither the name of Olivier Chafik nor the 17 | * names of its contributors may be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * OpenCL UJMP float/double dense matrix implementations with many asynchronous accelerated operations (multiplication, transpose, piece-wise unary or binary operations...).
33 | * To install these implementations, please use the following calls : 34 | *
{@code
35 |  * MatrixMapper.getInstance().setDenseDoubleMatrix2DClass(CLDenseDoubleMatrix2D.class);
36 |  * MatrixMapper.getInstance().setDenseFloatMatrix2DClass(CLDenseFloatMatrix2D.class);
37 |  * }
38 | */ 39 | package com.nativelibs4java.opencl.blas.ujmp; 40 | -------------------------------------------------------------------------------- /Blas/src/test/java/com/nativelibs4java/opencl/blas/CLMatrixUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.blas; 2 | 3 | import static com.nativelibs4java.opencl.blas.CLMatrixUtils.roundUp; 4 | import static org.junit.Assert.*; 5 | 6 | import org.junit.Test; 7 | /** 8 | * 9 | * @author ochafik 10 | */ 11 | 12 | public class CLMatrixUtilsTest { 13 | 14 | @Test 15 | public void testRoundUp() { 16 | assertEquals(0, roundUp(0, 16)); 17 | assertEquals(16, roundUp(1, 16)); 18 | assertEquals(16, roundUp(16, 16)); 19 | assertEquals(32, roundUp(17, 16)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Contributions/Kazo Csaba/BinaryKernelTest - issue 30.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl; 2 | 3 | import static com.nativelibs4java.util.NIOUtils.directBuffer; 4 | import java.util.Map; 5 | import static org.junit.Assert.assertEquals; 6 | 7 | import java.nio.IntBuffer; 8 | 9 | import org.junit.BeforeClass; 10 | import org.junit.Test; 11 | 12 | import com.nativelibs4java.test.MiscTestUtils; 13 | 14 | /** 15 | * 16 | * @author Kazó Csaba 17 | */ 18 | @SuppressWarnings("unchecked") 19 | public class BinaryKernelTest extends AbstractCommon { 20 | 21 | @BeforeClass 22 | public static void setup() { 23 | MiscTestUtils.protectJNI(); 24 | } 25 | 26 | @Test 27 | public void simpleTest() throws CLBuildException { 28 | CLProgram program = context.createProgram( 29 | "__kernel void copy(__global int* a, __global int* b) {\n" + 30 | " int i = get_global_id(0);\n" + 31 | " b[i]=a[i];\n" + 32 | "} "); 33 | program.build(); 34 | Map binaries = program.getBinaries(); 35 | program.release(); 36 | 37 | CLProgram binaryProgram = context.createProgram(binaries); 38 | CLKernel kernel=binaryProgram.createKernel("copy"); 39 | 40 | CLIntBuffer a=context.createIntBuffer(CLMem.Usage.Input, 4); 41 | CLIntBuffer b=context.createIntBuffer(CLMem.Usage.Output, 4); 42 | 43 | IntBuffer source = directBuffer(4, context.getByteOrder(), IntBuffer.class); 44 | for (int i=0; i<4; i++) 45 | source.put(i, 3*i+10); 46 | 47 | a.write(queue, source, true); 48 | 49 | kernel.setArgs(a, b); 50 | kernel.enqueueNDRange(queue, new int[]{4}, new int[]{1}).waitFor(); 51 | 52 | IntBuffer target = b.read(queue); 53 | 54 | assertEquals(target.capacity(), source.capacity()); 55 | for (int i=0; i<4; i++) 56 | assertEquals(source.get(i), target.get(i)); 57 | } 58 | } -------------------------------------------------------------------------------- /Contributions/Kazo Csaba/CreateBinaryProgram - issue 30.README: -------------------------------------------------------------------------------- 1 | See http://code.google.com/p/nativelibs4java/issues/detail?id=30 2 | 3 | kazocsaba's first comment : 4 | <<< 5 | Certainly, I'm happy to contribute the patch under LGPL and BSD. 6 | 7 | Csaba 8 | >>> 9 | -------------------------------------------------------------------------------- /Core/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Core/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /Core/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Core 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.maven.ide.eclipse.maven2Builder 15 | 16 | 17 | 18 | 19 | org.eclipse.iam.jdt.core.mavenIncrementalBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.maven.ide.eclipse.maven2Nature 26 | org.eclipse.iam.jdt.core.mavenNature 27 | org.eclipse.jdt.core.javanature 28 | 29 | 30 | -------------------------------------------------------------------------------- /Core/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:48:18 CET 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /Core/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:46:12 CET 2010 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /Core/javacl-core-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Core/javacl-core.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Core/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | all 17 | 18 | 19 | -------------------------------------------------------------------------------- /Core/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Core/src/main/jnlp/HardwareReport.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | JavaCL-BridJ HardwareReport 8 | Olivier Chafik 9 | 10 | JavaCL-BridJ HardwareReport 11 | JavaCL-BridJ HardwareReport 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 35 | 36 | -------------------------------------------------------------------------------- /Core/src/main/jnlp/InteractiveImageTransformDemo.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | JavaCL-BridJ Interactive Image Transform Demo 8 | Olivier Chafik 9 | 10 | Image Transform Kernel Editor + Demos for JavaCL-BridJ (Object-Oriented OpenCL Library for Java) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | -------------------------------------------------------------------------------- /Core/src/main/jnlp/JavaCL.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | JavaCL-BridJ 8 | Olivier Chafik 9 | 10 | Object-Oriented OpenCL-BridJ Library for Java 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Core/src/main/jnlp/MandelbrotDemo.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | JavaCL-BridJ Mandelbrot Demos 8 | Olivier Chafik (demo adapted from Bob Boothby's) 9 | 10 | Mandelbrot Demo for JavaCL-BridJ (Object-Oriented OpenCL Library for Java) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 28 | 29 | 30 | 33 | 34 | -------------------------------------------------------------------------------- /Core/src/main/jnlp/OpenCL4Java.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | OpenCL4Java-BridJ 8 | Olivier Chafik 9 | 10 | OpenCL-BridJ bindings for Java 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Core/src/main/jnlp/ParticlesDemo.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | JavaCL-BridJ Particles Demos 8 | Olivier Chafik 9 | 10 | Demos for JavaCL (Object-Oriented OpenCL Library for Java) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | -------------------------------------------------------------------------------- /Core/src/main/jnlp/ScalaCL.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | ScalaCL 8 | Olivier Chafik 9 | 10 | OpenCL for Scala: natural DSL and Object-Oriented API 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Core/src/main/velocity/com/nativelibs4java/opencl/CLBuildException.java: -------------------------------------------------------------------------------- 1 | #parse("main/Header.vm") 2 | package com.nativelibs4java.opencl; 3 | 4 | import com.ochafik.util.string.StringUtils; 5 | import java.util.Collection; 6 | 7 | /** 8 | * OpenCL program build exception 9 | * @author ochafik 10 | */ 11 | @SuppressWarnings("serial") 12 | public class CLBuildException extends CLException { 13 | final CLProgram program; 14 | CLBuildException(CLProgram program, String string, Collection errors) { 15 | super(string + "\n" + StringUtils.implode(errors, "\n"), -1); 16 | this.program = program; 17 | } 18 | public CLProgram getProgram() { 19 | return program; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/src/main/velocity/com/nativelibs4java/opencl/CLUserEvent.java: -------------------------------------------------------------------------------- 1 | #parse("main/Header.vm") 2 | package com.nativelibs4java.opencl; 3 | 4 | 5 | import static com.nativelibs4java.opencl.JavaCL.CL; 6 | import static com.nativelibs4java.opencl.CLException.error; 7 | import static com.nativelibs4java.opencl.library.OpenCLLibrary.*; 8 | import static com.nativelibs4java.opencl.library.IOpenCLLibrary.*; 9 | import com.nativelibs4java.opencl.library.IOpenCLLibrary.cl_event; 10 | 11 | public class CLUserEvent extends CLEvent { 12 | CLUserEvent(CLQueue queue, long evt) { 13 | super(queue, evt); 14 | } 15 | /** 16 | #documentCallsFunction("clSetUserEventStatus") 17 | * Sets the execution status of a this event object. 18 | * NOTE: Enqueued commands that specify user events in the event_wait_list argument of clEnqueue*** commands must ensure that the status of these user events being waited on are set using clSetUserEventStatus before any OpenCL APIs that release OpenCL objects except for event objects are called; otherwise the behavior is undefined. More details in the OpenCL specifications at section 5.9. 19 | * @param executionStatus specifies the new execution status to be set and can be CL_COMPLETE or a negative integer value to indicate an error. A negative integer value causes all enqueued commands that wait on this user event to be terminated. setStatus can only be called once to change the execution status of event. 20 | */ 21 | public void setStatus(int executionStatus) { 22 | error(CL.clSetUserEventStatus(getEntity(), executionStatus)); 23 | } 24 | 25 | /** 26 | * Calls setStatus(CL_COMPLETE) 27 | */ 28 | public void setComplete() { 29 | setStatus(CL_COMPLETE); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Core/src/main/velocity/com/nativelibs4java/opencl/InfoName.java: -------------------------------------------------------------------------------- 1 | #parse("main/Header.vm") 2 | package com.nativelibs4java.opencl; 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * Tagging annotation to indicate the name of an OpenCL information in the OpenCL specifications. 11 | * @author ochafik 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.METHOD) 15 | public @interface InfoName { 16 | String value(); 17 | } 18 | -------------------------------------------------------------------------------- /Core/src/main/velocity/com/nativelibs4java/opencl/LocalSize.java: -------------------------------------------------------------------------------- 1 | #parse("main/Header.vm") 2 | package com.nativelibs4java.opencl; 3 | import org.bridj.*; 4 | import org.bridj.util.*; 5 | import java.lang.reflect.Type; 6 | /** 7 | * Size in bytes of a __local argument. 8 | */ 9 | public class LocalSize { 10 | long size; 11 | public LocalSize(long size) { 12 | this.size = size; 13 | } 14 | 15 | #foreach ($prim in $primitivesNoBool) 16 | 17 | /** 18 | * Returns the size in bytes of an array of ${prim.Name} values of the specified length.
19 | * @return arrayLength * sizeof(${prim.Name}) = arrayLength * ${prim.Size} 20 | */ 21 | public static LocalSize of${prim.CapName}Array(long arrayLength) { 22 | return new LocalSize(arrayLength * ${prim.Size}); 23 | } 24 | 25 | #end 26 | 27 | /** 28 | * Returns the size in bytes of an array of T values of the specified length.
29 | */ 30 | public static LocalSize ofArray(long arrayLength, Type componentType) { 31 | PointerIO io = PointerIO.getInstance(componentType); 32 | if (io == null) 33 | throw new RuntimeException("Unsupported type : " + Utils.toString(componentType)); 34 | return new LocalSize(arrayLength * io.getTargetSize()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Core/src/main/velocity/com/nativelibs4java/opencl/PlatformUtils.java: -------------------------------------------------------------------------------- 1 | #parse("main/Header.vm") 2 | package com.nativelibs4java.opencl; 3 | 4 | class PlatformUtils { 5 | public enum PlatformKind { 6 | AMDApp, 7 | NVIDIA, 8 | Apple, 9 | Intel 10 | } 11 | public static PlatformKind guessPlatformKind(CLPlatform p) { 12 | String name = p.getName(); 13 | if (name != null) { 14 | if (name.equals("Apple")) 15 | return PlatformKind.Apple; 16 | else if (name.equals("ATI Stream") || name.equals("AMD Accelerated Parallel Processing")) 17 | return PlatformKind.AMDApp; 18 | else { 19 | String vendor = p.getVendor().toLowerCase(); 20 | if (vendor.contains("nvidia")) 21 | return PlatformKind.NVIDIA; 22 | } 23 | } 24 | return null; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Core/src/main/velocity/com/nativelibs4java/opencl/ReusablePointer.java: -------------------------------------------------------------------------------- 1 | #parse("main/Header.vm") 2 | package com.nativelibs4java.opencl; 3 | import org.bridj.*; 4 | 5 | /** 6 | * 7 | * @author ochafik 8 | */ 9 | final class ReusablePointer { 10 | private final Pointer pointer; 11 | private final long bytesCapacity; 12 | 13 | public ReusablePointer(long bytesCapacity) { 14 | this.bytesCapacity = bytesCapacity; 15 | this.pointer = allocateAlignedBytes(bytesCapacity).withoutValidityInformation(); 16 | } 17 | 18 | static Pointer allocateAlignedBytes(long count) { 19 | // Allocate memory aligned to 128 bytes to match alignment of cl_double16. 20 | return Pointer.allocateAlignedBytes(null /* io */, count, 128 /* alignment */, null /* beforeDeallocation */); 21 | } 22 | 23 | public Pointer pointerToInts(int... values) { 24 | if (values == null) 25 | return null; 26 | long needed = 4 * values.length; 27 | if (needed > bytesCapacity) { 28 | return Pointer.pointerToInts(values); 29 | } else { 30 | return (Pointer)pointer.setInts(values); 31 | } 32 | } 33 | public Pointer pointerToSizeTs(long... values) { 34 | if (values == null) 35 | return null; 36 | long needed = SizeT.SIZE * values.length; 37 | if (needed > bytesCapacity) { 38 | return Pointer.pointerToSizeTs(values); 39 | } else { 40 | return (Pointer)pointer.setSizeTs(values); 41 | } 42 | } 43 | public Pointer pointerToSizeTs(int... values) { 44 | if (values == null) 45 | return null; 46 | long needed = SizeT.SIZE * values.length; 47 | if (needed > bytesCapacity) { 48 | return Pointer.pointerToSizeTs(values); 49 | } else { 50 | return (Pointer)pointer.setSizeTs(values); 51 | } 52 | } 53 | public Pointer allocatedBytes(int needed) { 54 | if (needed == 0) 55 | return null; 56 | if (needed > bytesCapacity) { 57 | return (Pointer)allocateAlignedBytes(needed); 58 | } else { 59 | return (Pointer)pointer; 60 | } 61 | } 62 | public Pointer allocatedSizeTs(int needed) { 63 | return allocatedBytes(needed * SizeT.SIZE); 64 | } 65 | public Pointer allocatedInts(int needed) { 66 | return allocatedBytes(needed * 4); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Core/src/main/velocity/com/nativelibs4java/opencl/ReusablePointers.java: -------------------------------------------------------------------------------- 1 | #parse("main/Header.vm") 2 | package com.nativelibs4java.opencl; 3 | import com.nativelibs4java.opencl.library.IOpenCLLibrary.cl_event; 4 | import org.bridj.*; 5 | import static org.bridj.Pointer.*; 6 | /** 7 | * 8 | * @author ochafik 9 | */ 10 | final class ReusablePointers { 11 | public final int[] int1Array = new int[1]; 12 | 13 | public final ReusablePointer 14 | sizeT3_1 = new ReusablePointer(3 * SizeT.SIZE), 15 | sizeT3_2 = new ReusablePointer(3 * SizeT.SIZE), 16 | sizeT3_3 = new ReusablePointer(3 * SizeT.SIZE); 17 | 18 | public final Pointer 19 | int1 = allocateInt().withoutValidityInformation(), 20 | int2 = allocateInt().withoutValidityInformation(); 21 | 22 | public final Pointer 23 | sizeT1 = allocateSizeT().withoutValidityInformation(); 24 | 25 | public final Pointer 26 | long1 = allocateLong().withoutValidityInformation(); 27 | 28 | public final Pointer> 29 | ptr1 = allocatePointer().withoutValidityInformation(); 30 | 31 | public final ReusablePointer 32 | int3_1 = new ReusablePointer(4 * 3); 33 | 34 | public final ReusablePointer 35 | kernelArg = new ReusablePointer(8 * 16); // double16 arguments ! 36 | 37 | public final Pointer event_out = allocateTypedPointer(cl_event.class).withoutValidityInformation(); 38 | 39 | public final Pointer pErr = allocateInt().withoutValidityInformation(); 40 | 41 | public final int[] event_count = new int[1]; 42 | public final ReusablePointer events_in = new ReusablePointer(Pointer.SIZE * 10); 43 | 44 | private ReusablePointers() {} 45 | 46 | public static ReusablePointers get() { 47 | return local.get(); 48 | } 49 | private static final ThreadLocal local = new ThreadLocal() { 50 | 51 | @Override 52 | protected ReusablePointers initialValue() { 53 | return new ReusablePointers(); 54 | } 55 | 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Core/src/main/velocity/com/nativelibs4java/opencl/package-info.java: -------------------------------------------------------------------------------- 1 | #parse("main/Header.vm") 2 | /** 3 | * Object-oriented wrappers around the OpenCL API ({@link com.nativelibs4java.opencl.JavaCL}, {@link com.nativelibs4java.opencl.CLPlatform}, {@link com.nativelibs4java.opencl.CLContext}, {@link com.nativelibs4java.opencl.CLProgram}, {@link com.nativelibs4java.opencl.CLKernel}, {@link com.nativelibs4java.opencl.CLBuffer}...)
4 | * Also see the low-level bindings : {@link com.nativelibs4java.opencl.library.OpenCLLibrary} 5 | */ 6 | package com.nativelibs4java.opencl; 7 | -------------------------------------------------------------------------------- /Core/src/test/java/com/nativelibs4java/opencl/AbstractCommon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl; 7 | 8 | import org.junit.Before; 9 | import org.junit.BeforeClass; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import org.junit.After; 14 | import org.junit.runner.RunWith; 15 | import org.junit.runners.Parameterized; 16 | 17 | /** 18 | * 19 | * @author ochafik 20 | */ 21 | @RunWith(Parameterized.class) 22 | public abstract class AbstractCommon { 23 | 24 | CLPlatform platform; 25 | CLContext context; 26 | CLQueue queue; 27 | CLDevice device; 28 | CLImageFormat[] formatsRead2D, formatsRead3D, formatsWrite2D, formatsWrite3D, formatsReadWrite2D, formatsReadWrite3D; 29 | 30 | static boolean listedPlatforms; 31 | 32 | AbstractCommon(CLDevice device) { 33 | this.device = device; 34 | platform = device.getPlatform(); 35 | context = platform.createContext(null, device); 36 | queue = context.createDefaultQueue(); 37 | device = context.getDevices()[0]; 38 | formatsRead2D = context.getSupportedImageFormats(CLMem.Flags.ReadOnly, CLMem.ObjectType.Image2D); 39 | formatsWrite2D = context.getSupportedImageFormats(CLMem.Flags.WriteOnly, CLMem.ObjectType.Image2D); 40 | formatsRead3D = context.getSupportedImageFormats(CLMem.Flags.ReadOnly, CLMem.ObjectType.Image3D); 41 | formatsWrite3D = context.getSupportedImageFormats(CLMem.Flags.WriteOnly, CLMem.ObjectType.Image3D); 42 | formatsReadWrite2D = context.getSupportedImageFormats(CLMem.Flags.ReadWrite, CLMem.ObjectType.Image2D); 43 | formatsReadWrite3D = context.getSupportedImageFormats(CLMem.Flags.ReadWrite, CLMem.ObjectType.Image3D); 44 | } 45 | 46 | @Parameterized.Parameters 47 | public static List getDeviceParameters() { 48 | List ret = new ArrayList(); 49 | for (CLPlatform platform : JavaCL.listPlatforms()) 50 | for (CLDevice device : platform.listAllDevices(true)) 51 | ret.add(new Object[] { device }); 52 | return ret; 53 | } 54 | /* 55 | @After 56 | public void cleanup() { 57 | queue.finish(); 58 | queue.release(); 59 | context.release(); 60 | device.release(); 61 | platform.release(); 62 | } 63 | */ 64 | } 65 | -------------------------------------------------------------------------------- /Core/src/test/java/com/nativelibs4java/opencl/ByteOrderHackTest.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl; 2 | 3 | import java.util.Map; 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import org.junit.BeforeClass; 7 | import org.junit.Test; 8 | 9 | import org.bridj.Pointer; 10 | import static org.bridj.Pointer.*; 11 | import java.util.List; 12 | import org.junit.runners.Parameterized; 13 | 14 | @SuppressWarnings("unchecked") 15 | public class ByteOrderHackTest extends AbstractCommon { 16 | public ByteOrderHackTest(CLDevice device) { 17 | super(device); 18 | } 19 | 20 | @Parameterized.Parameters 21 | public static List getDeviceParameters() { 22 | return AbstractCommon.getDeviceParameters(); 23 | } 24 | 25 | @Test 26 | public void test() { 27 | if (!ByteOrderHack.hackEnabled) 28 | return; 29 | for (CLPlatform platform : JavaCL.listPlatforms()) { 30 | for (CLDevice device : platform.listAllDevices(true)) { 31 | assertEquals(device.getByteOrder(), ByteOrderHack.checkByteOrderNeededForBuffers(device)); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Core/src/test/java/com/nativelibs4java/opencl/CLPlatformTest.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl; 2 | import static com.nativelibs4java.opencl.JavaCL.*; 3 | 4 | import java.util.*; 5 | 6 | import static org.junit.Assert.*; 7 | import org.junit.*; 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.Parameterized; 10 | import org.junit.runners.Parameterized.Parameters; 11 | 12 | @RunWith(Parameterized.class) 13 | public class CLPlatformTest { 14 | final CLPlatform platform; 15 | 16 | public CLPlatformTest(CLPlatform platform) { 17 | this.platform = platform; 18 | } 19 | @Test 20 | public void ensureHasDevices() { 21 | CLDevice[] devices = platform.listAllDevices(false); 22 | assertTrue("No device in platform " + platform, devices.length > 0); 23 | } 24 | @Parameters 25 | public static List readParameters() { 26 | List data = new ArrayList(); 27 | 28 | for (CLPlatform platform : JavaCL.listPlatforms()) { 29 | data.add(new Object[] { platform }); 30 | } 31 | 32 | return data; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Core/src/test/java/com/nativelibs4java/opencl/EventTest.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl; 2 | 3 | import java.util.Map; 4 | import static org.junit.Assert.*; 5 | 6 | import org.junit.BeforeClass; 7 | import org.junit.Test; 8 | 9 | import org.bridj.Pointer; 10 | import static org.bridj.Pointer.*; 11 | import java.util.List; 12 | import org.junit.runners.Parameterized; 13 | 14 | @SuppressWarnings("unchecked") 15 | public class EventTest extends AbstractCommon { 16 | public EventTest(CLDevice device) { 17 | super(device); 18 | } 19 | 20 | @Parameterized.Parameters 21 | public static List getDeviceParameters() { 22 | return AbstractCommon.getDeviceParameters(); 23 | } 24 | 25 | @Test 26 | public void simpleTest() throws CLBuildException { 27 | CLKernel kernel = context.createProgram( 28 | "__kernel void copy(__global int* a, __global int* b) {\n" + 29 | " int i = get_global_id(0);\n" + 30 | " b[i]=a[i];\n" + 31 | "} " 32 | ).createKernel("copy"); 33 | 34 | CLBuffer 35 | a = context.createBuffer(CLMem.Usage.Input, Integer.class, 4), 36 | b = context.createBuffer(CLMem.Usage.Output, Integer.class, 4); 37 | 38 | kernel.setArgs(a, b); 39 | 40 | int[] globalSizes = new int[]{4}; 41 | CLEvent e = kernel.enqueueNDRange(queue, globalSizes); 42 | assertNotNull(e); 43 | e.waitFor(); 44 | assertNull(kernel.enqueueNDRange(queue, globalSizes, CLEvent.FIRE_AND_FORGET)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Core/src/test/java/com/nativelibs4java/opencl/StressTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.nativelibs4java.opencl; 6 | 7 | import org.bridj.Pointer; 8 | //import org.junit.Test; 9 | 10 | /** 11 | 12 | 13 | javac -d target/classes -cp target/javacl-core-1.0-SNAPSHOT.jar:/Users/ochafik/.m2/repository/com/nativelibs4java/ochafik-util/0.12-SNAPSHOT/ochafik-util-0.12-SNAPSHOT.jar:/Users/ochafik/.m2/repository/com/nativelibs4java/opencl4java/1.0-SNAPSHOT/opencl4java-1.0-SNAPSHOT.jar:/Users/ochafik/.m2/repository/com/nativelibs4java/bridj/0.7-SNAPSHOT/bridj-0.7-SNAPSHOT.jar src/test/java/com/nativelibs4java/opencl/StressTest.java && java -cp target/classes:target/javacl-core-1.0-SNAPSHOT.jar:/Users/ochafik/.m2/repository/com/nativelibs4java/nativelibs4java-utils/1.6-SNAPSHOT/nativelibs4java-utils-1.6-SNAPSHOT.jar:/Users/ochafik/.m2/repository/com/nativelibs4java/ochafik-util/0.12-SNAPSHOT/ochafik-util-0.12-SNAPSHOT.jar:/Users/ochafik/.m2/repository/com/nativelibs4java/opencl4java/1.0-SNAPSHOT/opencl4java-1.0-SNAPSHOT.jar:/Users/ochafik/.m2/repository/com/nativelibs4java/bridj/0.7-SNAPSHOT/bridj-0.7-SNAPSHOT.jar com.nativelibs4java.opencl.StressTest 14 | 15 | 16 | */ 17 | public class StressTest { 18 | // @Test 19 | public static void main(String[] args) { 20 | CLContext context = JavaCL.createBestContext(CLPlatform.DeviceFeature.GPU); 21 | System.out.println(context); 22 | int n = 128;// * 128; 23 | // Pointer p = Pointer.allocateInts(n); 24 | for (int i = 0; i < 100000; i++) { 25 | // if ((i & 0xff) == 0xff) 26 | System.out.print("."); 27 | CLQueue queue = context.createDefaultQueue(); 28 | CLBuffer buffer = context.createByteBuffer(CLMem.Usage.Output, 4 * n).as(Integer.class);//p); 29 | CLProgram program = context.createProgram("kernel void f(global int* input, int n) {\n" + 30 | "int i = get_global_id(0);\n" + 31 | "if (i >= n) return;\n" + 32 | "input[i] = i;\n" + 33 | "}"); 34 | CLKernel kernel = program.createKernel("f"); 35 | 36 | for (int j = 0; j < 100; j++) { 37 | kernel.setArgs(buffer, n); 38 | kernel.enqueueNDRange(queue, new int[] { n }); 39 | } 40 | queue.finish(); 41 | queue.release(); 42 | kernel.release(); 43 | program.release(); 44 | buffer.release(); 45 | } 46 | context.release(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Core/src/test/java/com/nativelibs4java/opencl/SweatTest.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl; 2 | 3 | import org.junit.Test; 4 | 5 | public class SweatTest { 6 | static { 7 | System.setProperty("bridj.debug.pointer.releases", "true"); 8 | } 9 | @Test 10 | public void sweatTest() { 11 | long tot = 0; 12 | for (boolean cached : new boolean[] { false, true }) { 13 | for (int time = 0; time < 100; time++) { 14 | CLContext context = JavaCL.createBestContext(CLPlatform.DeviceFeature.GPU); 15 | CLQueue queue = context.createDefaultQueue(); 16 | CLProgram program = context.createProgram("kernel void f(global int* a) { a[0] = 1; }"); 17 | program.setCached(cached); 18 | program.build(); 19 | CLKernel kernel = program.createKernel("f"); 20 | kernel.release(); 21 | program.release(); 22 | queue.release(); 23 | context.release(); 24 | System.gc(); 25 | } 26 | } 27 | System.out.println(tot); 28 | } 29 | } -------------------------------------------------------------------------------- /Core/src/test/java/com/nativelibs4java/test/BenchmarkUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.test; 7 | 8 | /** 9 | * 10 | * @author ochafik 11 | */ 12 | public class BenchmarkUtils { 13 | public static void gc() { 14 | try { 15 | System.gc(); 16 | Thread.sleep(200); 17 | System.gc(); 18 | Thread.sleep(200); 19 | } catch (InterruptedException ex) {} 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Core/src/test/resources/com/nativelibs4java/opencl/BufferReadTest.c: -------------------------------------------------------------------------------- 1 | __kernel void testLongRead( __global const long* input, 2 | __global long* output) { 3 | int i = get_global_id(0); 4 | 5 | output[i] = input[i] + 1; 6 | } 7 | -------------------------------------------------------------------------------- /Demos/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Demos/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /Demos/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Demos 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.maven.ide.eclipse.maven2Builder 15 | 16 | 17 | 18 | 19 | org.eclipse.iam.jdt.core.mavenIncrementalBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.maven.ide.eclipse.maven2Nature 26 | org.eclipse.iam.jdt.core.mavenNature 27 | org.eclipse.jdt.core.javanature 28 | 29 | 30 | -------------------------------------------------------------------------------- /Demos/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:48:20 CET 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /Demos/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:46:11 CET 2010 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /Demos/javacl-demos-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Demos/javacl-demos.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Demos/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | com.nativelibs4java 6 | javacl-demos 7 | JavaCL Demos / BridJ 8 | http://code.google.com/p/javacl/ 9 | jar 10 | 11 | 12 | com.nativelibs4java 13 | javacl-parent 14 | 1.0-SNAPSHOT 15 | .. 16 | 17 | 18 | 19 | true 20 | com.nativelibs4java.opencl.demos.hardware.HardwareReport 21 | 22 | 23 | 24 | 25 | 26 | com.nativelibs4java 27 | javacl 28 | 29 | 30 | 31 | org.swinglabs 32 | swing-layout 33 | 1.0.3 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | com.nativelibs4java 42 | maven-javacl-plugin 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-shade-plugin 47 | 48 | 49 | full-package 50 | package 51 | 52 | shade 53 | 54 | 55 | ${shadedArtifactAttached} 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Demos/src/main/java/com/nativelibs4java/opencl/demos/vectoradd/VectorAdd.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.demos.vectoradd; 2 | import com.nativelibs4java.opencl.*; 3 | import java.nio.*; 4 | import org.bridj.Pointer; 5 | import static org.bridj.Pointer.*; 6 | 7 | 8 | /** 9 | * This is about the simplest possible JavaCL program.
10 | * It adds two vectors of floats in parallel.
11 | * This program can be written more easily with the JavaCL BLAS Library : 12 | * 13 | * LinearAlgebraUtils la = new LinearAlgebraUtils(); 14 | * CLKernel kernel = new LinearAlgebraUtils().getKernel(LinearAlgebraUtils.Fun2.add, LinearAlgebraUtils.Primitive.Float); 15 | * 16 | * @author ochafik 17 | */ 18 | public class VectorAdd { 19 | 20 | public static void main(String[] args) { 21 | try { 22 | Pointer a = pointerToFloats(1, 2, 3, 4 ); 23 | Pointer b = pointerToFloats(10, 20, 30, 40); 24 | 25 | Pointer sum = add(a, b); 26 | for (long i = 0, n = sum.getValidElements(); i < n; i++) 27 | System.out.println(sum.get(i)); 28 | } catch (Exception ex) { 29 | ex.printStackTrace(); 30 | } 31 | } 32 | 33 | public static Pointer add(Pointer a, Pointer b) throws CLBuildException { 34 | int n = (int)a.getValidElements(); 35 | 36 | CLContext context = JavaCL.createBestContext(); 37 | CLQueue queue = context.createDefaultQueue(); 38 | 39 | String source = 40 | "__kernel void addFloats(__global const float* a, __global const float* b, __global float* output) " + 41 | "{ " + 42 | " int i = get_global_id(0); " + 43 | " output[i] = a[i] + b[i]; " + 44 | "} "; 45 | 46 | CLKernel kernel = context.createProgram(source).createKernel("addFloats"); 47 | CLBuffer aBuf = context.createBuffer(CLMem.Usage.Input, a, true); 48 | CLBuffer bBuf = context.createBuffer(CLMem.Usage.Input, b, true); 49 | CLBuffer outBuf = context.createBuffer(CLMem.Usage.Output, Float.class, n); 50 | kernel.setArgs(aBuf, bBuf, outBuf); 51 | 52 | kernel.enqueueNDRange(queue, new int[]{n}); 53 | queue.finish(); 54 | 55 | return outBuf.read(queue); 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Demos/src/main/opencl/com/nativelibs4java/opencl/demos/mandelbrot/Mandelbrot.cl: -------------------------------------------------------------------------------- 1 | /** 2 | * Copied and adapted from Bob Boothby's code : 3 | * http://bbboblog.blogspot.com/2009/10/gpgpu-mandelbrot-with-opencl-and-java.html 4 | */ 5 | __kernel void mandelbrot( 6 | const float2 delta, 7 | const float2 minimum, 8 | const unsigned int maxIter, 9 | const unsigned int magicNumber, 10 | const unsigned int hRes, 11 | __global int* outputi 12 | ) 13 | { 14 | int2 id = (int2)(get_global_id(0), get_global_id(1)); 15 | 16 | float2 pos = minimum + delta * (float2)(id.x, id.y); 17 | float2 squared = pos * pos; 18 | float2 val = pos; 19 | 20 | int iter = 0; 21 | while ( (iter < maxIter) && ((squared.x + squared.y) < magicNumber) ) 22 | { 23 | val.y = (2 * (val.x * val.y)); 24 | val.x = squared.x - squared.y; 25 | val += pos; 26 | squared = val * val; 27 | 28 | iter++; 29 | } 30 | if(iter >= maxIter) 31 | iter = 0; 32 | 33 | outputi[id.y * hRes + id.x] = iter; 34 | } -------------------------------------------------------------------------------- /Demos/src/test/java/com/nativelibs4java/opencl/demos/SetupUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.nativelibs4java.opencl.demos; 6 | 7 | import java.io.IOException; 8 | import java.net.HttpURLConnection; 9 | import java.net.URLConnection; 10 | import org.junit.Test; 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * 15 | * @author ochafik 16 | */ 17 | public class SetupUtilsTest { 18 | @Test 19 | public void checkValidDownloadLinks() throws IOException { 20 | for (SetupUtils.DownloadURL url : SetupUtils.DownloadURL.values()) { 21 | HttpURLConnection con = (HttpURLConnection) url.url.openConnection(); 22 | con.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36"); 23 | assertEquals("Bad url for " + url + " : " + url.url, 200, con.getResponseCode()); 24 | con.disconnect(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Demos/src/test/java/com/nativelibs4java/opencl/demos/TestReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.nativelibs4java.opencl.demos; 6 | import com.nativelibs4java.opencl.*; 7 | 8 | import com.nativelibs4java.opencl.demos.hardware.HardwareReport; 9 | import java.util.List; 10 | import java.util.Map; 11 | import org.junit.Test; 12 | 13 | /** 14 | * Test that HardwareReport runs without exception 15 | * @author ochafik 16 | */ 17 | public class TestReport { 18 | 19 | @Test 20 | public void runReport() { 21 | for (CLPlatform platform : JavaCL.listPlatforms()) { 22 | List> list = HardwareReport.listInfos(platform); 23 | HardwareReport.toHTML(list); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Generator/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Generator/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /Generator/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Generator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.maven.ide.eclipse.maven2Builder 15 | 16 | 17 | 18 | 19 | org.eclipse.iam.jdt.core.mavenIncrementalBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.maven.ide.eclipse.maven2Nature 26 | org.eclipse.iam.jdt.core.mavenNature 27 | org.eclipse.jdt.core.javanature 28 | 29 | 30 | -------------------------------------------------------------------------------- /Generator/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:48:18 CET 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /Generator/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:46:11 CET 2010 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /Generator/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | com.nativelibs4java 6 | javacl-generator 7 | JavaCL Generator / BridJ 8 | http://code.google.com/p/javacl/ 9 | jar 10 | 11 | 12 | com.nativelibs4java 13 | javacl-parent 14 | 1.0-SNAPSHOT 15 | .. 16 | 17 | 18 | 19 | 20 | 21 | com.nativelibs4java 22 | jnaerator 23 | 24 | 25 | 26 | com.nativelibs4java 27 | javacl-core 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /InteractiveImageDemo/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /InteractiveImageDemo/javacl-interactive-image-demo-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /InteractiveImageDemo/javacl-interactive-image-demo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /InteractiveImageDemo/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | com.nativelibs4java 6 | javacl-interactive-image-demo 7 | JavaCL Interactive Image Demo / BridJ 8 | http://code.google.com/p/javacl/ 9 | jar 10 | 11 | 12 | com.nativelibs4java 13 | javacl-parent 14 | 1.0-SNAPSHOT 15 | .. 16 | 17 | 18 | 19 | com.nativelibs4java.opencl.demos.interactiveimage.InteractiveImageDemo 20 | true 21 | 22 | 23 | 24 | 25 | 26 | com.nativelibs4java 27 | javacl-core 28 | 29 | 30 | com.nativelibs4java 31 | javacl-demos 32 | 33 | 34 | com.nativelibs4java 35 | libcl 36 | 37 | 38 | com.nativelibs4java 39 | ochafik-swing 40 | ${jnaerator.version} 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-shade-plugin 51 | 52 | 53 | full-package 54 | package 55 | 56 | shade 57 | 58 | 59 | ${shadedArtifactAttached} 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /InteractiveImageDemo/project/build.properties: -------------------------------------------------------------------------------- 1 | #Project properties 2 | #Fri Dec 17 13:30:54 CET 2010 3 | project.organization=com.nativelibs4java 4 | project.name=javacl-interactive-image-demo 5 | sbt.version=0.7.4 6 | project.version=1.0-SNAPSHOT 7 | build.scala.versions=2.8.1 8 | project.initialize=false 9 | -------------------------------------------------------------------------------- /InteractiveImageDemo/project/build/InteractiveImageDemoProject.scala: -------------------------------------------------------------------------------- 1 | import sbt._ 2 | 3 | class InteractiveImageDemoProject(info: ProjectInfo) extends DefaultProject(info) with AutoCompilerPlugins 4 | { 5 | val nativelibs4javaRepo = "NativeLibs4Java Repository" at "http://nativelibs4java.sourceforge.net/maven/" 6 | 7 | val jnaeratorVersion = "0.9.6-SNAPSHOT" 8 | val javaclVersion = "1.0-SNAPSHOT" 9 | 10 | val javacl = "com.nativelibs4java" % "javacl" % javaclVersion 11 | val ochafikSwing = "com.ochafik" % "ochafik-swing" % jnaeratorVersion 12 | } 13 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/Blur.cl: -------------------------------------------------------------------------------- 1 | /** 2 | Blur example : naive square blur. 3 | This example also demonstrates the chaining of multiple kernels (see commented code at the end). 4 | Written by Olivier Chafik, no right reserved :-) */ 5 | 6 | void performBlur( 7 | int blurSize, 8 | read_only image2d_t inputImage, 9 | write_only image2d_t outputImage) 10 | { 11 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_dim.html 12 | int2 dimensions = get_image_dim(inputImage); 13 | int width = dimensions.x, height = dimensions.y; 14 | 15 | int x = get_global_id(0), y = get_global_id(1); 16 | 17 | float4 transformedPixel = (float4)0; 18 | 19 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html 20 | const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE; 21 | 22 | int minDiff = -(blurSize - 1); 23 | for (int dx = minDiff; dx < blurSize; dx++) { 24 | for (int dy = minDiff; dy < blurSize; dy++) { 25 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/read_imagef2d.html 26 | float4 pixel = read_imagef(inputImage, sampler, (int2)(x + dx, y + dy)); 27 | transformedPixel += pixel; 28 | } 29 | } 30 | 31 | int n = (2 * blurSize - 1); 32 | n *= n; 33 | 34 | transformedPixel /= (float)n; 35 | 36 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/write_image.html 37 | write_imagef(outputImage, (int2)(x, y), transformedPixel); 38 | } 39 | 40 | __kernel void test( 41 | read_only image2d_t inputImage, 42 | write_only image2d_t outputImage) 43 | { 44 | const float matrix[] = { 45 | 3.f, 0.f, -3.f, 46 | 10.f, 0.f, -10.f, 47 | 3.f, 0.f, -3.f, 48 | }; 49 | convolveImage(inputImage, matrix, 3, outputImage); 50 | } 51 | 52 | // Perform a blur 53 | __kernel void pass1(read_only image2d_t inputImage, write_only image2d_t outputImage) { 54 | performBlur(10, inputImage, outputImage); 55 | } 56 | 57 | /** 58 | You can chain as many kernel calls as you want : 59 | each new kernel takes the output of the previous one as input image. 60 | */ 61 | /* 62 | __kernel void pass2(read_only image2d_t inputImage, write_only image2d_t outputImage) { 63 | performBlur(10, inputImage, outputImage); 64 | } 65 | */ 66 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/Convolution.cl: -------------------------------------------------------------------------------- 1 | /** 2 | Generic Convolution example with a 5x5 gaussian blur matrix. 3 | This sample also shows how to chain two kernels, with a color to b&w conversion pass ready to be uncommented (see below). 4 | Written by Olivier Chafik, no right reserved :-) */ 5 | 6 | // Import LibCL's image convolution functions 7 | // See sources here : http://code.google.com/p/nativelibs4java/source/browse/trunk/libraries/OpenCL/LibCL/src/main/resources#resources%2FLibCL 8 | #include "LibCL/ImageConvolution.cl" 9 | 10 | // Matrix values taken from http://en.wikipedia.org/wiki/Gaussian_blur : 11 | __constant float gaussian7x7Matrix[] = { 12 | 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f, 13 | 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f, 14 | 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f, 15 | 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f, 16 | 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f, 17 | 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f, 18 | 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f 19 | }; 20 | 21 | 22 | __kernel void convolve( 23 | read_only image2d_t inputImage, 24 | write_only image2d_t outputImage) 25 | { 26 | convolveFloatImage(inputImage, gaussian7x7Matrix, 7 /* matrixSize */, outputImage); 27 | } 28 | 29 | // Uncomment this kernel to add a pass that transforms the image from color to gray levels : 30 | /* 31 | __kernel void toGray( 32 | read_only image2d_t inputImage, 33 | write_only image2d_t outputImage) 34 | { 35 | int x = get_global_id(0), y = get_global_id(1); 36 | 37 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html 38 | const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE; 39 | 40 | float4 pixel = read_imagef(inputImage, sampler, (int2)(x, y)); 41 | float luminance = dot(pixel, (float4)(1, 1, 1, 0)) / 3; 42 | write_imagef(outputImage, (int2)(x, y), (float4)(luminance, luminance, luminance, 1)); 43 | } 44 | */ 45 | 46 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/DesaturateColors.cl: -------------------------------------------------------------------------------- 1 | /** 2 | Color Desaturation example : make an image look more gray 3 | Written by Olivier Chafik, no right reserved :-) */ 4 | 5 | void desaturate( 6 | float greyFactor, 7 | read_only image2d_t inputImage, 8 | write_only image2d_t outputImage) 9 | { 10 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_dim.html 11 | int2 dimensions = get_image_dim(inputImage); 12 | int width = dimensions.x, height = dimensions.y; 13 | 14 | int x = get_global_id(0), y = get_global_id(1); 15 | 16 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html 17 | const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE; 18 | 19 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/read_imagef2d.html 20 | float4 pixel = read_imagef(inputImage, sampler, (int2)(x, y)); 21 | 22 | // If the image is of type BGRA, UNormInt8, the pixel is in the form : 23 | // (float4)(red, green, blue, alpha) with each component beinge [0.0f; 1.0f] interval. 24 | 25 | // Compute pixel luminance using a dot product, equivalent to the following two lines : 26 | // float red = pixel.x, green = pixel.y, blue = pixel.z, alpha = pixel.w; 27 | // float luminance = (red + green + blue) / 3; 28 | float luminance = dot((float4)(1/3.f, 1/3.f, 1/3.f, 0), pixel); 29 | 30 | // Lower color saturation of pixel : 31 | const float colorFactor = 1.f - greyFactor; 32 | float4 transformedPixel = colorFactor * pixel + greyFactor * ((float4)(luminance, luminance, luminance, 1.f)); 33 | 34 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/write_image.html 35 | write_imagef(outputImage, (int2)(x, y), transformedPixel); 36 | } 37 | 38 | __kernel void pass( 39 | read_only image2d_t inputImage, 40 | write_only image2d_t outputImage) 41 | { 42 | desaturate(0.5f, inputImage, outputImage); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/DummySample.cl: -------------------------------------------------------------------------------- 1 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html 2 | const sampler_t sampler = 3 | CLK_NORMALIZED_COORDS_FALSE | 4 | CLK_FILTER_NEAREST | 5 | CLK_ADDRESS_CLAMP_TO_EDGE; 6 | 7 | __kernel void test( 8 | __read_only image2d_t inputImage, 9 | __write_only image2d_t outputImage) 10 | { 11 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_dim.html 12 | int2 dimensions = get_image_dim(inputImage); 13 | int width = dimensions.x, height = dimensions.y; 14 | 15 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_channel_data_type.html 16 | int channelDataType = get_image_channel_data_type(inputImage); 17 | 18 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_channel_order.html 19 | int channelOrder = get_image_channel_order(inputImage); 20 | 21 | int x = get_global_id(0); 22 | int y = get_global_id(1); 23 | int2 coordinates = (int2)(x, y); 24 | 25 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/read_imagef2d.html 26 | float4 pixel = read_imagef(inputImage, sampler, coordinates); 27 | 28 | float4 transformedPixel = (float4)(0);//pixel; 29 | 30 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/write_image.html 31 | write_imagef(outputImage, coordinates, transformedPixel); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/Identity.cl: -------------------------------------------------------------------------------- 1 | /** 2 | Identity example : simply copy the input image into the output image. 3 | Written by Olivier Chafik, no right reserved :-) */ 4 | 5 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html 6 | const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE; 7 | 8 | __kernel void test( 9 | read_only image2d_t inputImage, 10 | write_only image2d_t outputImage) 11 | { 12 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_dim.html 13 | int2 dimensions = get_image_dim(inputImage); 14 | int width = dimensions.x, height = dimensions.y; 15 | 16 | int x = get_global_id(0), y = get_global_id(1); 17 | 18 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/read_imagef2d.html 19 | float4 pixel = read_imagef(inputImage, sampler, (int2)(x, y)); 20 | 21 | // If the image is of type BGRA / UNormInt8, each component is in the [0.0f; 1.0f] interval : 22 | float red = pixel.x, green = pixel.y, blue = pixel.z, alpha = pixel.w; 23 | 24 | // Perform no transformation : 25 | // float4 transformedPixel = pixel; 26 | float4 transformedPixel = (float4)(red, green, blue, alpha); 27 | 28 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/write_image.html 29 | write_imagef(outputImage, (int2)(x, y), transformedPixel); 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/LuminanceThreshold.cl: -------------------------------------------------------------------------------- 1 | /** 2 | Image luminance threshold example : hide pixels that are not bright enough (with gaussian smoothing) 3 | Written by Olivier Chafik, no right reserved :-) */ 4 | 5 | // Import LibCL functions, which sources can be browsed here : 6 | // http://code.google.com/p/nativelibs4java/source/browse/trunk/libraries/OpenCL/LibCL/src/main/resources#resources%2FLibCL 7 | #include "LibCL/ImageConvolution.cl" 8 | #include "LibCL/SobelOperator.cl" 9 | #include "LibCL/Gaussian7x7.cl" 10 | 11 | __kernel void imageThreshold( 12 | read_only image2d_t inputImage, 13 | write_only image2d_t outputImage) 14 | { 15 | int x = get_global_id(0), y = get_global_id(1); 16 | 17 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html 18 | const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE; 19 | float4 pixel = read_imagef(inputImage, sampler, (int2)(x, y)); 20 | 21 | // Get smoothed luminance (averaged from neighborhood with a gaussian) : 22 | float luminance = convolveFloatImagePixelGray(inputImage, x, y, gaussian7x7Matrix, 7); 23 | // Get exact local luminance : 24 | // float luminance = dot((float4)(1/3.f, 1/3.f, 1/3.f, 0), pixel); 25 | 26 | float2 sobel = sobelOperatorRGBFloat(inputImage, x, y); 27 | 28 | float threshold = 0.3f; 29 | if (luminance < threshold && (luminance * sobel.x) < threshold) 30 | pixel.w = 0; // make these pixels transparent 31 | 32 | write_imagef(outputImage, (int2)(x, y), pixel); 33 | } 34 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/QueryFormat.cl: -------------------------------------------------------------------------------- 1 | /** 2 | QueryFormat example : query image format dynamically inside the kernel 3 | Written by Olivier Chafik, no right reserved :-) */ 4 | 5 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/sampler_t.html 6 | const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE; 7 | 8 | __kernel void test( 9 | read_only image2d_t inputImage, 10 | write_only image2d_t outputImage) 11 | { 12 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_dim.html 13 | int2 dimensions = get_image_dim(inputImage); 14 | int width = dimensions.x, height = dimensions.y; 15 | 16 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_channel_data_type.html 17 | int channelDataType = get_image_channel_data_type(inputImage); 18 | 19 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/get_image_channel_order.html 20 | int channelOrder = get_image_channel_order(inputImage); 21 | 22 | int x = get_global_id(0), y = get_global_id(1); 23 | int2 coordinates = (int2)(x, y); 24 | 25 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/read_imagef2d.html 26 | //float4 pixel = read_imagef(inputImage, sampler, coordinates); 27 | float4 pixel = read_imagef(inputImage, sampler, coordinates); 28 | float4 transformedPixel = pixel; 29 | //float4 transformedPixel = (float4)(0);//pixel; 30 | 31 | // See http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/write_image.html 32 | write_imagef(outputImage, coordinates, transformedPixel); 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/RichardsonLucyDeconvolution.cl: -------------------------------------------------------------------------------- 1 | /** 2 | Deconvolution sample that uses the Richardson-Lucy algorithm. 3 | Knowing the exact "point-spread function" that made an image blurry, this algorithm tries to restore 4 | the original image. 5 | If the point-spread function is not well known, the results aren't good ! 6 | 7 | Written by Olivier Chafik, no right reserved :-) */ 8 | 9 | // Import LibCL functions, which sources can be browsed here : 10 | // http://code.google.com/p/nativelibs4java/source/browse/trunk/libraries/OpenCL/LibCL/src/main/resources#resources%2FLibCL 11 | #include "LibCL/RichardsonLucyImageDeconvolution.cl" 12 | 13 | // Gaussian point-spread function : 14 | // Matrix values taken from http://en.wikipedia.org/wiki/Gaussian_blur : 15 | __constant float pointSpreadFunction7x7[] = { 16 | 0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067, 17 | 0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292, 18 | 0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117, 19 | 0.00038771, 0.01330373, 0.11098164, 0.22508352, 0.11098164, 0.01330373, 0.00038771, 20 | 0.00019117, 0.00655965, 0.05472157, 0.11098164, 0.05472157, 0.00655965, 0.00019117, 21 | 0.00002292, 0.00078633, 0.00655965, 0.01330373, 0.00655965, 0.00078633, 0.00002292, 22 | 0.00000067, 0.00002292, 0.00019117, 0.00038771, 0.00019117, 0.00002292, 0.00000067 23 | }; 24 | 25 | // Blur the initial image 26 | /* 27 | __kernel void blur(read_only image2d_t inputImage, write_only image2d_t outputImage) { 28 | convolveFloatImage(inputImage, pointSpreadFunction7x7, 7, outputImage); 29 | } 30 | */ 31 | 32 | RICHARDSON_LUCY_DECONVOLUTION_PRE(pointSpreadFunction7x7, 7); 33 | 34 | // Chain a few deconvolution passes : 35 | RICHARDSON_LUCY_DECONVOLUTION_PASS(pointSpreadFunction7x7, 7, 1); 36 | RICHARDSON_LUCY_DECONVOLUTION_PASS(pointSpreadFunction7x7, 7, 2); 37 | RICHARDSON_LUCY_DECONVOLUTION_PASS(pointSpreadFunction7x7, 7, 3); 38 | //RICHARDSON_LUCY_DECONVOLUTION_PASS(pointSpreadFunction7x7, 7, 4); 39 | 40 | RICHARDSON_LUCY_DECONVOLUTION_POST(); 41 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/examples/SobelFilter.cl: -------------------------------------------------------------------------------- 1 | /** 2 | Sobel filter example : naive edge detection 3 | This sample includes Sobel and Scharr operators, please see below. 4 | See http://en.wikipedia.org/wiki/Sobel_operator 5 | Written by Olivier Chafik, no right reserved :-) */ 6 | 7 | // Import LibCL functions, which sources can be browsed here : 8 | // http://code.google.com/p/nativelibs4java/source/browse/trunk/libraries/OpenCL/LibCL/src/main/resources#resources%2FLibCL 9 | #include "LibCL/ImageConvolution.cl" 10 | 11 | __constant float2 sobel3x3MatrixXY[] = { 12 | (float2)(-1, -1), (float2)(0, -2), (float2)(1, -1), 13 | (float2)(-2, 0), (float2)(0, 0), (float2)(2, 0), 14 | (float2)(-1, 1), (float2)(0, 2), (float2)(1, 1) 15 | }; 16 | __constant float2 scharr3x3MatrixXY[] = { 17 | (float2)(3, 3), (float2)(0, 10), (float2)(-3, 3), 18 | (float2)(10, 0), (float2)(0, 0), (float2)(-10, 0), 19 | (float2)(3, -3), (float2)(0, -10), (float2)(-3, -3) 20 | }; 21 | 22 | __kernel void test( 23 | read_only image2d_t inputImage, 24 | write_only image2d_t outputImage) 25 | { 26 | int x = get_global_id(0), y = get_global_id(1); 27 | 28 | float scaling = 0.3f; // you can adjust this 29 | 30 | // Sobel operator 31 | float2 total = scaling * convolveFloatImagePixelGray2(inputImage, x, y, sobel3x3MatrixXY, 3); 32 | 33 | // Scharr operator (better rotational symmetry) : 34 | // float2 total = scaling * convolveFloatImagePixelGray2(inputImage, x, y, scharr3x3MatrixXY, 3); 35 | 36 | #if 1 37 | float gradient = fast_length(total); 38 | float value = gradient; 39 | #else 40 | float direction = atan2(total.y, total.x); 41 | float value = direction; 42 | #endif 43 | 44 | write_imagef(outputImage, (int2)(x, y), (float4)(value, value, value, 1.f)); 45 | } 46 | -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/images/lena.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nativelibs4java/JavaCL/2a07936f475052ab97f06d638f4af33a8dfa4b62/InteractiveImageDemo/src/main/resources/images/lena.jpg -------------------------------------------------------------------------------- /InteractiveImageDemo/src/main/resources/images/mandrill.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nativelibs4java/JavaCL/2a07936f475052ab97f06d638f4af33a8dfa4b62/InteractiveImageDemo/src/main/resources/images/mandrill.jpg -------------------------------------------------------------------------------- /JavaCL/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /JavaCL/javacl-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /JavaCL/javacl.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/OSGiBundleActivator.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl; 2 | 3 | import org.osgi.framework.BundleActivator; 4 | import org.osgi.framework.BundleContext; 5 | 6 | public class OSGiBundleActivator implements BundleActivator { 7 | 8 | public void start(BundleContext bundleContext) { 9 | System.out.println("Starting JavaCL"); 10 | } 11 | 12 | public void stop(BundleContext bundleContext) { 13 | System.out.println("Stopping JavaCL"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/Fun1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl.util; 7 | 8 | 9 | public enum Fun1 { 10 | not("!"), 11 | complement("~"), 12 | abs, 13 | log, 14 | exp, 15 | sqrt, 16 | sin, 17 | cos, 18 | tan, 19 | atan, 20 | asin, 21 | acos, 22 | sinh, 23 | cosh, 24 | tanh, 25 | asinh, 26 | acosh, 27 | atanh; 28 | 29 | final String prefixOp; 30 | Fun1(String op) { 31 | this.prefixOp = op; 32 | } 33 | Fun1() { 34 | this(null); 35 | } 36 | void expr(String a, StringBuilder out) { 37 | if (prefixOp != null) 38 | out.append('(').append(prefixOp).append(a).append(')'); 39 | out.append(name()).append('(').append(a).append(')'); 40 | } 41 | } -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/Fun2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl.util; 7 | 8 | 9 | public enum Fun2 { 10 | min, 11 | max, 12 | atan2, 13 | dist, 14 | modulo("%"), 15 | rshift(">>"), 16 | lshift("<<"), 17 | xor("^"), 18 | bitOr("|"), 19 | bitAnd("&"), 20 | add("+"), 21 | substract("-"), 22 | multiply("*"), 23 | divide("/"); 24 | 25 | String infixOp; 26 | Fun2() {} 27 | Fun2(String infixOp) { 28 | this.infixOp = infixOp; 29 | } 30 | void expr(String a, String b, StringBuilder out) { 31 | if (infixOp == null) 32 | out.append(name()).append('(').append(a).append(", ").append(b).append(")"); 33 | else 34 | out.append(a).append(' ').append(infixOp).append(' ').append(b); 35 | } 36 | } -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/OpenCLType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.nativelibs4java.opencl.util; 7 | 8 | public enum OpenCLType { 9 | Int(Integer.class), Char(Character.class), Long(Long.class), Short(Short.class), Byte(Byte.class), Double(Double.class), Float(Float.class), Half(null); 10 | 11 | OpenCLType(Class type) { 12 | this.type = type; 13 | } 14 | public final Class type; 15 | 16 | public String toCType() { 17 | if (this == Byte) 18 | return "char"; 19 | if (this == Char) 20 | return "short"; 21 | return name().toLowerCase(); 22 | } 23 | public static OpenCLType fromClass(Class valueType) { 24 | if (valueType == Integer.TYPE || valueType == Integer.class) 25 | return Int; 26 | if (valueType == java.lang.Long.TYPE || valueType == Long.class) 27 | return Long; 28 | if (valueType == java.lang.Short.TYPE || valueType == Short.class) 29 | return Short; 30 | if (valueType == java.lang.Double.TYPE || valueType == Double.class) 31 | return Double; 32 | if (valueType == java.lang.Float.TYPE || valueType == Float.class) 33 | return Float; 34 | if (valueType == java.lang.Byte.TYPE || valueType == Byte.class) 35 | return Byte; 36 | 37 | if (!valueType.isPrimitive()) 38 | throw new IllegalArgumentException("Value type is not a primitive: '" + valueType.getName() + "' !"); 39 | 40 | throw new IllegalArgumentException("Primitive type not handled: '" + valueType.getName() + "' !"); 41 | } 42 | } -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/fft/AbstractDFT.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.util.fft; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import com.nativelibs4java.opencl.util.Transformer.AbstractTransformer; 5 | import java.io.IOException; 6 | import java.nio.Buffer; 7 | 8 | abstract class AbstractDFT extends AbstractTransformer { 9 | 10 | // package-private constructor 11 | AbstractDFT(CLContext context, Class primitiveClass) throws IOException, CLException { 12 | super(context, primitiveClass); 13 | } 14 | protected abstract CLEvent dft(CLQueue queue, CLBuffer inBuf, CLBuffer outBuf, int length, int sign, int[] dims, CLEvent... events) throws CLException; 15 | 16 | @Override 17 | public CLEvent transform(CLQueue queue, CLBuffer inBuf, CLBuffer outBuf, boolean inverse, CLEvent... eventsToWaitFor) throws CLException { 18 | int length = (int)inBuf.getElementCount() / 2; 19 | return dft(queue, inBuf, outBuf, length, inverse ? -1 : 1, new int[]{length}, eventsToWaitFor); 20 | } 21 | } -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/fft/DoubleDFT.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.util.fft; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import com.nativelibs4java.opencl.CLPlatform.DeviceFeature; 5 | import java.io.IOException; 6 | import java.nio.DoubleBuffer; 7 | 8 | /** 9 | * Slow OpenCL Fourier Transform that works in all cases (double precision floating point numbers) 10 | */ 11 | public class DoubleDFT extends AbstractDFT { 12 | 13 | final DoubleDFTProgram program; 14 | 15 | public DoubleDFT(CLContext context) throws IOException { 16 | super(context, Double.class); 17 | this.program = new DoubleDFTProgram(context); 18 | } 19 | public DoubleDFT() throws IOException { 20 | this(JavaCL.createBestContext(DeviceFeature.DoubleSupport)); 21 | } 22 | 23 | @Override 24 | protected CLEvent dft(CLQueue queue, CLBuffer inBuf, CLBuffer outBuf, int length, int sign, int[] dims, CLEvent... events) throws CLException { 25 | return program.dft(queue, (CLBuffer)inBuf, (CLBuffer)outBuf, length, sign, dims, null, events); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/fft/DoubleFFTPow2.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.util.fft; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import com.nativelibs4java.opencl.CLPlatform.DeviceFeature; 5 | import java.io.IOException; 6 | import java.nio.DoubleBuffer; 7 | 8 | /** 9 | * OpenCL Fast Fourier Transform for array sizes that are powers of two (double precision floating point numbers) 10 | */ 11 | public class DoubleFFTPow2 extends AbstractFFTPow2 { 12 | 13 | final DoubleFFTProgram program; 14 | 15 | public DoubleFFTPow2(CLContext context) throws IOException, CLException { 16 | super(context, Double.class); 17 | this.program = new DoubleFFTProgram(context); 18 | program.getProgram().setFastRelaxedMath(); 19 | } 20 | public DoubleFFTPow2() throws IOException { 21 | this(JavaCL.createBestContext(DeviceFeature.DoubleSupport)); 22 | } 23 | 24 | protected CLEvent cooleyTukeyFFTTwiddleFactors(CLQueue queue, int N, CLBuffer buf, CLEvent... evts) throws CLException { 25 | return program.cooleyTukeyFFTTwiddleFactors(queue, N, buf, new int[] { N / 2 }, null, evts); 26 | } 27 | protected CLEvent cooleyTukeyFFTCopy(CLQueue queue, CLBuffer inBuf, CLBuffer outBuf, int length, CLBuffer offsetsBuf, boolean inverse, CLEvent... evts) throws CLException { 28 | return program.cooleyTukeyFFTCopy(queue, inBuf, outBuf, length, offsetsBuf, inverse ? 1.0 / length : 1, new int[] { length }, null, evts); 29 | } 30 | protected CLEvent cooleyTukeyFFT(CLQueue queue, CLBuffer Y, int N, CLBuffer twiddleFactors, int inverse, int[] dims, CLEvent... evts) throws CLException { 31 | return program.cooleyTukeyFFT(queue, Y, N, twiddleFactors, inverse, dims, null, evts); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/fft/FloatDFT.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.util.fft; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import com.nativelibs4java.opencl.CLPlatform.DeviceFeature; 5 | import com.nativelibs4java.util.*; 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.nio.FloatBuffer; 9 | 10 | /** 11 | * Slow OpenCL Fourier Transform that works in all cases (simple precision floating point numbers) 12 | */ 13 | public class FloatDFT extends AbstractDFT { 14 | 15 | final FloatDFTProgram program; 16 | 17 | public FloatDFT(CLContext context) throws IOException, CLException { 18 | super(context, Float.class); 19 | program = new FloatDFTProgram(context); 20 | } 21 | public FloatDFT() throws IOException { 22 | this(JavaCL.createBestContext()); 23 | } 24 | 25 | @Override 26 | protected CLEvent dft(CLQueue queue, CLBuffer inBuf, CLBuffer outBuf, int length, int sign, int[] dims, CLEvent... events) throws CLException { 27 | return program.dft(queue, inBuf, outBuf, length, sign, dims, null, events); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/fft/FloatFFTPow2.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.util.fft; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import java.io.IOException; 5 | import java.nio.FloatBuffer; 6 | 7 | /** 8 | * OpenCL Fast Fourier Transform for array sizes that are powers of two (simple precision floating point numbers) 9 | */ 10 | public class FloatFFTPow2 extends AbstractFFTPow2 { 11 | 12 | final FloatFFTProgram program; 13 | 14 | public FloatFFTPow2(CLContext context) throws IOException { 15 | super(context, Float.class); 16 | this.program = new FloatFFTProgram(context); 17 | program.getProgram().setFastRelaxedMath(); 18 | } 19 | public FloatFFTPow2() throws IOException { 20 | this(JavaCL.createBestContext()); 21 | } 22 | 23 | protected CLEvent cooleyTukeyFFTTwiddleFactors(CLQueue queue, int N, CLBuffer buf, CLEvent... evts) throws CLException { 24 | return program.cooleyTukeyFFTTwiddleFactors(queue, N, buf, new int[] { N / 2 }, null, evts); 25 | } 26 | protected CLEvent cooleyTukeyFFTCopy(CLQueue queue, CLBuffer inBuf, CLBuffer outBuf, int length, CLBuffer offsetsBuf, boolean inverse, CLEvent... evts) throws CLException { 27 | return program.cooleyTukeyFFTCopy(queue, inBuf, outBuf, length, offsetsBuf, inverse ? 1.0f / length : 1, new int[] { length }, null, evts); 28 | } 29 | protected CLEvent cooleyTukeyFFT(CLQueue queue, CLBuffer Y, int N, CLBuffer twiddleFactors, int inverse, int[] dims, CLEvent... evts) throws CLException { 30 | return program.cooleyTukeyFFT(queue, Y, N, twiddleFactors, inverse, dims, null, evts); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/fft/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JavaCL - Java API and utilities for OpenCL 3 | * http://javacl.googlecode.com/ 4 | * 5 | * Copyright (c) 2009-2015, Olivier Chafik (http://ochafik.com/) 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * * Neither the name of Olivier Chafik nor the 17 | * names of its contributors may be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * OpenCL-backed Fourier Analysis classes (DFT, power-of-two FFT and reverse DFT/FFT for complex doubles and floats inputs) 33 | */ 34 | package com.nativelibs4java.opencl.util.fft; 35 | -------------------------------------------------------------------------------- /JavaCL/src/main/java/com/nativelibs4java/opencl/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JavaCL - Java API and utilities for OpenCL 3 | * http://javacl.googlecode.com/ 4 | * 5 | * Copyright (c) 2009-2015, Olivier Chafik (http://ochafik.com/) 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * * Neither the name of Olivier Chafik nor the 17 | * names of its contributors may be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Utilitary classes (parallel random, parallel reduction, parallel math, linear algebra...) 33 | */ 34 | package com.nativelibs4java.opencl.util; 35 | -------------------------------------------------------------------------------- /JavaCL/src/main/opencl/com/nativelibs4java/opencl/util/XORShiftRandom.c: -------------------------------------------------------------------------------- 1 | #ifndef NUMBERS_COUNT 2 | #define NUMBERS_COUNT 0 3 | #endif 4 | 5 | #ifndef WORK_ITEMS_COUNT 6 | #define WORK_ITEMS_COUNT get_global_size(0) 7 | #endif 8 | 9 | /** 10 | * Logic copied from http://en.wikipedia.org/wiki/Xorshift 11 | * Requires 4 initial random seeds for each work item 12 | */ 13 | __kernel void gen_numbers(__global uint4* seeds, /*size_t nNumbersArg, */__global uint* output) 14 | { 15 | const uint iWorkItem = get_global_id(0); 16 | #if 1 17 | #define seedsOffset iWorkItem 18 | #define nNumbers NUMBERS_COUNT 19 | #define nWorkItems WORK_ITEMS_COUNT 20 | #define nNumbersByWorkItem (nNumbers / nWorkItems) 21 | #define REMAINDER (nNumbers - nNumbersByWorkItem * WORK_ITEMS_COUNT) 22 | uint nNumbersInThisWorkItem = nNumbersByWorkItem; 23 | if (iWorkItem == nWorkItems - 1) 24 | nNumbersInThisWorkItem += REMAINDER; 25 | #else 26 | const uint seedsOffset = iWorkItem; 27 | const uint nNumbers = nNumbersArg; 28 | const y nWorkItems = get_global_size(0); 29 | const uint nNumbersByWorkItem = nNumbers / nWorkItems; 30 | uint nNumbersInThisWorkItem = nNumbersByWorkItem; 31 | if (iWorkItem == nWorkItems - 1) 32 | nNumbersInThisWorkItem += nNumbers - nNumbersByWorkItem * nWorkItems; 33 | #endif 34 | 35 | output += iWorkItem * nNumbersByWorkItem;//outputOffset; 36 | 37 | //seeds += seedsOffset; 38 | //uint4 seed = *seeds; 39 | uint4 seed = seeds[seedsOffset]; 40 | #if 1 41 | uint x = seed.x, y = seed.y, z = seed.z, w = seed.w; 42 | for (uint i = 0; i < nNumbersInThisWorkItem; i++) { 43 | //for (uint i = nNumbersInThisWorkItem; i--;) { 44 | uint t = x ^ (x << 11); 45 | x = y; y = z; z = w; 46 | //output[outputOffset + i] = 47 | *(output++) = 48 | w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); 49 | } 50 | //*seeds = (uint4)(x, y, z, w); 51 | seeds[seedsOffset] = (uint4)(x, y, z, w); 52 | #else 53 | for (uint i = 0; i < nNumbersInThisWorkItem; i++) { 54 | uint t = seed.x ^ (seed.x << 11); 55 | seed.xyz = seed.yzw; 56 | *(output++) = seed.w = (seed.w ^ (seed.w >> 19)) ^ (t ^ (t >> 8)); 57 | } 58 | seeds[seedsOffset] = seed; 59 | #endif 60 | } 61 | 62 | #undef seedsOffset 63 | #undef nNumbers 64 | #undef nWorkItems 65 | #undef nNumbersByWorkItem 66 | #undef REMAINDER 67 | 68 | -------------------------------------------------------------------------------- /JavaCL/src/main/opencl/com/nativelibs4java/opencl/util/fft/DoubleDFTProgram.cl: -------------------------------------------------------------------------------- 1 | // Enable double-precision floating point numbers support. 2 | // Not all platforms / devices support this, so you may have to switch to floats. 3 | #pragma OPENCL EXTENSION cl_khr_fp64 : enable 4 | 5 | __kernel void dft( 6 | __global const double2 *in, // complex values input 7 | __global double2 *out, // complex values output 8 | int length, // number of input and output values 9 | int sign) // sign modifier in the exponential : 10 | // 1 for forward transform, -1 for backward. 11 | { 12 | // Get the varying parameter of the parallel execution : 13 | int i = get_global_id(0); 14 | 15 | // In case we're executed "too much", check bounds : 16 | if (i >= length) 17 | return; 18 | 19 | // Initialize sum and inner arguments 20 | double2 tot = 0; 21 | double param = (-2 * sign * i) * M_PI / (double)length; 22 | 23 | for (int k = 0; k < length; k++) { 24 | double2 value = in[k]; 25 | 26 | // Compute sin and cos in a single call : 27 | double c; 28 | double s = sincos(k * param, &c); 29 | 30 | // This adds (value.x * c - value.y * s, value.x * s + value.y * c) to the sum : 31 | tot += (double2)( 32 | dot(value, (double2)(c, -s)), 33 | dot(value, (double2)(s, c)) 34 | ); 35 | } 36 | 37 | if (sign == 1) { 38 | // forward transform (space -> frequential) 39 | out[i] = tot; 40 | } else { 41 | // backward transform (frequential -> space) 42 | out[i] = tot / (double)length; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /JavaCL/src/main/opencl/com/nativelibs4java/opencl/util/fft/FloatDFTProgram.cl: -------------------------------------------------------------------------------- 1 | __kernel void dft( 2 | __global const float2 *in, // complex values input 3 | __global float2 *out, // complex values output 4 | int length, // number of input and output values 5 | int sign) // sign modifier in the exponential : 6 | // 1 for forward transform, -1 for backward. 7 | { 8 | // Get the varying parameter of the parallel execution : 9 | int i = get_global_id(0); 10 | 11 | // In case we're executed "too much", check bounds : 12 | if (i >= length) 13 | return; 14 | 15 | // Initialize sum and inner arguments 16 | float2 tot = 0; 17 | float param = (-2 * sign * i) * 3.141593f / (float)length; 18 | 19 | for (int k = 0; k < length; k++) { 20 | float2 value = in[k]; 21 | 22 | // Compute sin and cos in a single call : 23 | float c; 24 | float s = sincos(k * param, &c); 25 | 26 | // This adds (value.x * c - value.y * s, value.x * s + value.y * c) to the sum : 27 | tot += (float2)( 28 | dot(value, (float2)(c, -s)), 29 | dot(value, (float2)(s, c)) 30 | ); 31 | } 32 | 33 | if (sign == 1) { 34 | // forward transform (space -> frequential) 35 | out[i] = tot; 36 | } else { 37 | // backward transform (frequential -> space) 38 | out[i] = tot / (float)length; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /JavaCL/src/main/opencl/com/nativelibs4java/opencl/util/fft/FloatFFTProgram.cl: -------------------------------------------------------------------------------- 1 | 2 | inline float2 rotateValue2(float2 value, float c, float s) { 3 | return (float2)( 4 | dot(value, (float2)(c, -s)), 5 | dot(value, (float2)(s, c)) 6 | ); 7 | } 8 | 9 | __kernel void cooleyTukeyFFTCopy( 10 | __global const float2* X, 11 | __global float2* Y, 12 | int N, 13 | __global const int* offsetsX, 14 | float factor) 15 | { 16 | int offsetY = get_global_id(0); 17 | if (offsetY >= N) 18 | return; 19 | 20 | int offsetX = offsetsX[offsetY]; 21 | Y[offsetY] = X[offsetX] * factor; 22 | } 23 | 24 | __kernel void cooleyTukeyFFTTwiddleFactors(int N, __global float2* twiddleFactors) 25 | { 26 | int k = get_global_id(0); 27 | float param = - 3.14159265359f * 2 * k / (float)N; 28 | float c, s = sincos(param, &c); 29 | twiddleFactors[k] = (float2)(c, s); 30 | } 31 | __kernel void cooleyTukeyFFT( 32 | __global float2* Y, 33 | int N, 34 | __global float2* twiddleFactors, 35 | int inverse) 36 | { 37 | int k = get_global_id(0); 38 | int halfN = N / 2;//>> 1; 39 | int offsetY = get_global_id(1) * N;//halfN; 40 | 41 | float2 tf = twiddleFactors[k]; 42 | float c = tf.x, s = tf.y; 43 | if (inverse) 44 | s = -s; 45 | 46 | int o1 = offsetY + k; 47 | int o2 = o1 + halfN; 48 | float2 y1 = Y[o1]; 49 | float2 y2 = Y[o2]; 50 | 51 | float2 v = rotateValue2(y2, c, s); 52 | Y[o1] = y1 + v; 53 | Y[o2] = y1 - v; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /JavaCL/src/main/resources/com/nativelibs4java/opencl/util/Reduction.c: -------------------------------------------------------------------------------- 1 | #define _mul_(tot, x) tot *= x; 2 | #define _add_(tot, x) tot += x; 3 | #define _min_(tot, x) tot = min(tot, x); 4 | #define _max_(tot, x) tot = max(tot, x); 5 | 6 | #ifndef SEED 7 | # error "No aggregation SEED defined !" 8 | #endif 9 | 10 | #ifndef OPERATION 11 | # error "No OPERATION defined !" 12 | #endif 13 | 14 | #ifndef OPERAND_TYPE 15 | #define OPERAND_TYPE int 16 | #endif 17 | 18 | #ifndef OUTPUT_TYPE 19 | #define OUTPUT_TYPE OPERAND_TYPE 20 | #endif 21 | 22 | __kernel void reduce( 23 | __global const OPERAND_TYPE* input, 24 | long blocks, 25 | long dataLength, 26 | long blockLength, 27 | __global OUTPUT_TYPE* output) 28 | { 29 | long block = get_global_id(0); 30 | if (block >= blocks) 31 | return; 32 | 33 | long inputStart = block * blockLength; 34 | long inputEnd = min(inputStart + blockLength, dataLength); 35 | 36 | OUTPUT_TYPE total = (OUTPUT_TYPE)SEED; 37 | for (int inputOffset = inputStart; inputOffset < inputEnd; inputOffset++) 38 | OPERATION(total, input[inputOffset]); 39 | 40 | output[block] = total; 41 | } 42 | -------------------------------------------------------------------------------- /JavaCL/src/test/java/com/nativelibs4java/opencl/generator/GeneratorTest.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.generator; 2 | 3 | import com.nativelibs4java.opencl.CLBuffer; 4 | import com.nativelibs4java.opencl.CLContext; 5 | import com.nativelibs4java.opencl.CLEvent; 6 | import com.nativelibs4java.opencl.CLMem; 7 | import com.nativelibs4java.opencl.CLQueue; 8 | import com.nativelibs4java.opencl.JavaCL; 9 | import java.io.IOException; 10 | import org.bridj.Pointer; 11 | import org.junit.Test; 12 | import static org.junit.Assert.*; 13 | import org.junit.Before; 14 | 15 | public class GeneratorTest { 16 | CLContext context; 17 | CLQueue queue; 18 | Structs structs; 19 | 20 | @Before 21 | public void setup() throws IOException { 22 | context = JavaCL.createBestContext(); 23 | queue = context.createDefaultQueue(); 24 | structs = new Structs(context); 25 | } 26 | 27 | @Test 28 | public void testStructs() throws IOException { 29 | Structs.S s = new Structs.S(); 30 | Pointer pS = Pointer.getPointer(s); 31 | CLBuffer b = context.createBuffer(CLMem.Usage.InputOutput, pS); 32 | 33 | CLEvent e = structs.f(queue, b, new int[] { 1 }, null); 34 | b.read(queue, pS, true, e); 35 | assertEquals(10, s.a()); 36 | assertEquals(100, s.b()); 37 | 38 | s.a(1).b(2); 39 | b.write(queue, pS, true); 40 | e = structs.f(queue, b, new int[] { 1 }, null); 41 | b.read(queue, pS, true, e); 42 | assertEquals(12, s.a()); 43 | assertEquals(120, s.b()); 44 | 45 | } 46 | 47 | @Test 48 | public void testFloat3() { 49 | float[] input = new float[] { 1, 2, 3 }; 50 | CLBuffer outputBuffer = context.createFloatBuffer(CLMem.Usage.Output, 3); 51 | CLEvent e = structs.g(queue, input, outputBuffer, new int[] { 1 }, null); 52 | float[] output = outputBuffer.read(queue, e).getFloats(); 53 | assertArrayEquals(input, output, 0.0f); 54 | } 55 | } -------------------------------------------------------------------------------- /JavaCL/src/test/java/com/nativelibs4java/opencl/util/ParallelRandomTest.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.util; 2 | 3 | import org.bridj.Pointer; 4 | import static org.bridj.Pointer.*; 5 | 6 | import com.nativelibs4java.opencl.JavaCL; 7 | 8 | import org.junit.Assert; 9 | import org.junit.Test; 10 | 11 | /** 12 | * 13 | * @author ochafik 14 | */ 15 | public class ParallelRandomTest { 16 | int nPoints = 1024 * 1024; 17 | int nLoops = 10; 18 | long seed = 1; 19 | 20 | static final int mask = 0x00ffffff; 21 | static final double divid = (1 << 24); 22 | //static final int mask = (1 << 30) - 1; 23 | //static final double divid = (1 << 30); 24 | 25 | /** 26 | * http://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#Exemples 27 | */ 28 | @Test 29 | public void testPICircle() { 30 | try { 31 | ParallelRandom random = new ParallelRandom( 32 | JavaCL.createBestContext().createDefaultQueue(), 33 | nPoints * 2, 34 | seed 35 | ); 36 | 37 | int nInside = 0, nTotalPoints = 0; 38 | 39 | for (int iLoop = 0; iLoop < nLoops; iLoop++) { 40 | Pointer values = random.next(); 41 | for (int iPoint = 0; iPoint < nPoints; iPoint++) { 42 | int offset = iPoint * 2; 43 | int ix = values.get(offset), iy = values.get(offset + 1); 44 | float x = (float)((ix & mask) / divid); 45 | float y = (float)((iy & mask) / divid); 46 | 47 | float dist = x * x + y * y; 48 | if (dist <= 1) 49 | nInside++; 50 | } 51 | nTotalPoints += nPoints; 52 | //checkPICircleProba(nInside, nTotalPoints); 53 | } 54 | checkPICircleProba(nInside, nTotalPoints); 55 | } catch (Exception ex) { 56 | throw new RuntimeException(ex); 57 | } 58 | } 59 | void checkPICircleProba(int nInside, int nTotalPoints) { 60 | double piRef = Math.PI; 61 | double probaInside = nInside / (double)nTotalPoints; // = Pi / 4 62 | double piApprox = probaInside * 4; 63 | double error = Math.abs(piApprox - piRef); 64 | double relError = error / piRef; 65 | System.out.println(nInside + " points inside the circle quarter over " + nTotalPoints); 66 | System.out.println("Approximated PI = " + piApprox); 67 | System.out.println(" Reference PI = " + piRef); 68 | System.out.println("\tAbsolute error = " + error); 69 | System.out.println("\tRelative error = " + (relError * 100) + " %"); 70 | Assert.assertEquals(piRef, piApprox, 0.001); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /JavaCL/src/test/opencl/com/nativelibs4java/opencl/generator/Structs.c: -------------------------------------------------------------------------------- 1 | typedef struct _S { 2 | int a, b; 3 | } S; 4 | 5 | kernel void f(__global S *pS) { 6 | pS->a = pS->a * 2 + 10; 7 | pS->b = pS->b * 10 + 100; 8 | } 9 | 10 | kernel void g(float3 floats, __global float *out) { 11 | out[0] = floats.x; 12 | out[1] = floats.y; 13 | out[2] = floats.z; 14 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2015, Olivier Chafik 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | * Neither the name of Olivier Chafik nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY 11 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 13 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 14 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 15 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 16 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 17 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 18 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 19 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 | -------------------------------------------------------------------------------- /LICENSE.header: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Olivier Chafik (http://ochafik.free.fr/) 3 | 4 | This file is part of OpenCL4Java (http://code.google.com/p/nativelibs4java/wiki/OpenCL). 5 | 6 | OpenCL4Java is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 2.1 of the License, or 9 | (at your option) any later version. 10 | 11 | OpenCL4Java is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with OpenCL4Java. If not, see . 18 | */ 19 | 20 | -------------------------------------------------------------------------------- /LibCL/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /LibCL/libcl-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /LibCL/libcl.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /LibCL/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | com.nativelibs4java 6 | libcl 7 | LibCL 8 | http://code.google.com/p/javacl/ 9 | jar 10 | 11 | 12 | Library of OpenCL functions for easy use from JavaCL 13 | 14 | 15 | 16 | com.nativelibs4java 17 | javacl-parent 18 | 1.0-SNAPSHOT 19 | .. 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /LibCL/src/main/resources/LibCL/Bits.cl: -------------------------------------------------------------------------------- 1 | #ifndef _LIBCL_BITS_CL_ 2 | #define _LIBCL_BITS_CL_ 3 | 4 | /** 5 | * SWAR algorithm 6 | * http://stackoverflow.com/questions/109023/best-algorithm-to-count-the-number-of-set-bits-in-a-32-bit-integer 7 | */ 8 | int countBitsInInt(int i) 9 | { 10 | i = i - ((i >> 1) & 0x55555555); 11 | i = (i & 0x33333333) + ((i >> 2) & 0x33333333); 12 | return ((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; 13 | } 14 | 15 | #define _LIBCL_BITS_CL_ 16 | -------------------------------------------------------------------------------- /LibCL/src/main/resources/LibCL/Gaussian7x7.cl: -------------------------------------------------------------------------------- 1 | #ifndef _LIBCL_GAUSSIAN_7x7_CL_ 2 | #define _LIBCL_GAUSSIAN_7x7_CL_ 3 | 4 | // Matrix values taken from http://en.wikipedia.org/wiki/Gaussian_blur : 5 | __constant float gaussian7x7Matrix[] = { 6 | 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f, 7 | 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f, 8 | 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f, 9 | 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f, 10 | 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f, 11 | 0.00002292f, 0.00078633f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f, 12 | 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f 13 | }; 14 | 15 | 16 | #endif // _LIBCL_GAUSSIAN_7x7_CL_ 17 | -------------------------------------------------------------------------------- /LibCL/src/main/resources/LibCL/ImageConvert.cl: -------------------------------------------------------------------------------- 1 | #ifndef _LIBCL_IMAGE_CONVERT_CL_ 2 | #define _LIBCL_IMAGE_CONVERT_CL_ 3 | 4 | __constant float4 luminanceDot = ((float4)(1 / 3.f, 1 / 3.f, 1 / 3.f, 0)); 5 | 6 | void convertFloatRGBImageToGray( 7 | read_only image2d_t inputImage, 8 | write_only image2d_t outputImage) 9 | { 10 | const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE; 11 | int x = get_global_id(0), y = get_global_id(1); 12 | 13 | int2 coords = (int2)(x, y); 14 | float4 pixel = read_imagef(inputImage, sampler, coords); 15 | float luminance = dot(luminanceDot, pixel); 16 | write_imagef(outputImage, coords, (float4)(luminance, luminance, luminance, 1)); 17 | } 18 | 19 | #endif // _LIBCL_IMAGE_CONVERT_CL_ 20 | -------------------------------------------------------------------------------- /LibCL/src/main/resources/LibCL/SobelOperator.cl: -------------------------------------------------------------------------------- 1 | #ifndef _LIBCL_SOBEL_OPERATOR_CL_ 2 | #define _LIBCL_SOBEL_OPERATOR_CL_ 3 | 4 | /** 5 | Sobel operator 6 | See http://en.wikipedia.org/wiki/Sobel_operator 7 | Written by Olivier Chafik, no right reserved :-) */ 8 | 9 | /** 10 | * Return (float2)(gradient, angle) of Sobel operator applied at given pixel. 11 | */ 12 | inline float2 sobelOperatorRGBFloat( 13 | read_only image2d_t inputImage, 14 | int x, 15 | int y) 16 | { 17 | const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE; 18 | 19 | #define PIXEL_CONTRIB(dx, dy, coefX, coefY) \ 20 | {\ 21 | float4 pixel = read_imagef(inputImage, sampler, (int2)(x + dx, y + dy)); \ 22 | total += (float2)(coefX, coefY) * (float2)(((pixel.x + (int)pixel.y + (int)pixel.z) / 3.f) * pixel.w); \ 23 | } 24 | 25 | float2 total = (float2)0; 26 | 27 | #define MX_NW 1 28 | #define MX_N 2 29 | #define MX_NE 1 30 | #define MX_W 0 31 | #define MX_C 0 32 | #define MX_E 0 33 | #define MX_SW -1 34 | #define MX_S -2 35 | #define MX_SE -1 36 | 37 | #define MY_NW 1 38 | #define MY_N 0 39 | #define MY_NE -1 40 | #define MY_W 2 41 | #define MY_C 0 42 | #define MY_E -2 43 | #define MY_SW 1 44 | #define MY_S 0 45 | #define MY_SE -1 46 | 47 | PIXEL_CONTRIB(-1, -1, MX_NW, MY_NW); 48 | PIXEL_CONTRIB(0, -1, MX_N, MY_N); 49 | PIXEL_CONTRIB(1, -1, MX_NE, MY_NE); 50 | PIXEL_CONTRIB(-1, 0, MX_W, MY_W); 51 | PIXEL_CONTRIB(0, 0, MX_C, MY_C); 52 | PIXEL_CONTRIB(1, 0, MX_E, MY_E); 53 | PIXEL_CONTRIB(-1, 1, MX_SW, MY_SW); 54 | PIXEL_CONTRIB(0, 1, MX_S, MY_S); 55 | PIXEL_CONTRIB(1, 1, MX_SE, MY_SE); 56 | 57 | float gradient = length(total); 58 | float direction = atan2(total.y, total.x); 59 | 60 | return (float2)(gradient, direction); 61 | } 62 | 63 | #endif // _LIBCL_SOBEL_OPERATOR_CL_ 64 | -------------------------------------------------------------------------------- /LibCL/src/main/resources/LibCL/hsla2rgba.cl: -------------------------------------------------------------------------------- 1 | #ifndef _LIBCL_HSLA_2_RGBA_CL_ 2 | #define _LIBCL_HSLA_2_RGBA_CL_ 3 | 4 | inline float hsla2rgba_sub(float x, float y, float z) { 5 | if (z < 0) 6 | z += 1.f; 7 | else if (z > 1) 8 | z -= 1.f; 9 | 10 | if (6 * z < 1) 11 | return x + (y - x) * 6 * z; 12 | if (2 * z < 1) 13 | return y; 14 | if (3 * z < 2) 15 | return x + (y - x) * ((2.f / 3.f) - z) * 6; 16 | return x; 17 | } 18 | 19 | inline float4 hsla2rgba(float4 hsla) { 20 | float 21 | h = hsla.x, 22 | s = hsla.y, 23 | l = hsla.z, 24 | a = hsla.w; 25 | 26 | float r, g, b; 27 | if (s == 0) 28 | r = g = b = l; 29 | else { 30 | float y; 31 | if (l < 0.5f) 32 | y = l * (1.0f + s); 33 | else 34 | y = l + s - l * s; 35 | float x = 2.0f * l - y; 36 | 37 | r = hsla2rgba_sub(x, y, h + 1.f / 3.f); 38 | g = hsla2rgba_sub(x, y, h); 39 | b = hsla2rgba_sub(x, y, h - 1.f / 3.f); 40 | } 41 | return (float4)(r, g, b, a); 42 | } 43 | 44 | #endif // _LIBCL_HSLA_2_RGBA_CL_ 45 | -------------------------------------------------------------------------------- /LibCL/src/main/resources/LibCL/rgba2hsla.cl: -------------------------------------------------------------------------------- 1 | #ifndef _LIBCL_RGBA_2_HSLA_CL_ 2 | #define _LIBCL_RGBA_2_HSLA_CL_ 3 | 4 | inline float4 rgba2hsla(float4 rgba) { 5 | float 6 | r = rgba.x, 7 | g = rgba.y, 8 | b = rgba.z, 9 | a = rgba.w; 10 | 11 | float mn = min(r, min(g, b)); 12 | float mx = max(r, max(g, b)); 13 | 14 | float l = (mn + mx) / 2.f; 15 | float s, h; 16 | if (mn == mx) { 17 | s = h = 0; 18 | } else { 19 | float diff = mx - mn; 20 | float sum = mx + mn; 21 | if (l < 0.5f) 22 | s = diff / sum; 23 | else 24 | s = diff / (2.0f - sum); 25 | if (r == mx) 26 | h = (g - b) / diff; 27 | else if (g == mx) 28 | h = 2.0f + (b - r) / diff; 29 | else //if (b == mx) 30 | h = 4.0f + (r - g) / diff; 31 | } 32 | h = clamp(h / 6.0f, 0.0f, 1.0f); 33 | return (float4)(h, s, l, a); 34 | } 35 | 36 | #endif // _LIBCL_HSLA_2_RGBA_CL_ 37 | -------------------------------------------------------------------------------- /LibCL/src/main/resources/LibCL/stdlib.h: -------------------------------------------------------------------------------- 1 | 2 | //#include "tcl.h" 3 | //#ifdef NO_STDLIB_H 4 | //# include "../compat/stdlib.h" 5 | //#else 6 | //# include 7 | //#endif 8 | //#include 9 | 10 | #ifndef CONST 11 | #define CONST const 12 | #endif 13 | 14 | #ifndef isspace 15 | #define isspace(c) (c == ' ' || c == '\t' || c == '\r' || c == '\n') 16 | #endif 17 | 18 | #ifndef isdigit 19 | #define isdigit(c) (c >= '0' && c <= '9') 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /LibCL/src/main/resources/LibCL/strstr.c: -------------------------------------------------------------------------------- 1 | 2 | /*__global const char * strstr ( __global const char * str1, const char * str2 ) { 3 | 4 | } 5 | */ 6 | -------------------------------------------------------------------------------- /MavenPlugin/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /NumericalBenchmark/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /NumericalBenchmark/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.nativelibs4java 5 | javacl-numerical-benchmark 6 | JavaCL Numerical Benchmark 7 | http://code.google.com/p/javacl/ 8 | jar 9 | 10 | 11 | com.nativelibs4java 12 | javacl-parent 13 | 1.0-SNAPSHOT 14 | .. 15 | 16 | 17 | 18 | 19 | com.nativelibs4java 20 | javacl 21 | 22 | 23 | org.apache.commons 24 | commons-math 25 | 2.2 26 | 27 | 28 | org.scala-lang 29 | scala-library 30 | 31 | 32 | 33 | 34 | 35 | 36 | com.nativelibs4java 37 | maven-javacl-plugin 38 | 39 | 40 | net.alchim31.maven 41 | scala-maven-plugin 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-shade-plugin 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | net.alchim31.maven 54 | scala-maven-plugin 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /OpenCL4Java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /OpenCL4Java/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /OpenCL4Java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | OpenCL4Java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.maven.ide.eclipse.maven2Builder 15 | 16 | 17 | 18 | 19 | org.eclipse.iam.jdt.core.mavenIncrementalBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.maven.ide.eclipse.maven2Nature 26 | org.eclipse.iam.jdt.core.mavenNature 27 | org.eclipse.jdt.core.javanature 28 | 29 | 30 | -------------------------------------------------------------------------------- /OpenCL4Java/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:48:17 CET 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.compliance=1.6 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /OpenCL4Java/.settings/org.maven.ide.eclipse.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jan 28 23:46:11 CET 2010 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | fullBuildGoals=process-test-resources 5 | includeModules=false 6 | resolveWorkspaceProjects=true 7 | resourceFilterGoals=process-resources resources\:testResources 8 | skipCompilerPlugin=true 9 | version=1 10 | -------------------------------------------------------------------------------- /OpenCL4Java/opencl4java-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /OpenCL4Java/opencl4java.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /OpenCL4Java/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | com.nativelibs4java 6 | opencl4java 7 | OpenCL4Java / BridJ 8 | http://code.google.com/p/nativelibs4java/wiki/OpenCL 9 | jar 10 | 11 | 12 | OpenCL4Java is a thin Java wrapper around OpenCL's C API. 13 | It uses JNA as its interop layer library, which means it works on all of the (many) JNA-supported platforms (see http://jna.dev.java.net/). 14 | It is autogenerated by JNAerator (http://jnaerator.googlecode.com/), so updates to newer OpenCL specs are a matter of seconds. 15 | 16 | Note that OpenCL4Java is used by JavaCL, an Object-Oriented API that presents OpenCL in a much more practical, powerful and idiomatic way to Java. 17 | For more info, please visit http://code.google.com/p/nativelibs4java/wiki/OpenCL. 18 | 19 | 20 | 21 | com.nativelibs4java 22 | javacl-parent 23 | 1.0-SNAPSHOT 24 | .. 25 | 26 | 27 | 28 | 29 | 30 | com.nativelibs4java 31 | bridj 32 | 33 | 0.7.1-SNAPSHOT 34 | 35 | 36 | 37 | 38 | 39 | 40 | regenerate 41 | 42 | 43 | 44 | com.nativelibs4java 45 | maven-jnaerator-plugin 46 | ${jnaerator.version} 47 | 48 | src/main/java 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /OpenCL4Java/regenerate.cmd: -------------------------------------------------------------------------------- 1 | mvn com.jnaerator:maven-jnaerator-plugin:jnaerate 2 | del src\main\scala\*.scala 3 | mvn install -------------------------------------------------------------------------------- /OpenCL4Java/src/main/headers/1.1/CL/opencl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2010 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | ******************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_H 27 | #define __OPENCL_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifdef __APPLE__ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #else 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #endif 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __OPENCL_H */ 54 | 55 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/headers/1.2/CL/opencl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2010 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | ******************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_H 27 | #define __OPENCL_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | //#ifdef __APPLE__ 34 | // 35 | //#include 36 | //#include 37 | //#include 38 | //#include 39 | // 40 | //#else 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | //#endif 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __OPENCL_H */ 54 | 55 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/java/com/nativelibs4java/opencl/library/OpenGLContextUtils.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.library; 2 | 3 | import org.bridj.*; 4 | import org.bridj.ann.*; 5 | import static org.bridj.Pointer.*; 6 | 7 | /** 8 | * JNA Wrapper for library OpenGL
9 | * This file was autogenerated by JNAerator,
10 | * a tool written by Olivier Chafik that uses a few opensource projects..
11 | * For help, please visit NativeLibs4Java, Rococoa, or JNA. 12 | */ 13 | @Library("OpenGL") 14 | @org.bridj.ann.Runtime(CRuntime.class) 15 | public class OpenGLContextUtils { 16 | static { 17 | if (Platform.isWindows()) 18 | BridJ.addNativeLibraryAlias("OpenGL", "OpenGL32"); // even in 64 bit mode ! 19 | else if (Platform.isUnix() && !Platform.isMacOSX()) 20 | BridJ.addNativeLibraryAlias("OpenGL", "GL"); 21 | 22 | BridJ.register(); 23 | } 24 | /// Original signature : CGLShareGroupObj CGLGetShareGroup(CGLContextObj) 25 | public static native Pointer CGLGetShareGroup(Pointer ctx); 26 | /** 27 | * * Current context functions
28 | * Original signature : CGLError CGLSetCurrentContext(CGLContextObj) 29 | */ 30 | @Optional 31 | public static native int CGLSetCurrentContext(Pointer ctx); 32 | /// Original signature : CGLContextObj CGLGetCurrentContext() 33 | @Optional 34 | public static native Pointer CGLGetCurrentContext(); 35 | 36 | /** 37 | * * Version numbers
38 | * Original signature : void CGLGetVersion(GLint*, GLint*) 39 | */ 40 | @Optional 41 | public static native void CGLGetVersion(Pointer majorvers, Pointer minorvers); 42 | /** 43 | * * Convert an error code to a string
44 | * Original signature : char* CGLErrorString(CGLError)
45 | * @param error @see CGLError 46 | */ 47 | @Optional 48 | public static native Pointer CGLErrorString(int error); 49 | 50 | @Optional 51 | public static native Pointer wglGetCurrentDC(); 52 | @Optional 53 | public static native Pointer wglGetCurrentContext(); 54 | @Optional 55 | public static native Pointer glXGetCurrentDisplay(); 56 | @Optional 57 | public static native Pointer glXGetCurrentContext(); 58 | } 59 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/java/com/nativelibs4java/opencl/library/cl_buffer_region.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.library; 2 | import org.bridj.Pointer; 3 | import org.bridj.StructObject; 4 | import org.bridj.ann.Field; 5 | import org.bridj.ann.Library; 6 | import org.bridj.ann.Ptr; 7 | /** 8 | * This file was autogenerated by JNAerator,
9 | * a tool written by Olivier Chafik that uses a few opensource projects..
10 | * For help, please visit NativeLibs4Java or BridJ . 11 | */ 12 | @Library("OpenCL") 13 | public class cl_buffer_region extends StructObject { 14 | @Ptr 15 | @Field(0) 16 | public long origin() { 17 | return this.io.getSizeTField(this, 0); 18 | } 19 | @Ptr 20 | @Field(0) 21 | public cl_buffer_region origin(long origin) { 22 | this.io.setSizeTField(this, 0, origin); 23 | return this; 24 | } 25 | @Ptr 26 | @Field(1) 27 | public long size() { 28 | return this.io.getSizeTField(this, 1); 29 | } 30 | @Ptr 31 | @Field(1) 32 | public cl_buffer_region size(long size) { 33 | this.io.setSizeTField(this, 1, size); 34 | return this; 35 | } 36 | public cl_buffer_region() { 37 | super(); 38 | } 39 | public cl_buffer_region(Pointer pointer) { 40 | super(pointer); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/java/com/nativelibs4java/opencl/library/cl_image_format.java: -------------------------------------------------------------------------------- 1 | package com.nativelibs4java.opencl.library; 2 | import org.bridj.Pointer; 3 | import org.bridj.StructObject; 4 | import org.bridj.ann.Field; 5 | import org.bridj.ann.Library; 6 | /** 7 | * This file was autogenerated by JNAerator,
8 | * a tool written by Olivier Chafik that uses a few opensource projects..
9 | * For help, please visit NativeLibs4Java or BridJ . 10 | */ 11 | @Library("OpenCL") 12 | public class cl_image_format extends StructObject { 13 | /** C type : cl_channel_order */ 14 | @Field(0) 15 | public int image_channel_order() { 16 | return this.io.getIntField(this, 0); 17 | } 18 | /** C type : cl_channel_order */ 19 | @Field(0) 20 | public cl_image_format image_channel_order(int image_channel_order) { 21 | this.io.setIntField(this, 0, image_channel_order); 22 | return this; 23 | } 24 | /** C type : cl_channel_type */ 25 | @Field(1) 26 | public int image_channel_data_type() { 27 | return this.io.getIntField(this, 1); 28 | } 29 | /** C type : cl_channel_type */ 30 | @Field(1) 31 | public cl_image_format image_channel_data_type(int image_channel_data_type) { 32 | this.io.setIntField(this, 1, image_channel_data_type); 33 | return this; 34 | } 35 | public cl_image_format() { 36 | super(); 37 | } 38 | public cl_image_format(Pointer pointer) { 39 | super(pointer); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/java/com/nativelibs4java/opencl/library/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Raw OpenCL API bindings. 3 | */ 4 | package com.nativelibs4java.opencl.library; 5 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/java/com/nativelibs4java/opencl/proxy/PointerUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package com.nativelibs4java.opencl.proxy; 6 | 7 | import org.bridj.NativeObject; 8 | import org.bridj.Pointer; 9 | import static org.bridj.Pointer.*; 10 | 11 | public class PointerUtils { 12 | 13 | protected static void setSizeT(long peer, long value) { 14 | pointerToAddress(peer).setSizeT(value); 15 | } 16 | 17 | protected static void setSizeTAtIndex(long peer, int index, long value) { 18 | pointerToAddress(peer).setSizeTAtIndex(index, value); 19 | } 20 | 21 | protected static void setPointerAtIndex(long peer, int index, Pointer value) { 22 | pointerToAddress(peer).setPointerAtIndex(index, value); 23 | } 24 | 25 | protected static void setPointerAtIndex(long peer, int index, NativeObject value) { 26 | pointerToAddress(peer).setSizeTAtIndex(index, Pointer.getPeer(Pointer.getPointer(value))); 27 | // pointerToAddress(peer).setSizeTAtIndex(index, Pointer.getPeer(Pointer.pointerTo(value))); 28 | } 29 | 30 | protected static long getSizeT(long peer) { 31 | return pointerToAddress(peer).getSizeT(); 32 | } 33 | 34 | protected static Pointer getPointer(long peer, Class targetClass) { 35 | return pointerToAddress(peer).getPointer(targetClass); 36 | } 37 | 38 | // public static Pointer getPointer(N instance) { 39 | // return pointerTo(instance); 40 | // } 41 | 42 | protected static void setInt(long peer, int value) { 43 | pointerToAddress(peer).setInt(value); 44 | } 45 | 46 | protected static int getInt(long peer) { 47 | return pointerToAddress(peer).getInt(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/jnaerator/OpenCL.MacOSX.jnaerator: -------------------------------------------------------------------------------- 1 | "$(DIR)/OpenCL.base.jnaerator" 2 | 3 | -DAVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER= 4 | -D__APPLE__= 5 | 6 | //-framework OpenCL 7 | 8 | //-framework OpenGL 9 | //-package com.nativelibs4java.opengl.library -framework OpenGL 10 | 11 | -v 12 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/jnaerator/OpenCL.OtherPlatforms.jnaerator: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/jnaerator/OpenCL.Win32ATIStream.jnaerator: -------------------------------------------------------------------------------- 1 | "$(DIR)/OpenCL.base.jnaerator" 2 | 3 | "-Dcl_bitfield=unsigned long" 4 | -library OpenCL 5 | "-D_MSC_VER=1" 6 | // "-D__CL_IMPORT=__declspec(dllimport)" 7 | "C:\Program Files\ATI Stream\include\CL\cl_platform.h" 8 | "-IC:\Program Files\ATI Stream\include" 9 | "C:\Program Files\ATI Stream\include\CL\cl.h" 10 | "C:\Program Files\ATI Stream\include\CL\cl_gl.h" 11 | 12 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/jnaerator/OpenCL.base.jnaerator: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/jnaerator/config-1.1.jnaerator: -------------------------------------------------------------------------------- 1 | -nocpp 2 | -noMangling 3 | -noJar -noComp 4 | -runtime BridJ 5 | 6 | -gccLong 7 | -limitComments 8 | 9 | "-Dextern=" 10 | "-D__stdcall=" 11 | "-D__declspec(x)=x" 12 | "-D__extension__=" 13 | 14 | -U_MSC_VER 15 | //-U__APPLE__ 16 | //-U__cplusplus 17 | //-U_WIN32 18 | -DCL_USE_DEPRECATED_OPENCL_1_0_APIS=1 19 | 20 | //-o "$(DIR)/../../../target/generated-sources/java" 21 | 22 | //-choicesOut "$(DIR)/OpenCL.choices" 23 | -v 24 | 25 | -package com.nativelibs4java.opencl.library 26 | -libraryNamingPrefixes cl 27 | -library OpenCL 28 | "-I$(DIR)/../headers/1.1" 29 | "$(DIR)/../headers/1.1/CL/cl_platform.h" 30 | "$(DIR)/../headers/1.1/CL/opencl.h" 31 | "$(DIR)/../headers/1.1/CL/cl.h" 32 | "$(DIR)/../headers/1.1/CL/cl_ext.h" 33 | "$(DIR)/../headers/1.1/CL/cl_gl.h" 34 | "$(DIR)/../headers/1.1/CL/cl_gl_ext.h" 35 | 36 | -onlineDoc "Khronos Documentation for {0}" "http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/{0}.html" 37 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/jnaerator/config-1.2.jnaerator: -------------------------------------------------------------------------------- 1 | -dontCastConstants 2 | 3 | -nocpp 4 | -noMangling 5 | //-noJar -noComp 6 | -runtime BridJ 7 | 8 | -parseInOnePiece 9 | -gccLong 10 | -limitComments 11 | 12 | "-Dextern=" 13 | "-D__stdcall=" 14 | "-D__declspec(x)=x" 15 | "-D__extension__=" 16 | 17 | -U_MSC_VER 18 | //-U__APPLE__ 19 | //-U__cplusplus 20 | //-U_WIN32 21 | -DCL_USE_DEPRECATED_OPENCL_1_0_APIS=1 22 | -DCL_USE_DEPRECATED_OPENCL_1_1_APIS=1 23 | -DCL_USE_DEPRECATED_OPENCL_1_2_APIS=1 24 | 25 | -v 26 | 27 | -package com.nativelibs4java.opencl.library 28 | -libraryNamingPrefixes cl 29 | -library OpenCL 30 | 31 | -skipStructs "cl_u?(double|float|int|char|short|long)\d*" 32 | -optionalFunctions "cl.+(KHR|EXT|APPLE)|clSetPrintfCallback" 33 | -noStaticInit 34 | -extractDeclarations IOpenCLLibrary 35 | "-I$(DIR)/../headers/1.2" 36 | //"$(DIR)/../headers/1.2/CL/cl_platform.h" 37 | "$(DIR)/../headers/1.2/CL/opencl.h" 38 | "$(DIR)/../headers/1.2/CL/cl_apple.h" 39 | 40 | //"$(DIR)/../headers/1.2/CL/cl.h" 41 | //"$(DIR)/../headers/1.2/CL/cl_ext.h" 42 | //"$(DIR)/../headers/1.2/CL/cl_gl.h" 43 | //"$(DIR)/../headers/1.2/CL/cl_gl_ext.h" 44 | //"$(DIR)/../headers/1.2/CL/t.h" 45 | 46 | 47 | -onlineDoc "Khronos Documentation for {0}" "http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/{0}.html" 48 | 49 | -optionalFunctions 50 | clCompileProgram|clCreateEventFromGLsyncKHR|clCreateFromGLTexture|clCreateImage|clCreateProgramWithBuiltInKernels|clCreateSubBuffer|clCreateSubDevices|clCreateSubDevicesEXT|clCreateUserEvent|clEnqueueBarrierWithWaitList|clEnqueueCopyBufferRect|clEnqueueFillBuffer|clEnqueueFillImage|clEnqueueMarkerWithWaitList|clEnqueueMigrateMemObjects|clEnqueueReadBufferRect|clEnqueueWriteBufferRect|clGetExtensionFunctionAddressForPlatform|clGetGLContextInfoAPPLE|clGetGLContextInfoAPPLE|clGetGLContextInfoKHR|clGetKernelArgInfo|clIcdGetPlatformIDsKHR|clLinkProgram|clLogMessagesToStderr|clLogMessagesToStderrAPPLE|clLogMessagesToStdout|clLogMessagesToStdoutAPPLE|clLogMessagesToSystemLog|clLogMessagesToSystemLogAPPLE|clReleaseDevice|clReleaseDeviceEXT|clRetainDevice|clRetainDeviceEXT|clSetEventCallback|clSetMemObjectCallbackFn|clSetMemObjectDestructorAPPLE|clSetMemObjectDestructorCallback|clSetPrintfCallback|clSetUserEventStatus|clUnloadPlatformCompiler 51 | -------------------------------------------------------------------------------- /OpenCL4Java/src/main/jnaerator/config.jnaerator: -------------------------------------------------------------------------------- 1 | "$(DIR)/config-1.2.jnaerator" 2 | -------------------------------------------------------------------------------- /OpenGLDemos/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /OpenGLDemos/javacl-opengl-demos-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /OpenGLDemos/javacl-opengl-demos.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /OpenGLDemos/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | com.nativelibs4java 6 | javacl-opengl-demos 7 | JavaCL OpenGL Demos / BridJ 8 | http://code.google.com/p/javacl/ 9 | jar 10 | 11 | 12 | true 13 | com.nativelibs4java.opencl.demos.particles.ParticlesDemo 14 | 15 | 16 | 17 | com.nativelibs4java 18 | javacl-parent 19 | 1.0-SNAPSHOT 20 | .. 21 | 22 | 23 | 24 | 25 | 26 | com.nativelibs4java 27 | javacl-demos 28 | 29 | 30 | 31 | org.jogamp.gluegen 32 | gluegen-rt-main 33 | 2.0.2-rc12 34 | 35 | 36 | org.jogamp.jogl 37 | jogl-all-main 38 | 2.0.2-rc12 39 | 40 | 41 | 42 | org.swinglabs 43 | swing-layout 44 | 1.0.3 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | com.nativelibs4java 53 | maven-javacl-plugin 54 | 55 | 56 | org.apache.maven.plugins 57 | maven-shade-plugin 58 | 59 | 60 | full-package 61 | package 62 | 63 | shade 64 | 65 | 66 | ${shadedArtifactAttached} 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /OpenGLDemos/src/main/opencl/com/nativelibs4java/opencl/demos/particles/HSVtoRGB.c: -------------------------------------------------------------------------------- 1 | 2 | // Copied from http://www.cs.rit.edu/~ncs/color/t_convert.html 3 | 4 | uchar4 HSVAtoRGBA(float4 hsva) 5 | { 6 | float h = hsva.x, s = hsva.y, v = hsva.z, a = hsva.w; 7 | float r, g, b; 8 | 9 | int i; 10 | float f, p, q, t; 11 | if (s == 0) { 12 | // achromatic (grey) 13 | r = g = b = v; 14 | return (uchar4)(r * 255, g * 255, b * 255, a * 255); 15 | } 16 | h /= 60; // sector 0 to 5 17 | i = floor( h ); 18 | f = h - i; // factorial part of h 19 | p = v * ( 1 - s ); 20 | q = v * ( 1 - s * f ); 21 | t = v * ( 1 - s * ( 1 - f ) ); 22 | switch( i ) { 23 | case 0: 24 | r = v; 25 | g = t; 26 | b = p; 27 | break; 28 | case 1: 29 | r = q; 30 | g = v; 31 | b = p; 32 | break; 33 | case 2: 34 | r = p; 35 | g = v; 36 | b = t; 37 | break; 38 | case 3: 39 | r = p; 40 | g = q; 41 | b = v; 42 | break; 43 | case 4: 44 | r = t; 45 | g = p; 46 | b = v; 47 | break; 48 | default: // case 5: 49 | r = v; 50 | g = p; 51 | b = q; 52 | break; 53 | } 54 | return (uchar4)(r * 255, g * 255, b * 255, a * 255); 55 | } -------------------------------------------------------------------------------- /Proxy/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.nativelibs4java 5 | opencl-impl-proxy 6 | JavalCL OpenCL Implementation Proxy 7 | http://code.google.com/p/javacl/ 8 | jar 9 | 10 | 11 | Native implementation of the OpenCL API (of its Icd) that relies on a Java proxy. 12 | That proxy channels implementations of com.nativelibs4java.opencl.library.IOpenCLLibrary discovered through the standard Java SPI discovery mechanism. 13 | This project also contains helpers to create such implementations. 14 | 15 | 16 | 17 | com.nativelibs4java 18 | javacl-parent 19 | 1.0-SNAPSHOT 20 | .. 21 | 22 | 23 | 24 | 25 | com.nativelibs4java 26 | opencl4java 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-jar-plugin 35 | 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-shade-plugin 40 | 41 | 42 | full-package 43 | package 44 | 45 | shade 46 | 47 | 48 | ${shadedArtifactAttached} 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Proxy/src/main/cpp/proxy/API.c: -------------------------------------------------------------------------------- 1 | #include "API.h" 2 | 3 | jclass gOpenCLProxyInterface = NULL; 4 | jmethodID gclGetPlatformIDsMethod = NULL; 5 | jobject gOpenCLProxyImplementation = NULL; 6 | 7 | #define PROXIED_CLASS_SIG "com/nativelibs4java/opencl/library/ProxiedOpenCLImplementation" 8 | 9 | void bindJavaAPI(void *instanceData) { 10 | jclass proxyClass = NULL; 11 | jmethodID getProxyInstanceMethod = NULL; 12 | jmethodID setIcdDispatchTableMethod = NULL; 13 | JNIEnv *env = GetEnv(); 14 | gOpenCLProxyInterface = GLOBAL_REF((*env)->FindClass(env, PROXY_INTERFACE_SIG)); 15 | gclGetPlatformIDsMethod = (*env)->GetMethodID(env, proxyClass, "clGetPlatformIDs", "(ILL)I"); 16 | 17 | proxyClass = (*env)->FindClass(env, PROXIED_CLASS_SIG); 18 | getProxyInstanceMethod = (*env)->GetStaticMethodID(env, proxyClass, "getInstance", "()L" PROXY_INTERFACE_SIG ";"); 19 | setIcdDispatchTableMethod = (*env)->GetStaticMethodID(env, proxyClass, "setIcdDispatchTable", "(L)V" PROXIED_CLASS_SIG ";"); 20 | 21 | (*env)->CallStaticVoidMethod(env, proxyClass, setIcdDispatchTableMethod, (jlong)(size_t)instanceData); 22 | gOpenCLProxyImplementation = GLOBAL_REF((*env)->CallStaticObjectMethod(env, proxyClass, getProxyInstanceMethod)); 23 | } 24 | 25 | void unbindJavaAPI() { 26 | JNIEnv *env = GetEnv(); 27 | DEL_GLOBAL_REF(gOpenCLProxyImplementation); 28 | DEL_GLOBAL_REF(gOpenCLProxyInterface); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Proxy/src/main/cpp/proxy/API.h: -------------------------------------------------------------------------------- 1 | #ifndef __JAVACL_PROXY_API_H 2 | #define __JAVACL_PROXY_API_H 3 | 4 | #ifdef __APPLE__ 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #include "Common.h" 11 | 12 | extern jclass gOpenCLProxyInterface; 13 | extern jmethodID gclGetPlatformIDsMethod; 14 | extern jobject gOpenCLProxyImplementation; 15 | 16 | void bindJavaAPI(void *instanceData); 17 | void unbindJavaAPI(); 18 | 19 | #endif // __JAVACL_PROXY_API_H 20 | -------------------------------------------------------------------------------- /Proxy/src/main/cpp/proxy/Common.h: -------------------------------------------------------------------------------- 1 | #ifndef __JAVACL_PROXY_COMMON_H 2 | #define __JAVACL_PROXY_COMMON_H 3 | 4 | // /System/Library/Frameworks/OpenCL.framework/Headers/cl.h 5 | // http://manpages.ubuntu.com/manpages/raring/man7/libOpenCL.7.html 6 | // http://www.khronos.org/registry/cl/extensions/khr/cl_khr_icd.txt 7 | // git clone https://forge.imag.fr/anonscm/git/ocl-icd/ocl-icd.git 8 | 9 | #include 10 | 11 | #ifdef __GNUC__ 12 | #define JAVACL_PROXY_API 13 | #define __cdecl 14 | #define __stdcall 15 | #else 16 | #ifdef JAVACL_PROXY_EXPORTS 17 | #define JAVACL_PROXY_API __declspec(dllexport) 18 | #else 19 | #define JAVACL_PROXY_API __declspec(dllimport) 20 | #endif 21 | #endif 22 | 23 | JNIEnv* GetEnv(); 24 | 25 | #define GLOBAL_REF(v) (*env)->NewGlobalRef(env, v) 26 | #define DEL_GLOBAL_REF(v) (*env)->DeleteGlobalRef(env, v) 27 | 28 | #define PROXY_INTERFACE_SIG "com/nativelibs4java/opencl/library/IOpenCLLibrary" 29 | 30 | struct _cl_icd_dispatch; 31 | 32 | #endif // __JAVACL_PROXY_COMMON_H 33 | -------------------------------------------------------------------------------- /Proxy/src/main/cpp/proxy/Library.c: -------------------------------------------------------------------------------- 1 | #include "Common.h" 2 | #include "API.h" 3 | #include "Proxy.h" 4 | 5 | JavaVM* gJVM = NULL; 6 | #define JNI_VERSION JNI_VERSION_1_4 7 | 8 | JNIEnv* GetEnv() { 9 | JNIEnv* env = NULL; 10 | if ((*gJVM)->GetEnv(gJVM, (void*)&env, JNI_VERSION) != JNI_OK) { 11 | if ((*gJVM)->AttachCurrentThreadAsDaemon(gJVM, (void*)&env, NULL) != JNI_OK) { 12 | printf("JavaCL Proxy: Cannot attach current JVM thread !\n"); 13 | return NULL; 14 | } 15 | } 16 | return env; 17 | } 18 | 19 | struct _cl_icd_dispatch dispatch; 20 | 21 | void createJVM() { 22 | JNIEnv *env; 23 | JavaVMInitArgs vm_args; 24 | JavaVMOption options; 25 | options.optionString = "-Djava.class.path=javacl-proxy.jar"; // TODO: change this 26 | vm_args.version = JNI_VERSION_1_6; 27 | vm_args.nOptions = 1; 28 | vm_args.options = &options; 29 | vm_args.ignoreUnrecognized = 0; 30 | JNI_CreateJavaVM(&gJVM, (void**)&env, &vm_args); 31 | // TODO: handle errors. 32 | } 33 | void initializeLibrary() { 34 | // Create JVM, based on env. OPENCL_PROXY_JAR 35 | createJVM(); 36 | 37 | // Bind classes and methods. 38 | bindJavaAPI(&gJavaCLProxyDispatch); 39 | } 40 | 41 | void cleanupLibrary() { 42 | // Unbind classes and methods 43 | unbindJavaAPI(); 44 | 45 | // Stop JVM 46 | (*gJVM)->DestroyJavaVM(gJVM); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Proxy/src/main/cpp/proxy/Proxy.h: -------------------------------------------------------------------------------- 1 | #ifndef __JAVACL_PROXY_PROXY_H 2 | #define __JAVACL_PROXY_PROXY_H 3 | 4 | struct _cl_icd_dispatch { 5 | void *funcptr[109]; 6 | }; 7 | 8 | extern struct _cl_icd_dispatch gJavaCLProxyDispatch; 9 | 10 | #endif // __JAVACL_PROXY_PROXY_H 11 | -------------------------------------------------------------------------------- /Proxy/src/main/cpp/proxy/build.sh: -------------------------------------------------------------------------------- 1 | export DYNCALL_HOME=../../../../../../BridJ/dyncall 2 | 3 | set -e 4 | 5 | cd $(dirname $0) 6 | CURR="`pwd`" 7 | 8 | export MAKE_CMD=make 9 | if [[ "`which gmake`" != "" ]] ; then 10 | export MAKE_CMD=gmake ; 11 | fi 12 | 13 | cd "$DYNCALL_HOME/dyncall" 14 | 15 | sh ./configure 16 | #if [[ -d /System/Library/Frameworks/ && ! -d /Applications/MobilePhone.app ]] ; then 17 | # # Avoid LC_DYLD_INFO (https://discussions.apple.com/thread/3197542?start=0&tstart=0) 18 | # export MACOSX_DEPLOYMENT_TARGET=10.4 19 | # sh ./configure --target-universal 20 | #else 21 | # sh ./configure 22 | #fi 23 | 24 | cd "$CURR" 25 | $MAKE_CMD $@ 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | __BEWARE__: _This project hasn't been maintained in many years. An effort to refresh the BridJ / JNAerator / JavaCL stack is in progress (Nov 2022), with no guarantees_. 2 | 3 | [![Maven Central](https://img.shields.io/maven-central/v/com.nativelibs4java/javacl.svg)]() [![Build Status](https://travis-ci.org/nativelibs4java/JavaCL.svg?branch=feature_travis-build)](https://travis-ci.org/nativelibs4java/JavaCL) [![Join the chat at https://gitter.im/nativelibs4java/JavaCL](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nativelibs4java/JavaCL?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | [JavaCL](http://javacl.googlecode.com) provides OpenCL bindings for Java. It wraps low-level bindings in a clean object-oriented API, which adds a few goodies. 6 | 7 | A comprehensive documentation is available on its [WebSite](http://javacl.googlecode.com) and [Wiki](https://code.google.com/p/javacl/wiki/FAQ?tm=6). 8 | 9 | It was previously hosted on [ochafik/nativelibs4java](http://github.com/ochafik/nativelibs4java). 10 | 11 | # Quick links 12 | 13 | * [CHANGELOG](./CHANGELOG.md) 14 | * [FAQ](http://code.google.com/p/javacl/wiki/FAQ) 15 | * [JavaDoc](http://nativelibs4java.sourceforge.net/javacl/api/stable/) 16 | * [Credits and License](http://code.google.com/p/bridj/wiki/CreditsAndLicense) 17 | 18 | # Building 19 | 20 | ``` 21 | git clone http://github.com/nativelibs4java/JavaCL.git 22 | mvn clean install 23 | ``` 24 | 25 | # Support 26 | 27 | Please use the [mailing-list](https://groups.google.com/forum/#!forum/nativelibs4java) and [file bugs](https://github.com/ochafik/nativelibs4java/issues/new). 28 | 29 | # TODO 30 | 31 | * Finalize OpenCL 1.2 support 32 | * Push a final 1.0 version 33 | -------------------------------------------------------------------------------- /Tutorials/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /Tutorials/DFT/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /Tutorials/DFT/javacl-dft-tutorial.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Tutorials/DFT/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.nativelibs4java 5 | javacl-dft-tutorial 6 | JavaCL Tutorial 7 | http://code.google.com/p/javacl/ 8 | jar 9 | 10 | 11 | com.nativelibs4java 12 | javacl-parent 13 | 1.0-SNAPSHOT 14 | ../.. 15 | 16 | 17 | 18 | 19 | com.nativelibs4java 20 | javacl 21 | 22 | 23 | org.apache.commons 24 | commons-math 25 | 2.2 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.nativelibs4java 33 | maven-javacl-plugin 34 | 35 | 36 | org.apache.maven.plugins 37 | maven-shade-plugin 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Tutorials/DFT/src/main/java/tutorial/DFT2.java: -------------------------------------------------------------------------------- 1 | package tutorial; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import java.io.IOException; 5 | import java.nio.DoubleBuffer; 6 | import org.bridj.Pointer; 7 | 8 | public class DFT2 { 9 | 10 | final CLQueue queue; 11 | final CLContext context; 12 | final DiscreteFourierTransformProgram program; 13 | 14 | public DFT2(CLQueue queue) throws IOException, CLBuildException { 15 | this.queue = queue; 16 | this.context = queue.getContext(); 17 | this.program = new DiscreteFourierTransformProgram(context); 18 | } 19 | 20 | public synchronized Pointer dft(Pointer in, boolean forward) throws CLBuildException { 21 | assert in.getValidElements() % 2 == 0; 22 | int length = (int)in.getValidElements() / 2; 23 | 24 | CLBuffer inBuf = context.createDoubleBuffer(CLMem.Usage.Input, in, true); // true = copy 25 | CLBuffer outBuf = context.createDoubleBuffer(CLMem.Usage.Output, length * 2); 26 | 27 | // The following call is type-safe, thanks to the JavaCL Maven generator : 28 | // (if the OpenCL function signature changes, the generated Java definition will be updated and compilation will fail) 29 | CLEvent dftEvt = program.dft(queue, inBuf, outBuf, length, forward ? 1 : -1, new int[]{length}, null); 30 | return outBuf.read(queue, dftEvt); 31 | } 32 | 33 | public double[] dft(double[] complexValues, boolean forward) throws CLBuildException { 34 | Pointer outBuffer = dft(Pointer.pointerToDoubles(complexValues), forward); 35 | return outBuffer.getDoubles(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Tutorials/DFT/src/main/opencl/tutorial/DiscreteFourierTransformProgram.c: -------------------------------------------------------------------------------- 1 | void dft( 2 | const double *in, // complex values input (packed real and imaginary) 3 | double *out, // complex values output 4 | int length, // number of input and output values 5 | int sign) // sign modifier in the exponential : 6 | // 1 for forward transform, -1 for backward. 7 | { 8 | for (int i = 0; i < length; i++) 9 | { 10 | // Initialize sum and inner arguments 11 | double totReal = 0, totImag = 0; 12 | double param = (-2 * sign * i) * M_PI / (double)length; 13 | 14 | for (int k = 0; k < length; k++) { 15 | double valueReal = in[k * 2], valueImag = in[k * 2 + 1]; 16 | double arg = k * param; 17 | double c = cos(arg), sin(arg); 18 | 19 | totReal += valueReal * c - valueImag * s; 20 | totImag += valueReal * s + valueImag * c; 21 | } 22 | 23 | if (sign == 1) { 24 | // forward transform (space -> frequential) 25 | out[i * 2] = totReal; 26 | out[i * 2 + 1] = totImag; 27 | } else { 28 | // backward transform (frequential -> space) 29 | out[i * 2] = totReal / (double)length; 30 | out[i * 2 + 1] = totImag / (double)length; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Tutorials/DFT/src/main/opencl/tutorial/DiscreteFourierTransformProgram.cl: -------------------------------------------------------------------------------- 1 | // Enable double-precision floating point numbers support. 2 | // Not all platforms / devices support this, so you may have to switch to floats. 3 | #pragma OPENCL EXTENSION cl_khr_fp64 : enable 4 | 5 | __kernel void dft( 6 | __global const double2 *in, // complex values input 7 | __global double2 *out, // complex values output 8 | int length, // number of input and output values 9 | int sign) // sign modifier in the exponential : 10 | // 1 for forward transform, -1 for backward. 11 | { 12 | // Get the varying parameter of the parallel execution : 13 | int i = get_global_id(0); 14 | 15 | // In case we're executed "too much", check bounds : 16 | if (i >= length) 17 | return; 18 | 19 | // Initialize sum and inner arguments 20 | double2 tot = 0; 21 | double param = (-2 * sign * i) * M_PI / (double)length; 22 | 23 | for (int k = 0; k < length; k++) { 24 | double2 value = in[k]; 25 | 26 | // Compute sin and cos in a single call : 27 | double c; 28 | double s = sincos(k * param, &c); 29 | 30 | // This adds (value.x * c - value.y * s, value.x * s + value.y * c) to the sum : 31 | tot += (double2)( 32 | dot(value, (double2)(c, -s)), 33 | dot(value, (double2)(s, c)) 34 | ); 35 | } 36 | 37 | if (sign == 1) { 38 | // forward transform (space -> frequential) 39 | out[i] = tot; 40 | } else { 41 | // backward transform (frequential -> space) 42 | out[i] = tot / (double)length; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Tutorials/Simple/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /Tutorials/Simple/javacl-simple-tutorial.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Tutorials/Simple/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.nativelibs4java 4 | javacl-simple-tutorial 5 | jar 6 | JavaCL Simple Tutorial Archetype 7 | 8 | 12 | 13 | 14 | com.nativelibs4java 15 | javacl-parent 16 | 1.0-SNAPSHOT 17 | ../.. 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Tutorials/Simple/src/main/resources/META-INF/maven/archetype-metadata.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | JavaCLTutorial 9 | 10 | 11 | 12 | com.mycompany 13 | 14 | 15 | 16 | com.mycompany 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | src/main/java 25 | 26 | **/*.java 27 | 28 | 29 | 30 | 31 | src/main/opencl 32 | 33 | **/*.cl 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Tutorials/Simple/src/main/resources/archetype-resources/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | project/boot 3 | project/target 4 | *~ 5 | -------------------------------------------------------------------------------- /Tutorials/Simple/src/main/resources/archetype-resources/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | JavaCL Tutorial 5 | ${groupId} 6 | ${artifactId} 7 | ${version} 8 | jar 9 | 10 | 11 | 12 | sonatype 13 | Sonatype OSS Snapshots Repository 14 | http://oss.sonatype.org/content/groups/public 15 | 16 | 17 | 18 | 19 | 20 | sonatype 21 | Sonatype OSS Snapshots Repository 22 | http://oss.sonatype.org/content/groups/public 23 | 24 | 25 | 26 | 27 | 28 | com.nativelibs4java 29 | javacl 30 | 1.0-SNAPSHOT 31 | 32 | 33 | 34 | 35 | 36 | 37 | 42 | com.nativelibs4java 43 | maven-javacl-plugin 44 | 1.0-SNAPSHOT 45 | 46 | 47 | 48 | compile 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Tutorials/Simple/src/main/resources/archetype-resources/src/main/java/JavaCLTutorial1.java: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import com.nativelibs4java.opencl.CLMem.Usage; 5 | import com.nativelibs4java.opencl.util.*; 6 | import com.nativelibs4java.util.*; 7 | import org.bridj.Pointer; 8 | import java.nio.ByteOrder; 9 | import static org.bridj.Pointer.*; 10 | import static java.lang.Math.*; 11 | import java.io.IOException; 12 | 13 | public class JavaCLTutorial1 { 14 | public static void main(String[] args) throws IOException { 15 | CLContext context = JavaCL.createBestContext(); 16 | CLQueue queue = context.createDefaultQueue(); 17 | ByteOrder byteOrder = context.getByteOrder(); 18 | 19 | int n = 1024; 20 | Pointer 21 | aPtr = allocateFloats(n).order(byteOrder), 22 | bPtr = allocateFloats(n).order(byteOrder); 23 | 24 | for (int i = 0; i < n; i++) { 25 | aPtr.set(i, (float)cos(i)); 26 | bPtr.set(i, (float)sin(i)); 27 | } 28 | 29 | // Create OpenCL input buffers (using the native memory pointers aPtr and bPtr) : 30 | CLBuffer 31 | a = context.createFloatBuffer(Usage.Input, aPtr), 32 | b = context.createFloatBuffer(Usage.Input, bPtr); 33 | 34 | // Create an OpenCL output buffer : 35 | CLBuffer out = context.createFloatBuffer(Usage.Output, n); 36 | 37 | // Read the program sources and compile them : 38 | String src = IOUtils.readText(JavaCLTutorial1.class.getResource("TutorialKernels.cl")); 39 | CLProgram program = context.createProgram(src); 40 | 41 | // Get and call the kernel : 42 | CLKernel addFloatsKernel = program.createKernel("add_floats"); 43 | addFloatsKernel.setArgs(a, b, out, n); 44 | int[] globalSizes = new int[] { n }; 45 | CLEvent addEvt = addFloatsKernel.enqueueNDRange(queue, globalSizes); 46 | 47 | Pointer outPtr = out.read(queue, addEvt); // blocks until add_floats finished 48 | 49 | // Print the first 10 output values : 50 | for (int i = 0; i < 10 && i < n; i++) 51 | System.out.println("out[" + i + "] = " + outPtr.get(i)); 52 | 53 | } 54 | } -------------------------------------------------------------------------------- /Tutorials/Simple/src/main/resources/archetype-resources/src/main/java/JavaCLTutorial2.java: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import com.nativelibs4java.opencl.CLMem.Usage; 5 | import com.nativelibs4java.opencl.util.*; 6 | import com.nativelibs4java.util.*; 7 | import org.bridj.Pointer; 8 | import java.nio.ByteOrder; 9 | import static org.bridj.Pointer.*; 10 | import static java.lang.Math.*; 11 | import java.io.IOException; 12 | 13 | public class JavaCLTutorial2 { 14 | public static void main(String[] args) throws IOException { 15 | CLContext context = JavaCL.createBestContext(); 16 | CLQueue queue = context.createDefaultQueue(); 17 | ByteOrder byteOrder = context.getByteOrder(); 18 | 19 | int n = 1024; 20 | Pointer 21 | aPtr = allocateFloats(n).order(byteOrder), 22 | bPtr = allocateFloats(n).order(byteOrder); 23 | 24 | for (int i = 0; i < n; i++) { 25 | aPtr.set(i, (float)cos(i)); 26 | bPtr.set(i, (float)sin(i)); 27 | } 28 | 29 | // Create OpenCL input buffers (using the native memory pointers aPtr and bPtr) : 30 | CLBuffer 31 | a = context.createFloatBuffer(Usage.Input, aPtr), 32 | b = context.createFloatBuffer(Usage.Input, bPtr); 33 | 34 | // Create an OpenCL output buffer : 35 | CLBuffer out = context.createFloatBuffer(Usage.Output, n); 36 | 37 | TutorialKernels kernels = new TutorialKernels(context); 38 | int[] globalSizes = new int[] { n }; 39 | CLEvent addEvt = kernels.add_floats(queue, a, b, out, n, globalSizes, null); 40 | 41 | Pointer outPtr = out.read(queue, addEvt); // blocks until add_floats finished 42 | 43 | // Print the first 10 output values : 44 | for (int i = 0; i < 10 && i < n; i++) 45 | System.out.println("out[" + i + "] = " + outPtr.get(i)); 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Tutorials/Simple/src/main/resources/archetype-resources/src/main/java/JavaCLTutorial3.java: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import com.nativelibs4java.opencl.*; 4 | import com.nativelibs4java.opencl.CLMem.Usage; 5 | import com.nativelibs4java.opencl.util.*; 6 | import com.nativelibs4java.util.*; 7 | import org.bridj.Pointer; 8 | import static org.bridj.Pointer.*; 9 | import static java.lang.Math.*; 10 | import java.io.IOException; 11 | 12 | public class JavaCLTutorial3 { 13 | public static void main(String[] args) throws IOException { 14 | CLContext context = JavaCL.createBestContext(); 15 | CLQueue queue = context.createDefaultQueue(); 16 | 17 | int n = 1024; 18 | 19 | // Create OpenCL input and output buffers 20 | CLBuffer 21 | a = context.createFloatBuffer(Usage.InputOutput, n), // a and b and read AND written to 22 | b = context.createFloatBuffer(Usage.InputOutput, n), 23 | out = context.createFloatBuffer(Usage.Output, n); 24 | 25 | TutorialKernels kernels = new TutorialKernels(context); 26 | int[] globalSizes = new int[] { n }; 27 | CLEvent fillEvt = kernels.fill_in_values(queue, a, b, n, globalSizes, null); 28 | CLEvent addEvt = kernels.add_floats(queue, a, b, out, n, globalSizes, null, fillEvt); 29 | 30 | Pointer outPtr = out.read(queue, addEvt); // blocks until add_floats finished 31 | 32 | // Print the first 10 output values : 33 | for (int i = 0; i < 10 && i < n; i++) 34 | System.out.println("out[" + i + "] = " + outPtr.get(i)); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Tutorials/Simple/src/main/resources/archetype-resources/src/main/opencl/TutorialKernels.cl: -------------------------------------------------------------------------------- 1 | __kernel void add_floats(__global const float* a, __global const float* b, __global float* out, int n) 2 | { 3 | int i = get_global_id(0); 4 | if (i >= n) 5 | return; 6 | 7 | out[i] = a[i] + b[i]; 8 | } 9 | 10 | __kernel void fill_in_values(__global float* a, __global float* b, int n) 11 | { 12 | int i = get_global_id(0); 13 | if (i >= n) 14 | return; 15 | 16 | a[i] = cos((float)i); 17 | b[i] = sin((float)i); 18 | } -------------------------------------------------------------------------------- /Tutorials/javacl-tutorials-root.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Tutorials/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.nativelibs4java 5 | javacl-tutorials-root 6 | pom 7 | JavaCL Tutorials Root / BridJ 8 | 9 | 10 | com.nativelibs4java 11 | javacl-parent 12 | 1.0-SNAPSHOT 13 | .. 14 | 15 | 16 | 17 | DFT 18 | Simple 19 | 20 | 21 | -------------------------------------------------------------------------------- /buildWebStartArtifacts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mvn -Pwebstart -Dstorepass=$KEYSTORE_PASS -DskipTests clean install || exit 1 4 | 5 | rm -fR target-webstart 6 | mkdir target-webstart 7 | cd target-webstart 8 | 9 | for SUB in InteractiveImageDemo Demos OpenGLDemos ; do 10 | cp ../$SUB/target/*-shaded.jar . || exit 1 11 | done 12 | 13 | open . 14 | open /Applications/Cyberduck.app/ || exit 1 15 | 16 | -------------------------------------------------------------------------------- /getJOGL: -------------------------------------------------------------------------------- 1 | 2 | BASE_URL="http://jogamp.org/deployment/webstart" 3 | OS_NAMES="macosx-universal linux-i586 linux-amd64 windows-i586 windows-amd64" 4 | 5 | mkdir jogl 6 | cd jogl 7 | 8 | for OS_NAME in $OS_NAMES ; do 9 | mkdir $OS_NAME 10 | cd $OS_NAME 11 | 12 | for N in gluegen-rt jogl.all nativewindow.all ; do 13 | wget $BASE_URL/$N.jar.gz 14 | gzip -d $N.jar.gz ; 15 | done 16 | 17 | for N in gluegen-rt jogl nativewindow ; do 18 | wget $BASE_URL/$N-natives-$OS_NAME.jar 19 | unzip $N-natives-$OS_NAME.jar 20 | rm $N-natives-$OS_NAME.jar 21 | rm -fR META-INF ; 22 | done 23 | 24 | zip ../jogl-$OS_NAME.zip * 25 | 26 | cd .. 27 | rm -fR $OS_NAME 28 | 29 | cp jogl-$OS_NAME.zip jogl-$OS_NAME-`date '+%Y%m%d'`.zip 30 | mv jogl-$OS_NAME.zip jogl-$OS_NAME-latest.zip ; 31 | done 32 | 33 | for OS_NAME in $OS_NAMES ; do 34 | echo "Platform $OS_NAME :" 35 | unzip -l jogl-$OS_NAME-latest.zip 36 | echo "" ; 37 | done 38 | -------------------------------------------------------------------------------- /opencl4java-root-bridj.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /opencl4java-root.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /runComp: -------------------------------------------------------------------------------- 1 | cd target/classes 2 | scala -classpath ~/.m2/repository/com/jnaerator/jnaerator-runtime/0.9.2-SNAPSHOT/jnaerator-runtime-0.9.2-SNAPSHOT.jar:. scalacl.ScalaCLTestRun 3 | -------------------------------------------------------------------------------- /runComp.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enabledelayedexpansion 3 | 4 | set M2REPO=\Users\Olivier\.m2\repository 5 | pushd . 6 | cd target\classes 7 | scala -classpath %M2REPO%\com\jnaerator\jnaerator-runtime\0.9.3-SNAPSHOT\jnaerator-runtime-0.9.3-SNAPSHOT.jar;. scalacl.ScalaCLTestRun 8 | 9 | popd 10 | --------------------------------------------------------------------------------