diff options
author | Michael Bien <[email protected]> | 2010-02-22 12:47:41 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-02-22 12:47:41 +0100 |
commit | 7c83da1d2e3e8d122e562408a63a13928cc97c83 (patch) | |
tree | 78957152423cc8b3623feae6b7376e047b0d04ae | |
parent | b014104bc4d2c7b05767bf5364b8b972474850d1 (diff) |
several small refactorings, api and javadoc improvements.
added automatically generated specialized CLExceptions for each known OpenCL error.
added get/set Properties to CLCommandQueue.
-rw-r--r-- | resources/cl-common.cfg | 1 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLCommandQueue.java | 59 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLContext.java | 54 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLDevice.java | 10 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLException.java | 727 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLGLContext.java | 26 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLKernel.java | 14 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLMemory.java | 3 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLPlatform.java | 12 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLProgram.java | 32 | ||||
-rw-r--r-- | test/com/mbien/opencl/CLBufferTest.java | 12 | ||||
-rw-r--r-- | test/com/mbien/opencl/CLCommandQueueTest.java | 8 | ||||
-rw-r--r-- | test/com/mbien/opencl/HighLevelBindingTest.java | 51 |
13 files changed, 814 insertions, 195 deletions
diff --git a/resources/cl-common.cfg b/resources/cl-common.cfg index 79c2845c..c6b7b07f 100644 --- a/resources/cl-common.cfg +++ b/resources/cl-common.cfg @@ -78,6 +78,7 @@ NioDirectOnly clSetCommandQueueProperty NioDirectOnly clWaitForEvents #NioDirectOnly clCreateContext #NioDirectOnly clBuildProgram +NioDirectOnly clIcdGetPlatformIDsKHR #extensions NioDirectOnly clGetGLContextInfoKHR diff --git a/src/com/mbien/opencl/CLCommandQueue.java b/src/com/mbien/opencl/CLCommandQueue.java index c8b862be..1a70605a 100644 --- a/src/com/mbien/opencl/CLCommandQueue.java +++ b/src/com/mbien/opencl/CLCommandQueue.java @@ -11,12 +11,13 @@ import static com.mbien.opencl.CLException.*; import static com.mbien.opencl.CL.*; /** - * The command-queue can be used to queue a set of operations in order. Having multiple - * command-queues allows applications to queue multiple independent commands without + * The command queue is used to queue a set of operations for a specific {@link CLDevice}. + * Having multiple command-queues allows applications to queue multiple independent commands without * requiring synchronization. Note that this should work as long as these objects are * not being shared.<br/> - * Sharing of objects across multiple command-queues or using a CLCommandQueue + * Sharing of objects across multiple queues or using a CLCommandQueue * form multiple Threads will require the application to perform appropriate synchronization. + * @see CLDevice#createCommandQueue(com.mbien.opencl.CLCommandQueue.Mode[]) * @author Michael Bien */ public class CLCommandQueue implements CLResource { @@ -49,7 +50,7 @@ public class CLCommandQueue implements CLResource { this.ID = cl.clCreateCommandQueue(context.ID, device.ID, properties, status, 0); if(status[0] != CL_SUCCESS) - throw new CLException(status[0], "can not create command queue on "+device); + throw newException(status[0], "can not create command queue on "+device); } public CLCommandQueue putWriteBuffer(CLBuffer<?> writeBuffer, boolean blockingRead) { @@ -64,7 +65,7 @@ public class CLCommandQueue implements CLResource { 0, null, events==null ? null : events.IDs); if(ret != CL_SUCCESS) - throw new CLException(ret, "can not enqueue WriteBuffer: " + writeBuffer); + throw newException(ret, "can not enqueue WriteBuffer: " + writeBuffer); if(events != null) { events.createEvent(context); @@ -86,7 +87,7 @@ public class CLCommandQueue implements CLResource { 0, null, events==null ? null : events.IDs); if(ret != CL_SUCCESS) - throw new CLException(ret, "can not enqueue ReadBuffer: " + readBuffer); + throw newException(ret, "can not enqueue ReadBuffer: " + readBuffer); if(events != null) { events.createEvent(context); @@ -710,7 +711,7 @@ public class CLCommandQueue implements CLResource { events==null ? null : events.IDs); if(ret != CL_SUCCESS) - throw new CLException(ret, "can not enqueue NDRangeKernel: " + kernel); + throw newException(ret, "can not enqueue NDRangeKernel: " + kernel); if(events != null) { events.createEvent(context); @@ -733,7 +734,7 @@ public class CLCommandQueue implements CLResource { events==null ? null : events.IDs); if(ret != CL_SUCCESS) - throw new CLException(ret, "can not aquire GLObject: " + glObject); + throw newException(ret, "can not aquire GLObject: " + glObject); if(events != null) { events.createEvent(context); @@ -756,7 +757,7 @@ public class CLCommandQueue implements CLResource { events==null ? null : events.IDs); if(ret != CL_SUCCESS) - throw new CLException(ret, "can not release GLObject: " + glObject); + throw newException(ret, "can not release GLObject: " + glObject); if(events != null) { events.createEvent(context); @@ -779,10 +780,10 @@ public class CLCommandQueue implements CLResource { } /** - * Returns true only when {@link Mode#OUT_OF_ORDER_EXEC_MODE} mode has been enabled. + * Returns true only when {@link Mode#OUT_OF_ORDER_MODE} mode has been enabled. */ public boolean isOutOfOrderModeEnabled() { - return (Mode.OUT_OF_ORDER_EXEC_MODE.QUEUE_MODE & properties) != 0; + return (Mode.OUT_OF_ORDER_MODE.QUEUE_MODE & properties) != 0; } public void release() { @@ -803,6 +804,36 @@ public class CLCommandQueue implements CLResource { return buffer.rewind().put(a).put(b).put(c).rewind(); } + /** + * Returns the device of this command queue. + */ + public CLDevice getDevice() { + return device; + } + + /** + * Returns the command queue properties as EnumSet. + */ + public EnumSet<Mode> getProperties() { + return Mode.valuesOf(properties); + } + + /** + * Setting properties after a command queue has been created can be implementation specific, + * please refere to the specification ({@native clSetCommandQueueProperty}) or vendor documentation. + */ + public void setProperty(Mode property, boolean enabled) { + int ret = cl.clSetCommandQueueProperty(ID, property.QUEUE_MODE, enabled ? CL_TRUE : CL_FALSE, null); + if(ret != CL_SUCCESS) { + checkForError(ret, "can not set command queue property: " + property); + } + if(enabled) { + properties |= property.QUEUE_MODE; + }else{ + properties &= ~property.QUEUE_MODE; + } + } + @Override public boolean equals(Object obj) { if (obj == null) { @@ -841,7 +872,7 @@ public class CLCommandQueue implements CLResource { * If set, the commands in the command-queue are * executed out-of-order. Otherwise, commands are executed in-order. */ - OUT_OF_ORDER_EXEC_MODE(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE), + OUT_OF_ORDER_MODE(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE), /** * Enables profiling of commands in the command-queue. @@ -862,14 +893,14 @@ public class CLCommandQueue implements CLResource { public static Mode valueOf(int queueMode) { switch(queueMode) { case(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE): - return OUT_OF_ORDER_EXEC_MODE; + return OUT_OF_ORDER_MODE; case(CL_QUEUE_PROFILING_ENABLE): return PROFILING_MODE; } return null; } - public static EnumSet<Mode> valuesOf(int bitfield) { + public static EnumSet<Mode> valuesOf(long bitfield) { List<Mode> matching = new ArrayList<Mode>(); Mode[] values = Mode.values(); for (Mode value : values) { diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java index f92213fc..bab61c19 100644 --- a/src/com/mbien/opencl/CLContext.java +++ b/src/com/mbien/opencl/CLContext.java @@ -45,11 +45,13 @@ public class CLContext implements CLResource { protected final List<CLSampler> samplers; protected final List<CLMemory<? extends Buffer>> memoryObjects; protected final Map<CLDevice, List<CLCommandQueue>> queuesMap; + protected final CLPlatform platform; - protected CLContext(long contextID) { - this.cl = CLPlatform.getLowLevelBinding(); + protected CLContext(CLPlatform platform, long contextID) { + this.cl = CLPlatform.getLowLevelCLInterface(); this.ID = contextID; + this.platform = platform; this.programs = new ArrayList<CLProgram>(); this.samplers = new ArrayList<CLSampler>(); this.memoryObjects = new ArrayList<CLMemory<? extends Buffer>>(); @@ -82,8 +84,7 @@ public class CLContext implements CLResource { * The platform to be used is implementation dependent. */ public static final CLContext create() { - PointerBuffer properties = setupContextProperties(null); - return new CLContext(createContextFromType(properties, CL.CL_DEVICE_TYPE_ALL)); + return create((CLPlatform)null, Type.ALL); } /** @@ -115,10 +116,14 @@ public class CLContext implements CLResource { */ public static final CLContext create(CLPlatform platform, CLDevice.Type... deviceTypes) { + if(platform == null) { + platform = CLPlatform.getDefault(); + } + long type = toDeviceBitmap(deviceTypes); PointerBuffer properties = setupContextProperties(platform); - return new CLContext(createContextFromType(properties, type)); + return new CLContext(platform, createContextFromType(properties, type)); } /** @@ -127,8 +132,12 @@ public class CLContext implements CLResource { */ public static final CLContext create(CLPlatform platform, CLDevice... devices) { + if(platform == null) { + platform = CLPlatform.getDefault(); + } + PointerBuffer properties = setupContextProperties(platform); - CLContext context = new CLContext(createContext(properties, devices)); + CLContext context = new CLContext(platform, createContext(properties, devices)); if(devices != null) { for (int i = 0; i < devices.length; i++) { devices[i].setContext(context); @@ -140,7 +149,7 @@ public class CLContext implements CLResource { protected static final long createContextFromType(PointerBuffer properties, long deviceType) { IntBuffer status = IntBuffer.allocate(1); - long context = CLPlatform.getLowLevelBinding().clCreateContextFromType(properties, deviceType, null, null, status); + long context = CLPlatform.getLowLevelCLInterface().clCreateContextFromType(properties, deviceType, null, null, status); checkForError(status.get(), "can not create CL context"); @@ -157,7 +166,7 @@ public class CLContext implements CLResource { pb.put(i, devices[i].ID); } } - long context = CLPlatform.getLowLevelBinding().clCreateContext(properties, pb, null, null, status); + long context = CLPlatform.getLowLevelCLInterface().clCreateContext(properties, pb, null, null, status); checkForError(status.get(), "can not create CL context"); @@ -167,10 +176,6 @@ public class CLContext implements CLResource { private static final PointerBuffer setupContextProperties(CLPlatform platform) { if(platform == null) { - platform = CLPlatform.getDefault(); - } - - if(platform == null) { throw new RuntimeException("no OpenCL installation found"); } @@ -376,23 +381,30 @@ public class CLContext implements CLResource { } /** + * Returns the CLPlatform this context is running on. + */ + public CLPlatform getPlatform() { + return platform; + } + + /** * Returns a read only view of all programs associated with this context. */ - public List<CLProgram> getCLPrograms() { + public List<CLProgram> getPrograms() { return Collections.unmodifiableList(programs); } /** * Returns a read only view of all allocated memory objects associated with this context. */ - public List<CLMemory<? extends Buffer>> getCLMemoryObjects() { + public List<CLMemory<? extends Buffer>> getMemoryObjects() { return Collections.unmodifiableList(memoryObjects); } /** * Returns a read only view of all samplers associated with this context. */ - public List<CLSampler> getCLSamplers() { + public List<CLSampler> getSamplers() { return Collections.unmodifiableList(samplers); } @@ -403,7 +415,7 @@ public class CLContext implements CLResource { * @see #getMaxFlopsDevice(com.mbien.opencl.CLDevice.Type) */ public CLDevice getMaxFlopsDevice() { - return CLPlatform.findMaxFlopsDevice(getCLDevices()); + return CLPlatform.findMaxFlopsDevice(getDevices()); } /** @@ -412,19 +424,19 @@ public class CLContext implements CLResource { * MAX_COMPUTE_UNITS and MAX_CLOCK_FREQUENCY. */ public CLDevice getMaxFlopsDevice(CLDevice.Type type) { - return CLPlatform.findMaxFlopsDevice(getCLDevices(), type); + return CLPlatform.findMaxFlopsDevice(getDevices(), type); } /** * Returns all devices associated with this CLContext. */ - public CLDevice[] getCLDevices() { + public CLDevice[] getDevices() { initDevices(); return devices; } - CLDevice getCLDevice(long dID) { - CLDevice[] deviceArray = getCLDevices(); + CLDevice getDevice(long dID) { + CLDevice[] deviceArray = getDevices(); for (int i = 0; i < deviceArray.length; i++) { if(dID == deviceArray[i].ID) return deviceArray[i]; @@ -445,7 +457,7 @@ public class CLContext implements CLResource { @Override public String toString() { return "CLContext [id: " + ID - + " #devices: " + getCLDevices().length + + " #devices: " + getDevices().length + "]"; } diff --git a/src/com/mbien/opencl/CLDevice.java b/src/com/mbien/opencl/CLDevice.java index cd569586..941b8560 100644 --- a/src/com/mbien/opencl/CLDevice.java +++ b/src/com/mbien/opencl/CLDevice.java @@ -15,7 +15,11 @@ import java.util.Set; import static com.mbien.opencl.CL.*; /** - * + * This object represents an OpenCL device. + * @see CLPlatform#listCLDevices(com.mbien.opencl.CLDevice.Type) + * @see CLPlatform#getMaxFlopsDevice(com.mbien.opencl.CLDevice.Type) + * @see CLContext#getDevices() + * @see CLContext#getMaxFlopsDevice(com.mbien.opencl.CLDevice.Type) * @author Michael Bien */ public final class CLDevice { @@ -68,11 +72,11 @@ public final class CLDevice { return context.createCommandQueue(this, properties); } - /*keep this package private for now, may be null*/ - CLContext getContext() { + public CLContext getContext() { return context; } + /*keep this package private*/ void setContext(CLContext context) { this.context = context; } diff --git a/src/com/mbien/opencl/CLException.java b/src/com/mbien/opencl/CLException.java index 81e96789..2f6a02a4 100644 --- a/src/com/mbien/opencl/CLException.java +++ b/src/com/mbien/opencl/CLException.java @@ -3,191 +3,702 @@ package com.mbien.opencl; import static com.mbien.opencl.CL.*; /** - * Main Exception type for runtime OpenCL errors and unsuccessful function calls (e.g. returning not CL_SUCCESS). + * Main Exception type for runtime OpenCL errors and failed function calls (e.g. returning not CL_SUCCESS). * @author Michael Bien */ public class CLException extends RuntimeException { + // must be positive + private static final long serialVersionUID = 6573520735486076436L; + public final int errorcode; + public final String error; - private final static String ERROR_CODE_DOC = "http://www.khronos.org/opencl/sdk/1.0/docs/man/xhtml/errors.html"; + private final static String ERROR_CODE_DOC = + "http://www.khronos.org/opencl/sdk/1.0/docs/man/xhtml/errors.html"; public CLException(String message) { super(message); errorcode = 0; + error = "none"; } - public CLException(int error, String message) { - super(message + "\nerror: " + identifyError(error) + " (man page: "+ERROR_CODE_DOC+")"); - errorcode = error; + private CLException(int errorcode, String errorStr, String message) { + super(message + "\nerror: " + errorStr + " (man page: "+ERROR_CODE_DOC+")"); + this.error = errorStr; + this.errorcode = errorcode; } /** * Throws a CLException when <code>status != CL_SUCCESS</code>. */ public static final void checkForError(int status, String message) { - if(status != CL_SUCCESS) - throw new CLException(status, message); + if(status != CL_SUCCESS) { + CLException ex = newException(status, message); + ex.fillInStackTrace(); + throw ex; + } + } + + /** + * Returns a CLException specific to the error code. + */ + public static final CLException newException(int status, String message) { + CLException specificEx = createSpecificException(status, message); + if(specificEx != null) { + specificEx.fillInStackTrace(); + return specificEx; + } + return new CLException(status, "unknown", "unknown cause: code" + status); } /** * Returns a human readable String for the OpenCL error code. */ public String getCLErrorString() { - return identifyError(errorcode); + return error; } - private static final String identifyError(int error) { - switch (error) { - case CL_DEVICE_NOT_FOUND: - return "CL_DEVICE_NOT_FOUND"; + // - - - generated code do not edit - - - - case CL_DEVICE_NOT_AVAILABLE: - return "CL_DEVICE_NOT_AVAILABLE"; + /** + * Returns a human readable String for the OpenCL error code or null if not known. + */ + public static String resolveErrorCode(int error) { + switch(error) { + case CL_DEVICE_NOT_FOUND: return "CL_DEVICE_NOT_FOUND"; + case CL_DEVICE_NOT_AVAILABLE: return "CL_DEVICE_NOT_AVAILABLE"; + case CL_COMPILER_NOT_AVAILABLE: return "CL_COMPILER_NOT_AVAILABLE"; + case CL_MEM_OBJECT_ALLOCATION_FAILURE: return "CL_MEM_OBJECT_ALLOCATION_FAILURE"; + case CL_OUT_OF_RESOURCES: return "CL_OUT_OF_RESOURCES"; + case CL_OUT_OF_HOST_MEMORY: return "CL_OUT_OF_HOST_MEMORY"; + case CL_PROFILING_INFO_NOT_AVAILABLE: return "CL_PROFILING_INFO_NOT_AVAILABLE"; + case CL_MEM_COPY_OVERLAP: return "CL_MEM_COPY_OVERLAP"; + case CL_IMAGE_FORMAT_MISMATCH: return "CL_IMAGE_FORMAT_MISMATCH"; + case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "CL_IMAGE_FORMAT_NOT_SUPPORTED"; + case CL_BUILD_PROGRAM_FAILURE: return "CL_BUILD_PROGRAM_FAILURE"; + case CL_MAP_FAILURE: return "CL_MAP_FAILURE"; + case CL_INVALID_VALUE: return "CL_INVALID_VALUE"; + case CL_INVALID_DEVICE_TYPE: return "CL_INVALID_DEVICE_TYPE"; + case CL_INVALID_PLATFORM: return "CL_INVALID_PLATFORM"; + case CL_INVALID_DEVICE: return "CL_INVALID_DEVICE"; + case CL_INVALID_CONTEXT: return "CL_INVALID_CONTEXT"; + case CL_INVALID_QUEUE_PROPERTIES: return "CL_INVALID_QUEUE_PROPERTIES"; + case CL_INVALID_COMMAND_QUEUE: return "CL_INVALID_COMMAND_QUEUE"; + case CL_INVALID_HOST_PTR: return "CL_INVALID_HOST_PTR"; + case CL_INVALID_MEM_OBJECT: return "CL_INVALID_MEM_OBJECT"; + case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"; + case CL_INVALID_IMAGE_SIZE: return "CL_INVALID_IMAGE_SIZE"; + case CL_INVALID_SAMPLER: return "CL_INVALID_SAMPLER"; + case CL_INVALID_BINARY: return "CL_INVALID_BINARY"; + case CL_INVALID_BUILD_OPTIONS: return "CL_INVALID_BUILD_OPTIONS"; + case CL_INVALID_PROGRAM: return "CL_INVALID_PROGRAM"; + case CL_INVALID_PROGRAM_EXECUTABLE: return "CL_INVALID_PROGRAM_EXECUTABLE"; + case CL_INVALID_KERNEL_NAME: return "CL_INVALID_KERNEL_NAME"; + case CL_INVALID_KERNEL_DEFINITION: return "CL_INVALID_KERNEL_DEFINITION"; + case CL_INVALID_KERNEL: return "CL_INVALID_KERNEL"; + case CL_INVALID_ARG_INDEX: return "CL_INVALID_ARG_INDEX"; + case CL_INVALID_ARG_VALUE: return "CL_INVALID_ARG_VALUE"; + case CL_INVALID_ARG_SIZE: return "CL_INVALID_ARG_SIZE"; + case CL_INVALID_KERNEL_ARGS: return "CL_INVALID_KERNEL_ARGS"; + case CL_INVALID_WORK_DIMENSION: return "CL_INVALID_WORK_DIMENSION"; + case CL_INVALID_WORK_GROUP_SIZE: return "CL_INVALID_WORK_GROUP_SIZE"; + case CL_INVALID_WORK_ITEM_SIZE: return "CL_INVALID_WORK_ITEM_SIZE"; + case CL_INVALID_GLOBAL_OFFSET: return "CL_INVALID_GLOBAL_OFFSET"; + case CL_INVALID_EVENT_WAIT_LIST: return "CL_INVALID_EVENT_WAIT_LIST"; + case CL_INVALID_EVENT: return "CL_INVALID_EVENT"; + case CL_INVALID_OPERATION: return "CL_INVALID_OPERATION"; + case CL_INVALID_GL_OBJECT: return "CL_INVALID_GL_OBJECT"; + case CL_INVALID_BUFFER_SIZE: return "CL_INVALID_BUFFER_SIZE"; + case CL_INVALID_MIP_LEVEL: return "CL_INVALID_MIP_LEVEL"; + case CL_INVALID_GLOBAL_WORK_SIZE: return "CL_INVALID_GLOBAL_WORK_SIZE"; + case CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR"; + case CL_PLATFORM_NOT_FOUND_KHR: return "CL_PLATFORM_NOT_FOUND_KHR"; + default: return null; + } + } - case CL_COMPILER_NOT_AVAILABLE: - return "CL_COMPILER_NOT_AVAILABLE"; + private static CLException createSpecificException(int error, String message) { + switch(error) { + case CL_DEVICE_NOT_FOUND: return new CLDeviceNotFoundException(message); + case CL_DEVICE_NOT_AVAILABLE: return new CLDeviceNotAvailableException(message); + case CL_COMPILER_NOT_AVAILABLE: return new CLCompilerNotAvailableException(message); + case CL_MEM_OBJECT_ALLOCATION_FAILURE: return new CLMemObjectAllocationFailureException(message); + case CL_OUT_OF_RESOURCES: return new CLOutOfResourcesException(message); + case CL_OUT_OF_HOST_MEMORY: return new CLOutOfHostMemoryException(message); + case CL_PROFILING_INFO_NOT_AVAILABLE: return new CLProfilingInfoNotAvailableException(message); + case CL_MEM_COPY_OVERLAP: return new CLMemCopyOverlapException(message); + case CL_IMAGE_FORMAT_MISMATCH: return new CLImageFormatMismatchException(message); + case CL_IMAGE_FORMAT_NOT_SUPPORTED: return new CLImageFormatNotSupportedException(message); + case CL_BUILD_PROGRAM_FAILURE: return new CLBuildProgramFailureException(message); + case CL_MAP_FAILURE: return new CLMapFailureException(message); + case CL_INVALID_VALUE: return new CLInvalidValueException(message); + case CL_INVALID_DEVICE_TYPE: return new CLInvalidDeviceTypeException(message); + case CL_INVALID_PLATFORM: return new CLInvalidPlatformException(message); + case CL_INVALID_DEVICE: return new CLInvalidDeviceException(message); + case CL_INVALID_CONTEXT: return new CLInvalidContextException(message); + case CL_INVALID_QUEUE_PROPERTIES: return new CLInvalidQueuePropertiesException(message); + case CL_INVALID_COMMAND_QUEUE: return new CLInvalidCommandQueueException(message); + case CL_INVALID_HOST_PTR: return new CLInvalidHostPtrException(message); + case CL_INVALID_MEM_OBJECT: return new CLInvalidMemObjectException(message); + case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return new CLInvalidImageFormatDescriptorException(message); + case CL_INVALID_IMAGE_SIZE: return new CLInvalidImageSizeException(message); + case CL_INVALID_SAMPLER: return new CLInvalidSamplerException(message); + case CL_INVALID_BINARY: return new CLInvalidBinaryException(message); + case CL_INVALID_BUILD_OPTIONS: return new CLInvalidBuildOptionsException(message); + case CL_INVALID_PROGRAM: return new CLInvalidProgramException(message); + case CL_INVALID_PROGRAM_EXECUTABLE: return new CLInvalidProgramExecutableException(message); + case CL_INVALID_KERNEL_NAME: return new CLInvalidKernelNameException(message); + case CL_INVALID_KERNEL_DEFINITION: return new CLInvalidKernelDefinitionException(message); + case CL_INVALID_KERNEL: return new CLInvalidKernelException(message); + case CL_INVALID_ARG_INDEX: return new CLInvalidArgIndexException(message); + case CL_INVALID_ARG_VALUE: return new CLInvalidArgValueException(message); + case CL_INVALID_ARG_SIZE: return new CLInvalidArgSizeException(message); + case CL_INVALID_KERNEL_ARGS: return new CLInvalidKernelArgsException(message); + case CL_INVALID_WORK_DIMENSION: return new CLInvalidWorkDimensionException(message); + case CL_INVALID_WORK_GROUP_SIZE: return new CLInvalidWorkGroupSizeException(message); + case CL_INVALID_WORK_ITEM_SIZE: return new CLInvalidWorkItemSizeException(message); + case CL_INVALID_GLOBAL_OFFSET: return new CLInvalidGlobalOffsetException(message); + case CL_INVALID_EVENT_WAIT_LIST: return new CLInvalidEventWaitListException(message); + case CL_INVALID_EVENT: return new CLInvalidEventException(message); + case CL_INVALID_OPERATION: return new CLInvalidOperationException(message); + case CL_INVALID_GL_OBJECT: return new CLInvalidGLObjectException(message); + case CL_INVALID_BUFFER_SIZE: return new CLInvalidBufferSizeException(message); + case CL_INVALID_MIP_LEVEL: return new CLInvalidMipLevelException(message); + case CL_INVALID_GLOBAL_WORK_SIZE: return new CLInvalidGlobalWorkSizeException(message); + case CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR: return new CLInvalidGLSharegroupReferenceKhrException(message); + case CL_PLATFORM_NOT_FOUND_KHR: return new CLPlatformNotFoundKhrException(message); + default: return null; + } + } - case CL_MEM_OBJECT_ALLOCATION_FAILURE: - return "CL_MEM_OBJECT_ALLOCATION_FAILURE"; + /** + * {@link CLException} thrown on CL.CL_DEVICE_NOT_FOUND errors. + * @author Michael Bien + */ + public final static class CLDeviceNotFoundException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_DEVICE_NOT_FOUND; + public CLDeviceNotFoundException(String message) { + super(CL_DEVICE_NOT_FOUND, "CL_DEVICE_NOT_FOUND", message); + } + } - case CL_OUT_OF_RESOURCES: - return "CL_OUT_OF_RESOURCES"; + /** + * {@link CLException} thrown on CL.CL_DEVICE_NOT_AVAILABLE errors. + * @author Michael Bien + */ + public final static class CLDeviceNotAvailableException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_DEVICE_NOT_AVAILABLE; + public CLDeviceNotAvailableException(String message) { + super(CL_DEVICE_NOT_AVAILABLE, "CL_DEVICE_NOT_AVAILABLE", message); + } + } - case CL_OUT_OF_HOST_MEMORY: - return "CL_OUT_OF_HOST_MEMORY"; + /** + * {@link CLException} thrown on CL.CL_COMPILER_NOT_AVAILABLE errors. + * @author Michael Bien + */ + public final static class CLCompilerNotAvailableException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_COMPILER_NOT_AVAILABLE; + public CLCompilerNotAvailableException(String message) { + super(CL_COMPILER_NOT_AVAILABLE, "CL_COMPILER_NOT_AVAILABLE", message); + } + } - case CL_PROFILING_INFO_NOT_AVAILABLE: - return "CL_PROFILING_INFO_NOT_AVAILABLE"; + /** + * {@link CLException} thrown on CL.CL_MEM_OBJECT_ALLOCATION_FAILURE errors. + * @author Michael Bien + */ + public final static class CLMemObjectAllocationFailureException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_MEM_OBJECT_ALLOCATION_FAILURE; + public CLMemObjectAllocationFailureException(String message) { + super(CL_MEM_OBJECT_ALLOCATION_FAILURE, "CL_MEM_OBJECT_ALLOCATION_FAILURE", message); + } + } - case CL_MEM_COPY_OVERLAP: - return "CL_MEM_COPY_OVERLAP"; + /** + * {@link CLException} thrown on CL.CL_OUT_OF_RESOURCES errors. + * @author Michael Bien + */ + public final static class CLOutOfResourcesException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_OUT_OF_RESOURCES; + public CLOutOfResourcesException(String message) { + super(CL_OUT_OF_RESOURCES, "CL_OUT_OF_RESOURCES", message); + } + } - case CL_IMAGE_FORMAT_MISMATCH: - return "CL_IMAGE_FORMAT_MISMATCH"; + /** + * {@link CLException} thrown on CL.CL_OUT_OF_HOST_MEMORY errors. + * @author Michael Bien + */ + public final static class CLOutOfHostMemoryException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_OUT_OF_HOST_MEMORY; + public CLOutOfHostMemoryException(String message) { + super(CL_OUT_OF_HOST_MEMORY, "CL_OUT_OF_HOST_MEMORY", message); + } + } - case CL_IMAGE_FORMAT_NOT_SUPPORTED: - return "CL_IMAGE_FORMAT_NOT_SUPPORTED"; + /** + * {@link CLException} thrown on CL.CL_PROFILING_INFO_NOT_AVAILABLE errors. + * @author Michael Bien + */ + public final static class CLProfilingInfoNotAvailableException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_PROFILING_INFO_NOT_AVAILABLE; + public CLProfilingInfoNotAvailableException(String message) { + super(CL_PROFILING_INFO_NOT_AVAILABLE, "CL_PROFILING_INFO_NOT_AVAILABLE", message); + } + } + + /** + * {@link CLException} thrown on CL.CL_MEM_COPY_OVERLAP errors. + * @author Michael Bien + */ + public final static class CLMemCopyOverlapException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_MEM_COPY_OVERLAP; + public CLMemCopyOverlapException(String message) { + super(CL_MEM_COPY_OVERLAP, "CL_MEM_COPY_OVERLAP", message); + } + } - case CL_BUILD_PROGRAM_FAILURE: - return "CL_BUILD_PROGRAM_FAILURE"; + /** + * {@link CLException} thrown on CL.CL_IMAGE_FORMAT_MISMATCH errors. + * @author Michael Bien + */ + public final static class CLImageFormatMismatchException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_IMAGE_FORMAT_MISMATCH; + public CLImageFormatMismatchException(String message) { + super(CL_IMAGE_FORMAT_MISMATCH, "CL_IMAGE_FORMAT_MISMATCH", message); + } + } - case CL_MAP_FAILURE: - return "CL_MAP_FAILURE"; + /** + * {@link CLException} thrown on CL.CL_IMAGE_FORMAT_NOT_SUPPORTED errors. + * @author Michael Bien + */ + public final static class CLImageFormatNotSupportedException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_IMAGE_FORMAT_NOT_SUPPORTED; + public CLImageFormatNotSupportedException(String message) { + super(CL_IMAGE_FORMAT_NOT_SUPPORTED, "CL_IMAGE_FORMAT_NOT_SUPPORTED", message); + } + } - case CL_INVALID_VALUE: - return "CL_INVALID_VALUE"; + /** + * {@link CLException} thrown on CL.CL_BUILD_PROGRAM_FAILURE errors. + * @author Michael Bien + */ + public final static class CLBuildProgramFailureException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_BUILD_PROGRAM_FAILURE; + public CLBuildProgramFailureException(String message) { + super(CL_BUILD_PROGRAM_FAILURE, "CL_BUILD_PROGRAM_FAILURE", message); + } + } - case CL_INVALID_DEVICE_TYPE: - return "CL_INVALID_DEVICE_TYPE"; + /** + * {@link CLException} thrown on CL.CL_MAP_FAILURE errors. + * @author Michael Bien + */ + public final static class CLMapFailureException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_MAP_FAILURE; + public CLMapFailureException(String message) { + super(CL_MAP_FAILURE, "CL_MAP_FAILURE", message); + } + } - case CL_INVALID_PLATFORM: - return "CL_INVALID_PLATFORM"; + /** + * {@link CLException} thrown on CL.CL_INVALID_VALUE errors. + * @author Michael Bien + */ + public final static class CLInvalidValueException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_VALUE; + public CLInvalidValueException(String message) { + super(CL_INVALID_VALUE, "CL_INVALID_VALUE", message); + } + } - case CL_INVALID_DEVICE: - return "CL_INVALID_DEVICE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_DEVICE_TYPE errors. + * @author Michael Bien + */ + public final static class CLInvalidDeviceTypeException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_DEVICE_TYPE; + public CLInvalidDeviceTypeException(String message) { + super(CL_INVALID_DEVICE_TYPE, "CL_INVALID_DEVICE_TYPE", message); + } + } - case CL_INVALID_CONTEXT: - return "CL_INVALID_CONTEXT"; + /** + * {@link CLException} thrown on CL.CL_INVALID_PLATFORM errors. + * @author Michael Bien + */ + public final static class CLInvalidPlatformException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_PLATFORM; + public CLInvalidPlatformException(String message) { + super(CL_INVALID_PLATFORM, "CL_INVALID_PLATFORM", message); + } + } - case CL_INVALID_QUEUE_PROPERTIES: - return "CL_INVALID_QUEUE_PROPERTIES"; + /** + * {@link CLException} thrown on CL.CL_INVALID_DEVICE errors. + * @author Michael Bien + */ + public final static class CLInvalidDeviceException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_DEVICE; + public CLInvalidDeviceException(String message) { + super(CL_INVALID_DEVICE, "CL_INVALID_DEVICE", message); + } + } - case CL_INVALID_COMMAND_QUEUE: - return "CL_INVALID_COMMAND_QUEUE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_CONTEXT errors. + * @author Michael Bien + */ + public final static class CLInvalidContextException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_CONTEXT; + public CLInvalidContextException(String message) { + super(CL_INVALID_CONTEXT, "CL_INVALID_CONTEXT", message); + } + } - case CL_INVALID_HOST_PTR: - return "CL_INVALID_HOST_PTR"; + /** + * {@link CLException} thrown on CL.CL_INVALID_QUEUE_PROPERTIES errors. + * @author Michael Bien + */ + public final static class CLInvalidQueuePropertiesException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_QUEUE_PROPERTIES; + public CLInvalidQueuePropertiesException(String message) { + super(CL_INVALID_QUEUE_PROPERTIES, "CL_INVALID_QUEUE_PROPERTIES", message); + } + } - case CL_INVALID_MEM_OBJECT: - return "CL_INVALID_MEM_OBJECT"; + /** + * {@link CLException} thrown on CL.CL_INVALID_COMMAND_QUEUE errors. + * @author Michael Bien + */ + public final static class CLInvalidCommandQueueException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_COMMAND_QUEUE; + public CLInvalidCommandQueueException(String message) { + super(CL_INVALID_COMMAND_QUEUE, "CL_INVALID_COMMAND_QUEUE", message); + } + } - case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: - return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"; + /** + * {@link CLException} thrown on CL.CL_INVALID_HOST_PTR errors. + * @author Michael Bien + */ + public final static class CLInvalidHostPtrException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_HOST_PTR; + public CLInvalidHostPtrException(String message) { + super(CL_INVALID_HOST_PTR, "CL_INVALID_HOST_PTR", message); + } + } - case CL_INVALID_IMAGE_SIZE: - return "CL_INVALID_IMAGE_SIZE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_MEM_OBJECT errors. + * @author Michael Bien + */ + public final static class CLInvalidMemObjectException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_MEM_OBJECT; + public CLInvalidMemObjectException(String message) { + super(CL_INVALID_MEM_OBJECT, "CL_INVALID_MEM_OBJECT", message); + } + } - case CL_INVALID_SAMPLER: - return "CL_INVALID_SAMPLER"; + /** + * {@link CLException} thrown on CL.CL_INVALID_IMAGE_FORMAT_DESCRIPTOR errors. + * @author Michael Bien + */ + public final static class CLInvalidImageFormatDescriptorException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; + public CLInvalidImageFormatDescriptorException(String message) { + super(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR, "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR", message); + } + } - case CL_INVALID_BINARY: - return "CL_INVALID_BINARY"; + /** + * {@link CLException} thrown on CL.CL_INVALID_IMAGE_SIZE errors. + * @author Michael Bien + */ + public final static class CLInvalidImageSizeException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_IMAGE_SIZE; + public CLInvalidImageSizeException(String message) { + super(CL_INVALID_IMAGE_SIZE, "CL_INVALID_IMAGE_SIZE", message); + } + } - case CL_INVALID_BUILD_OPTIONS: - return "CL_INVALID_BUILD_OPTIONS"; + /** + * {@link CLException} thrown on CL.CL_INVALID_SAMPLER errors. + * @author Michael Bien + */ + public final static class CLInvalidSamplerException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_SAMPLER; + public CLInvalidSamplerException(String message) { + super(CL_INVALID_SAMPLER, "CL_INVALID_SAMPLER", message); + } + } - case CL_INVALID_PROGRAM: - return "CL_INVALID_PROGRAM"; + /** + * {@link CLException} thrown on CL.CL_INVALID_BINARY errors. + * @author Michael Bien + */ + public final static class CLInvalidBinaryException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_BINARY; + public CLInvalidBinaryException(String message) { + super(CL_INVALID_BINARY, "CL_INVALID_BINARY", message); + } + } - case CL_INVALID_PROGRAM_EXECUTABLE: - return "CL_INVALID_PROGRAM_EXECUTABLE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_BUILD_OPTIONS errors. + * @author Michael Bien + */ + public final static class CLInvalidBuildOptionsException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_BUILD_OPTIONS; + public CLInvalidBuildOptionsException(String message) { + super(CL_INVALID_BUILD_OPTIONS, "CL_INVALID_BUILD_OPTIONS", message); + } + } - case CL_INVALID_KERNEL_NAME: - return "CL_INVALID_KERNEL_NAME"; + /** + * {@link CLException} thrown on CL.CL_INVALID_PROGRAM errors. + * @author Michael Bien + */ + public final static class CLInvalidProgramException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_PROGRAM; + public CLInvalidProgramException(String message) { + super(CL_INVALID_PROGRAM, "CL_INVALID_PROGRAM", message); + } + } - case CL_INVALID_KERNEL_DEFINITION: - return "CL_INVALID_KERNEL_DEFINITION"; + /** + * {@link CLException} thrown on CL.CL_INVALID_PROGRAM_EXECUTABLE errors. + * @author Michael Bien + */ + public final static class CLInvalidProgramExecutableException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_PROGRAM_EXECUTABLE; + public CLInvalidProgramExecutableException(String message) { + super(CL_INVALID_PROGRAM_EXECUTABLE, "CL_INVALID_PROGRAM_EXECUTABLE", message); + } + } - case CL_INVALID_KERNEL: - return "CL_INVALID_KERNEL"; + /** + * {@link CLException} thrown on CL.CL_INVALID_KERNEL_NAME errors. + * @author Michael Bien + */ + public final static class CLInvalidKernelNameException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_KERNEL_NAME; + public CLInvalidKernelNameException(String message) { + super(CL_INVALID_KERNEL_NAME, "CL_INVALID_KERNEL_NAME", message); + } + } - case CL_INVALID_ARG_INDEX: - return "CL_INVALID_ARG_INDEX"; + /** + * {@link CLException} thrown on CL.CL_INVALID_KERNEL_DEFINITION errors. + * @author Michael Bien + */ + public final static class CLInvalidKernelDefinitionException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_KERNEL_DEFINITION; + public CLInvalidKernelDefinitionException(String message) { + super(CL_INVALID_KERNEL_DEFINITION, "CL_INVALID_KERNEL_DEFINITION", message); + } + } - case CL_INVALID_ARG_VALUE: - return "CL_INVALID_ARG_VALUE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_KERNEL errors. + * @author Michael Bien + */ + public final static class CLInvalidKernelException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_KERNEL; + public CLInvalidKernelException(String message) { + super(CL_INVALID_KERNEL, "CL_INVALID_KERNEL", message); + } + } - case CL_INVALID_ARG_SIZE: - return "CL_INVALID_ARG_SIZE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_ARG_INDEX errors. + * @author Michael Bien + */ + public final static class CLInvalidArgIndexException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_ARG_INDEX; + public CLInvalidArgIndexException(String message) { + super(CL_INVALID_ARG_INDEX, "CL_INVALID_ARG_INDEX", message); + } + } - case CL_INVALID_KERNEL_ARGS: - return "CL_INVALID_KERNEL_ARGS"; + /** + * {@link CLException} thrown on CL.CL_INVALID_ARG_VALUE errors. + * @author Michael Bien + */ + public final static class CLInvalidArgValueException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_ARG_VALUE; + public CLInvalidArgValueException(String message) { + super(CL_INVALID_ARG_VALUE, "CL_INVALID_ARG_VALUE", message); + } + } - case CL_INVALID_WORK_DIMENSION: - return "CL_INVALID_WORK_DIMENSION"; + /** + * {@link CLException} thrown on CL.CL_INVALID_ARG_SIZE errors. + * @author Michael Bien + */ + public final static class CLInvalidArgSizeException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_ARG_SIZE; + public CLInvalidArgSizeException(String message) { + super(CL_INVALID_ARG_SIZE, "CL_INVALID_ARG_SIZE", message); + } + } - case CL_INVALID_WORK_GROUP_SIZE: - return "CL_INVALID_WORK_GROUP_SIZE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_KERNEL_ARGS errors. + * @author Michael Bien + */ + public final static class CLInvalidKernelArgsException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_KERNEL_ARGS; + public CLInvalidKernelArgsException(String message) { + super(CL_INVALID_KERNEL_ARGS, "CL_INVALID_KERNEL_ARGS", message); + } + } - case CL_INVALID_WORK_ITEM_SIZE: - return "CL_INVALID_WORK_ITEM_SIZE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_WORK_DIMENSION errors. + * @author Michael Bien + */ + public final static class CLInvalidWorkDimensionException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_WORK_DIMENSION; + public CLInvalidWorkDimensionException(String message) { + super(CL_INVALID_WORK_DIMENSION, "CL_INVALID_WORK_DIMENSION", message); + } + } - case CL_INVALID_GLOBAL_OFFSET: - return "CL_INVALID_GLOBAL_OFFSET"; + /** + * {@link CLException} thrown on CL.CL_INVALID_WORK_GROUP_SIZE errors. + * @author Michael Bien + */ + public final static class CLInvalidWorkGroupSizeException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_WORK_GROUP_SIZE; + public CLInvalidWorkGroupSizeException(String message) { + super(CL_INVALID_WORK_GROUP_SIZE, "CL_INVALID_WORK_GROUP_SIZE", message); + } + } - case CL_INVALID_EVENT_WAIT_LIST: - return "CL_INVALID_EVENT_WAIT_LIST"; + /** + * {@link CLException} thrown on CL.CL_INVALID_WORK_ITEM_SIZE errors. + * @author Michael Bien + */ + public final static class CLInvalidWorkItemSizeException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_WORK_ITEM_SIZE; + public CLInvalidWorkItemSizeException(String message) { + super(CL_INVALID_WORK_ITEM_SIZE, "CL_INVALID_WORK_ITEM_SIZE", message); + } + } - case CL_INVALID_EVENT: - return "CL_INVALID_EVENT"; + /** + * {@link CLException} thrown on CL.CL_INVALID_GLOBAL_OFFSET errors. + * @author Michael Bien + */ + public final static class CLInvalidGlobalOffsetException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_GLOBAL_OFFSET; + public CLInvalidGlobalOffsetException(String message) { + super(CL_INVALID_GLOBAL_OFFSET, "CL_INVALID_GLOBAL_OFFSET", message); + } + } - case CL_INVALID_OPERATION: - return "CL_INVALID_OPERATION"; + /** + * {@link CLException} thrown on CL.CL_INVALID_EVENT_WAIT_LIST errors. + * @author Michael Bien + */ + public final static class CLInvalidEventWaitListException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_EVENT_WAIT_LIST; + public CLInvalidEventWaitListException(String message) { + super(CL_INVALID_EVENT_WAIT_LIST, "CL_INVALID_EVENT_WAIT_LIST", message); + } + } - case CL_INVALID_GL_OBJECT: - return "CL_INVALID_GL_OBJECT"; + /** + * {@link CLException} thrown on CL.CL_INVALID_EVENT errors. + * @author Michael Bien + */ + public final static class CLInvalidEventException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_EVENT; + public CLInvalidEventException(String message) { + super(CL_INVALID_EVENT, "CL_INVALID_EVENT", message); + } + } - case CL_INVALID_BUFFER_SIZE: - return "CL_INVALID_BUFFER_SIZE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_OPERATION errors. + * @author Michael Bien + */ + public final static class CLInvalidOperationException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_OPERATION; + public CLInvalidOperationException(String message) { + super(CL_INVALID_OPERATION, "CL_INVALID_OPERATION", message); + } + } - case CL_INVALID_MIP_LEVEL: - return "CL_INVALID_MIP_LEVEL"; + /** + * {@link CLException} thrown on CL.CL_INVALID_GL_OBJECT errors. + * @author Michael Bien + */ + public final static class CLInvalidGLObjectException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_GL_OBJECT; + public CLInvalidGLObjectException(String message) { + super(CL_INVALID_GL_OBJECT, "CL_INVALID_GL_OBJECT", message); + } + } - case CL_INVALID_GLOBAL_WORK_SIZE: - return "CL_INVALID_GLOBAL_WORK_SIZE"; + /** + * {@link CLException} thrown on CL.CL_INVALID_BUFFER_SIZE errors. + * @author Michael Bien + */ + public final static class CLInvalidBufferSizeException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_BUFFER_SIZE; + public CLInvalidBufferSizeException(String message) { + super(CL_INVALID_BUFFER_SIZE, "CL_INVALID_BUFFER_SIZE", message); + } + } - case CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR: - return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR"; + /** + * {@link CLException} thrown on CL.CL_INVALID_MIP_LEVEL errors. + * @author Michael Bien + */ + public final static class CLInvalidMipLevelException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_MIP_LEVEL; + public CLInvalidMipLevelException(String message) { + super(CL_INVALID_MIP_LEVEL, "CL_INVALID_MIP_LEVEL", message); + } + } - case CL_PLATFORM_NOT_FOUND_KHR: - return "CL_PLATFORM_NOT_FOUND_KHR"; + /** + * {@link CLException} thrown on CL.CL_INVALID_GLOBAL_WORK_SIZE errors. + * @author Michael Bien + */ + public final static class CLInvalidGlobalWorkSizeException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_GLOBAL_WORK_SIZE; + public CLInvalidGlobalWorkSizeException(String message) { + super(CL_INVALID_GLOBAL_WORK_SIZE, "CL_INVALID_GLOBAL_WORK_SIZE", message); + } + } - default: - return "unknown cause: code" + error; + /** + * {@link CLException} thrown on CL.CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR errors. + * @author Michael Bien + */ + public final static class CLInvalidGLSharegroupReferenceKhrException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR; + public CLInvalidGLSharegroupReferenceKhrException(String message) { + super(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR, "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR", message); } } + /** + * {@link CLException} thrown on CL.CL_PLATFORM_NOT_FOUND_KHR errors. + * @author Michael Bien + */ + public final static class CLPlatformNotFoundKhrException extends CLException { + private static final long serialVersionUID = CLException.serialVersionUID+CL_PLATFORM_NOT_FOUND_KHR; + public CLPlatformNotFoundKhrException(String message) { + super(CL_PLATFORM_NOT_FOUND_KHR, "CL_PLATFORM_NOT_FOUND_KHR", message); + } + } }
\ No newline at end of file diff --git a/src/com/mbien/opencl/CLGLContext.java b/src/com/mbien/opencl/CLGLContext.java index 6fb0251f..46f0dea3 100644 --- a/src/com/mbien/opencl/CLGLContext.java +++ b/src/com/mbien/opencl/CLGLContext.java @@ -20,8 +20,8 @@ public final class CLGLContext extends CLContext { final long glID; - private CLGLContext(long clContextID, long glContextID) { - super(clContextID); + private CLGLContext(CLPlatform platform, long clContextID, long glContextID) { + super(platform, clContextID); this.glID = glContextID; } @@ -61,11 +61,15 @@ public final class CLGLContext extends CLContext { */ public static final CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice.Type... deviceTypes) { + if(platform == null) { + platform = CLPlatform.getDefault(); + } + long[] glID = new long[1]; - PointerBuffer properties = setupContextProperties(glContext, platform, glID); + PointerBuffer properties = setupContextProperties(platform, glContext, glID); long clID = createContextFromType(properties, toDeviceBitmap(deviceTypes)); - return new CLGLContext(clID, glID[0]); + return new CLGLContext(platform, clID, glID[0]); } @@ -75,11 +79,15 @@ public final class CLGLContext extends CLContext { */ public static final CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice... devices) { + if(platform == null) { + platform = CLPlatform.getDefault(); + } + long[] glID = new long[1]; - PointerBuffer properties = setupContextProperties(glContext, platform, glID); + PointerBuffer properties = setupContextProperties(platform, glContext, glID); long clID = createContext(properties, devices); - CLGLContext context = new CLGLContext(clID, glID[0]); + CLGLContext context = new CLGLContext(platform, clID, glID[0]); if(devices != null) { for (int i = 0; i < devices.length; i++) { devices[i].setContext(context); @@ -89,11 +97,7 @@ public final class CLGLContext extends CLContext { } - private static final PointerBuffer setupContextProperties(GLContext glContext, CLPlatform platform, long[] glID) { - - if(platform == null) { - platform = CLPlatform.getDefault(); - } + private static final PointerBuffer setupContextProperties(CLPlatform platform, GLContext glContext, long[] glID) { if(platform == null) { throw new RuntimeException("no OpenCL installation found"); diff --git a/src/com/mbien/opencl/CLKernel.java b/src/com/mbien/opencl/CLKernel.java index eb817f14..a8c1ff10 100644 --- a/src/com/mbien/opencl/CLKernel.java +++ b/src/com/mbien/opencl/CLKernel.java @@ -91,6 +91,11 @@ public class CLKernel implements CLResource, Cloneable { return this; } + public CLKernel rewind() { + argIndex = 0; + return this; + } + public CLKernel setArg(int argumentIndex, CLMemory<?> value) { setArgument(argumentIndex, CPU.is32Bit()?4:8, wrap(value.ID)); return this; @@ -157,6 +162,10 @@ public class CLKernel implements CLResource, Cloneable { this.force32BitArgs = force; return this; } + + public CLProgram getProgram() { + return program; + } /** * @see #setForce32BitArgs(boolean) @@ -181,11 +190,6 @@ public class CLKernel implements CLResource, Cloneable { return buffer.putLong(value).rewind(); } - public CLKernel rewind() { - argIndex = 0; - return this; - } - /** * Releases all resources of this kernel from its context. */ diff --git a/src/com/mbien/opencl/CLMemory.java b/src/com/mbien/opencl/CLMemory.java index 0c59e0c5..884744ad 100644 --- a/src/com/mbien/opencl/CLMemory.java +++ b/src/com/mbien/opencl/CLMemory.java @@ -91,6 +91,9 @@ public abstract class CLMemory <B extends Buffer> implements CLResource { return sizeOfBufferElem(buffer) * buffer.capacity(); } + /** + * Returns the size of the allocated OpenCL memory. + */ public long getCLSize() { PointerBuffer pb = PointerBuffer.allocateDirect(1); int ret = cl.clGetMemObjectInfo(ID, CL_MEM_SIZE, PointerBuffer.elementSize(), pb.getBuffer(), null); diff --git a/src/com/mbien/opencl/CLPlatform.java b/src/com/mbien/opencl/CLPlatform.java index c3b1a1f2..687cf130 100644 --- a/src/com/mbien/opencl/CLPlatform.java +++ b/src/com/mbien/opencl/CLPlatform.java @@ -2,7 +2,6 @@ package com.mbien.opencl; import com.mbien.opencl.impl.CLImpl; import com.sun.gluegen.runtime.PointerBuffer; -import com.sun.gluegen.runtime.ProcAddressHelper; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; @@ -77,11 +76,20 @@ public final class CLPlatform { /** * Returns the low level binding interface to the OpenCL APIs. */ - public static CL getLowLevelBinding() { + public static CL getLowLevelCLInterface() { return cl; } /** + * Hint to allow the implementation to release the resources allocated by the OpenCL compiler. + * Calls to {@link CLProgram#build()} after unloadCompiler will reload the compiler if necessary. + */ + public static void unloadCompiler() { + int ret = cl.clUnloadCompiler(); + checkForError(ret, "error while sending unload compiler hint"); + } + + /** * Lists all physical devices available on this platform. * @see #listCLDevices(com.mbien.opencl.CLDevice.Type) */ diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java index dfe084c7..aafca855 100644 --- a/src/com/mbien/opencl/CLProgram.java +++ b/src/com/mbien/opencl/CLProgram.java @@ -17,6 +17,10 @@ import static com.mbien.opencl.CL.*; /** * Represents a OpenCL program executed on one or more {@link CLDevice}s. + * A CLProgram must be build using one of the build methods before creating {@link CLKernel}s. + * @see CLContext#createProgram(java.io.InputStream) + * @see CLContext#createProgram(java.lang.String) + * @see CLContext#createProgram(java.util.Map) * @author Michael Bien */ public class CLProgram implements CLResource { @@ -231,7 +235,7 @@ public class CLProgram implements CLResource { int ret = cl.clBuildProgram(ID, count, deviceIDs, options, null, null); if(ret != CL_SUCCESS) { - throw new CLException(ret, "\n"+getBuildLog()); + throw newException(ret, "\n"+getBuildLog()); } return this; @@ -304,7 +308,7 @@ public class CLProgram implements CLResource { if(!isExecutable()) { // It is illegal to create kernels from a not executable program. // For consistency between AMD and NVIDIA drivers throw an exception at this point. - throw new CLException(CL_INVALID_PROGRAM_EXECUTABLE, + throw newException(CL_INVALID_PROGRAM_EXECUTABLE, "can not initialize kernels, program is not executable. status: "+buildStatusMap); } } @@ -342,6 +346,10 @@ public class CLProgram implements CLResource { } } + public CLContext getContext() { + return context; + } + /** * Returns all devices associated with this program. */ @@ -360,7 +368,7 @@ public class CLProgram implements CLResource { int count = bb.capacity() / (CPU.is32Bit()?4:8); CLDevice[] devices = new CLDevice[count]; for (int i = 0; i < count; i++) { - devices[i] = context.getCLDevice(CPU.is32Bit()?bb.getInt():bb.getLong()); + devices[i] = context.getDevice(CPU.is32Bit()?bb.getInt():bb.getLong()); } return devices; @@ -439,8 +447,8 @@ public class CLProgram implements CLResource { } /** - * Returns the binaries for this program in a map containing the device as key - * and the byte array as value. + * Returns the binaries for this program in a Map containing the device as key + * and the program binaries as value. */ public Map<CLDevice, byte[]> getBinaries() { @@ -497,6 +505,20 @@ public class CLProgram implements CLResource { return sb.toString(); } + /** + * Utility method for defining macros as build options (Returns "-D name"). + */ + public static String define(String name) { + return "-D "+name; + } + + /** + * Utility method for defining macros as build options (Returns "-D name=value"). + */ + public static String define(String name, String value) { + return "-D "+name+"="+value; + } + @Override public String toString() { return "CLProgram [id: " + ID diff --git a/test/com/mbien/opencl/CLBufferTest.java b/test/com/mbien/opencl/CLBufferTest.java index f768c5ae..39f85a75 100644 --- a/test/com/mbien/opencl/CLBufferTest.java +++ b/test/com/mbien/opencl/CLBufferTest.java @@ -33,7 +33,7 @@ public class CLBufferTest { // fill only first read buffer -> we will copy the payload to the second later. fillBuffer(clBufferA.buffer, 12345); - CLCommandQueue queue = context.getCLDevices()[0].createCommandQueue(); + CLCommandQueue queue = context.getDevices()[0].createCommandQueue(); // asynchronous write of data to GPU device, blocking read later to get the computed results back. queue.putWriteBuffer(clBufferA, false) // write A @@ -62,7 +62,7 @@ public class CLBufferTest { // fill only first read buffer -> we will copy the payload to the second later. fillBuffer(buffer, 12345); - CLCommandQueue queue = context.getCLDevices()[0].createCommandQueue(); + CLCommandQueue queue = context.getDevices()[0].createCommandQueue(); Mem[] bufferConfig = new Mem[] {Mem.COPY_BUFFER, Mem.USE_BUFFER}; @@ -78,11 +78,11 @@ public class CLBufferTest { .putReadBuffer(clBufferB, true) // read B .finish(); - assertEquals(2, context.getCLMemoryObjects().size()); + assertEquals(2, context.getMemoryObjects().size()); clBufferA.release(); - assertEquals(1, context.getCLMemoryObjects().size()); + assertEquals(1, context.getMemoryObjects().size()); clBufferB.release(); - assertEquals(0, context.getCLMemoryObjects().size()); + assertEquals(0, context.getMemoryObjects().size()); // uploading worked when a==b. out.println("validating computed results..."); @@ -121,7 +121,7 @@ public class CLBufferTest { clBufferB = context.createByteBuffer(sizeInBytes, Mem.READ_WRITE, Mem.USE_BUFFER); } - CLCommandQueue queue = context.getCLDevices()[0].createCommandQueue(); + CLCommandQueue queue = context.getDevices()[0].createCommandQueue(); // fill only first buffer -> we will copy the payload to the second later. ByteBuffer mappedBufferA = queue.putMapBuffer(clBufferA, Map.READ_WRITE, true); diff --git a/test/com/mbien/opencl/CLCommandQueueTest.java b/test/com/mbien/opencl/CLCommandQueueTest.java index b52ef5ed..2cf9c1bf 100644 --- a/test/com/mbien/opencl/CLCommandQueueTest.java +++ b/test/com/mbien/opencl/CLCommandQueueTest.java @@ -26,7 +26,7 @@ public class CLCommandQueueTest { //CLCommandQueueEnums EnumSet<Mode> queueMode = Mode.valuesOf(CL.CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL.CL_QUEUE_PROFILING_ENABLE); - assertTrue(queueMode.contains(Mode.OUT_OF_ORDER_EXEC_MODE)); + assertTrue(queueMode.contains(Mode.OUT_OF_ORDER_MODE)); assertTrue(queueMode.contains(Mode.PROFILING_MODE)); assertNotNull(Mode.valuesOf(0)); @@ -69,7 +69,7 @@ public class CLCommandQueueTest { CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build(); CLKernel vectorAddKernel = program.createCLKernel("VectorAddGM").setArg(3, elements); - CLCommandQueue queue = context.getCLDevices()[0].createCommandQueue(); + CLCommandQueue queue = context.getDevices()[0].createCommandQueue(); final CLEventList events = new CLEventList(2); @@ -126,7 +126,7 @@ public class CLCommandQueueTest { CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build(); CLKernel vectorAddKernel = program.createCLKernel("VectorAddGM").setArg(3, elements); - CLCommandQueue queue = context.getCLDevices()[0].createCommandQueue(Mode.PROFILING_MODE); + CLCommandQueue queue = context.getDevices()[0].createCommandQueue(Mode.PROFILING_MODE); queue.putWriteBuffer(clBufferA, true) // write A .putWriteBuffer(clBufferB, true);// write B @@ -165,7 +165,7 @@ public class CLCommandQueueTest { CLContext context = CLContext.create(); - CLDevice[] devices = context.getCLDevices(); + CLDevice[] devices = context.getDevices(); if (devices.length < 2) { out.println("aborting test... need at least 2 devices"); diff --git a/test/com/mbien/opencl/HighLevelBindingTest.java b/test/com/mbien/opencl/HighLevelBindingTest.java index 21014e8a..3a75e03c 100644 --- a/test/com/mbien/opencl/HighLevelBindingTest.java +++ b/test/com/mbien/opencl/HighLevelBindingTest.java @@ -1,7 +1,10 @@ package com.mbien.opencl; import com.mbien.opencl.CLMemory.Mem; -import com.mbien.opencl.CLCommandQueue.Mode; +import com.mbien.opencl.CLSampler.AddressingMode; +import com.mbien.opencl.CLSampler.FilteringMode; +import com.mbien.opencl.CLImageFormat.ChannelOrder; +import com.mbien.opencl.CLImageFormat.ChannelType; import com.mbien.opencl.CLDevice.FPConfig; import com.mbien.opencl.CLDevice.GlobalMemCacheType; import com.mbien.opencl.CLDevice.LocalMemType; @@ -62,6 +65,22 @@ public class HighLevelBindingTest { assertEquals(e, Mem.valueOf(e.CONFIG)); } + // CLSampler enums + for (AddressingMode e : AddressingMode.values()) { + assertEquals(e, AddressingMode.valueOf(e.MODE)); + } + for (FilteringMode e : FilteringMode.values()) { + assertEquals(e, FilteringMode.valueOf(e.MODE)); + } + + // CLImage enums + for (ChannelOrder e : ChannelOrder.values()) { + assertEquals(e, ChannelOrder.valueOf(e.ORDER)); + } + for (ChannelType e : ChannelType.values()) { + assertEquals(e, ChannelType.valueOf(e.TYPE)); + } + } @@ -142,32 +161,32 @@ public class HighLevelBindingTest { CLContext c = CLContext.create(); assertNotNull(c); - assertEquals(deviceCount, c.getCLDevices().length); + assertEquals(deviceCount, c.getDevices().length); c.release(); c = CLContext.create(platform); assertNotNull(c); - assertEquals(deviceCount, c.getCLDevices().length); + assertEquals(deviceCount, c.getDevices().length); c.release(); c = CLContext.create(firstDevice); assertNotNull(c); - assertEquals(1, c.getCLDevices().length); + assertEquals(1, c.getDevices().length); c.release(); c = CLContext.create(CLDevice.Type.ALL); assertNotNull(c); - assertEquals(deviceCount, c.getCLDevices().length); + assertEquals(deviceCount, c.getDevices().length); c.release(); c = CLContext.create(platform, firstDevice); assertNotNull(c); - assertEquals(1, c.getCLDevices().length); + assertEquals(1, c.getDevices().length); c.release(); c = CLContext.create(platform, CLDevice.Type.ALL); assertNotNull(c); - assertEquals(deviceCount, c.getCLDevices().length); + assertEquals(deviceCount, c.getDevices().length); c.release(); } @@ -180,7 +199,7 @@ public class HighLevelBindingTest { CLPlatform[] clPlatforms = CLPlatform.listCLPlatforms(); CLContext context = CLContext.create(clPlatforms[0]); - CLDevice[] contextDevices = context.getCLDevices(); + CLDevice[] contextDevices = context.getDevices(); out.println("context devices:"); for (CLDevice device : contextDevices) { @@ -251,22 +270,22 @@ public class HighLevelBindingTest { out.print(dest.getInt()+", "); out.println("...; "+dest.remaining()/SIZEOF_INT + " more"); - assertTrue(3 == context.getCLMemoryObjects().size()); + assertTrue(3 == context.getMemoryObjects().size()); clBufferA.release(); - assertTrue(2 == context.getCLMemoryObjects().size()); + assertTrue(2 == context.getMemoryObjects().size()); - assertTrue(2 == context.getCLMemoryObjects().size()); + assertTrue(2 == context.getMemoryObjects().size()); clBufferB.release(); - assertTrue(1 == context.getCLMemoryObjects().size()); + assertTrue(1 == context.getMemoryObjects().size()); - assertTrue(1 == context.getCLMemoryObjects().size()); + assertTrue(1 == context.getMemoryObjects().size()); clBufferC.release(); - assertTrue(0 == context.getCLMemoryObjects().size()); + assertTrue(0 == context.getMemoryObjects().size()); - assertTrue(1 == context.getCLPrograms().size()); + assertTrue(1 == context.getPrograms().size()); program.release(); - assertTrue(0 == context.getCLPrograms().size()); + assertTrue(0 == context.getPrograms().size()); context.release(); } |