Merge pull request #91 from tazz4843/metal-feature-flag

Add a feature flag for Metal acceleration support
This commit is contained in:
Niko 2023-10-27 14:23:37 +00:00 committed by GitHub
commit 73e33a182c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View file

@ -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]

View file

@ -39,6 +39,7 @@ coreml = []
cuda = []
opencl = []
openblas = []
metal = []
[build-dependencies]
cmake = "0.1"

View file

@ -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")]
@ -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") {