diff options
author | Michael Bien <[email protected]> | 2010-03-30 17:19:15 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-03-30 17:19:15 +0200 |
commit | 9ec0937d729faade497a3d2a394f76992dcdaa45 (patch) | |
tree | 5ae54ffaf676f988609e66f6a88858f468f296bf /src | |
parent | 8b6228d7978c515d1d8de160c45fe52b77874779 (diff) |
refactorings due to newly introduced Int64Buffer in gluegen.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/mbien/opencl/CLCommandQueue.java | 146 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLContext.java | 10 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLDevice.java | 8 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLEvent.java | 6 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLImage.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLInfoAccessor.java | 20 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLKernel.java | 12 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLPlatform.java | 8 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLProgram.java | 63 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLSampler.java | 3 |
10 files changed, 149 insertions, 131 deletions
diff --git a/src/com/mbien/opencl/CLCommandQueue.java b/src/com/mbien/opencl/CLCommandQueue.java index aca7cf6f..b1f43c50 100644 --- a/src/com/mbien/opencl/CLCommandQueue.java +++ b/src/com/mbien/opencl/CLCommandQueue.java @@ -1,5 +1,6 @@ package com.mbien.opencl; +import com.jogamp.gluegen.runtime.Int64Buffer; import com.mbien.opencl.gl.CLGLI; import com.jogamp.gluegen.runtime.PointerBuffer; import java.nio.ByteBuffer; @@ -30,9 +31,10 @@ public class CLCommandQueue extends CLObject implements CLResource { /* * Those direct memory buffers are used to move data between the JVM and OpenCL. */ - private final PointerBuffer bufferA; - private final PointerBuffer bufferB; - private final PointerBuffer bufferC; + private final PointerBuffer pbA; + private final Int64Buffer ibA; + private final Int64Buffer ibB; + private final Int64Buffer ibC; private CLCommandQueue(CLContext context, long id, CLDevice device, long properties) { super(context, id); @@ -40,9 +42,11 @@ public class CLCommandQueue extends CLObject implements CLResource { this.device = device; this.properties = properties; - this.bufferA = PointerBuffer.allocateDirect(3); - this.bufferB = PointerBuffer.allocateDirect(3); - this.bufferC = PointerBuffer.allocateDirect(3); + this.ibA = Int64Buffer.allocateDirect(3); + this.ibB = Int64Buffer.allocateDirect(3); + this.ibC = Int64Buffer.allocateDirect(3); + + this.pbA = PointerBuffer.wrap(ibA.getBuffer()); } @@ -231,11 +235,11 @@ public class CLCommandQueue extends CLObject implements CLResource { // spec: CL_INVALID_VALUE if image is a 2D image object and origin[2] is not equal to 0 // or region[2] is not equal to 1 or slice_pitch is not equal to 0. - copy2NIO(bufferA, originX, originY, 0); - copy2NIO(bufferB, rangeX, rangeY, 1); + copy2NIO(ibA, originX, originY, 0); + copy2NIO(ibB, rangeX, rangeY, 1); int ret = cl.clEnqueueWriteImage(ID, writeImage.ID, clBoolean(blockingWrite), - bufferA, bufferB, inputRowPitch, 0, writeImage.buffer, + ibA, ibB, inputRowPitch, 0, writeImage.buffer, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not write Image"); @@ -288,11 +292,11 @@ public class CLCommandQueue extends CLObject implements CLResource { conditions = condition.size; } - copy2NIO(bufferA, originX, originY, originZ); - copy2NIO(bufferB, rangeX, rangeY, rangeZ); + copy2NIO(ibA, originX, originY, originZ); + copy2NIO(ibB, rangeX, rangeY, rangeZ); int ret = cl.clEnqueueWriteImage(ID, writeImage.ID, clBoolean(blockingWrite), - bufferA, bufferB, inputRowPitch, inputSlicePitch, writeImage.buffer, + ibA, ibB, inputRowPitch, inputSlicePitch, writeImage.buffer, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not write Image"); @@ -347,11 +351,11 @@ public class CLCommandQueue extends CLObject implements CLResource { // spec: CL_INVALID_VALUE if image is a 2D image object and origin[2] is not equal to 0 // or region[2] is not equal to 1 or slice_pitch is not equal to 0. - copy2NIO(bufferA, originX, originY, 0); - copy2NIO(bufferB, rangeX, rangeY, 1); + copy2NIO(ibA, originX, originY, 0); + copy2NIO(ibB, rangeX, rangeY, 1); int ret = cl.clEnqueueReadImage(ID, readImage.ID, clBoolean(blockingRead), - bufferA, bufferB, inputRowPitch, 0, readImage.buffer, + ibA, ibB, inputRowPitch, 0, readImage.buffer, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not read Image"); @@ -404,11 +408,11 @@ public class CLCommandQueue extends CLObject implements CLResource { conditions = condition.size; } - copy2NIO(bufferA, originX, originY, originZ); - copy2NIO(bufferB, rangeX, rangeY, rangeZ); + copy2NIO(ibA, originX, originY, originZ); + copy2NIO(ibB, rangeX, rangeY, rangeZ); int ret = cl.clEnqueueReadImage(ID, readImage.ID, clBoolean(blockingRead), - bufferA, bufferB, inputRowPitch, inputSlicePitch, readImage.buffer, + ibA, ibB, inputRowPitch, inputSlicePitch, readImage.buffer, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not read Image"); @@ -467,11 +471,11 @@ public class CLCommandQueue extends CLObject implements CLResource { //spec: CL_INVALID_VALUE if src_image is a 2D image object and origin[2] or dst_origin[2] is not equal to 0 // or region[2] is not equal to 1. - copy2NIO(bufferA, srcOriginX, srcOriginY, 0); - copy2NIO(bufferB, dstOriginX, dstOriginY, 0); - copy2NIO(bufferC, rangeX, rangeY, 1); + copy2NIO(ibA, srcOriginX, srcOriginY, 0); + copy2NIO(ibB, dstOriginX, dstOriginY, 0); + copy2NIO(ibC, rangeX, rangeY, 1); - int ret = cl.clEnqueueCopyImage(ID, srcImage.ID, dstImage.ID, bufferA, bufferB, bufferC, + int ret = cl.clEnqueueCopyImage(ID, srcImage.ID, dstImage.ID, ibA, ibB, ibC, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not copy Image"); @@ -530,11 +534,11 @@ public class CLCommandQueue extends CLObject implements CLResource { conditions = condition.size; } - copy2NIO(bufferA, srcOriginX, srcOriginY, srcOriginZ); - copy2NIO(bufferB, dstOriginX, dstOriginY, dstOriginZ); - copy2NIO(bufferC, rangeX, rangeY, rangeZ); + copy2NIO(ibA, srcOriginX, srcOriginY, srcOriginZ); + copy2NIO(ibB, dstOriginX, dstOriginY, dstOriginZ); + copy2NIO(ibC, rangeX, rangeY, rangeZ); - int ret = cl.clEnqueueCopyImage(ID, srcImage.ID, dstImage.ID, bufferA, bufferB, bufferC, + int ret = cl.clEnqueueCopyImage(ID, srcImage.ID, dstImage.ID, ibA, ibB, ibC, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not copy Image"); @@ -592,11 +596,11 @@ public class CLCommandQueue extends CLObject implements CLResource { // spec: CL_INVALID_VALUE if dst_image is a 2D image object and dst_origin[2] is not equal to 0 // or region[2] is not equal to 1. - copy2NIO(bufferA, dstOriginX, dstOriginY, 0); - copy2NIO(bufferB, rangeX, rangeY, 1); + copy2NIO(ibA, dstOriginX, dstOriginY, 0); + copy2NIO(ibB, rangeX, rangeY, 1); int ret = cl.clEnqueueCopyBufferToImage(ID, srcBuffer.ID, dstImage.ID, - srcOffset, bufferA, bufferB, + srcOffset, ibA, ibB, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not copy buffer to image2d"); @@ -653,11 +657,11 @@ public class CLCommandQueue extends CLObject implements CLResource { conditions = condition.size; } - copy2NIO(bufferA, dstOriginX, dstOriginY, dstOriginZ); - copy2NIO(bufferB, rangeX, rangeY, rangeZ); + copy2NIO(ibA, dstOriginX, dstOriginY, dstOriginZ); + copy2NIO(ibB, rangeX, rangeY, rangeZ); int ret = cl.clEnqueueCopyBufferToImage(ID, srcBuffer.ID, dstImage.ID, - srcOffset, bufferA, bufferB, + srcOffset, ibA, ibB, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not copy buffer to image3d"); @@ -715,11 +719,11 @@ public class CLCommandQueue extends CLObject implements CLResource { // spec: CL_INVALID_VALUE if src_image is a 2D image object and src_origin[2] is not equal to 0 // or region[2] is not equal to 1. - copy2NIO(bufferA, srcOriginX, srcOriginY, 0); - copy2NIO(bufferB, rangeX, rangeY, 1); + copy2NIO(ibA, srcOriginX, srcOriginY, 0); + copy2NIO(ibB, rangeX, rangeY, 1); int ret = cl.clEnqueueCopyImageToBuffer(ID, dstBuffer.ID, srcImage.ID, - bufferA, bufferB, dstOffset, + ibA, ibB, dstOffset, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not copy buffer to image2d"); @@ -776,11 +780,11 @@ public class CLCommandQueue extends CLObject implements CLResource { conditions = condition.size; } - copy2NIO(bufferA, srcOriginX, srcOriginY, srcOriginZ); - copy2NIO(bufferB, rangeX, rangeY, rangeZ); + copy2NIO(ibA, srcOriginX, srcOriginY, srcOriginZ); + copy2NIO(ibB, rangeX, rangeY, rangeZ); int ret = cl.clEnqueueCopyImageToBuffer(ID, dstBuffer.ID, srcImage.ID, - bufferA, bufferB, dstOffset, + ibA, ibB, dstOffset, conditions, conditionIDs, events==null ? null : events.IDs); checkForError(ret, "can not copy buffer to image3d"); @@ -830,7 +834,7 @@ public class CLCommandQueue extends CLObject implements CLResource { conditions = condition.size; } - IntBuffer error = bufferA.position(0).getBuffer().asIntBuffer(); + IntBuffer error = pbA.position(0).getBuffer().asIntBuffer(); ByteBuffer mappedBuffer = cl.clEnqueueMapBuffer(ID, buffer.ID, clBoolean(blockingMap), flag.FLAGS, offset, length, conditions, conditionIDs, events==null ? null : events.IDs, error); @@ -887,14 +891,14 @@ public class CLCommandQueue extends CLObject implements CLResource { conditions = condition.size; } - IntBuffer error = bufferA.position(0).getBuffer().asIntBuffer(); + IntBuffer error = pbA.position(0).getBuffer().asIntBuffer(); // spec: CL_INVALID_VALUE if image is a 2D image object and origin[2] is not equal to 0 or region[2] is not equal to 1 - copy2NIO(bufferB, offsetX, offsetY, 0); - copy2NIO(bufferC, rangeX, rangeY, 1); + copy2NIO(ibB, offsetX, offsetY, 0); + copy2NIO(ibC, rangeX, rangeY, 1); ByteBuffer mappedImage = cl.clEnqueueMapImage(ID, buffer.ID, clBoolean(blockingMap), - flag.FLAGS, bufferB, bufferC, null, null, + flag.FLAGS, ibB, ibC, null, null, conditions, conditionIDs, events==null ? null : events.IDs, error); checkForError(error.get(), "can not map image2d"); @@ -950,11 +954,11 @@ public class CLCommandQueue extends CLObject implements CLResource { conditions = condition.size; } - IntBuffer error = bufferA.position(0).getBuffer().asIntBuffer(); - copy2NIO(bufferB, offsetX, offsetY, offsetZ); - copy2NIO(bufferC, rangeX, rangeY, rangeZ); + IntBuffer error = pbA.position(0).getBuffer().asIntBuffer(); + copy2NIO(ibB, offsetX, offsetY, offsetZ); + copy2NIO(ibC, rangeX, rangeY, rangeZ); ByteBuffer mappedImage = cl.clEnqueueMapImage(ID, buffer.ID, clBoolean(blockingMap), - flag.FLAGS, bufferB, bufferC, null, null, + flag.FLAGS, ibB, ibC, null, null, conditions, conditionIDs, events==null ? null : events.IDs, error); checkForError(error.get(), "can not map image3d"); @@ -1105,18 +1109,18 @@ public class CLCommandQueue extends CLObject implements CLResource { * Calls {@native clEnqueueNDRangeKernel}. */ public CLCommandQueue put1DRangeKernel(CLKernel kernel, long globalWorkOffset, long globalWorkSize, long localWorkSize, CLEventList condition, CLEventList events) { - PointerBuffer globWO = null; - PointerBuffer globWS = null; - PointerBuffer locWS = null; + Int64Buffer globWO = null; + Int64Buffer globWS = null; + Int64Buffer locWS = null; if(globalWorkOffset != 0) { - globWO = copy2NIO(bufferA, globalWorkOffset); + globWO = copy2NIO(ibA, globalWorkOffset); } if(globalWorkSize != 0) { - globWS = copy2NIO(bufferB, globalWorkSize); + globWS = copy2NIO(ibB, globalWorkSize); } if(localWorkSize != 0) { - locWS = copy2NIO(bufferC, localWorkSize); + locWS = copy2NIO(ibC, localWorkSize); } this.putNDRangeKernel(kernel, 1, globWO, globWS, locWS, condition, events); @@ -1156,18 +1160,18 @@ public class CLCommandQueue extends CLObject implements CLResource { public CLCommandQueue put2DRangeKernel(CLKernel kernel, long globalWorkOffsetX, long globalWorkOffsetY, long globalWorkSizeX, long globalWorkSizeY, long localWorkSizeX, long localWorkSizeY, CLEventList condition, CLEventList events) { - PointerBuffer globalWorkOffset = null; - PointerBuffer globalWorkSize = null; - PointerBuffer localWorkSize = null; + Int64Buffer globalWorkOffset = null; + Int64Buffer globalWorkSize = null; + Int64Buffer localWorkSize = null; if(globalWorkOffsetX != 0 && globalWorkOffsetY != 0) { - globalWorkOffset = copy2NIO(bufferA, globalWorkOffsetX, globalWorkOffsetY); + globalWorkOffset = copy2NIO(ibA, globalWorkOffsetX, globalWorkOffsetY); } if(globalWorkSizeX != 0 && globalWorkSizeY != 0) { - globalWorkSize = copy2NIO(bufferB, globalWorkSizeX, globalWorkSizeY); + globalWorkSize = copy2NIO(ibB, globalWorkSizeX, globalWorkSizeY); } if(localWorkSizeX != 0 && localWorkSizeY !=0) { - localWorkSize = copy2NIO(bufferC, localWorkSizeX, localWorkSizeY); + localWorkSize = copy2NIO(ibC, localWorkSizeX, localWorkSizeY); } this.putNDRangeKernel(kernel, 2, globalWorkOffset, globalWorkSize, localWorkSize, condition, events); return this; @@ -1176,7 +1180,7 @@ public class CLCommandQueue extends CLObject implements CLResource { /** * Calls {@native clEnqueueNDRangeKernel}. */ - public CLCommandQueue putNDRangeKernel(CLKernel kernel, int workDimension, PointerBuffer globalWorkOffset, PointerBuffer globalWorkSize, PointerBuffer localWorkSize) { + public CLCommandQueue putNDRangeKernel(CLKernel kernel, int workDimension, Int64Buffer globalWorkOffset, Int64Buffer globalWorkSize, Int64Buffer localWorkSize) { this.putNDRangeKernel(kernel, workDimension, globalWorkOffset, globalWorkSize, localWorkSize, null, null); return this; } @@ -1184,7 +1188,7 @@ public class CLCommandQueue extends CLObject implements CLResource { /** * Calls {@native clEnqueueNDRangeKernel}. */ - public CLCommandQueue putNDRangeKernel(CLKernel kernel, int workDimension, PointerBuffer globalWorkOffset, PointerBuffer globalWorkSize, PointerBuffer localWorkSize, CLEventList events) { + public CLCommandQueue putNDRangeKernel(CLKernel kernel, int workDimension, Int64Buffer globalWorkOffset, Int64Buffer globalWorkSize, Int64Buffer localWorkSize, CLEventList events) { this.putNDRangeKernel(kernel, workDimension, globalWorkOffset, globalWorkSize, localWorkSize, null, events); return this; } @@ -1192,8 +1196,8 @@ public class CLCommandQueue extends CLObject implements CLResource { /** * Calls {@native clEnqueueNDRangeKernel}. */ - public CLCommandQueue putNDRangeKernel(CLKernel kernel, int workDimension, PointerBuffer globalWorkOffset, - PointerBuffer globalWorkSize, PointerBuffer localWorkSize, CLEventList condition, CLEventList events) { + public CLCommandQueue putNDRangeKernel(CLKernel kernel, int workDimension, Int64Buffer globalWorkOffset, + Int64Buffer globalWorkSize, Int64Buffer localWorkSize, CLEventList condition, CLEventList events) { PointerBuffer conditionIDs = null; int conditions = 0; @@ -1250,7 +1254,7 @@ public class CLCommandQueue extends CLObject implements CLResource { CLGLI xl = (CLGLI) cl; - PointerBuffer glObj = copy2NIO(bufferA, glObject); + PointerBuffer glObj = copy2NIO(pbA, glObject); int ret = xl.clEnqueueAcquireGLObjects(ID, 1, glObj, conditions, conditionIDs, @@ -1296,7 +1300,7 @@ public class CLCommandQueue extends CLObject implements CLResource { CLGLI xl = (CLGLI) cl; - PointerBuffer glObj = copy2NIO(bufferA, glObject); + PointerBuffer glObj = copy2NIO(pbA, glObject); int ret = xl.clEnqueueReleaseGLObjects(ID, 1, glObj, conditions, conditionIDs, @@ -1366,6 +1370,18 @@ public class CLCommandQueue extends CLObject implements CLResource { return buffer.rewind().put(a).put(b).put(c).rewind(); } + private static Int64Buffer copy2NIO(Int64Buffer buffer, long a) { + return buffer.put(2, a).position(2); + } + + private static Int64Buffer copy2NIO(Int64Buffer buffer, long a, long b) { + return buffer.position(1).put(a).put(b).position(1); + } + + private static Int64Buffer copy2NIO(Int64Buffer buffer, long a, long b, long c) { + return buffer.rewind().put(a).put(b).put(c).rewind(); + } + /** * Returns the device of this command queue. */ diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java index 9f7f1096..1acfbbb3 100644 --- a/src/com/mbien/opencl/CLContext.java +++ b/src/com/mbien/opencl/CLContext.java @@ -5,7 +5,7 @@ import com.mbien.opencl.CLMemory.Mem; import com.mbien.opencl.CLSampler.AddressingMode; import com.mbien.opencl.CLSampler.FilteringMode; import com.jogamp.gluegen.runtime.Buffers; -import com.jogamp.gluegen.runtime.CPU; +import com.jogamp.gluegen.runtime.Int64Buffer; import com.jogamp.gluegen.runtime.PointerBuffer; import java.io.BufferedReader; import java.io.IOException; @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import static com.mbien.opencl.CLException.*; import static com.jogamp.gluegen.runtime.Buffers.*; +import static com.jogamp.gluegen.runtime.Platform.*; /** * CLContext is responsible for managing objects such as command-queues, memory, @@ -60,8 +61,7 @@ public class CLContext extends CLObject implements CLResource { if (devices == null) { - int sizeofDeviceID = CPU.is32Bit() ? 4 : 8; - PointerBuffer deviceCount = PointerBuffer.allocateDirect(1); + Int64Buffer deviceCount = Int64Buffer.allocateDirect(1); int ret = cl.clGetContextInfo(ID, CL.CL_CONTEXT_DEVICES, 0, null, deviceCount); checkForError(ret, "can not enumerate devices"); @@ -70,9 +70,9 @@ public class CLContext extends CLObject implements CLResource { ret = cl.clGetContextInfo(ID, CL.CL_CONTEXT_DEVICES, deviceIDs.capacity(), deviceIDs, null); checkForError(ret, "can not enumerate devices"); - devices = new CLDevice[deviceIDs.capacity() / sizeofDeviceID]; + devices = new CLDevice[deviceIDs.capacity() / (is32Bit() ? 4 : 8)]; for (int i = 0; i < devices.length; i++) { - devices[i] = new CLDevice(this, CPU.is32Bit() ? deviceIDs.getInt() : deviceIDs.getLong()); + devices[i] = new CLDevice(this, is32Bit() ? deviceIDs.getInt() : deviceIDs.getLong()); } } } diff --git a/src/com/mbien/opencl/CLDevice.java b/src/com/mbien/opencl/CLDevice.java index 624fd1f7..3436a726 100644 --- a/src/com/mbien/opencl/CLDevice.java +++ b/src/com/mbien/opencl/CLDevice.java @@ -1,8 +1,8 @@ package com.mbien.opencl; import com.mbien.opencl.util.CLUtil; -import com.jogamp.gluegen.runtime.CPU; -import com.jogamp.gluegen.runtime.PointerBuffer; +import com.jogamp.gluegen.runtime.Int64Buffer; +import com.jogamp.gluegen.runtime.Platform; import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -516,7 +516,7 @@ public final class CLDevice extends CLObject { private final class CLDeviceInfoAccessor extends CLInfoAccessor { @Override - protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) { + protected int getInfo(int name, long valueSize, Buffer value, Int64Buffer valueSizeRet) { return cl.clGetDeviceInfo(ID, name, valueSize, value, valueSizeRet); } @@ -528,7 +528,7 @@ public final class CLDevice extends CLObject { int[] array = new int[n]; for(int i = 0; i < array.length; i++) { - if(CPU.is32Bit()) { + if(Platform.is32Bit()) { array[i] = buffer.getInt(); }else{ array[i] = (int)buffer.getLong(); diff --git a/src/com/mbien/opencl/CLEvent.java b/src/com/mbien/opencl/CLEvent.java index eb77f194..e7221ee0 100644 --- a/src/com/mbien/opencl/CLEvent.java +++ b/src/com/mbien/opencl/CLEvent.java @@ -1,6 +1,6 @@ package com.mbien.opencl; -import com.jogamp.gluegen.runtime.PointerBuffer; +import com.jogamp.gluegen.runtime.Int64Buffer; import java.nio.Buffer; import static com.mbien.opencl.CL.*; @@ -93,7 +93,7 @@ public class CLEvent extends CLObject implements CLResource { private class CLEventInfoAccessor extends CLInfoAccessor { @Override - protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) { + protected int getInfo(int name, long valueSize, Buffer value, Int64Buffer valueSizeRet) { return cl.clGetEventInfo(ID, name, valueSize, value, valueSizeRet); } @@ -102,7 +102,7 @@ public class CLEvent extends CLObject implements CLResource { private class CLEventProfilingInfoAccessor extends CLInfoAccessor { @Override - protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) { + protected int getInfo(int name, long valueSize, Buffer value, Int64Buffer valueSizeRet) { return cl.clGetEventProfilingInfo(ID, name, valueSize, value, valueSizeRet); } diff --git a/src/com/mbien/opencl/CLImage.java b/src/com/mbien/opencl/CLImage.java index 1718ac3a..5a6ebb41 100644 --- a/src/com/mbien/opencl/CLImage.java +++ b/src/com/mbien/opencl/CLImage.java @@ -1,6 +1,6 @@ package com.mbien.opencl; -import com.jogamp.gluegen.runtime.PointerBuffer; +import com.jogamp.gluegen.runtime.Int64Buffer; import java.nio.Buffer; import static com.mbien.opencl.CL.*; @@ -81,7 +81,7 @@ public abstract class CLImage<B extends Buffer> extends CLMemory<B> { this.id = id; } @Override - public int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) { + public int getInfo(int name, long valueSize, Buffer value, Int64Buffer valueSizeRet) { return cl.clGetImageInfo(id, name, valueSize, value, valueSizeRet); } } diff --git a/src/com/mbien/opencl/CLInfoAccessor.java b/src/com/mbien/opencl/CLInfoAccessor.java index 44eb5fe4..ea69db33 100644 --- a/src/com/mbien/opencl/CLInfoAccessor.java +++ b/src/com/mbien/opencl/CLInfoAccessor.java @@ -1,10 +1,10 @@ package com.mbien.opencl; +import com.jogamp.gluegen.runtime.Buffers; +import com.jogamp.gluegen.runtime.Int64Buffer; import com.mbien.opencl.util.CLUtil; -import com.jogamp.gluegen.runtime.PointerBuffer; import java.nio.Buffer; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import static com.mbien.opencl.CLException.*; @@ -19,15 +19,15 @@ abstract class CLInfoAccessor { @Override protected ByteBuffer initialValue() { - return ByteBuffer.allocateDirect(512).order(ByteOrder.nativeOrder()); + return Buffers.newDirectByteBuffer(512); } }; - protected final static ThreadLocal<PointerBuffer> localPB = new ThreadLocal<PointerBuffer>() { + protected final static ThreadLocal<Int64Buffer> localPB = new ThreadLocal<Int64Buffer>() { @Override - protected PointerBuffer initialValue() { - return PointerBuffer.allocateDirect(1); + protected Int64Buffer initialValue() { + return Int64Buffer.allocateDirect(1); } }; @@ -44,11 +44,11 @@ abstract class CLInfoAccessor { public final String getString(int key) { ByteBuffer buffer = localBB.get(); - PointerBuffer pbuffer = localPB.get(); - int ret = getInfo(key, buffer.capacity(), buffer, pbuffer); + Int64Buffer sizeBuffer = localPB.get(); + int ret = getInfo(key, buffer.capacity(), buffer, sizeBuffer); checkForError(ret, "error while asking for info string"); - int clSize = (int)pbuffer.get(0); + int clSize = (int)sizeBuffer.get(0); byte[] array = new byte[clSize-1]; // last char is always null buffer.get(array).rewind(); @@ -56,7 +56,7 @@ abstract class CLInfoAccessor { } - protected abstract int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet); + protected abstract int getInfo(int name, long valueSize, Buffer value, Int64Buffer valueSizeRet); } diff --git a/src/com/mbien/opencl/CLKernel.java b/src/com/mbien/opencl/CLKernel.java index 12d1047b..31315531 100644 --- a/src/com/mbien/opencl/CLKernel.java +++ b/src/com/mbien/opencl/CLKernel.java @@ -2,8 +2,8 @@ package com.mbien.opencl; import com.mbien.opencl.util.CLUtil; import com.jogamp.gluegen.runtime.Buffers; -import com.jogamp.gluegen.runtime.CPU; -import com.jogamp.gluegen.runtime.PointerBuffer; +import com.jogamp.gluegen.runtime.Platform; +import com.jogamp.gluegen.runtime.Int64Buffer; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -39,13 +39,13 @@ public class CLKernel extends CLObject implements CLResource, Cloneable { this.program = program; this.buffer = Buffers.newDirectByteBuffer(8); - PointerBuffer pb = PointerBuffer.allocateDirect(1); + Int64Buffer size = Int64Buffer.allocateDirect(1); // get function name - int ret = cl.clGetKernelInfo(ID, CL_KERNEL_FUNCTION_NAME, 0, null, pb); + int ret = cl.clGetKernelInfo(ID, CL_KERNEL_FUNCTION_NAME, 0, null, size); checkForError(ret, "error while asking for kernel function name"); - ByteBuffer bb = ByteBuffer.allocateDirect((int)pb.get(0)).order(ByteOrder.nativeOrder()); + ByteBuffer bb = ByteBuffer.allocateDirect((int)size.get(0)).order(ByteOrder.nativeOrder()); ret = cl.clGetKernelInfo(ID, CL_KERNEL_FUNCTION_NAME, bb.capacity(), bb, null); checkForError(ret, "error while asking for kernel function name"); @@ -112,7 +112,7 @@ public class CLKernel extends CLObject implements CLResource, Cloneable { // } public CLKernel setArg(int argumentIndex, CLMemory<?> value) { - setArgument(argumentIndex, CPU.is32Bit()?4:8, wrap(value.ID)); + setArgument(argumentIndex, Platform.is32Bit()?4:8, wrap(value.ID)); return this; } diff --git a/src/com/mbien/opencl/CLPlatform.java b/src/com/mbien/opencl/CLPlatform.java index 85868387..b6b502b9 100644 --- a/src/com/mbien/opencl/CLPlatform.java +++ b/src/com/mbien/opencl/CLPlatform.java @@ -1,5 +1,6 @@ package com.mbien.opencl; +import com.jogamp.gluegen.runtime.Int64Buffer; import com.mbien.opencl.util.CLUtil; import com.mbien.opencl.impl.CLImpl; import com.jogamp.gluegen.runtime.PointerBuffer; @@ -257,13 +258,14 @@ public final class CLPlatform { * Returns a info string in exchange for a key (CL_PLATFORM_*). */ public String getInfoString(int key) { - PointerBuffer pb = PointerBuffer.allocateDirect(1); + Int64Buffer size = Int64Buffer.allocateDirect(1); + // TODO use cache/query size ByteBuffer bb = ByteBuffer.allocateDirect(512); - int ret = cl.clGetPlatformInfo(ID, key, bb.capacity(), bb, pb); + int ret = cl.clGetPlatformInfo(ID, key, bb.capacity(), bb, size); checkForError(ret, "can not receive info string"); - return CLUtil.clString2JavaString(bb, (int)pb.get(0)); + return CLUtil.clString2JavaString(bb, (int)size.get(0)); } @Override diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java index 79195f78..1895df12 100644 --- a/src/com/mbien/opencl/CLProgram.java +++ b/src/com/mbien/opencl/CLProgram.java @@ -2,11 +2,10 @@ package com.mbien.opencl; import com.mbien.opencl.util.CLProgramConfiguration; import com.mbien.opencl.util.CLUtil; -import com.jogamp.gluegen.runtime.Buffers; -import com.jogamp.gluegen.runtime.CPU; +import com.jogamp.gluegen.runtime.Int64Buffer; +import com.jogamp.gluegen.runtime.Platform; import com.jogamp.gluegen.runtime.PointerBuffer; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.nio.IntBuffer; import java.util.Collections; import java.util.HashMap; @@ -17,6 +16,7 @@ import java.util.Map; import static com.mbien.opencl.CLException.*; import static com.mbien.opencl.CL.*; +import static com.jogamp.gluegen.runtime.Buffers.*; /** * Represents a OpenCL program executed on one or more {@link CLDevice}s. @@ -43,10 +43,10 @@ public class CLProgram extends CLObject implements CLResource { static CLProgram create(CLContext context, String src) { - IntBuffer status = Buffers.newDirectByteBuffer(4).asIntBuffer(); + IntBuffer status = newDirectByteBuffer(4).asIntBuffer(); // Create the program long id = context.cl.clCreateProgramWithSource(context.ID, 1, new String[] {src}, - PointerBuffer.allocateDirect(1).put(src.length()), status); + Int64Buffer.allocateDirect(1).put(src.length()), status); checkForError(status.get(), "can not create program with source"); @@ -56,8 +56,8 @@ public class CLProgram extends CLObject implements CLResource { static CLProgram create(CLContext context, Map<CLDevice, byte[]> binaries) { PointerBuffer devices = PointerBuffer.allocateDirect(binaries.size()); - PointerBuffer lengths = PointerBuffer.allocateDirect(binaries.size()); - ByteBuffer[] codeBuffers = new ByteBuffer[binaries.size()]; + PointerBuffer codeBuffers = PointerBuffer.allocateDirect(binaries.size()); + Int64Buffer lengths = Int64Buffer.allocateDirect(binaries.size()); int i = 0; Set<CLDevice> keys = binaries.keySet(); @@ -68,15 +68,14 @@ public class CLProgram extends CLObject implements CLResource { devices.put(device.ID); lengths.put(bytes.length); - codeBuffers[i] = Buffers.newDirectByteBuffer(bytes.length).put(bytes); - codeBuffers[i].rewind(); + codeBuffers.referenceBuffer(i, newDirectByteBuffer(bytes)); i++; } devices.rewind(); lengths.rewind(); - IntBuffer err = Buffers.newDirectByteBuffer(4).asIntBuffer(); -// IntBuffer status = Buffers.newDirectByteBuffer(binaries.size()*4).asIntBuffer(); + IntBuffer err = newDirectIntBuffer(1); +// IntBuffer status = newDirectByteBuffer(binaries.size()*4).asIntBuffer(); long id = context.cl.clCreateProgramWithBinary(context.ID, devices.capacity(), devices, lengths, codeBuffers, /*status*/null, err); // while(status.remaining() != 0) { @@ -112,17 +111,17 @@ public class CLProgram extends CLObject implements CLResource { return ""; } - PointerBuffer pb = PointerBuffer.allocateDirect(1); + Int64Buffer size = Int64Buffer.allocateDirect(1); - int ret = cl.clGetProgramBuildInfo(ID, device, flag, 0, null, pb); + int ret = cl.clGetProgramBuildInfo(ID, device, flag, 0, null, size); checkForError(ret, "on clGetProgramBuildInfo"); - ByteBuffer bb = ByteBuffer.allocateDirect((int)pb.get(0)).order(ByteOrder.nativeOrder()); + ByteBuffer buffer = newDirectByteBuffer((int)size.get(0)); - ret = cl.clGetProgramBuildInfo(ID, device, flag, bb.capacity(), bb, null); + ret = cl.clGetProgramBuildInfo(ID, device, flag, buffer.capacity(), buffer, null); checkForError(ret, "on clGetProgramBuildInfo"); - return CLUtil.clString2JavaString(bb, (int)pb.get(0)); + return CLUtil.clString2JavaString(buffer, (int)size.get(0)); } private String getProgramInfoString(int flag) { @@ -131,17 +130,17 @@ public class CLProgram extends CLObject implements CLResource { return ""; } - PointerBuffer pb = PointerBuffer.allocateDirect(1); + Int64Buffer size = Int64Buffer.allocateDirect(1); - int ret = cl.clGetProgramInfo(ID, flag, 0, null, pb); + int ret = cl.clGetProgramInfo(ID, flag, 0, null, size); checkForError(ret, "on clGetProgramInfo"); - ByteBuffer bb = ByteBuffer.allocateDirect((int)pb.get(0)).order(ByteOrder.nativeOrder()); + ByteBuffer buffer = newDirectByteBuffer((int)size.get(0)); - ret = cl.clGetProgramInfo(ID, flag, bb.capacity(), bb, null); + ret = cl.clGetProgramInfo(ID, flag, buffer.capacity(), buffer, null); checkForError(ret, "on clGetProgramInfo"); - return CLUtil.clString2JavaString(bb, (int)pb.get(0)); + return CLUtil.clString2JavaString(buffer, (int)size.get(0)); } // private int getProgramInfoInt(int flag) { @@ -156,12 +155,12 @@ public class CLProgram extends CLObject implements CLResource { private int getBuildInfoInt(long device, int flag) { - ByteBuffer bb = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()); + ByteBuffer buffer = newDirectByteBuffer(4); - int ret = cl.clGetProgramBuildInfo(ID, device, flag, bb.capacity(), bb, null); + int ret = cl.clGetProgramBuildInfo(ID, device, flag, buffer.capacity(), buffer, null); checkForError(ret, "error on clGetProgramBuildInfo"); - return bb.getInt(); + return buffer.getInt(); } @@ -293,7 +292,7 @@ public class CLProgram extends CLObject implements CLResource { HashMap<String, CLKernel> newKernels = new HashMap<String, CLKernel>(); - IntBuffer numKernels = Buffers.newDirectByteBuffer(4).asIntBuffer(); + IntBuffer numKernels = newDirectByteBuffer(4).asIntBuffer(); int ret = cl.clCreateKernelsInProgram(ID, 0, null, numKernels); checkForError(ret, "can not create kernels for program"); @@ -362,18 +361,18 @@ public class CLProgram extends CLObject implements CLResource { if(released) { return new CLDevice[0]; } - PointerBuffer pb = PointerBuffer.allocateDirect(1); - int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, 0, null, pb); + Int64Buffer size = Int64Buffer.allocateDirect(1); + int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, 0, null, size); checkForError(ret, "on clGetProgramInfo"); - ByteBuffer bb = ByteBuffer.allocateDirect((int) pb.get(0)).order(ByteOrder.nativeOrder()); + ByteBuffer bb = newDirectByteBuffer((int) size.get(0)); ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, bb.capacity(), bb, null); checkForError(ret, "on clGetProgramInfo"); - int count = bb.capacity() / (CPU.is32Bit()?4:8); + int count = bb.capacity() / (Platform.is32Bit()?4:8); CLDevice[] devices = new CLDevice[count]; for (int i = 0; i < count; i++) { - devices[i] = context.getDevice(CPU.is32Bit()?bb.getInt():bb.getLong()); + devices[i] = context.getDevice(Platform.is32Bit()?bb.getInt():bb.getLong()); } return devices; @@ -463,7 +462,7 @@ public class CLProgram extends CLObject implements CLResource { CLDevice[] devices = getCLDevices(); - ByteBuffer sizes = ByteBuffer.allocateDirect(8*devices.length).order(ByteOrder.nativeOrder()); + ByteBuffer sizes = newDirectByteBuffer(8*devices.length); int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_BINARY_SIZES, sizes.capacity(), sizes, null); checkForError(ret, "on clGetProgramInfo"); @@ -472,7 +471,7 @@ public class CLProgram extends CLObject implements CLResource { int size = (int) sizes.getLong(); binariesSize += size; } - ByteBuffer binaries = ByteBuffer.allocateDirect(binariesSize).order(ByteOrder.nativeOrder()); + ByteBuffer binaries = newDirectByteBuffer(binariesSize); long address = InternalBufferUtil.getDirectBufferAddress(binaries); diff --git a/src/com/mbien/opencl/CLSampler.java b/src/com/mbien/opencl/CLSampler.java index 8b7c9386..f5c74f6e 100644 --- a/src/com/mbien/opencl/CLSampler.java +++ b/src/com/mbien/opencl/CLSampler.java @@ -1,5 +1,6 @@ package com.mbien.opencl; +import com.jogamp.gluegen.runtime.Int64Buffer; import com.jogamp.gluegen.runtime.PointerBuffer; import java.nio.Buffer; @@ -57,7 +58,7 @@ public class CLSampler extends CLObject implements CLResource { private class CLSamplerInfoAccessor extends CLInfoAccessor { @Override - protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) { + protected int getInfo(int name, long valueSize, Buffer value, Int64Buffer valueSizeRet) { return cl.clGetSamplerInfo(ID, name, valueSize, value, valueSizeRet); } |