Skip to content

Commit 47e5667

Browse files
committed
refactor: gate preload_dylib behind separate feature
now that we exclusively use statically-linked `libonnxruntime`. It would be silly to require the whole library be dynamically linked in order to use preloading.
1 parent 25fc551 commit 47e5667

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ tracing = [ "dep:tracing" ]
6161

6262
fetch-models = [ "std", "dep:ureq", "dep:sha2" ]
6363
download-binaries = [ "ort-sys/download-binaries" ]
64-
load-dynamic = [ "std", "libloading", "ort-sys/disable-linking" ]
64+
preload-dylibs = [ "dep:libloading" ]
65+
load-dynamic = [ "std", "preload-dylibs", "ort-sys/disable-linking" ]
6566
copy-dylibs = [ "ort-sys/copy-dylibs" ]
6667

6768
tls-rustls = [ "ort-sys/tls-rustls", "ureq?/rustls" ]

docs/content/setup/cargo-features.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ title: Cargo features
1111
-**`copy-dylibs`**: In case dynamic libraries are used (like with the CUDA execution provider), creates a symlink to them in the relevant places in the `target` folder to make [compile-time dynamic linking](/setup/linking#compile-time-dynamic-linking) work.
1212
- ⚒️ **`half`**: Enables support for creating & extracting float16/bfloat16 tensors via the [`half`](https://crates.io/crates/half) crate. ONNX models that are converted to 16-bit precision will typically convert to/from 32-bit floats at the input/output, so you will likely never actually need to interact with a 16-bit tensor on the Rust side.
1313
- ⚒️ **`num-complex`**: Enables support for creating & extracting complex32/complex64 tensors via the [`num-complex`](https://crates.io/crates/num-complex) crate.
14+
- ⚒️ **`preload-dylibs`**: Enables [dynamic library preloading](https://docs.rs/ort/2.0.0-rc.10/ort/util/fn.preload_dylib.html); useful if you want to ship CUDA alongside your application instead of requiring the user to install it themselves.
1415
- ⚒️ **`load-dynamic`**: Enables [runtime dynamic linking](/setup/linking#runtime-loading-with-load-dynamic), which alleviates many of the troubles with compile-time dynamic linking and offers greater flexibility.
1516
- ⚒️ **`alternative-backend`**: Disables linking to ONNX Runtime, allowing you to instead configure an [alternative backend](/backends).
1617
- ⚒️ **`fetch-models`**: Enables the [`SessionBuilder::commit_from_url`](https://docs.rs/ort/2.0.0-rc.10/ort/session/builder/struct.SessionBuilder.html#method.commit_from_url) method, allowing you to quickly download & run a model from a URL. This should only be used for quick testing.

src/execution_providers/cuda.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ impl ExecutionProvider for CUDAExecutionProvider {
391391
}
392392
}
393393

394+
// Take care in how these are ordered, since some of them depend on each other. Dependencies need to be loaded before
395+
// their dependents.
394396
#[cfg(windows)]
395397
pub const CUDA_DYLIBS: &[&str] = &["cudart64_12.dll", "cublasLt64_12.dll", "cublas64_12.dll", "cufft64_11.dll"];
396398
#[cfg(not(windows))]
@@ -444,8 +446,8 @@ pub const CUDNN_DYLIBS: &[&str] = &[
444446
/// // Only preload cuDNN
445447
/// let _ = cuda::preload_dylibs(None, Some(cudnn_root));
446448
/// ```
447-
#[cfg(feature = "load-dynamic")]
448-
#[cfg_attr(docsrs, doc(cfg(feature = "load-dynamic")))]
449+
#[cfg_attr(docsrs, doc(cfg(any(feature = "preload-dylibs", feature = "load-dynamic"))))]
450+
#[cfg(feature = "preload-dylibs")]
449451
pub fn preload_dylibs(cuda_root_dir: Option<&std::path::Path>, cudnn_root_dir: Option<&std::path::Path>) -> Result<()> {
450452
use crate::util::preload_dylib;
451453
if let Some(cuda_root_dir) = cuda_root_dir {

src/util/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ pub(crate) use self::{
4747
/// let application_dir = current_exe().unwrap();
4848
/// let _ = ort::util::preload_dylib(application_dir.join("DirectML.dll"));
4949
/// ```
50-
#[cfg(feature = "load-dynamic")]
50+
#[cfg_attr(docsrs, doc(cfg(any(feature = "preload-dylibs", feature = "load-dynamic"))))]
51+
#[cfg(feature = "preload-dylibs")]
5152
pub fn preload_dylib<P: AsRef<std::ffi::OsStr>>(path: P) -> Result<(), libloading::Error> {
5253
let library = unsafe { libloading::Library::new(path) }?;
5354
// Do not run `FreeLibrary` so the library remains in the loaded modules list.

0 commit comments

Comments
 (0)