Merge pull request #148 from hlhr202/feature/fix-metal
Feature/fix metal
This commit is contained in:
commit
f1030ef762
5 changed files with 32 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
**/target
|
**/target
|
||||||
**/Cargo.lock
|
**/Cargo.lock
|
||||||
/.idea
|
/.idea
|
||||||
|
/.vscode
|
||||||
|
|
@ -81,7 +81,13 @@ pub unsafe fn set_log_callback(
|
||||||
log_callback: crate::WhisperLogCallback,
|
log_callback: crate::WhisperLogCallback,
|
||||||
user_data: *mut std::ffi::c_void,
|
user_data: *mut std::ffi::c_void,
|
||||||
) {
|
) {
|
||||||
unsafe { whisper_rs_sys::whisper_log_set(log_callback, user_data) }
|
unsafe {
|
||||||
|
whisper_rs_sys::whisper_log_set(log_callback, user_data);
|
||||||
|
#[cfg(feature = "metal")]
|
||||||
|
{
|
||||||
|
whisper_rs_sys::ggml_backend_metal_log_set_callback(log_callback, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print system information.
|
/// Print system information.
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,13 @@ unsafe extern "C" fn whisper_cpp_log_trampoline(
|
||||||
/// You should only call this once (subsequent calls have no ill effect).
|
/// You should only call this once (subsequent calls have no ill effect).
|
||||||
pub fn install_whisper_log_trampoline() {
|
pub fn install_whisper_log_trampoline() {
|
||||||
crate::LOG_TRAMPOLINE_INSTALL.call_once(|| unsafe {
|
crate::LOG_TRAMPOLINE_INSTALL.call_once(|| unsafe {
|
||||||
whisper_rs_sys::whisper_log_set(Some(whisper_cpp_log_trampoline), std::ptr::null_mut())
|
whisper_rs_sys::whisper_log_set(Some(whisper_cpp_log_trampoline), std::ptr::null_mut());
|
||||||
|
#[cfg(feature = "metal")]
|
||||||
|
{
|
||||||
|
whisper_rs_sys::ggml_backend_metal_log_set_callback(
|
||||||
|
Some(whisper_cpp_log_trampoline),
|
||||||
|
std::ptr::null_mut(),
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,13 @@ unsafe extern "C" fn whisper_cpp_tracing_trampoline(
|
||||||
/// You should only call this once (subsequent calls have no effect).
|
/// You should only call this once (subsequent calls have no effect).
|
||||||
pub fn install_whisper_tracing_trampoline() {
|
pub fn install_whisper_tracing_trampoline() {
|
||||||
crate::LOG_TRAMPOLINE_INSTALL.call_once(|| unsafe {
|
crate::LOG_TRAMPOLINE_INSTALL.call_once(|| unsafe {
|
||||||
whisper_rs_sys::whisper_log_set(Some(whisper_cpp_tracing_trampoline), std::ptr::null_mut())
|
whisper_rs_sys::whisper_log_set(Some(whisper_cpp_tracing_trampoline), std::ptr::null_mut());
|
||||||
|
#[cfg(feature = "metal")]
|
||||||
|
{
|
||||||
|
whisper_rs_sys::ggml_backend_metal_log_set_callback(
|
||||||
|
Some(whisper_cpp_tracing_trampoline),
|
||||||
|
std::ptr::null_mut(),
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
sys/build.rs
10
sys/build.rs
|
|
@ -101,8 +101,12 @@ fn main() {
|
||||||
let _: u64 = std::fs::copy("src/bindings.rs", out.join("bindings.rs"))
|
let _: u64 = std::fs::copy("src/bindings.rs", out.join("bindings.rs"))
|
||||||
.expect("Failed to copy bindings.rs");
|
.expect("Failed to copy bindings.rs");
|
||||||
} else {
|
} else {
|
||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default().header("wrapper.h");
|
||||||
.header("wrapper.h")
|
|
||||||
|
#[cfg(feature = "metal")]
|
||||||
|
let bindings = bindings.header("whisper.cpp/ggml-metal.h");
|
||||||
|
|
||||||
|
let bindings = bindings
|
||||||
.clang_arg("-I./whisper.cpp")
|
.clang_arg("-I./whisper.cpp")
|
||||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||||
.generate();
|
.generate();
|
||||||
|
|
@ -169,6 +173,8 @@ fn main() {
|
||||||
|
|
||||||
if cfg!(feature = "metal") {
|
if cfg!(feature = "metal") {
|
||||||
config.define("WHISPER_METAL", "ON");
|
config.define("WHISPER_METAL", "ON");
|
||||||
|
config.define("WHISPER_METAL_NDEBUG", "ON");
|
||||||
|
config.define("WHISPER_METAL_EMBED_LIBRARY", "ON");
|
||||||
} else {
|
} else {
|
||||||
// Metal is enabled by default, so we need to explicitly disable it
|
// Metal is enabled by default, so we need to explicitly disable it
|
||||||
config.define("WHISPER_METAL", "OFF");
|
config.define("WHISPER_METAL", "OFF");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue