diff options
author | Michael Bien <[email protected]> | 2009-11-02 02:18:21 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-11-02 02:18:21 +0100 |
commit | b2dfcb34a4cdc9c45d5ce20a2b1559b4bf3ebb8c (patch) | |
tree | 1245bfc07fdf03618a7d867c46e49e0762ccb967 | |
parent | 1690ead6c21b61bd337706b836c04164940eed69 (diff) |
refactoring and more utility methods.
-rw-r--r-- | build.xml | 10 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLContext.java | 21 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLPlatform.java | 32 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLProgram.java | 33 | ||||
-rw-r--r-- | test/com/mbien/opencl/HighLevelBindingTest.java | 13 |
5 files changed, 75 insertions, 34 deletions
@@ -17,6 +17,7 @@ <property name="jogl.root" value="${basedir}/../jogl" /> <property name="etc.build.dir" value="${basedir}/etc/build" /> + <property name="headers.dest" value="${basedir}/resources/includes/CL" /> <!-- Pull in GlueGen cpptasks build file --> <import file="${gluegen.root}/make/gluegen-cpptasks.xml" /> @@ -69,8 +70,11 @@ <target name="prepare-build"> + <property name="headers.orig" value="${basedir}/resources/includes/CL_orig" /> + <!--compile build utilities--> <mkdir dir="${etc.build.dir}"/> + <mkdir dir="${headers.dest}"/> <javac destdir="${etc.build.dir}" classpath="${ant.core.lib}" source="1.5" debug="true" debuglevel="lines,vars,source"> <src path="${basedir}/etc/src"/> @@ -78,15 +82,12 @@ <taskdef name="uncomment-function-params" classname="com.mbien.ant.FunctionParamUncommenter" classpath="${etc.build.dir}"/> - <property name="headers.orig" value="${basedir}/resources/includes/CL_orig" /> - <property name="headers.dest" value="${basedir}/resources/includes/CL" /> - <!--uncomment function names in c headers and copy modified files into include path--> <uncomment-function-params src="${headers.orig}/cl.h" dest="${headers.dest}/cl.h"/> <uncomment-function-params src="${headers.orig}/cl_gl.h" dest="${headers.dest}/cl_gl.h"/> <!--nothing to uncomment in cl_platform.h--> - <copyfile src="${headers.orig}/cl_platform.h" dest="${headers.dest}/cl_platform.h" forceoverwrite="true"/> + <copy file="${headers.orig}/cl_platform.h" toDir="${headers.dest}" overwrite="true"/> </target> @@ -200,6 +201,7 @@ <target name="-post-clean"> <delete dir="gensrc"/> <delete dir="${etc.build.dir}"/> + <delete dir="${headers.dest}"/> </target> <!-- diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java index 66716e41..c87f2310 100644 --- a/src/com/mbien/opencl/CLContext.java +++ b/src/com/mbien/opencl/CLContext.java @@ -299,26 +299,7 @@ public final class CLContext { * MAX_COMPUTE_UNITS and MAX_CLOCK_FREQUENCY. */ public CLDevice getMaxFlopsDevice() { - - CLDevice[] clDevices = getCLDevices(); - CLDevice maxFLOPSDevice = null; - - int maxflops = -1; - - for (int i = 0; i < clDevices.length; i++) { - - CLDevice device = clDevices[i]; - int maxComputeUnits = device.getMaxComputeUnits(); - int maxClockFrequency = device.getMaxClockFrequency(); - int flops = maxComputeUnits*maxClockFrequency; - - if(flops > maxflops) { - maxflops = flops; - maxFLOPSDevice = device; - } - } - - return maxFLOPSDevice; + return CLPlatform.findMaxFlopsDevice(getCLDevices()); } /** diff --git a/src/com/mbien/opencl/CLPlatform.java b/src/com/mbien/opencl/CLPlatform.java index 56ef3713..f1ecdd86 100644 --- a/src/com/mbien/opencl/CLPlatform.java +++ b/src/com/mbien/opencl/CLPlatform.java @@ -82,6 +82,38 @@ public final class CLPlatform { } + static final CLDevice findMaxFlopsDevice(CLDevice[] devices) { + + CLDevice maxFLOPSDevice = null; + + int maxflops = -1; + + for (int i = 0; i < devices.length; i++) { + + CLDevice device = devices[i]; + int maxComputeUnits = device.getMaxComputeUnits(); + int maxClockFrequency = device.getMaxClockFrequency(); + int flops = maxComputeUnits*maxClockFrequency; + + if(flops > maxflops) { + maxflops = flops; + maxFLOPSDevice = device; + } + } + + return maxFLOPSDevice; + } + + + /** + * Gets the device with maximal FLOPS from this platform. + * The device speed is estimated by calulating the product of + * MAX_COMPUTE_UNITS and MAX_CLOCK_FREQUENCY. + */ + public CLDevice getMaxFlopsDevice() { + return findMaxFlopsDevice(listCLDevices()); + } + /** * Returns the platform name. */ diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java index ff2919e8..da0a0447 100644 --- a/src/com/mbien/opencl/CLProgram.java +++ b/src/com/mbien/opencl/CLProgram.java @@ -210,8 +210,37 @@ public class CLProgram { } /** - * Returns the build log for this program. The contents of the log are - * implementation dependent log can be an empty String. + * Returns the build log of this program on all devices. The contents of the log are + * implementation dependent. + */ + public String getBuildLog() { + StringBuilder sb = new StringBuilder(); + CLDevice[] devices = getCLDevices(); + for (int i = 0; i < devices.length; i++) { + CLDevice device = devices[i]; + sb.append(device).append(" build log:"); + sb.append(getBuildLog(device)); + if(i != devices.length-1) + sb.append("\n"); + } + return sb.toString(); + } + + /** + * Returns the build status enum of this program for each device as Map. + */ + public Map<CLDevice,Status> getBuildStatus() { + Map<CLDevice,Status> statusMap = new HashMap<CLDevice, Status>(); + CLDevice[] devices = getCLDevices(); + for (CLDevice device : devices) { + statusMap.put(device, getBuildStatus(device)); + } + return Collections.unmodifiableMap(statusMap); + } + + /** + * Returns the build log for this program on the specified device. The contents + * of the log are implementation dependent log can be an empty String. */ public String getBuildLog(CLDevice device) { return getBuildInfoString(device.ID, CL.CL_PROGRAM_BUILD_LOG); diff --git a/test/com/mbien/opencl/HighLevelBindingTest.java b/test/com/mbien/opencl/HighLevelBindingTest.java index 915a5ce2..4665c27d 100644 --- a/test/com/mbien/opencl/HighLevelBindingTest.java +++ b/test/com/mbien/opencl/HighLevelBindingTest.java @@ -54,6 +54,7 @@ public class HighLevelBindingTest { out.println(" profile: "+platform.getProfile()); out.println(" version: "+platform.getVersion()); out.println(" vendor: "+platform.getVendor()); + out.println(" max FLOPS device: "+platform.getMaxFlopsDevice()); CLDevice[] clDevices = platform.listCLDevices(); for (CLDevice device : clDevices) { @@ -95,18 +96,16 @@ public class HighLevelBindingTest { out.println(" "+device.toString()); } + out.println("max FLOPS device: " + context.getMaxFlopsDevice()); + CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build(); CLDevice[] programDevices = program.getCLDevices(); assertEquals(contextDevices.length, programDevices.length); - out.println("program devices:"); - for (CLDevice device : programDevices) { - out.println(" "+device.toString()); - out.println(" build log: "+program.getBuildLog(device)); - out.println(" build status: "+program.getBuildStatus(device)); - } + out.println("build log:\n"+program.getBuildLog()); + out.println("build status:\n"+program.getBuildStatus()); String source = program.getSource(); assertFalse(source.trim().isEmpty()); @@ -178,8 +177,6 @@ public class HighLevelBindingTest { program.release(); assertTrue(0 == context.getCLPrograms().size()); -// CLDevice device = ctx.getMaxFlopsDevice(); -// out.println("max FLOPS device: " + device); context.release(); } |