Skip to content

Commit

Permalink
#274 Adding options for dynamic loading that include versions after .so
Browse files Browse the repository at this point in the history
  • Loading branch information
coreylowman committed Jul 16, 2024
1 parent 01c1be6 commit 42b9683
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/cublas/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub unsafe fn lib() -> &'static Lib {
let lib_name = "cublas";
let choices = crate::get_lib_name_candidates(lib_name);
for choice in choices.iter() {
if let Ok(lib) = Lib::new(libloading::library_filename(choice)) {
if let Ok(lib) = Lib::new(choice) {
return lib;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cublaslt/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub unsafe fn lib() -> &'static Lib {
let lib_name = "cublasLt";
let choices = crate::get_lib_name_candidates(lib_name);
for choice in choices.iter() {
if let Ok(lib) = Lib::new(libloading::library_filename(choice)) {
if let Ok(lib) = Lib::new(choice) {
return lib;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cudnn/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub unsafe fn lib() -> &'static Lib {
let lib_name = "cudnn";
let choices = crate::get_lib_name_candidates(lib_name);
for choice in choices.iter() {
if let Ok(lib) = Lib::new(libloading::library_filename(choice)) {
if let Ok(lib) = Lib::new(choice) {
return lib;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/curand/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub unsafe fn lib() -> &'static Lib {
let lib_name = "curand";
let choices = crate::get_lib_name_candidates(lib_name);
for choice in choices.iter() {
if let Ok(lib) = Lib::new(libloading::library_filename(choice)) {
if let Ok(lib) = Lib::new(choice) {
return lib;
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ pub(crate) fn panic_no_lib_found<S: std::fmt::Debug>(lib_name: &str, choices: &[
}

pub(crate) fn get_lib_name_candidates(lib_name: &str) -> std::vec::Vec<std::string::String> {
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};

let pointer_width = if cfg!(target_pointer_width = "32") {
"32"
} else if cfg!(target_pointer_width = "64") {
Expand All @@ -111,18 +113,22 @@ pub(crate) fn get_lib_name_candidates(lib_name: &str) -> std::vec::Vec<std::stri
let minor = env!("CUDA_MINOR_VERSION");

[
lib_name.into(),
std::format!("{lib_name}{pointer_width}"),
std::format!("{lib_name}{pointer_width}_{major}"),
std::format!("{lib_name}{pointer_width}_{major}{minor}"),
std::format!("{lib_name}{pointer_width}_{major}{minor}_0"),
std::format!("{lib_name}{pointer_width}_{major}0_{minor}"),
std::format!("{DLL_PREFIX}{lib_name}{DLL_SUFFIX}"),
std::format!("{DLL_PREFIX}{lib_name}{pointer_width}{DLL_SUFFIX}"),
std::format!("{DLL_PREFIX}{lib_name}{pointer_width}_{major}{DLL_SUFFIX}"),
std::format!("{DLL_PREFIX}{lib_name}{pointer_width}_{major}{minor}{DLL_SUFFIX}"),
std::format!("{DLL_PREFIX}{lib_name}{pointer_width}_{major}{minor}_0{DLL_SUFFIX}"),
std::format!("{DLL_PREFIX}{lib_name}{pointer_width}_{major}0_{minor}{DLL_SUFFIX}"),
// See issue #242
std::format!("{lib_name}{pointer_width}_10"),
std::format!("{DLL_PREFIX}{lib_name}{pointer_width}_10{DLL_SUFFIX}"),
// See issue #246
std::format!("{lib_name}{pointer_width}_{major}0_0"),
std::format!("{DLL_PREFIX}{lib_name}{pointer_width}_{major}0_0{DLL_SUFFIX}"),
// See issue #260
std::format!("{lib_name}{pointer_width}_9"),
std::format!("{DLL_PREFIX}{lib_name}{pointer_width}_9{DLL_SUFFIX}"),
// See issue #274
std::format!("{DLL_PREFIX}{lib_name}{DLL_SUFFIX}.{major}"),
std::format!("{DLL_PREFIX}{lib_name}{DLL_SUFFIX}.11"),
std::format!("{DLL_PREFIX}{lib_name}{DLL_SUFFIX}.10"),
]
.into()
}
2 changes: 1 addition & 1 deletion src/nccl/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub unsafe fn lib() -> &'static Lib {
let lib_name = "nccl";
let choices = crate::get_lib_name_candidates(lib_name);
for choice in choices.iter() {
if let Ok(lib) = Lib::new(libloading::library_filename(choice)) {
if let Ok(lib) = Lib::new(choice) {
return lib;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/nvrtc/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub unsafe fn lib() -> &'static Lib {
let lib_name = "nvrtc";
let choices = crate::get_lib_name_candidates(lib_name);
for choice in choices.iter() {
if let Ok(lib) = Lib::new(libloading::library_filename(choice)) {
if let Ok(lib) = Lib::new(choice) {
return lib;
}
}
Expand Down

0 comments on commit 42b9683

Please sign in to comment.