diff options
Diffstat (limited to 'src/com/mbien')
-rw-r--r-- | src/com/mbien/opencl/CLContext.java | 37 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLGLContext.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLProgram.java | 13 |
3 files changed, 30 insertions, 24 deletions
diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java index 30197f37..ebd5821d 100644 --- a/src/com/mbien/opencl/CLContext.java +++ b/src/com/mbien/opencl/CLContext.java @@ -3,6 +3,7 @@ package com.mbien.opencl; import com.mbien.opencl.CLMemory.Mem; import com.mbien.opencl.CLSampler.AddressingMode; import com.mbien.opencl.CLSampler.FilteringMode; +import com.sun.gluegen.runtime.BufferFactory; import com.sun.gluegen.runtime.CPU; import com.sun.gluegen.runtime.PointerBuffer; import java.io.BufferedReader; @@ -80,7 +81,7 @@ public class CLContext implements CLResource { * The platform to be used is implementation dependent. */ public static final CLContext create() { - Buffer properties = setupContextProperties(null); + PointerBuffer properties = setupContextProperties(null); return new CLContext(createContextFromType(properties, CL.CL_DEVICE_TYPE_ALL)); } @@ -120,7 +121,7 @@ public class CLContext implements CLResource { } } - Buffer properties = setupContextProperties(platform); + PointerBuffer properties = setupContextProperties(platform); return new CLContext(createContextFromType(properties, type)); } @@ -136,11 +137,11 @@ public class CLContext implements CLResource { deviceIDs[i] = devices[i].ID; } - Buffer properties = setupContextProperties(platform); + PointerBuffer properties = setupContextProperties(platform); return new CLContext(createContext(properties, deviceIDs)); } - protected static final long createContextFromType(Buffer properties, long deviceType) { + protected static final long createContextFromType(PointerBuffer properties, long deviceType) { IntBuffer status = IntBuffer.allocate(1); long context = CLPlatform.getLowLevelBinding().clCreateContextFromType(properties, deviceType, null, null, status); @@ -150,17 +151,24 @@ public class CLContext implements CLResource { return context; } - protected static final long createContext(Buffer properties, long[] devices) { + protected static final long createContext(PointerBuffer properties, long[] devices) { - IntBuffer status = IntBuffer.allocate(1); - long context = CLPlatform.getLowLevelBinding().clCreateContext(properties, devices, null, null, status); + IntBuffer status = BufferFactory.newDirectByteBuffer(4).asIntBuffer(); + PointerBuffer pb = null; + if(devices != null && devices.length != 0) { + pb = PointerBuffer.allocateDirect(devices.length); + for (int i = 0; i < devices.length; i++) { + pb.put(i, devices[i]); + } + } + long context = CLPlatform.getLowLevelBinding().clCreateContext(properties, pb, null, null, status); checkForError(status.get(), "can not create CL context"); return context; } - private static final Buffer setupContextProperties(CLPlatform platform) { + private static final PointerBuffer setupContextProperties(CLPlatform platform) { if(platform == null) { CLPlatform[] platforms = CLPlatform.listCLPlatforms(); @@ -168,16 +176,11 @@ public class CLContext implements CLResource { platform = platforms[0]; } - Buffer properties = null; + PointerBuffer properties = null; if(platform != null) { - if(CPU.is32Bit()){ - properties = ByteBuffer.allocate(4*3).order(ByteOrder.nativeOrder()) - .putInt(CL.CL_CONTEXT_PLATFORM).putInt((int)platform.ID).putInt(0); // 0 terminated array - }else{ - properties = LongBuffer.allocate(3) - .put(CL.CL_CONTEXT_PLATFORM).put(platform.ID).put(0); // 0 terminated array - } - properties.rewind(); + properties = PointerBuffer.allocateDirect(3) + .put(CL.CL_CONTEXT_PLATFORM).put(platform.ID).put(0) // 0 terminated array + .rewind(); } return properties; } diff --git a/src/com/mbien/opencl/CLGLContext.java b/src/com/mbien/opencl/CLGLContext.java index 03367a35..a76c15ab 100644 --- a/src/com/mbien/opencl/CLGLContext.java +++ b/src/com/mbien/opencl/CLGLContext.java @@ -2,11 +2,11 @@ package com.mbien.opencl; import java.nio.Buffer; import com.mbien.opencl.CLMemory.Mem; +import com.sun.gluegen.runtime.PointerBuffer; import com.sun.opengl.impl.GLContextImpl; import com.sun.opengl.impl.macosx.cgl.MacOSXCGLContext; import com.sun.opengl.impl.windows.wgl.WindowsWGLContext; import com.sun.opengl.impl.x11.glx.X11GLXContext; -import java.nio.LongBuffer; import javax.media.nativewindow.DefaultGraphicsConfiguration; import javax.media.opengl.GLContext; @@ -52,7 +52,7 @@ public final class CLGLContext extends CLContext { DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration)ctxImpl.getDrawableImpl() .getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - LongBuffer properties = LongBuffer.allocate(5); + PointerBuffer properties = PointerBuffer.allocateDirect(5); if(glContext instanceof X11GLXContext) { long handle = config.getScreen().getDevice().getHandle(); glID = ((X11GLXContext)glContext).getContext(); diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java index 0c4325ee..6f1ed551 100644 --- a/src/com/mbien/opencl/CLProgram.java +++ b/src/com/mbien/opencl/CLProgram.java @@ -241,12 +241,15 @@ public class CLProgram implements CLResource { releaseKernels(); } - long[] deviceIDs = null; + PointerBuffer deviceIDs = null; + int count = 0; if(devices != null) { - deviceIDs = new long[devices.length]; - for (int i = 0; i < deviceIDs.length; i++) { - deviceIDs[i] = devices[i].ID; + deviceIDs = PointerBuffer.allocateDirect(devices.length); + for (int i = 0; i < devices.length; i++) { + deviceIDs.put(i, devices[i].ID); } + deviceIDs.rewind(); + count = devices.length; } // invalidate build status @@ -254,7 +257,7 @@ public class CLProgram implements CLResource { executable = false; // Build the program - int ret = cl.clBuildProgram(ID, deviceIDs, options, null, null); + int ret = cl.clBuildProgram(ID, count, deviceIDs, options, null, null); if(ret != CL_SUCCESS) { throw new CLException(ret, "\n"+getBuildLog()); |