Add a feature flag for Metal acceleration support

This commit is contained in:
Niko 2023-10-09 17:02:54 -06:00
parent 7dac364460
commit 253ac1bb6f
No known key found for this signature in database
GPG key ID: 3861E636EA1E0E2B
3 changed files with 17 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 = []
[dependencies]

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");
}
}
println!("cargo:rustc-link-search={}", env::var("OUT_DIR").unwrap());
@ -119,6 +125,15 @@ fn main() {
#[cfg(feature = "opencl")]
cmd.arg("-DWHISPER_CLBLAST=ON");
cfg_if! {
if #[cfg(feature = "metal")] {
cmd.arg("-DWHISPER_METAL=ON");
} else {
// Metal is enabled by default so we need to explicitly disable it
cmd.arg("-DWHISPER_METAL=OFF");
}
};
cmd.arg("-DCMAKE_POSITION_INDEPENDENT_CODE=ON");
let code = cmd