Skip to content

Commit

Permalink
added Capabilities enum and getter to CLDevice.
Browse files Browse the repository at this point in the history
updated tests.
  • Loading branch information
mbien committed Mar 16, 2010
1 parent 68b70f6 commit 81b94f8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
58 changes: 57 additions & 1 deletion src/com/mbien/opencl/CLDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ public long getProfilingTimerResolution() {
return deviceInfo.getLong(CL_DEVICE_PROFILING_TIMER_RESOLUTION);
}

/**
* Returns the execution capabilities as EnumSet.
*/
public EnumSet<Capabilities> getExecutionCapabilities() {
return Capabilities.valuesOf((int)deviceInfo.getLong(CL_DEVICE_EXECUTION_CAPABILITIES));
}

/**
* Returns the optional half precision floating-point capability of the device.
* The required minimum half precision floating-point capabilities as implemented by this
Expand Down Expand Up @@ -432,7 +439,7 @@ public boolean isCompilerAvailable() {
/**
* Returns true if the OpenCL device is a little endian device and false otherwise.
*/
public boolean isLittleEndianAvailable() {
public boolean isLittleEndian() {
return deviceInfo.getLong(CL_DEVICE_ENDIAN_LITTLE) == CL_TRUE;
}

Expand Down Expand Up @@ -545,6 +552,55 @@ public int hashCode() {
return hash;
}

/**
* Enumeration for the execution capabilities of the device.
*/
public enum Capabilities {

/**
* The OpenCL device can execute OpenCL kernels.
*/
EXEC_KERNEL(CL_EXEC_KERNEL),

/**
* The OpenCL device can execute native kernels.
*/
EXEC_NATIVE_KERNEL(CL_EXEC_NATIVE_KERNEL);

/**
* Value of wrapped OpenCL device type.
*/
public final int CAPS;

private Capabilities(int type) {
this.CAPS = type;
}

public static Capabilities valueOf(int caps) {
switch(caps) {
case(CL_EXEC_KERNEL):
return EXEC_KERNEL;
case(CL_EXEC_NATIVE_KERNEL):
return EXEC_NATIVE_KERNEL;
}
return null;
}

public static EnumSet<Capabilities> valuesOf(int bitfield) {
if((EXEC_KERNEL.CAPS & bitfield) != 0) {
if((EXEC_NATIVE_KERNEL.CAPS & bitfield) != 0) {
return EnumSet.of(EXEC_KERNEL, EXEC_NATIVE_KERNEL);
}else{
return EnumSet.of(EXEC_KERNEL);
}
}else if((EXEC_NATIVE_KERNEL.CAPS & bitfield) != 0){
return EnumSet.of(EXEC_NATIVE_KERNEL);
}
return null;
}

}

/**
* Enumeration for the type of a device.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/com/mbien/opencl/CLProgramBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
* CLProgramBuilder is a helper for building programs with more complex configurations or
* building multiple programs with the same configuration.
* building multiple programs with similar configurations.
* @see CLProgram#prepare()
* @see #createConfiguration()
* @see #createConfiguration(com.mbien.opencl.CLProgram)
Expand Down
3 changes: 2 additions & 1 deletion src/com/mbien/opencl/util/CLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ public static Map<String, String> obtainDeviceProperties(CLDevice dev) {
map.put("CL_DEVICE_IMAGE2D_MAX_DIMENSIONS", Arrays.asList(dev.getMaxImage2dWidth(), dev.getMaxImage2dHeight()).toString());
map.put("CL_DEVICE_IMAGE3D_MAX_DIMENSIONS", Arrays.asList(dev.getMaxImage2dWidth(), dev.getMaxImage2dHeight(), dev.getMaxImage3dDepth()).toString());
map.put("CL_DEVICE_MAX_SAMPLERS", dev.getMaxSamplers()+"");
map.put("CL_DEVICE_EXECUTION_CAPABILITIES", dev.getExecutionCapabilities()+"");

map.put("CL_DEVICE_ADDRESS_BITS", dev.getAddressBits()+"");
map.put("cl_khr_fp16", dev.isHalfFPAvailable()+"");
map.put("cl_khr_fp64", dev.isDoubleFPAvailable()+"");
map.put("CL_DEVICE_ENDIAN_LITTLE", dev.isLittleEndianAvailable()+"");
map.put("CL_DEVICE_ENDIAN_LITTLE", dev.isLittleEndian()+"");
map.put("CL_DEVICE_HALF_FP_CONFIG", dev.getHalfFPConfig()+"");
map.put("CL_DEVICE_SINGLE_FP_CONFIG", dev.getSingleFPConfig()+"");
map.put("CL_DEVICE_DOUBLE_FP_CONFIG", dev.getDoubleFPConfig()+"");
Expand Down
7 changes: 6 additions & 1 deletion test/com/mbien/opencl/HighLevelBindingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.mbien.opencl.CLDevice.GlobalMemCacheType;
import com.mbien.opencl.CLDevice.LocalMemType;
import com.mbien.opencl.CLDevice.Type;
import com.mbien.opencl.CLDevice.Capabilities;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
Expand Down Expand Up @@ -60,6 +61,9 @@ public void enumsTest() {
for (Type e : Type.values()) {
assertEquals(e, Type.valueOf(e.TYPE));
}
for (Capabilities e : Capabilities.values()) {
assertEquals(e, Capabilities.valueOf(e.CAPS));
}

// CLMemory enums
for (Mem e : Mem.values()) {
Expand Down Expand Up @@ -145,10 +149,11 @@ public void contextlessTest() {
out.println(" number of address bits: "+device.getAddressBits());
out.println(" half FP available: "+device.isHalfFPAvailable());
out.println(" double FP available: "+device.isDoubleFPAvailable());
out.println(" little endian: "+device.isLittleEndianAvailable());
out.println(" little endian: "+device.isLittleEndian());
out.println(" half FP config: "+device.getHalfFPConfig());
out.println(" single FP config: "+device.getSingleFPConfig());
out.println(" double FP config: "+device.getDoubleFPConfig());
out.println(" execution capabilities: "+device.getExecutionCapabilities());
out.println(" extensions: "+device.getExtensions());
}
}
Expand Down

0 comments on commit 81b94f8

Please sign in to comment.