singe-loader
Loads the NVIDIA libraries behind Singe's *-sys crates at run time, so a program that uses them builds and starts on a machine without them.
A function whose library or symbol is missing returns a fixed value of its return type instead of failing to link.
This crate provides:
Library: one library made of one or more files, with aconstconstructor per NVIDIA library, such asLibrary::cublas()orLibrary::nvjpeg2k(), andLibrary::newfor any other.functions!: turns the declarations of a bindgenextern "C"block into functions of the same names and signatures that look up their symbol on first call.Missing: what a function returns when it cannot be called: zero for integers, null for pointers, and nothing for(), withmissing_status!andmissing_value!to implement it for a library's own types.take_absence: returns and clears theAbsencethat the last status-returning call on the current thread recorded, so a safe wrapper can turn that status into a load error.LoadError: a library with no files on this platform, a library that would not load, with eachAttemptthe loader made, or a missing symbol.
Example
Load cuBLAS and print where each of its files was found, or each place the loader tried:
use ;
static CUBLAS: Library = cublas;
A library loads at most once and stays loaded for the life of the process, so the functions that cached its symbols stay valid.
Its load result is cached too: a library that failed to load returns the same LoadError on every later call.
Search order
The loader tries each file by name through the system loader's search first, then in the library directories under CUDA_PATH and CUDA_HOME, and on Linux under /usr/local/cuda and in /run/opengl-driver/lib.
The NVIDIA libraries have file names only on Linux and Windows; elsewhere, loading one returns LoadError::Unsupported.