diff options
author | Michael Bien <[email protected]> | 2010-01-16 20:21:31 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-01-16 20:21:31 +0100 |
commit | c4aeea288271f57b3c8640a8cd4ba87d1c331814 (patch) | |
tree | ac06175804b6a690a4ef19a2550dacea7b99d9f2 | |
parent | 5193eb3c98bfa14ca8eb5767452c8e97f9f495c6 (diff) |
more utility getters for CLDevice.
-rw-r--r-- | src/com/mbien/opencl/CLDevice.java | 129 | ||||
-rw-r--r-- | test/com/mbien/opencl/HighLevelBindingTest.java | 19 |
2 files changed, 125 insertions, 23 deletions
diff --git a/src/com/mbien/opencl/CLDevice.java b/src/com/mbien/opencl/CLDevice.java index 7a676fe6..f1a402be 100644 --- a/src/com/mbien/opencl/CLDevice.java +++ b/src/com/mbien/opencl/CLDevice.java @@ -20,6 +20,7 @@ public final class CLDevice { private final CL cl; private CLContext context; + private Set<String> extensions; private final CLDeviceInfoAccessor deviceInfo; @@ -92,6 +93,29 @@ public final class CLDevice { } /** + * Returns the vendor id of this device. + */ + public long getVendorID() { + return deviceInfo.getLong(CL_DEVICE_VENDOR_ID); + } + + /** + * Returns OpenCL version string. Returns the OpenCL version supported by the device. + * This version string has the following format:<br> + * OpenCL[space][major_version.minor_version][space][vendor-specific information] + */ + public String getVersion() { + return deviceInfo.getString(CL_DEVICE_VERSION); + } + + /** + * Returns OpenCL software driver version string in the form major_number.minor_number. + */ + public String getDriverVersion() { + return deviceInfo.getString(CL_DRIVER_VERSION); + } + + /** * Returns the type of this device. */ public Type getType() { @@ -99,6 +123,14 @@ public final class CLDevice { } /** + * The default compute device address space size specified in bits. + * Currently supported values are 32 or 64 bits. + */ + public int getAddressBits() { + return (int)deviceInfo.getLong(CL_DEVICE_ADDRESS_BITS); + } + + /** * Returns the number of parallel compute cores on the OpenCL device. * The minimum value is 1. */ @@ -132,6 +164,21 @@ public final class CLDevice { } /** + * Returns the max size in bytes of the arguments that can be passed to a kernel. + * The minimum value is 256. + */ + public long getMaxParameterSize() { + return deviceInfo.getLong(CL_DEVICE_MAX_PARAMETER_SIZE); + } + + /** + * Returns the maximal allocatable memory on this device. + */ + public long getMaxMemAllocSize() { + return deviceInfo.getLong(CL_DEVICE_MAX_MEM_ALLOC_SIZE); + } + + /** * Returns the global memory size in bytes. */ public long getGlobalMemSize() { @@ -246,10 +293,41 @@ public final class CLDevice { } /** + * Returns the optional half precision floating-point capability of the device. + * The required minimum half precision floating-point capabilities as implemented by this + * extension are {@link FPConfig#ROUND_TO_ZERO}, {@link FPConfig#ROUND_TO_INF} + * and {@link FPConfig#INF_NAN}. + * @return An EnumSet containing the extensions, never null. + */ + public EnumSet<FPConfig> getHalfFPConfig() { + if(isHalfFPAvailable()) + return FPConfig.valuesOf((int)deviceInfo.getLong(CL_DEVICE_HALF_FP_CONFIG)); + else + return EnumSet.noneOf(FPConfig.class); + } + + /** * Returns the single precision floating-point capability of the device. + * The mandated minimum floating-point capabilities are {@link FPConfig#ROUND_TO_NEAREST} and + * {@link FPConfig#INF_NAN}. + * @return An EnumSet containing the extensions, never null. + */ + public EnumSet<FPConfig> getSingleFPConfig() { + return FPConfig.valuesOf((int)deviceInfo.getLong(CL_DEVICE_SINGLE_FP_CONFIG)); + } + + /** + * Returns the optional double precision floating-point capability of the device. + * The mandated minimum double precision floating-point capabilities are {@link FPConfig#FMA}, + * {@link FPConfig#ROUND_TO_NEAREST}, {@link FPConfig#_ROUND_TO_ZERO}, + * {@link FPConfig#ROUND_TO_INF}, {@link FPConfig#INF_NAN}, and {@link FPConfig#DENORM}. + * @return An EnumSet containing the extensions, never null. */ - public EnumSet<SingleFPConfig> getSingleFPConfig() { - return SingleFPConfig.valuesOf((int)deviceInfo.getLong(CL_DEVICE_SINGLE_FP_CONFIG)); + public EnumSet<FPConfig> getDoubleFPConfig() { + if(isDoubleFPAvailable()) + return FPConfig.valuesOf((int)deviceInfo.getLong(CL_DEVICE_DOUBLE_FP_CONFIG)); + else + return EnumSet.noneOf(FPConfig.class); } /** @@ -306,19 +384,36 @@ public final class CLDevice { } /** + * Returns {@link #getExtensions()}.contains("cl_khr_fp16"); + */ + public boolean isHalfFPAvailable() { + return getExtensions().contains("cl_khr_fp16"); + } + + /** + * Returns {@link #getExtensions()}.contains("cl_khr_fp64"); + */ + public boolean isDoubleFPAvailable() { + return getExtensions().contains("cl_khr_fp64"); + } + + /** * Returns all device extension names as unmodifiable Set. */ public Set<String> getExtensions() { - String ext = deviceInfo.getString(CL_DEVICE_EXTENSIONS); + if(extensions == null) { + extensions = new HashSet<String>(); + String ext = deviceInfo.getString(CL_DEVICE_EXTENSIONS); + Scanner scanner = new Scanner(ext); - Scanner scanner = new Scanner(ext); - Set<String> extSet = new HashSet<String>(); + while(scanner.hasNext()) + extensions.add(scanner.next()); - while(scanner.hasNext()) - extSet.add(scanner.next()); + extensions = Collections.unmodifiableSet(extensions); + } - return Collections.unmodifiableSet(extSet); + return extensions; } @@ -418,10 +513,10 @@ public final class CLDevice { } /** - * Describes single precision floating-point capability of the device. - * One or more values are possible. + * Describes floating-point capability of the device. + * Zero or more values are possible. */ - public enum SingleFPConfig { + public enum FPConfig { /** * denorms are supported. @@ -459,22 +554,22 @@ public final class CLDevice { */ public final int CONFIG; - private SingleFPConfig(int config) { + private FPConfig(int config) { this.CONFIG = config; } /** * Returns a EnumSet for the given bitfield. */ - public static EnumSet<SingleFPConfig> valuesOf(int bitfield) { - List<SingleFPConfig> matching = new ArrayList<SingleFPConfig>(); - SingleFPConfig[] values = SingleFPConfig.values(); - for (SingleFPConfig value : values) { + public static EnumSet<FPConfig> valuesOf(int bitfield) { + List<FPConfig> matching = new ArrayList<FPConfig>(); + FPConfig[] values = FPConfig.values(); + for (FPConfig value : values) { if((value.CONFIG & bitfield) != 0) matching.add(value); } if(matching.isEmpty()) - return EnumSet.noneOf(SingleFPConfig.class); + return EnumSet.noneOf(FPConfig.class); else return EnumSet.copyOf(matching); } diff --git a/test/com/mbien/opencl/HighLevelBindingTest.java b/test/com/mbien/opencl/HighLevelBindingTest.java index cf19c5b1..84c2a33b 100644 --- a/test/com/mbien/opencl/HighLevelBindingTest.java +++ b/test/com/mbien/opencl/HighLevelBindingTest.java @@ -2,7 +2,7 @@ package com.mbien.opencl; import com.mbien.opencl.CLBuffer.Mem; import com.mbien.opencl.CLCommandQueue.Mode; -import com.mbien.opencl.CLDevice.SingleFPConfig; +import com.mbien.opencl.CLDevice.FPConfig; import java.io.IOException; import java.nio.ByteBuffer; import java.util.EnumSet; @@ -35,10 +35,10 @@ public class HighLevelBindingTest { out.println(" - - - highLevelTest; contextless - - - "); // enum tests - final EnumSet<SingleFPConfig> singleFPConfig = SingleFPConfig.valuesOf(CL.CL_FP_DENORM | CL.CL_FP_ROUND_TO_INF); - assertEquals(0, SingleFPConfig.valuesOf(0).size()); - assertTrue(singleFPConfig.contains(SingleFPConfig.DENORM)); - assertTrue(singleFPConfig.contains(SingleFPConfig.ROUND_TO_INF)); + final EnumSet<FPConfig> singleFPConfig = FPConfig.valuesOf(CL.CL_FP_DENORM | CL.CL_FP_ROUND_TO_INF); + assertEquals(0, FPConfig.valuesOf(0).size()); + assertTrue(singleFPConfig.contains(FPConfig.DENORM)); + assertTrue(singleFPConfig.contains(FPConfig.ROUND_TO_INF)); final EnumSet<Mode> queueMode = Mode.valuesOf(CL.CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL.CL_QUEUE_PROFILING_ENABLE); assertEquals(0, Mode.valuesOf(0).size()); @@ -64,8 +64,13 @@ public class HighLevelBindingTest { out.println(" name: "+device.getName()); out.println(" profile: "+device.getProfile()); out.println(" vendor: "+device.getVendor()); + out.println(" vendor id: "+device.getVendorID()); + out.println(" version: "+device.getVersion()); + out.println(" driver version: "+device.getDriverVersion()); out.println(" type: "+device.getType()); out.println(" global mem: "+device.getGlobalMemSize()/(1024*1024)+" MB"); + out.println(" max alloc mem: "+device.getMaxMemAllocSize()/(1024*1024)+" MB"); + out.println(" max param size: "+device.getMaxParameterSize()+" byte"); out.println(" local mem: "+device.getLocalMemSize()/1024+" KB"); out.println(" local mem type: "+device.getLocalMemType()); out.println(" global mem cache size: "+device.getGlobalMemCachSize()); @@ -74,9 +79,11 @@ public class HighLevelBindingTest { out.println(" queue properties: "+device.getQueueProperties()); out.println(" clock: "+device.getMaxClockFrequency()+" MHz"); out.println(" timer res: "+device.getProfilingTimerResolution()+" ns"); - out.println(" single FP config: "+device.getSingleFPConfig()); out.println(" max work group size: "+device.getMaxWorkGroupSize()); out.println(" max compute units: "+device.getMaxComputeUnits()); + out.println(" half FP config: "+device.getHalfFPConfig()); + out.println(" single FP config: "+device.getSingleFPConfig()); + out.println(" double FP config: "+device.getDoubleFPConfig()); out.println(" extensions: "+device.getExtensions()); } } |