From 9ca000faa6aea6771ff5cf209846ef7fb9ff227a Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Fri, 22 Jan 2010 18:02:35 +0100 Subject: dynamic dispatch via CLProcAddressTable for OpenCL extensions. made CLProgram failsafe, updated tests. --- src/com/mbien/opencl/CLProgram.java | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src/com') diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java index 306a5b66..39663e54 100644 --- a/src/com/mbien/opencl/CLProgram.java +++ b/src/com/mbien/opencl/CLProgram.java @@ -29,6 +29,7 @@ public class CLProgram implements CLResource { private Map buildStatusMap; private boolean executable; + private boolean released; CLProgram(CLContext context, String src) { @@ -127,10 +128,12 @@ public class CLProgram implements CLResource { } } - // TODO serialization, program build options - private final String getBuildInfoString(long device, int flag) { + if(released) { + return ""; + } + PointerBuffer pb = PointerBuffer.allocateDirect(1); int ret = cl.clGetProgramBuildInfo(ID, device, flag, 0, null, pb); @@ -146,6 +149,10 @@ public class CLProgram implements CLResource { private final String getProgramInfoString(int flag) { + if(released) { + return ""; + } + PointerBuffer pb = PointerBuffer.allocateDirect(1); int ret = cl.clGetProgramInfo(ID, flag, 0, null, pb); @@ -254,6 +261,10 @@ public class CLProgram implements CLResource { releaseKernels(); + executable = false; + released = true; + buildStatusMap = null; + int ret = cl.clReleaseProgram(ID); context.onProgramReleased(this); checkForError(ret, "can not release program"); @@ -274,6 +285,9 @@ public class CLProgram implements CLResource { * @throws IllegalArgumentException when no kernel with the specified name exists in this program. */ public CLKernel getCLKernel(String kernelName) { + if(released) { + return null; + } initKernels(); final CLKernel kernel = kernels.get(kernelName); if(kernel == null) { @@ -289,6 +303,9 @@ public class CLProgram implements CLResource { * with the kernel function names as keys. */ public Map getCLKernels() { + if(released) { + return Collections.emptyMap(); + } initKernels(); return Collections.unmodifiableMap(kernels); } @@ -297,7 +314,9 @@ public class CLProgram implements CLResource { * Returns all devices associated with this program. */ public CLDevice[] getCLDevices() { - + if(released) { + return new CLDevice[0]; + } PointerBuffer pb = PointerBuffer.allocateDirect(1); int ret = cl.clGetProgramInfo(ID, CL_PROGRAM_DEVICES, 0, null, pb); checkForError(ret, "on clGetProgramInfo"); @@ -321,6 +340,9 @@ public class CLProgram implements CLResource { * implementation dependent. */ public String getBuildLog() { + if(released) { + return ""; + } StringBuilder sb = new StringBuilder(); CLDevice[] devices = getCLDevices(); for (int i = 0; i < devices.length; i++) { @@ -338,6 +360,9 @@ public class CLProgram implements CLResource { * Returns the build status enum of this program for each device as Map. */ public Map getBuildStatus() { + if(released) { + return Collections.emptyMap(); + } initBuildStatus(); return buildStatusMap; } @@ -347,6 +372,9 @@ public class CLProgram implements CLResource { * of this program exists. */ public boolean isExecutable() { + if(released) { + return false; + } initBuildStatus(); return executable; } @@ -363,6 +391,9 @@ public class CLProgram implements CLResource { * Returns the build status enum for this program on the specified device. */ public Status getBuildStatus(CLDevice device) { + if(released) { + return Status.BUILD_NONE; + } int clStatus = getBuildInfoInt(device.ID, CL_PROGRAM_BUILD_STATUS); return Status.valueOf(clStatus); } @@ -381,6 +412,10 @@ public class CLProgram implements CLResource { */ public Map getBinaries() { + if(!isExecutable()) { + return Collections.emptyMap(); + } + CLDevice[] devices = getCLDevices(); ByteBuffer sizes = ByteBuffer.allocateDirect(8*devices.length).order(ByteOrder.nativeOrder()); -- cgit v1.2.3