Class NativeDepsLoader

java.lang.Object
ai.rapids.cudf.NativeDepsLoader

public class NativeDepsLoader extends Object
This class will load the native dependencies.
  • Constructor Details

    • NativeDepsLoader

      public NativeDepsLoader()
  • Method Details

    • loadNativeDeps

      public static void loadNativeDeps()
      Load the native libraries needed for libcudf, if not loaded already.
    • loadNativeDeps

      public static void loadNativeDeps(String[] loadOrder) throws IOException
      Allows other libraries to reuse the same native deps loading logic. Libraries will be searched for under ${os.arch}/${os.name}/ in the class path using the class loader for this class.
      Because this just loads the libraries and loading the libraries themselves needs to be a singleton operation it is recommended that any library using this provide their own wrapper function similar to
           private static boolean loaded = false;
           static synchronized void loadNativeDeps() {
               if (!loaded) {
                   try {
                       // If you also depend on the cudf liobrary being loaded, be sure it is loaded
                       // first
                       ai.rapids.cudf.NativeDepsLoader.loadNativeDeps();
                       ai.rapids.cudf.NativeDepsLoader.loadNativeDeps(new String[]{...});
                       loaded = true;
                   } catch (Throwable t) {
                       log.error("Could not load ...", t);
                   }
               }
           }
       
      This function should be called from the static initialization block of any class that uses JNI. For example
           public class UsesJNI {
               static {
                   MyNativeDepsLoader.loadNativeDeps();
               }
           }
       
      Parameters:
      loadOrder - the base name of the libraries. For example libfoo.so would be passed in as "foo". The libraries are loaded in the order provided.
      Throws:
      IOException - on any error trying to load the libraries.
    • loadNativeDeps

      public static void loadNativeDeps(String[] loadOrder, boolean preserveDeps) throws IOException
      Allows other libraries to reuse the same native deps loading logic. Libraries will be searched for under ${os.arch}/${os.name}/ in the class path using the class loader for this class.
      Because this just loads the libraries and loading the libraries themselves needs to be a singleton operation it is recommended that any library using this provide their own wrapper function similar to
           private static boolean loaded = false;
           static synchronized void loadNativeDeps() {
               if (!loaded) {
                   try {
                       // If you also depend on the cudf liobrary being loaded, be sure it is loaded
                       // first
                       ai.rapids.cudf.NativeDepsLoader.loadNativeDeps();
                       ai.rapids.cudf.NativeDepsLoader.loadNativeDeps(new String[]{...});
                       loaded = true;
                   } catch (Throwable t) {
                       log.error("Could not load ...", t);
                   }
               }
           }
       
      This function should be called from the static initialization block of any class that uses JNI. For example
           public class UsesJNI {
               static {
                   MyNativeDepsLoader.loadNativeDeps();
               }
           }
       
      Parameters:
      loadOrder - the base name of the libraries. For example libfoo.so would be passed in as "foo". The libraries are loaded in the order provided.
      preserveDeps - if false the dependencies will be deleted immediately after loading rather than on exit.
      Throws:
      IOException - on any error trying to load the libraries.
    • loadOptionalNativeDeps

      public static boolean loadOptionalNativeDeps(String[] loadOrder)
      Optionally load native dependencies. This method attempts to load the specified libraries but does not throw exceptions on failure. Instead, it returns true if all libraries were loaded successfully, false otherwise.
      Parameters:
      loadOrder - the base name of the libraries. For example libfoo.so would be passed in as "foo". The libraries are loaded in the order provided.
      Returns:
      true if all libraries were loaded successfully, false otherwise
    • loadNativeDep

      public static File loadNativeDep(String depName, boolean preserveDep) throws IOException
      Allows other libraries to reuse the same native deps loading logic. Library will be searched for under ${os.arch}/${os.name}/ in the class path using the class loader for this class.
      Parameters:
      depName - the base name of the library. For example libfoo.so would be passed in as "foo". The libraries are loaded in the order provided.
      preserveDep - if false the dependencies will be deleted immediately after loading rather than on exit.
      Returns:
      path where the dependency was loaded
      Throws:
      IOException - on any error trying to load the libraries.
    • libraryLoaded

      public static boolean libraryLoaded()