Skip to content

Commit

Permalink
Bug 978: Promote CLAbstractImpl.isAvailable() to CLPlatform, public A…
Browse files Browse the repository at this point in the history
…PI. isAvailable() simply shall return true if JOCL/OpenCL libs could be loaded.

- Promote CLAbstractImpl.isAvailable() to CLPlatform, public API.

- CLAbstractImpl.isAvailable() simply shall return true if JOCL/OpenCL libs could be loaded.
  • Loading branch information
sgothel committed Sep 3, 2014
1 parent 87eb9b9 commit c720767
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
35 changes: 18 additions & 17 deletions src/com/jogamp/opencl/CLPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
*
* optional eager initialization:
* <p><pre>
* if( !CLPlatform.isAvailable() ) {
* return; // abort
* }
* try{
* CLPlatform.initialize();
* }catch(JogampRuntimeException ex) {
Expand All @@ -77,6 +80,9 @@
*
* Example initialization:
* <p><pre>
* if( !CLPlatform.isAvailable() ) {
* return; // abort
* }
* CLPlatform platform = CLPlatform.getDefault(type(GPU));
*
* if(platform == null) {
Expand All @@ -94,6 +100,7 @@
* CLPlatform is threadsafe.
*
* @author Michael Bien, et al.
* @see #isAvailable()
* @see #initialize()
* @see #getDefault()
* @see #listCLPlatforms()
Expand Down Expand Up @@ -134,9 +141,16 @@ protected CLPlatform(final long id, final CLAccessorFactory factory) {
this.version = new CLVersion(getInfoString(CL_PLATFORM_VERSION));
}

/**
* @returns true if OpenCL is available on this machine,
* i.e. all native libraries could be loaded (CL and CL/JNI).
*/
public static boolean isAvailable() { return CLAbstractImpl.isAvailable(); }

/**
* Eagerly initializes JOCL. Subsequent calls do nothing.
* @throws JogampRuntimeException if something went wrong in the initialization (e.g. OpenCL lib not found).
* @see #isAvailable()
*/
public static void initialize() throws JogampRuntimeException {
initialize(null);
Expand All @@ -147,9 +161,9 @@ public static void initialize() throws JogampRuntimeException {
* Eagerly initializes JOCL. Subsequent calls do nothing.
* @param factory CLAccessorFactory used for creating the bindings.
* @throws JogampRuntimeException if something went wrong in the initialization (e.g. OpenCL lib not found).
* @see #isAvailable()
*/
synchronized static void initialize(final CLAccessorFactory factory) throws JogampRuntimeException {

if(cl != null) {
return;
}
Expand All @@ -162,19 +176,10 @@ synchronized static void initialize(final CLAccessorFactory factory) throws Joga
}
}

try {
if( null == CLAbstractImpl.getCLProcAddressTable() ) {
throw new JogampRuntimeException("JOCL ProcAddressTable is NULL");
}
cl = new CLImpl();
}catch(final UnsatisfiedLinkError ex) {
System.err.println(JoclVersion.getInstance().getAllVersions(null).toString());
throw ex;
}catch(final Exception ex) {
System.err.println(JoclVersion.getInstance().getAllVersions(null).toString());
throw new JogampRuntimeException("JOCL initialization error.", ex);
if( !CLAbstractImpl.isAvailable() ) {
throw new JogampRuntimeException("JOCL is not available");
}

cl = new CLImpl();
}

/**
Expand All @@ -188,7 +193,6 @@ public static CLPlatform getDefault() {
/**
* Returns the default OpenCL platform or null when no platform found.
*/
@SuppressWarnings("unchecked")
public static CLPlatform getDefault(final Filter<CLPlatform>... filter) {
final CLPlatform[] platforms = listCLPlatforms(filter);
if(platforms.length > 0) {
Expand Down Expand Up @@ -221,7 +225,6 @@ public static CLPlatform[] listCLPlatforms() {
* @param filter Acceptance filter for the returned platforms.
* @throws CLException if something went wrong initializing OpenCL
*/
@SuppressWarnings("unchecked")
public static CLPlatform[] listCLPlatforms(final Filter<CLPlatform>... filter) {
initialize();

Expand Down Expand Up @@ -297,7 +300,6 @@ public CLDevice[] listCLDevices(final CLDevice.Type... types) {
/**
* Lists all physical devices available on this platform matching the given {@link Filter}.
*/
@SuppressWarnings("unchecked")
public CLDevice[] listCLDevices(final Filter<CLDevice>... filters) {
initialize();

Expand Down Expand Up @@ -393,7 +395,6 @@ public CLDevice getMaxFlopsDevice(final CLDevice.Type... types) {
* The device speed is estimated by calculating the product of
* MAX_COMPUTE_UNITS and MAX_CLOCK_FREQUENCY.
*/
@SuppressWarnings("unchecked")
public CLDevice getMaxFlopsDevice(final Filter<CLDevice>... filter) {
return findMaxFlopsDevice(listCLDevices(filter));
}
Expand Down
8 changes: 6 additions & 2 deletions src/com/jogamp/opencl/JoclVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,12 @@ public static void main(final String args[]) {
// System.err.println(NativeWindowVersion.getInstance());
final JoclVersion v = JoclVersion.getInstance();
System.err.println(v.toString());
System.err.println(v.getOpenCLTextInfo(null).toString());
// System.err.println(v.getOpenCLHtmlInfo(null).toString());
if( CLPlatform.isAvailable() ) {
System.err.println(v.getOpenCLTextInfo(null).toString());
// System.err.println(v.getOpenCLHtmlInfo(null).toString());
} else {
System.err.println("JOCL/OpenCL not available");
}
}
}

3 changes: 0 additions & 3 deletions test/com/jogamp/opencl/gl/CLGLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,7 @@ public void vboSharing() {

@Test(timeout=15000)
public void textureSharing() {

out.println(" - - - glcl; textureSharing - - - ");
if(MiscUtils.isOpenCLUnavailable())
return;

initGL();
makeGLCurrent();
Expand Down
8 changes: 6 additions & 2 deletions test/com/jogamp/opencl/test/util/MiscUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ public static final void checkIfEqual(final ByteBuffer a, final ByteBuffer b, fi
* @return true if OpenCL is not available for this operating system, CPU architecture, et cetera.
* This is meant to be a check that there can't possibly be a driver installed because
* nobody makes one, not just a check that we didn't see one.
* <p>
* To check whether an OpenCL implementation/library has actually been loaded,
* use {@link CLAbstractImpl#isAvailable()}.
* </p>
*/
public static final boolean isOpenCLUnavailable() {
return !CLAbstractImpl.isAvailable() && knownOSWithoutCLImpl.contains(Platform.getOSType());
public static final boolean isKnownOSWithoutCLImpl() {
return knownOSWithoutCLImpl.contains(Platform.getOSType());
}
}
3 changes: 2 additions & 1 deletion test/com/jogamp/opencl/test/util/UITestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import com.jogamp.common.os.Platform;
import com.jogamp.common.util.locks.SingletonInstance;
import com.jogamp.opencl.CLPlatform;

import org.junit.Assume;
import org.junit.Before;
Expand Down Expand Up @@ -126,7 +127,7 @@ public static void oneTimeTearDown() {
@Before
public void setUp() {
System.err.print("++++ UITestCase.setUp: "+getFullTestName(" - "));
final boolean isOpenCLUnavailable = MiscUtils.isOpenCLUnavailable();
final boolean isOpenCLUnavailable = !CLPlatform.isAvailable();
final boolean abortTest = isOpenCLUnavailable || !testSupported;
if( abortTest ) {
if( isOpenCLUnavailable ) {
Expand Down

0 comments on commit c720767

Please sign in to comment.