summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-04-15 21:36:21 +0200
committerMichael Bien <[email protected]>2010-04-15 21:36:21 +0200
commitbb14f43134a9332c014e969b600e094edadd2fb0 (patch)
treea63678de5a0b8b5f5c21bd732b159ba151c274f9 /src/com
parent966153e376f9932cea29d8bd891a164115a4049c (diff)
code review: improved exception messages to be more verbose whenever possible.
began with CLKernel testcase.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/jogamp/opencl/CLCommandQueue.java9
-rw-r--r--src/com/jogamp/opencl/CLContext.java6
-rw-r--r--src/com/jogamp/opencl/CLKernel.java21
-rw-r--r--src/com/jogamp/opencl/CLMemory.java6
-rw-r--r--src/com/jogamp/opencl/CLObject.java4
-rw-r--r--src/com/jogamp/opencl/CLProgram.java70
-rw-r--r--src/com/jogamp/opencl/CLSampler.java4
-rw-r--r--src/com/jogamp/opencl/gl/CLGLBuffer.java2
-rw-r--r--src/com/jogamp/opencl/gl/CLGLContext.java7
9 files changed, 86 insertions, 43 deletions
diff --git a/src/com/jogamp/opencl/CLCommandQueue.java b/src/com/jogamp/opencl/CLCommandQueue.java
index 1781a8ae..288e5b00 100644
--- a/src/com/jogamp/opencl/CLCommandQueue.java
+++ b/src/com/jogamp/opencl/CLCommandQueue.java
@@ -1418,7 +1418,9 @@ public class CLCommandQueue extends CLObject implements CLResource {
public void release() {
int ret = cl.clReleaseCommandQueue(ID);
context.onCommandQueueReleased(device, this);
- checkForError(ret, "can not release command queue");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "can not release "+this);
+ }
}
public void close() {
@@ -1503,6 +1505,11 @@ public class CLCommandQueue extends CLObject implements CLResource {
}
@Override
+ public String toString() {
+ return getClass().getSimpleName() +" "+getProperties()+" on "+ getDevice();
+ }
+
+ @Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java
index a3157777..a50bf628 100644
--- a/src/com/jogamp/opencl/CLContext.java
+++ b/src/com/jogamp/opencl/CLContext.java
@@ -474,9 +474,9 @@ public class CLContext extends CLObject implements CLResource {
@Override
public String toString() {
- return "CLContext [id: " + ID
- + " #devices: " + getDevices().length
- + "]";
+ return getClass().getSimpleName()+" [id: " + ID
+ + " #devices: " + getDevices().length
+ + "]";
}
@Override
diff --git a/src/com/jogamp/opencl/CLKernel.java b/src/com/jogamp/opencl/CLKernel.java
index 6fc20f56..37d355c3 100644
--- a/src/com/jogamp/opencl/CLKernel.java
+++ b/src/com/jogamp/opencl/CLKernel.java
@@ -162,7 +162,7 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
private void setArgument(int argumentIndex, int size, Buffer value) {
if(argumentIndex >= numArgs || argumentIndex < 0) {
- throw new IndexOutOfBoundsException("kernel "+ toString() +" has "+numArgs+
+ throw new IndexOutOfBoundsException("kernel "+ this +" has "+numArgs+
" arguments, can not set argument with index "+argumentIndex);
}
if(!program.isExecutable()) {
@@ -171,7 +171,9 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
}
int ret = cl.clSetKernelArg(ID, argumentIndex, size, value);
- checkForError(ret, "error on clSetKernelArg");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "error setting arg "+argumentIndex+" to value "+value+" of size "+size+" of "+this);
+ }
}
/**
@@ -235,18 +237,23 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
}
/**
- * Returns the work-group size specified by the <code>__attribute__((reqd_work_gr oup_size(X, Y, Z)))</code> qualifier in kernel sources.
+ * Returns the work-group size specified by the <code>__attribute__((reqd_work_group_size(X, Y, Z)))</code> qualifier in kernel sources.
* If the work-group size is not specified using the above attribute qualifier <code>new long[]{(0, 0, 0)}</code> is returned.
+ * The returned array has always three elements.
*/
public long[] getCompileWorkGroupSize(CLDevice device) {
int ret = cl.clGetKernelWorkGroupInfo(ID, device.ID, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, 8*3, buffer, null);
- checkForError(ret, "error while asking for clGetKernelWorkGroupInfo");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "error while asking for CL_KERNEL_COMPILE_WORK_GROUP_SIZE of "+this+" on "+device);
+ }
return new long[] { buffer.getLong(0), buffer.getLong(1), buffer.getLong(2) };
}
private long getWorkGroupInfo(CLDevice device, int flag) {
int ret = cl.clGetKernelWorkGroupInfo(ID, device.ID, flag, 8, buffer, null);
- checkForError(ret, "error while asking for clGetKernelWorkGroupInfo");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "error while asking for clGetKernelWorkGroupInfo of "+this+" on "+device);
+ }
return buffer.getLong(0);
}
@@ -256,7 +263,9 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
public void release() {
int ret = cl.clReleaseKernel(ID);
program.onKernelReleased(this);
- checkForError(ret, "can not release kernel");
+ if(ret != CL.CL_SUCCESS) {
+ throw newException(ret, "can not release "+this);
+ }
}
public void close() {
diff --git a/src/com/jogamp/opencl/CLMemory.java b/src/com/jogamp/opencl/CLMemory.java
index 55a04af9..aac76790 100644
--- a/src/com/jogamp/opencl/CLMemory.java
+++ b/src/com/jogamp/opencl/CLMemory.java
@@ -147,7 +147,9 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL
public void release() {
int ret = cl.clReleaseMemObject(ID);
context.onMemoryReleased(this);
- checkForError(ret, "can not release mem object");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "can not release "+this);
+ }
}
public void close() {
@@ -203,7 +205,7 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL
@Override
public String toString() {
- return "CLMemory [id: " + ID+"]";
+ return getClass().getSimpleName()+" [id: " + ID+"]";
}
/**
diff --git a/src/com/jogamp/opencl/CLObject.java b/src/com/jogamp/opencl/CLObject.java
index 58c8485c..ec17a518 100644
--- a/src/com/jogamp/opencl/CLObject.java
+++ b/src/com/jogamp/opencl/CLObject.java
@@ -50,8 +50,8 @@ abstract class CLObject {
@Override
public String toString() {
- return "CLObject [id: " + ID
- + " context: " + context+"]";
+ return getClass().getSimpleName() + " [id: " + ID
+ + " context: " + context+"]";
}
}
diff --git a/src/com/jogamp/opencl/CLProgram.java b/src/com/jogamp/opencl/CLProgram.java
index bb5abccf..ce2b9dff 100644
--- a/src/com/jogamp/opencl/CLProgram.java
+++ b/src/com/jogamp/opencl/CLProgram.java
@@ -48,7 +48,10 @@ public class CLProgram extends CLObject implements CLResource {
long id = context.cl.clCreateProgramWithSource(context.ID, 1, new String[] {src},
(Int64Buffer)Int64Buffer.allocateDirect(1).put(src.length()), status);
- checkForError(status.get(), "can not create program with source");
+ int err = status.get();
+ if(err != CL_SUCCESS) {
+ throw newException(err, "can not create program with source on "+context);
+ }
return new CLProgram(context, id);
}
@@ -74,15 +77,18 @@ public class CLProgram extends CLObject implements CLResource {
devices.rewind();
lengths.rewind();
- IntBuffer err = newDirectIntBuffer(1);
+ IntBuffer errBuffer = newDirectIntBuffer(1);
// IntBuffer status = newDirectByteBuffer(binaries.size()*4).asIntBuffer();
- long id = context.cl.clCreateProgramWithBinary(context.ID, devices.capacity(), devices, lengths, codeBuffers, /*status*/null, err);
+ long id = context.cl.clCreateProgramWithBinary(context.ID, devices.capacity(), devices, lengths, codeBuffers, /*status*/null, errBuffer);
// while(status.remaining() != 0) {
// checkForError(status.get(), "unable to load binaries on all devices");
// }
- checkForError(err.get(), "can not create program with binary");
+ int err = errBuffer.get();
+ if(err != CL_SUCCESS) {
+ throw newException(err, "can not create program on "+context +" with binaries "+binaries);
+ }
return new CLProgram(context, id);
}
@@ -105,7 +111,7 @@ public class CLProgram extends CLObject implements CLResource {
}
}
- private String getBuildInfoString(long device, int flag) {
+ private String getBuildInfoString(CLDevice device, int flag) {
if(released) {
return "";
@@ -113,13 +119,17 @@ public class CLProgram extends CLObject implements CLResource {
Int64Buffer size = Int64Buffer.allocateDirect(1);
- int ret = cl.clGetProgramBuildInfo(ID, device, flag, 0, null, size);
- checkForError(ret, "on clGetProgramBuildInfo");
+ int ret = cl.clGetProgramBuildInfo(ID, device.ID, flag, 0, null, size);
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "on clGetProgramBuildInfo with "+device);
+ }
ByteBuffer buffer = newDirectByteBuffer((int)size.get(0));
- ret = cl.clGetProgramBuildInfo(ID, device, flag, buffer.capacity(), buffer, null);
- checkForError(ret, "on clGetProgramBuildInfo");
+ ret = cl.clGetProgramBuildInfo(ID, device.ID, flag, buffer.capacity(), buffer, null);
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "on clGetProgramBuildInfo with "+device);
+ }
return CLUtil.clString2JavaString(buffer, (int)size.get(0));
}
@@ -153,11 +163,11 @@ public class CLProgram extends CLObject implements CLResource {
// return bb.getInt();
// }
- private int getBuildInfoInt(long device, int flag) {
+ private int getBuildInfoInt(CLDevice device, int flag) {
ByteBuffer buffer = newDirectByteBuffer(4);
- int ret = cl.clGetProgramBuildInfo(ID, device, flag, buffer.capacity(), buffer, null);
+ int ret = cl.clGetProgramBuildInfo(ID, device.ID, flag, buffer.capacity(), buffer, null);
checkForError(ret, "error on clGetProgramBuildInfo");
return buffer.getInt();
@@ -274,7 +284,9 @@ public class CLProgram extends CLObject implements CLResource {
int[] err = new int[1];
long id = cl.clCreateKernel(ID, kernelName, err, 0);
- checkForError(err[0], "unable to create Kernel with name: "+kernelName);
+ if(err[0] != CL_SUCCESS) {
+ throw newException(err[0], "unable to create Kernel with name: "+kernelName);
+ }
CLKernel kernel = new CLKernel(this, id);
kernels.add(kernel);
@@ -294,13 +306,17 @@ public class CLProgram extends CLObject implements CLResource {
IntBuffer numKernels = newDirectByteBuffer(4).asIntBuffer();
int ret = cl.clCreateKernelsInProgram(ID, 0, null, numKernels);
- checkForError(ret, "can not create kernels for program");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "can not create kernels for "+this);
+ }
if(numKernels.get(0) > 0) {
PointerBuffer kernelIDs = PointerBuffer.allocateDirect(numKernels.get(0));
ret = cl.clCreateKernelsInProgram(ID, kernelIDs.capacity(), kernelIDs, null);
- checkForError(ret, "can not create kernels for program");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "can not create "+kernelIDs.capacity()+" kernels for "+this);
+ }
for (int i = 0; i < kernelIDs.capacity(); i++) {
CLKernel kernel = new CLKernel(this, kernelIDs.get(i));
@@ -337,7 +353,9 @@ public class CLProgram extends CLObject implements CLResource {
int ret = cl.clReleaseProgram(ID);
context.onProgramReleased(this);
- checkForError(ret, "can not release program");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "can not release "+this);
+ }
}
public void close() {
@@ -363,11 +381,15 @@ public class CLProgram extends CLObject implements CLResource {
}
Int64Buffer size = Int64Buffer.allocateDirect(1);
int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, 0, null, size);
- checkForError(ret, "on clGetProgramInfo");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "on clGetProgramInfo of "+this);
+ }
ByteBuffer bb = newDirectByteBuffer((int) size.get(0));
ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, bb.capacity(), bb, null);
- checkForError(ret, "on clGetProgramInfo");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "on clGetProgramInfo of "+this);
+ }
int count = bb.capacity() / (Platform.is32Bit()?4:8);
CLDevice[] devices = new CLDevice[count];
@@ -387,7 +409,7 @@ public class CLProgram extends CLObject implements CLResource {
if(released) {
return "";
}
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb = new StringBuilder(200);
CLDevice[] devices = getCLDevices();
for (int i = 0; i < devices.length; i++) {
CLDevice device = devices[i];
@@ -428,7 +450,7 @@ public class CLProgram extends CLObject implements CLResource {
* of the log are implementation dependent log can be an empty String.
*/
public String getBuildLog(CLDevice device) {
- return getBuildInfoString(device.ID, CL_PROGRAM_BUILD_LOG);
+ return getBuildInfoString(device, CL_PROGRAM_BUILD_LOG);
}
/**
@@ -438,7 +460,7 @@ public class CLProgram extends CLObject implements CLResource {
if(released) {
return Status.BUILD_NONE;
}
- int clStatus = getBuildInfoInt(device.ID, CL_PROGRAM_BUILD_STATUS);
+ int clStatus = getBuildInfoInt(device, CL_PROGRAM_BUILD_STATUS);
return Status.valueOf(clStatus);
}
@@ -464,7 +486,9 @@ public class CLProgram extends CLObject implements CLResource {
ByteBuffer sizes = newDirectByteBuffer(8*devices.length);
int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_BINARY_SIZES, sizes.capacity(), sizes, null);
- checkForError(ret, "on clGetProgramInfo");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "on clGetProgramInfo(CL_PROGRAM_BINARY_SIZES) of "+this);
+ }
int binariesSize = 0;
while(sizes.remaining() != 0) {
@@ -483,7 +507,9 @@ public class CLProgram extends CLObject implements CLResource {
}
ret = cl.clGetProgramInfo(ID, CL_PROGRAM_BINARIES, addresses.capacity(), addresses.getBuffer(), null);
- checkForError(ret, "on clGetProgramInfo");
+ if(ret != CL_SUCCESS) {
+ throw newException(ret, "on clGetProgramInfo(CL_PROGRAM_BINARIES) of "+this);
+ }
Map<CLDevice, byte[]> map = new LinkedHashMap<CLDevice, byte[]>();
sizes.rewind();
diff --git a/src/com/jogamp/opencl/CLSampler.java b/src/com/jogamp/opencl/CLSampler.java
index 79ef6067..5f6a9485 100644
--- a/src/com/jogamp/opencl/CLSampler.java
+++ b/src/com/jogamp/opencl/CLSampler.java
@@ -48,7 +48,9 @@ public class CLSampler extends CLObject implements CLResource {
public void release() {
int ret = cl.clReleaseSampler(ID);
context.onSamplerReleased(this);
- checkForError(ret, "can not release sampler");
+ if(ret != CL.CL_SUCCESS) {
+ throw newException(ret, "can not release "+this);
+ }
}
public void close() {
diff --git a/src/com/jogamp/opencl/gl/CLGLBuffer.java b/src/com/jogamp/opencl/gl/CLGLBuffer.java
index c7f14c4c..6a658ea5 100644
--- a/src/com/jogamp/opencl/gl/CLGLBuffer.java
+++ b/src/com/jogamp/opencl/gl/CLGLBuffer.java
@@ -71,7 +71,7 @@ public final class CLGLBuffer<B extends Buffer> extends CLBuffer<B> implements C
@Override
public String toString() {
- return "CLGLBuffer [id: " + ID+" glID: "+GLID+"]";
+ return getClass().getSimpleName()+" [id: " + ID+" glID: "+GLID+"]";
}
}
diff --git a/src/com/jogamp/opencl/gl/CLGLContext.java b/src/com/jogamp/opencl/gl/CLGLContext.java
index 92618729..5fd669b8 100644
--- a/src/com/jogamp/opencl/gl/CLGLContext.java
+++ b/src/com/jogamp/opencl/gl/CLGLContext.java
@@ -110,13 +110,10 @@ public final class CLGLContext extends CLContext {
GLContextImpl ctxImpl = (GLContextImpl)glContext;
- DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration)ctxImpl.getDrawableImpl()
- .getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
-
PointerBuffer properties;
if(glContext instanceof X11GLXContext) {
properties = PointerBuffer.allocateDirect(7);
- long handle = config.getScreen().getDevice().getHandle();
+ long handle = ctxImpl.getDrawableImpl().getNativeWindow().getSurfaceHandle();
glID[0] = ((X11GLXContext)glContext).getContext();
properties.put(CL_GL_CONTEXT_KHR).put(glID[0])
.put(CL_GLX_DISPLAY_KHR).put(handle)
@@ -129,7 +126,7 @@ public final class CLGLContext extends CLContext {
// CL_WGL_HDC_KHR, (cl_context_properties)0,
// CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform, 0};
properties = PointerBuffer.allocateDirect(7);
- long handle = config.getScreen().getDevice().getHandle();
+ long handle = ctxImpl.getDrawableImpl().getNativeWindow().getSurfaceHandle();
glID[0] = ((WindowsWGLContext)glContext).getHGLRC();
properties.put(CL_GL_CONTEXT_KHR).put(glID[0])
.put(CL_WGL_HDC_KHR).put(handle)