From c720767642618cfb4f3739dc6962cde0465e25c5 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 3 Sep 2014 03:16:10 +0200 Subject: Bug 978: Promote CLAbstractImpl.isAvailable() to CLPlatform, public API. 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. --- src/com/jogamp/opencl/CLPlatform.java | 35 +++++++++++++++++----------------- src/com/jogamp/opencl/JoclVersion.java | 8 ++++++-- 2 files changed, 24 insertions(+), 19 deletions(-) (limited to 'src/com') diff --git a/src/com/jogamp/opencl/CLPlatform.java b/src/com/jogamp/opencl/CLPlatform.java index 8e31b74a..d63f6708 100644 --- a/src/com/jogamp/opencl/CLPlatform.java +++ b/src/com/jogamp/opencl/CLPlatform.java @@ -68,6 +68,9 @@ import static com.jogamp.opencl.llb.CL.*; * * optional eager initialization: *

+ *     if( !CLPlatform.isAvailable() ) {
+ *        return; // abort
+ *     }
  *     try{
  *          CLPlatform.initialize();
  *     }catch(JogampRuntimeException ex) {
@@ -77,6 +80,9 @@ import static com.jogamp.opencl.llb.CL.*;
  *
  * Example initialization:
  * 

+ *     if( !CLPlatform.isAvailable() ) {
+ *        return; // abort
+ *     }
  *     CLPlatform platform = CLPlatform.getDefault(type(GPU));
  *
  *     if(platform == null) {
@@ -94,6 +100,7 @@ import static com.jogamp.opencl.llb.CL.*;
  * CLPlatform is threadsafe.
  *
  * @author Michael Bien, et al.
+ * @see #isAvailable()
  * @see #initialize()
  * @see #getDefault()
  * @see #listCLPlatforms()
@@ -134,9 +141,16 @@ public class CLPlatform {
         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);
@@ -147,9 +161,9 @@ public class CLPlatform {
      * 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;
         }
@@ -162,19 +176,10 @@ public class CLPlatform {
             }
         }
 
-        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();
     }
 
     /**
@@ -188,7 +193,6 @@ public class CLPlatform {
     /**
      * Returns the default OpenCL platform or null when no platform found.
      */
-    @SuppressWarnings("unchecked")
     public static CLPlatform getDefault(final Filter... filter) {
         final CLPlatform[] platforms = listCLPlatforms(filter);
         if(platforms.length > 0) {
@@ -221,7 +225,6 @@ public class CLPlatform {
      * @param filter Acceptance filter for the returned platforms.
      * @throws CLException if something went wrong initializing OpenCL
      */
-    @SuppressWarnings("unchecked")
     public static CLPlatform[] listCLPlatforms(final Filter... filter) {
         initialize();
 
@@ -297,7 +300,6 @@ public class CLPlatform {
     /**
      * Lists all physical devices available on this platform matching the given {@link Filter}.
      */
-    @SuppressWarnings("unchecked")
     public CLDevice[] listCLDevices(final Filter... filters) {
         initialize();
 
@@ -393,7 +395,6 @@ public class CLPlatform {
      * The device speed is estimated by calculating the product of
      * MAX_COMPUTE_UNITS and MAX_CLOCK_FREQUENCY.
      */
-    @SuppressWarnings("unchecked")
     public CLDevice getMaxFlopsDevice(final Filter... filter) {
         return findMaxFlopsDevice(listCLDevices(filter));
     }
diff --git a/src/com/jogamp/opencl/JoclVersion.java b/src/com/jogamp/opencl/JoclVersion.java
index 15e868cf..3519add0 100644
--- a/src/com/jogamp/opencl/JoclVersion.java
+++ b/src/com/jogamp/opencl/JoclVersion.java
@@ -247,8 +247,12 @@ public class JoclVersion extends JogampVersion {
         // 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");
+        }
     }
 }
 
-- 
cgit v1.2.3