Class NativeLibrary
smile.onnx.NativeLibrary for the ONNX Runtime.
The generated bindings obtain their symbols through
SymbolLookup.libraryLookup(System.mapLibraryName(name)), which calls
dlopen on a bare name. That lookup consults neither
java.library.path nor LD_LIBRARY_PATH, and on macOS the system
integrity protection (SIP) strips DYLD_* variables when the JVM is
started through the /usr/bin/java stub. A Homebrew
libarpack.dylib is therefore not found unless the working directory
happens to contain it — which used to force a copy or symlink.
An explicit absolute-path System.load does not go through
dyld's name search, so SIP cannot interfere with it. Loading the library first
binds the image into the process; the binding's
SymbolLookup.loaderLookup() then resolves the
symbols from that image.
Resolution order
- a JVM system property (e.g.
-Darpack.native.path) - an environment variable (e.g.
ARPACK_NATIVE_PATH) - the well-known installation directories for the platform
PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
The search-path scan deliberately skips System32 and
SysWOW64, so a stale Windows system copy is never treated as the
intended one.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBare (unmapped) name of the ARPACK library.static final StringEnvironment variable counterpart ofARPACK_NATIVE_PATH_PROPERTY.static final StringSystem property naming the directory that contains ARPACK.static final StringEnvironment variable counterpart ofBACKEND_PROPERTY.static final StringSystem property to select linear algebra backend ("auto", "native", "java").static final StringBare (unmapped) default name of the BLAS library.static final StringEnvironment variable counterpart ofBLAS_NATIVE_PATH_PROPERTY.static final StringSystem property naming the directory that contains BLAS.static final StringBare (unmapped) default name of the LAPACK library.static final StringEnvironment variable counterpart ofLAPACK_NATIVE_PATH_PROPERTY.static final StringSystem property naming the directory that contains LAPACK. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringbackend()Returns the configured linear algebra backend mode ("auto", "native", or "java").static booleanLoads the ARPACK library by absolute path, if it can be resolved.static booleanLoads the BLAS library by absolute path, if it can be resolved.static booleanLoads the LAPACK library by absolute path, if it can be resolved.static booleanensureLoaded(String property, String env, String bareName) Loads a native library by absolute path, at most once per library stem.static StringfindLibraryFile(String bareName) Finds a mapped library file under the well-known directories or on the OS library search path.static booleanReturns whether native CBLAS is available and enabled.static booleanReturns whether native CLAPACK is available and enabled.static booleanlibraryFilePresent(String bareName) Returns whether a mapped library file is present (loaded or not).static StringresolveDir(String property, String env, String bareName) Resolves the directory holding a mapped native library.
-
Field Details
-
BACKEND_PROPERTY
System property to select linear algebra backend ("auto", "native", "java").- See Also:
-
BACKEND_ENV
Environment variable counterpart ofBACKEND_PROPERTY.- See Also:
-
BLAS_NATIVE_PATH_PROPERTY
System property naming the directory that contains BLAS.- See Also:
-
BLAS_NATIVE_PATH_ENV
Environment variable counterpart ofBLAS_NATIVE_PATH_PROPERTY.- See Also:
-
LAPACK_NATIVE_PATH_PROPERTY
System property naming the directory that contains LAPACK.- See Also:
-
LAPACK_NATIVE_PATH_ENV
Environment variable counterpart ofLAPACK_NATIVE_PATH_PROPERTY.- See Also:
-
ARPACK_NATIVE_PATH_PROPERTY
System property naming the directory that contains ARPACK.- See Also:
-
ARPACK_NATIVE_PATH_ENV
Environment variable counterpart ofARPACK_NATIVE_PATH_PROPERTY.- See Also:
-
BLAS_LIBRARY
Bare (unmapped) default name of the BLAS library. -
LAPACK_LIBRARY
Bare (unmapped) default name of the LAPACK library. -
ARPACK_LIBRARY
-
-
Method Details
-
backend
Returns the configured linear algebra backend mode ("auto", "native", or "java").- Returns:
- the backend mode in lowercase.
-
isBlasAvailable
public static boolean isBlasAvailable()Returns whether native CBLAS is available and enabled.- Returns:
trueif native CBLAS should be used;falseto use pure Java.
-
isLapackAvailable
public static boolean isLapackAvailable()Returns whether native CLAPACK is available and enabled.- Returns:
trueif native CLAPACK should be used;falseto use pure Java.
-
resolveDir
Resolves the directory holding a mapped native library.An explicitly configured system property or environment variable wins outright, even if the named library is not actually there: silently falling back to a different copy found on the search path would be worse than letting the load fail with an honest "not found". The well-known directories and the search path are consulted only when neither is set.
- Parameters:
property- the JVM system property name (may benull).env- the environment variable name (may benull).bareName- the bare library stem, e.g.arpack.- Returns:
- the absolute directory path, or
nullwhen not found.
-
ensureLoaded
Loads a native library by absolute path, at most once per library stem.Safe to call from several classes' static initializers: the first call performs the load, later calls are no-ops. A failure to load is swallowed — the caller's own native lookup will produce a clearer error than this best-effort preload could.
- Parameters:
property- the JVM system property name (may benull).env- the environment variable name (may benull).bareName- the bare library stem, e.g.arpack.- Returns:
truewhen the library is loaded after this call.
-
ensureBlasLoaded
public static boolean ensureBlasLoaded()Loads the BLAS library by absolute path, if it can be resolved.- Returns:
truewhen the library is loaded after this call.
-
ensureLapackLoaded
public static boolean ensureLapackLoaded()Loads the LAPACK library by absolute path, if it can be resolved.- Returns:
truewhen the library is loaded after this call.
-
ensureArpackLoaded
public static boolean ensureArpackLoaded()Loads the ARPACK library by absolute path, if it can be resolved.- Returns:
truewhen the library is loaded after this call.
-
findLibraryFile
-
libraryFilePresent
Returns whether a mapped library file is present (loaded or not).- Parameters:
bareName- the bare library stem, e.g.arpack.- Returns:
truewhen the file exists somewhere resolvable.
-