Skip to content

Commit

Permalink
Merge pull request #91 from tazz4843/metal-feature-flag
Browse files Browse the repository at this point in the history
Add a feature flag for Metal acceleration support
  • Loading branch information
tazz4843 authored Oct 27, 2023
2 parents 9ec0fd6 + ba1b791 commit 73e33a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ coreml = ["whisper-rs-sys/coreml"]
cuda = ["whisper-rs-sys/cuda"]
opencl = ["whisper-rs-sys/opencl"]
openblas = ["whisper-rs-sys/openblas"]
metal = ["whisper-rs-sys/metal"]
test-with-tiny-model = []

[package.metadata.docs.rs]
Expand Down
1 change: 1 addition & 0 deletions sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ coreml = []
cuda = []
opencl = []
openblas = []
metal = []

[build-dependencies]
cmake = "0.1"
Expand Down
13 changes: 13 additions & 0 deletions sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ fn main() {
println!("cargo:rustc-link-lib=framework=Foundation");
println!("cargo:rustc-link-lib=framework=CoreML");
}
#[cfg(feature = "metal")]
{
println!("cargo:rustc-link-lib=framework=Foundation");
println!("cargo:rustc-link-lib=framework=Metal");
println!("cargo:rustc-link-lib=framework=MetalKit");
}
}

#[cfg(feature = "coreml")]
Expand Down Expand Up @@ -125,6 +131,13 @@ fn main() {
config.define("WHISPER_CLBLAST", "ON");
}

if cfg!(feature = "metal") {
config.define("WHISPER_METAL", "ON");
} else {
// Metal is enabled by default, so we need to explicitly disable it
config.define("WHISPER_METAL", "OFF");
}

let destination = config.build();

if env::var("TARGET").unwrap().contains("window") {
Expand Down

0 comments on commit 73e33a1

Please sign in to comment.