summaryrefslogtreecommitdiffstats
path: root/test/com/jogamp/opencl/LowLevelBindingTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/com/jogamp/opencl/LowLevelBindingTest.java')
-rw-r--r--test/com/jogamp/opencl/LowLevelBindingTest.java147
1 files changed, 76 insertions, 71 deletions
diff --git a/test/com/jogamp/opencl/LowLevelBindingTest.java b/test/com/jogamp/opencl/LowLevelBindingTest.java
index ef14534a..84aaa73e 100644
--- a/test/com/jogamp/opencl/LowLevelBindingTest.java
+++ b/test/com/jogamp/opencl/LowLevelBindingTest.java
@@ -33,6 +33,11 @@ import java.util.Random;
import com.jogamp.common.nio.PointerBuffer;
import com.jogamp.opencl.llb.impl.BuildProgramCallback;
import com.jogamp.opencl.llb.CL;
+import com.jogamp.opencl.llb.CLContextBinding;
+import com.jogamp.opencl.llb.CLDeviceBinding;
+import com.jogamp.opencl.llb.CLMemObjBinding;
+import com.jogamp.opencl.llb.CLPlatformBinding;
+import com.jogamp.opencl.llb.CLProgramBinding;
import com.jogamp.opencl.test.util.MiscUtils;
import com.jogamp.opencl.test.util.UITestCase;
@@ -104,64 +109,64 @@ public class LowLevelBindingTest extends UITestCase {
out.println(" - - - lowLevelTest; contextless binding - - - ");
- CL cl = CLPlatform.getLowLevelCLInterface();
+ final CL cl = CLPlatform.getLowLevelCLInterface();
// System.out.println(((CLImpl)cl).clGetExtensionFunctionAddress("clCreateFromGLBuffer"));
// System.out.println(((CLImpl)cl).clGetExtensionFunctionAddress("clEnqueueAcquireGLObjects"));
int ret = CL.CL_SUCCESS;
- IntBuffer intBuffer = newDirectIntBuffer(1);
+ final IntBuffer intBuffer = newDirectIntBuffer(1);
// find all available OpenCL platforms
ret = cl.clGetPlatformIDs(0, null, intBuffer);
checkForError(ret);
out.println("#platforms: "+intBuffer.get(0));
- PointerBuffer platformId = PointerBuffer.allocateDirect(intBuffer.get(0));
+ final PointerBuffer platformId = PointerBuffer.allocateDirect(intBuffer.get(0));
ret = cl.clGetPlatformIDs(platformId.capacity(), platformId, null);
checkForError(ret);
// print platform info
- PointerBuffer longBuffer = PointerBuffer.allocateDirect(1);
- ByteBuffer bb = newDirectByteBuffer(128);
+ final PointerBuffer longBuffer = PointerBuffer.allocateDirect(1);
+ final ByteBuffer bb = newDirectByteBuffer(128);
for (int i = 0; i < platformId.capacity(); i++) {
- long platform = platformId.get(i);
+ final long platform = platformId.get(i);
out.println("platform id: "+platform);
- ret = cl.clGetPlatformInfo(platform, CL.CL_PLATFORM_PROFILE, bb.capacity(), bb, longBuffer);
+ ret = cl.clGetPlatformInfo(platform, CLPlatformBinding.CL_PLATFORM_PROFILE, bb.capacity(), bb, longBuffer);
checkForError(ret);
out.println(" profile: " + clString2JavaString(bb, (int)longBuffer.get(0)));
- ret = cl.clGetPlatformInfo(platform, CL.CL_PLATFORM_VERSION, bb.capacity(), bb, longBuffer);
+ ret = cl.clGetPlatformInfo(platform, CLPlatformBinding.CL_PLATFORM_VERSION, bb.capacity(), bb, longBuffer);
checkForError(ret);
out.println(" version: " + clString2JavaString(bb, (int)longBuffer.get(0)));
- ret = cl.clGetPlatformInfo(platform, CL.CL_PLATFORM_NAME, bb.capacity(), bb, longBuffer);
+ ret = cl.clGetPlatformInfo(platform, CLPlatformBinding.CL_PLATFORM_NAME, bb.capacity(), bb, longBuffer);
checkForError(ret);
out.println(" name: " + clString2JavaString(bb, (int)longBuffer.get(0)));
- ret = cl.clGetPlatformInfo(platform, CL.CL_PLATFORM_VENDOR, bb.capacity(), bb, longBuffer);
+ ret = cl.clGetPlatformInfo(platform, CLPlatformBinding.CL_PLATFORM_VENDOR, bb.capacity(), bb, longBuffer);
checkForError(ret);
out.println(" vendor: " + clString2JavaString(bb, (int)longBuffer.get(0)));
//find all devices
- ret = cl.clGetDeviceIDs(platform, CL.CL_DEVICE_TYPE_ALL, 0, null, intBuffer);
+ ret = cl.clGetDeviceIDs(platform, CLDeviceBinding.CL_DEVICE_TYPE_ALL, 0, null, intBuffer);
checkForError(ret);
out.println("#devices: "+intBuffer.get(0));
- PointerBuffer devices = PointerBuffer.allocateDirect(intBuffer.get(0));
- ret = cl.clGetDeviceIDs(platform, CL.CL_DEVICE_TYPE_ALL, devices.capacity(), devices, null);
+ final PointerBuffer devices = PointerBuffer.allocateDirect(intBuffer.get(0));
+ ret = cl.clGetDeviceIDs(platform, CLDeviceBinding.CL_DEVICE_TYPE_ALL, devices.capacity(), devices, null);
//print device info
for (int j = 0; j < devices.capacity(); j++) {
- long device = devices.get(j);
- ret = cl.clGetDeviceInfo(device, CL.CL_DEVICE_NAME, bb.capacity(), bb, longBuffer);
+ final long device = devices.get(j);
+ ret = cl.clGetDeviceInfo(device, CLDeviceBinding.CL_DEVICE_NAME, bb.capacity(), bb, longBuffer);
checkForError(ret);
out.println(" device: " + clString2JavaString(bb, (int)longBuffer.get(0)));
- ret = cl.clGetDeviceInfo(device, CL.CL_DEVICE_TYPE, bb.capacity(), bb, longBuffer);
+ ret = cl.clGetDeviceInfo(device, CLDeviceBinding.CL_DEVICE_TYPE, bb.capacity(), bb, longBuffer);
checkForError(ret);
out.println(" type: " + CLDevice.Type.valueOf(bb.get()));
bb.rewind();
@@ -176,37 +181,37 @@ public class LowLevelBindingTest extends UITestCase {
out.println(" - - - createContextTest - - - ");
- CL cl = CLPlatform.getLowLevelCLInterface();
+ final CL cl = CLPlatform.getLowLevelCLInterface();
- IntBuffer intBuffer = newDirectIntBuffer(1);
+ final IntBuffer intBuffer = newDirectIntBuffer(1);
// find all available OpenCL platforms
int ret = cl.clGetPlatformIDs(0, null, intBuffer);
checkForError(ret);
out.println("#platforms: "+intBuffer.get(0));
- PointerBuffer pb = PointerBuffer.allocateDirect(intBuffer.get(0));
+ final PointerBuffer pb = PointerBuffer.allocateDirect(intBuffer.get(0));
ret = cl.clGetPlatformIDs(pb.capacity(), pb, null);
checkForError(ret);
- long platform = pb.get(0);
+ final long platform = pb.get(0);
//find all devices
- ret = cl.clGetDeviceIDs(platform, CL.CL_DEVICE_TYPE_ALL, 0, null, intBuffer);
+ ret = cl.clGetDeviceIDs(platform, CLDeviceBinding.CL_DEVICE_TYPE_ALL, 0, null, intBuffer);
checkForError(ret);
out.println("#devices: "+intBuffer.get(0));
- PointerBuffer devices = PointerBuffer.allocateDirect(intBuffer.get(0));
- ret = cl.clGetDeviceIDs(platform, CL.CL_DEVICE_TYPE_ALL, devices.capacity(), devices, null);
+ final PointerBuffer devices = PointerBuffer.allocateDirect(intBuffer.get(0));
+ ret = cl.clGetDeviceIDs(platform, CLDeviceBinding.CL_DEVICE_TYPE_ALL, devices.capacity(), devices, null);
- long context = cl.clCreateContext(null, devices, null, intBuffer);
+ final long context = cl.clCreateContext(null, devices, null, intBuffer);
checkError("on clCreateContext", intBuffer.get());
//get number of devices
- PointerBuffer longBuffer = PointerBuffer.allocateDirect(1);
- ret = cl.clGetContextInfo(context, CL.CL_CONTEXT_DEVICES, 0, null, longBuffer);
+ final PointerBuffer longBuffer = PointerBuffer.allocateDirect(1);
+ ret = cl.clGetContextInfo(context, CLContextBinding.CL_CONTEXT_DEVICES, 0, null, longBuffer);
checkError("on clGetContextInfo", ret);
- long contextDevices = longBuffer.get(0)/(is32Bit()?4:8);
+ final long contextDevices = longBuffer.get(0)/(is32Bit()?4:8);
out.println("context created on " + contextDevices + " devices");
//check if equal
@@ -221,40 +226,40 @@ public class LowLevelBindingTest extends UITestCase {
out.println(" - - - lowLevelTest2; VectorAdd kernel - - - ");
- CL cl = CLPlatform.getLowLevelCLInterface();
+ final CL cl = CLPlatform.getLowLevelCLInterface();
int ret = CL.CL_SUCCESS;
- IntBuffer intBuffer = newDirectIntBuffer(1);
+ final IntBuffer intBuffer = newDirectIntBuffer(1);
// find all available OpenCL platforms
ret = cl.clGetPlatformIDs(0, null, intBuffer);
checkForError(ret);
assertTrue(intBuffer.get(0) > 0);
- PointerBuffer pb = PointerBuffer.allocateDirect(intBuffer.get(0));
+ final PointerBuffer pb = PointerBuffer.allocateDirect(intBuffer.get(0));
ret = cl.clGetPlatformIDs(pb.capacity(), pb, null);
checkForError(ret);
- long platform = pb.get(0);
- PointerBuffer properties = PointerBuffer.allocateDirect(3).put(CL.CL_CONTEXT_PLATFORM)
+ final long platform = pb.get(0);
+ final PointerBuffer properties = PointerBuffer.allocateDirect(3).put(CLContextBinding.CL_CONTEXT_PLATFORM)
.put(platform).put(0) // 0 terminated array
.rewind();
- long context = cl.clCreateContextFromType(properties, CL.CL_DEVICE_TYPE_ALL, null, null);
+ final long context = cl.clCreateContextFromType(properties, CLDeviceBinding.CL_DEVICE_TYPE_ALL, null, null);
out.println("context handle: "+context);
checkError("on clCreateContextFromType", ret);
- PointerBuffer longBuffer = PointerBuffer.allocateDirect(1);
- ret = cl.clGetContextInfo(context, CL.CL_CONTEXT_DEVICES, 0, null, longBuffer);
+ final PointerBuffer longBuffer = PointerBuffer.allocateDirect(1);
+ ret = cl.clGetContextInfo(context, CLContextBinding.CL_CONTEXT_DEVICES, 0, null, longBuffer);
checkError("on clGetContextInfo", ret);
- int deviceCount = (int) (longBuffer.get(0) / (is32Bit() ? 4 : 8));
+ final int deviceCount = (int) (longBuffer.get(0) / (is32Bit() ? 4 : 8));
out.println("context created with " + deviceCount + " devices");
// Was originally 4096, but had to make this bigger or it would crash in UITestCase.oneTimeTearDown(){ System.gc() }
// without even dumping a stack when using AMD drivers. Presumably the drivers would write past the end
// of the block and mess up GC info somehow.
- ByteBuffer bb = newDirectByteBuffer(32768);
- ret = cl.clGetContextInfo(context, CL.CL_CONTEXT_DEVICES, bb.capacity(), bb, null);
+ final ByteBuffer bb = newDirectByteBuffer(32768);
+ ret = cl.clGetContextInfo(context, CLContextBinding.CL_CONTEXT_DEVICES, bb.capacity(), bb, null);
checkError("on clGetContextInfo", ret);
for (int i = 0; i < deviceCount; i++) {
@@ -265,19 +270,19 @@ public class LowLevelBindingTest extends UITestCase {
int offset = new Random().nextInt(deviceCount);
out.println("using device# " + offset);
offset *= (is32Bit() ? 4 : 8);
- long device = is32Bit()?bb.getInt(offset):bb.getLong(offset);
+ final long device = is32Bit()?bb.getInt(offset):bb.getLong(offset);
bb.rewind();
- ret = cl.clGetDeviceInfo(device, CL.CL_DEVICE_MAX_WORK_GROUP_SIZE, bb.capacity(), bb, null);
+ ret = cl.clGetDeviceInfo(device, CLDeviceBinding.CL_DEVICE_MAX_WORK_GROUP_SIZE, bb.capacity(), bb, null);
checkError("on clGetDeviceInfo", ret);
- int maxWGS = bb.getInt();
+ final int maxWGS = bb.getInt();
out.println("max WGS: " + maxWGS);
// Create a command-queue
- long commandQueue = cl.clCreateCommandQueue(context, device, 0, intBuffer);
+ final long commandQueue = cl.clCreateCommandQueue(context, device, 0, intBuffer);
checkError("on clCreateCommandQueue", intBuffer.get(0));
- int localWorkSize = Math.min(128, maxWGS); // set and log Global and Local work size dimensions
+ final int localWorkSize = Math.min(128, maxWGS); // set and log Global and Local work size dimensions
int elementCount = ELEMENT_COUNT;
int globalWorkSize = 0;
@@ -296,7 +301,7 @@ public class LowLevelBindingTest extends UITestCase {
dest = newDirectByteBuffer(globalWorkSize*SIZEOF_INT);
allocated = true;
}
- catch( OutOfMemoryError oome ) {
+ catch( final OutOfMemoryError oome ) {
++divisor;
elementCount /= divisor;
out.println("not enough direct buffer memory; retrying with smaller buffers");
@@ -304,25 +309,25 @@ public class LowLevelBindingTest extends UITestCase {
}
// Allocate the OpenCL buffer memory objects for source and result on the device GMEM
- long devSrcA = cl.clCreateBuffer(context, CL.CL_MEM_READ_ONLY, srcA.capacity(), null, intBuffer);
+ final long devSrcA = cl.clCreateBuffer(context, CLMemObjBinding.CL_MEM_READ_ONLY, srcA.capacity(), null, intBuffer);
checkError("on clCreateBuffer", intBuffer.get(0));
- long devSrcB = cl.clCreateBuffer(context, CL.CL_MEM_READ_ONLY, srcB.capacity(), null, intBuffer);
+ final long devSrcB = cl.clCreateBuffer(context, CLMemObjBinding.CL_MEM_READ_ONLY, srcB.capacity(), null, intBuffer);
checkError("on clCreateBuffer", intBuffer.get(0));
- long devDst = cl.clCreateBuffer(context, CL.CL_MEM_WRITE_ONLY, dest.capacity(), null, intBuffer);
+ final long devDst = cl.clCreateBuffer(context, CLMemObjBinding.CL_MEM_WRITE_ONLY, dest.capacity(), null, intBuffer);
checkError("on clCreateBuffer", intBuffer.get(0));
// Create the program
- PointerBuffer lengths = PointerBuffer.allocateDirect(1).put(programSource.length()).rewind();
+ final PointerBuffer lengths = PointerBuffer.allocateDirect(1).put(programSource.length()).rewind();
final long program = cl.clCreateProgramWithSource(context, 1, new String[] {programSource}, lengths, intBuffer);
out.println("program id: "+program);
checkError("on clCreateProgramWithSource", intBuffer.get(0));
// tests if the callback is called
final CountDownLatch latch = new CountDownLatch(1);
- BuildProgramCallback callback = new BuildProgramCallback() {
+ final BuildProgramCallback callback = new BuildProgramCallback() {
@Override
- public void buildFinished(long cl_program) {
+ public void buildFinished(final long cl_program) {
try{
assertEquals(program, cl_program);
}finally{
@@ -344,40 +349,40 @@ public class LowLevelBindingTest extends UITestCase {
// Read program infos
bb.rewind();
- ret = cl.clGetProgramInfo(program, CL.CL_PROGRAM_NUM_DEVICES, bb.capacity(), bb, null);
+ ret = cl.clGetProgramInfo(program, CLProgramBinding.CL_PROGRAM_NUM_DEVICES, bb.capacity(), bb, null);
checkError("on clGetProgramInfo1", ret);
out.println("program associated with "+bb.getInt(0)+" device(s)");
- ret = cl.clGetProgramInfo(program, CL.CL_PROGRAM_SOURCE, 0, null, longBuffer);
+ ret = cl.clGetProgramInfo(program, CLProgramBinding.CL_PROGRAM_SOURCE, 0, null, longBuffer);
checkError("on clGetProgramInfo CL_PROGRAM_SOURCE", ret);
out.println("program source length (cl): "+longBuffer.get(0));
out.println("program source length (java): "+programSource.length());
bb.rewind();
- ret = cl.clGetProgramInfo(program, CL.CL_PROGRAM_SOURCE, bb.capacity(), bb, null);
+ ret = cl.clGetProgramInfo(program, CLProgramBinding.CL_PROGRAM_SOURCE, bb.capacity(), bb, null);
checkError("on clGetProgramInfo CL_PROGRAM_SOURCE", ret);
out.println("program source:\n" + clString2JavaString(bb, (int)longBuffer.get(0)));
// Check program status
bb.rewind();
- ret = cl.clGetProgramBuildInfo(program, device, CL.CL_PROGRAM_BUILD_STATUS, bb.capacity(), bb, null);
+ ret = cl.clGetProgramBuildInfo(program, device, CLProgramBinding.CL_PROGRAM_BUILD_STATUS, bb.capacity(), bb, null);
checkError("on clGetProgramBuildInfo1", ret);
out.println("program build status: " + CLProgram.Status.valueOf(bb.getInt(0)));
- assertEquals("build status", CL.CL_BUILD_SUCCESS, bb.getInt(0));
+ assertEquals("build status", CLProgramBinding.CL_BUILD_SUCCESS, bb.getInt(0));
// Read build log
- ret = cl.clGetProgramBuildInfo(program, device, CL.CL_PROGRAM_BUILD_LOG, 0, null, longBuffer);
+ ret = cl.clGetProgramBuildInfo(program, device, CLProgramBinding.CL_PROGRAM_BUILD_LOG, 0, null, longBuffer);
checkError("on clGetProgramBuildInfo2", ret);
out.println("program log length: " + longBuffer.get(0));
bb.rewind();
- ret = cl.clGetProgramBuildInfo(program, device, CL.CL_PROGRAM_BUILD_LOG, bb.capacity(), bb, null);
+ ret = cl.clGetProgramBuildInfo(program, device, CLProgramBinding.CL_PROGRAM_BUILD_LOG, bb.capacity(), bb, null);
checkError("on clGetProgramBuildInfo3", ret);
out.println("log:\n" + clString2JavaString(bb, (int)longBuffer.get(0)));
// Create the kernel
- long kernel = cl.clCreateKernel(program, "VectorAdd", intBuffer);
+ final long kernel = cl.clCreateKernel(program, "VectorAdd", intBuffer);
out.println("kernel id: "+kernel);
checkError("on clCreateKernel", intBuffer.get(0));
@@ -402,8 +407,8 @@ public class LowLevelBindingTest extends UITestCase {
checkError("on clEnqueueWriteBuffer", ret);
// Launch kernel
- PointerBuffer gWS = PointerBuffer.allocateDirect(1).put(globalWorkSize).rewind();
- PointerBuffer lWS = PointerBuffer.allocateDirect(1).put(localWorkSize).rewind();
+ final PointerBuffer gWS = PointerBuffer.allocateDirect(1).put(globalWorkSize).rewind();
+ final PointerBuffer lWS = PointerBuffer.allocateDirect(1).put(localWorkSize).rewind();
ret = cl.clEnqueueNDRangeKernel(commandQueue, kernel, 1, null, gWS, lWS, 0, null, null);
checkError("on clEnqueueNDRangeKernel", ret);
@@ -447,8 +452,8 @@ public class LowLevelBindingTest extends UITestCase {
//for memory leak detection; e.g watch out for "out of host memory" errors
out.println(" - - - loadTest - - - ");
- ExecutorService pool = Executors.newFixedThreadPool(8);
- List<Callable<Object>> tasks = new ArrayList<Callable<Object>>();
+ final ExecutorService pool = Executors.newFixedThreadPool(8);
+ final List<Callable<Object>> tasks = new ArrayList<Callable<Object>>();
for(int i = 0; i < 100; i++) {
final int n = i;
@@ -457,11 +462,11 @@ public class LowLevelBindingTest extends UITestCase {
public Object call() {
try {
out.println("###start iteration " + n);
- LowLevelBindingTest test = new LowLevelBindingTest();
+ final LowLevelBindingTest test = new LowLevelBindingTest();
test.ELEMENT_COUNT = 123456;
test.lowLevelVectorAddTest();
out.println("###end iteration " + n);
- } catch (InterruptedException ex) {
+ } catch (final InterruptedException ex) {
throw new RuntimeException(ex);
}
return null;
@@ -469,10 +474,10 @@ public class LowLevelBindingTest extends UITestCase {
});
}
- for (Future<Object> future : pool.invokeAll(tasks)) {
+ for (final Future<Object> future : pool.invokeAll(tasks)) {
try {
future.get();
- } catch (ExecutionException ex) {
+ } catch (final ExecutionException ex) {
ex.printStackTrace();
pool.shutdown();
fail();
@@ -482,21 +487,21 @@ public class LowLevelBindingTest extends UITestCase {
pool.awaitTermination(300, TimeUnit.SECONDS);
}
- private ByteBuffer wrap(long value) {
+ private ByteBuffer wrap(final long value) {
return (ByteBuffer) newDirectByteBuffer(8).putLong(value).rewind();
}
- private void checkForError(int ret) {
+ private void checkForError(final int ret) {
this.checkError("", ret);
}
- private void checkError(String msg, int ret) {
+ private void checkError(final String msg, final int ret) {
if(ret != CL.CL_SUCCESS)
throw CLException.newException(ret, msg);
}
- public static void main(String[] args) throws IOException {
- String tstname = LowLevelBindingTest.class.getName();
+ public static void main(final String[] args) throws IOException {
+ final String tstname = LowLevelBindingTest.class.getName();
org.junit.runner.JUnitCore.main(tstname);
}