From 0a85f8013a7cdaf569ba1dcf2628bc5743eb7ffb Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Mon, 21 Aug 2023 20:36:48 +0200 Subject: [PATCH] Safely expose some of the ggml_cpu_has... routines --- src/standalone.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/standalone.rs b/src/standalone.rs index f5e7842..318e99f 100644 --- a/src/standalone.rs +++ b/src/standalone.rs @@ -80,3 +80,33 @@ pub fn print_system_info() -> &'static str { let c_str = unsafe { CStr::from_ptr(c_buf) }; c_str.to_str().unwrap() } + +/// Programmatically exposes the information provided by `print_system_info` +/// +/// # C++ equivalent +/// `int ggml_cpu_has_...` +pub struct SystemInfo { + pub avx: bool, + pub avx2: bool, + pub fma: bool, + pub f16c: bool, + pub blas: bool, + pub clblast: bool, + pub cublas: bool, +} + +impl Default for SystemInfo { + fn default() -> Self { + unsafe { + Self { + avx: whisper_rs_sys::ggml_cpu_has_avx() != 0, + avx2: whisper_rs_sys::ggml_cpu_has_avx2() != 0, + fma: whisper_rs_sys::ggml_cpu_has_fma() != 0, + f16c: whisper_rs_sys::ggml_cpu_has_f16c() != 0, + blas: whisper_rs_sys::ggml_cpu_has_blas() != 0, + clblast: whisper_rs_sys::ggml_cpu_has_clblast() != 0, + cublas: whisper_rs_sys::ggml_cpu_has_cublas() != 0, + } + } + } +}