Skip to content

Commit

Permalink
[rust] Update naming in build script, Gpu -> Cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
boydjohnson committed Sep 22, 2022
1 parent 886cf8a commit 1a18c7f
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions rust/onnxruntime-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const ORT_RUST_ENV_STRATEGY: &str = "ORT_RUST_STRATEGY";
/// Name of environment variable that, if present, contains the location of a pre-built library.
/// Only used if `ORT_STRATEGY=system`.
const ORT_RUST_ENV_SYSTEM_LIB_LOCATION: &str = "ORT_RUST_LIB_LOCATION";
/// Name of environment variable that, if present, controls wether to use CUDA or not.
/// Name of environment variable that, if present, controls whether to use CUDA or not.
const ORT_RUST_ENV_GPU: &str = "ORT_RUST_USE_CUDA";

/// Subdirectory (of the 'target' directory) into which to extract the prebuilt library.
Expand Down Expand Up @@ -249,26 +249,26 @@ impl OnnxPrebuiltArchive for Os {

#[derive(Debug, PartialEq, Eq)]
enum Accelerator {
None,
Gpu,
Cpu,
Cuda,
}

impl FromStr for Accelerator {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"1" | "yes" | "true" | "on" => Ok(Accelerator::Gpu),
_ => Ok(Accelerator::None),
"1" | "yes" | "true" | "on" => Ok(Accelerator::Cuda),
_ => Ok(Accelerator::Cpu),
}
}
}

impl OnnxPrebuiltArchive for Accelerator {
fn as_onnx_str(&self) -> Cow<str> {
match self {
Accelerator::None => Cow::from(""),
Accelerator::Gpu => Cow::from("gpu"),
Accelerator::Cpu => Cow::from(""),
Accelerator::Cuda => Cow::from("gpu"),
}
}
}
Expand All @@ -293,22 +293,22 @@ impl OnnxPrebuiltArchive for Triplet {
(
Os::Windows,
Architecture::X86 | Architecture::X86_64 | Architecture::Arm | Architecture::Arm64,
Accelerator::None,
Accelerator::Cpu,
)
| (Os::MacOs, Architecture::Arm64, Accelerator::None)
| (Os::Linux, Architecture::X86_64, Accelerator::None) => Cow::from(format!(
| (Os::MacOs, Architecture::Arm64, Accelerator::Cpu)
| (Os::Linux, Architecture::X86_64, Accelerator::Cpu) => Cow::from(format!(
"{}-{}",
self.os.as_onnx_str(),
self.arch.as_onnx_str()
)),
(Os::MacOs, Architecture::X86_64, Accelerator::None) => Cow::from(format!(
(Os::MacOs, Architecture::X86_64, Accelerator::Cpu) => Cow::from(format!(
"{}-x86_{}",
self.os.as_onnx_str(),
self.arch.as_onnx_str().trim_start_matches('x')
)),
// onnxruntime-win-x64-gpu-1.11.1.zip
// onnxruntime-linux-x64-gpu-1.11.1.tgz
(Os::Linux | Os::Windows, Architecture::X86_64, Accelerator::Gpu) => {
(Os::Linux | Os::Windows, Architecture::X86_64, Accelerator::Cuda) => {
Cow::from(format!(
"{}-{}-{}",
self.os.as_onnx_str(),
Expand Down Expand Up @@ -412,7 +412,7 @@ fn prepare_libort_dir_compiled() -> PathBuf {

config.define("onnxruntime_BUILD_SHARED_LIB", "ON");

if env::var(ORT_RUST_ENV_GPU).unwrap_or_default().parse() == Ok(Accelerator::Gpu) {
if env::var(ORT_RUST_ENV_GPU).unwrap_or_default().parse() == Ok(Accelerator::Cuda) {
config.define("onnxruntime_USE_CUDA", "ON");
}

Expand Down

0 comments on commit 1a18c7f

Please sign in to comment.