From 813a433a52006514ef63c6ed254439b152125fc5 Mon Sep 17 00:00:00 2001 From: arizhih Date: Tue, 23 Apr 2024 16:54:23 +0200 Subject: [PATCH 1/8] Update whisper.cpp version to 1.5.5 --- Cargo.toml | 4 ++-- src/lib.rs | 2 +- src/standalone.rs | 4 ++-- src/whisper_ctx.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++ sys/Cargo.toml | 2 +- sys/build.rs | 2 +- sys/whisper.cpp | 2 +- 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ce9adba..8b8c8fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ exclude = ["examples/full_usage"] [package] name = "whisper-rs" -version = "0.11.0" +version = "0.12.0" edition = "2021" description = "Rust bindings for whisper.cpp" license = "Unlicense" @@ -14,7 +14,7 @@ repository = "https://github.com/tazz4843/whisper-rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -whisper-rs-sys = { path = "sys", version = "0.8" } +whisper-rs-sys = { path = "sys", version = "0.10.0" } log = { version = "0.4", optional = true } tracing = { version = "0.1", optional = true } diff --git a/src/lib.rs b/src/lib.rs index a6da664..736eceb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,5 +42,5 @@ pub type WhisperNewSegmentCallback = whisper_rs_sys::whisper_new_segment_callbac pub type WhisperStartEncoderCallback = whisper_rs_sys::whisper_encoder_begin_callback; pub type WhisperProgressCallback = whisper_rs_sys::whisper_progress_callback; pub type WhisperLogitsFilterCallback = whisper_rs_sys::whisper_logits_filter_callback; -pub type WhisperAbortCallback = whisper_rs_sys::whisper_abort_callback; +pub type WhisperAbortCallback = whisper_rs_sys::ggml_abort_callback; pub type WhisperLogCallback = whisper_rs_sys::ggml_log_callback; diff --git a/src/standalone.rs b/src/standalone.rs index eb49751..8179943 100644 --- a/src/standalone.rs +++ b/src/standalone.rs @@ -105,7 +105,7 @@ pub struct SystemInfo { pub f16c: bool, pub blas: bool, pub clblast: bool, - pub cublas: bool, + pub cuda: bool, } impl Default for SystemInfo { @@ -118,7 +118,7 @@ impl Default for SystemInfo { 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, + cuda: whisper_rs_sys::ggml_cpu_has_cuda() != 0, } } } diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index 8d948cd..1f28d8e 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -552,6 +552,21 @@ pub struct WhisperContextParameters { /// **Warning**: Does not have an effect if OpenCL is selected as GPU backend /// (in that case, GPU is always enabled). pub use_gpu: bool, + /// GPU device id, default 0 + pub gpu_device: c_int, + /// [EXPERIMENTAL] Enable Token-level timestamps with DTW, default 0 + pub dtw_token_timestamps: bool, + /// Preset id for DTW, default whisper_alignment_heads_preset_WHISPER_AHEADS_NONE + pub dtw_aheads_preset : whisper_rs_sys::whisper_alignment_heads_preset, + /// Number of top text layers used from model. Only with whisper_alignment_heads_preset_WHISPER_AHEADS_N_TOP_MOST preset. + pub dtw_n_top : c_int, + /// Custom aheads, only with whisper_alignment_heads_preset_WHISPER_AHEADS_CUSTOM preset + /// See details https://github.com/ggerganov/whisper.cpp/pull/1485#discussion_r1519681143 + pub dtw_aheads: whisper_rs_sys::whisper_aheads, + /// Memory size for DTW + /// + /// **Warning**: Might be removed in next version of whisper.cpp + pub dtw_mem_size : usize } #[allow(clippy::derivable_impls)] // this impl cannot be derived @@ -559,6 +574,12 @@ impl Default for WhisperContextParameters { fn default() -> Self { Self { use_gpu: cfg!(feature = "_gpu"), + gpu_device: 0, + dtw_token_timestamps: false, + dtw_aheads_preset : whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_NONE, + dtw_n_top: -1, + dtw_aheads : whisper_rs_sys::whisper_aheads { n_heads: 0, heads: std::ptr::null() }, + dtw_mem_size : 1024 * 1024 * 128 } } } @@ -570,9 +591,39 @@ impl WhisperContextParameters { self.use_gpu = use_gpu; self } + pub fn gpu_device(&mut self, gpu_device: c_int) -> &mut Self { + self.gpu_device = gpu_device; + self + } + pub fn dtw_token_timestamps(&mut self, dtw_token_timestamps: bool) -> &mut Self { + self.dtw_token_timestamps = dtw_token_timestamps; + self + } + pub fn dtw_aheads_preset(&mut self, dtw_aheads_preset: whisper_rs_sys::whisper_alignment_heads_preset) -> &mut Self { + self.dtw_aheads_preset = dtw_aheads_preset; + self + } + pub fn dtw_n_top(&mut self, dtw_n_top: c_int) -> &mut Self { + self.dtw_n_top = dtw_n_top; + self + } + pub fn dtw_aheads(&mut self, dtw_aheads: whisper_rs_sys::whisper_aheads) -> &mut Self { + self.dtw_aheads = dtw_aheads; + self + } + pub fn dtw_mem_size(&mut self, dtw_mem_size: usize) -> &mut Self { + self.dtw_mem_size = dtw_mem_size; + self + } fn to_c_struct(&self) -> whisper_rs_sys::whisper_context_params { whisper_rs_sys::whisper_context_params { use_gpu: self.use_gpu, + gpu_device: self.gpu_device, + dtw_token_timestamps: self.dtw_token_timestamps, + dtw_aheads_preset: self.dtw_aheads_preset, + dtw_n_top: self.dtw_n_top, + dtw_aheads: self.dtw_aheads, + dtw_mem_size: self.dtw_mem_size, } } } diff --git a/sys/Cargo.toml b/sys/Cargo.toml index a6ddf80..d0ebdd2 100644 --- a/sys/Cargo.toml +++ b/sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whisper-rs-sys" -version = "0.8.1" +version = "0.10.0" edition = "2021" description = "Rust bindings for whisper.cpp (FFI bindings)" license = "Unlicense" diff --git a/sys/build.rs b/sys/build.rs index 0535637..c2560dc 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -121,7 +121,7 @@ fn main() { } if cfg!(feature = "cuda") { - config.define("WHISPER_CUBLAS", "ON"); + config.define("WHISPER_CUDA", "ON"); } if cfg!(feature = "openblas") { diff --git a/sys/whisper.cpp b/sys/whisper.cpp index 0b9af32..7395c70 160000 --- a/sys/whisper.cpp +++ b/sys/whisper.cpp @@ -1 +1 @@ -Subproject commit 0b9af32a8b3fa7e2ae5f15a9a08f5b10394993f5 +Subproject commit 7395c70a748753e3800b63e3422a2b558a097c80 From f6826200fc0893272d5eb5eba985bccb33223796 Mon Sep 17 00:00:00 2001 From: arizhih Date: Wed, 15 May 2024 22:55:14 +0200 Subject: [PATCH 2/8] Update whisper.cpp version to 1.6.0 --- src/whisper_ctx.rs | 8 ++++++++ sys/whisper.cpp | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index ea22ae0..0609af2 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -475,6 +475,8 @@ pub struct WhisperContextParameters { /// **Warning**: Does not have an effect if OpenCL is selected as GPU backend /// (in that case, GPU is always enabled). pub use_gpu: bool, + /// Enable flash attention, default false + pub flash_attn : bool, /// GPU device id, default 0 pub gpu_device: c_int, /// [EXPERIMENTAL] Enable Token-level timestamps with DTW, default 0 @@ -497,6 +499,7 @@ impl Default for WhisperContextParameters { fn default() -> Self { Self { use_gpu: cfg!(feature = "_gpu"), + flash_attn : false, gpu_device: 0, dtw_token_timestamps: false, dtw_aheads_preset : whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_NONE, @@ -514,6 +517,10 @@ impl WhisperContextParameters { self.use_gpu = use_gpu; self } + pub fn flash_attn(&mut self, flash_attn: bool) -> &mut Self { + self.flash_attn = flash_attn; + self + } pub fn gpu_device(&mut self, gpu_device: c_int) -> &mut Self { self.gpu_device = gpu_device; self @@ -541,6 +548,7 @@ impl WhisperContextParameters { fn to_c_struct(&self) -> whisper_rs_sys::whisper_context_params { whisper_rs_sys::whisper_context_params { use_gpu: self.use_gpu, + flash_attn: self.flash_attn, gpu_device: self.gpu_device, dtw_token_timestamps: self.dtw_token_timestamps, dtw_aheads_preset: self.dtw_aheads_preset, diff --git a/sys/whisper.cpp b/sys/whisper.cpp index 7395c70..08981d1 160000 --- a/sys/whisper.cpp +++ b/sys/whisper.cpp @@ -1 +1 @@ -Subproject commit 7395c70a748753e3800b63e3422a2b558a097c80 +Subproject commit 08981d1bacbe494ff1c943af6c577c669a2d9f4d From dcfcbced187905497f19f197cb427a5f4d04ee53 Mon Sep 17 00:00:00 2001 From: arizhih Date: Thu, 16 May 2024 15:29:38 +0200 Subject: [PATCH 3/8] Generate bindings + rustfmt --- src/whisper_ctx.rs | 24 +- sys/src/bindings.rs | 2055 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 1750 insertions(+), 329 deletions(-) diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index 0609af2..3857bcc 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -476,22 +476,22 @@ pub struct WhisperContextParameters { /// (in that case, GPU is always enabled). pub use_gpu: bool, /// Enable flash attention, default false - pub flash_attn : bool, + pub flash_attn: bool, /// GPU device id, default 0 pub gpu_device: c_int, /// [EXPERIMENTAL] Enable Token-level timestamps with DTW, default 0 pub dtw_token_timestamps: bool, /// Preset id for DTW, default whisper_alignment_heads_preset_WHISPER_AHEADS_NONE - pub dtw_aheads_preset : whisper_rs_sys::whisper_alignment_heads_preset, + pub dtw_aheads_preset: whisper_rs_sys::whisper_alignment_heads_preset, /// Number of top text layers used from model. Only with whisper_alignment_heads_preset_WHISPER_AHEADS_N_TOP_MOST preset. - pub dtw_n_top : c_int, + pub dtw_n_top: c_int, /// Custom aheads, only with whisper_alignment_heads_preset_WHISPER_AHEADS_CUSTOM preset /// See details https://github.com/ggerganov/whisper.cpp/pull/1485#discussion_r1519681143 pub dtw_aheads: whisper_rs_sys::whisper_aheads, /// Memory size for DTW /// /// **Warning**: Might be removed in next version of whisper.cpp - pub dtw_mem_size : usize + pub dtw_mem_size: usize, } #[allow(clippy::derivable_impls)] // this impl cannot be derived @@ -499,13 +499,16 @@ impl Default for WhisperContextParameters { fn default() -> Self { Self { use_gpu: cfg!(feature = "_gpu"), - flash_attn : false, + flash_attn: false, gpu_device: 0, dtw_token_timestamps: false, - dtw_aheads_preset : whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_NONE, + dtw_aheads_preset: whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_NONE, dtw_n_top: -1, - dtw_aheads : whisper_rs_sys::whisper_aheads { n_heads: 0, heads: std::ptr::null() }, - dtw_mem_size : 1024 * 1024 * 128 + dtw_aheads: whisper_rs_sys::whisper_aheads { + n_heads: 0, + heads: std::ptr::null(), + }, + dtw_mem_size: 1024 * 1024 * 128, } } } @@ -529,7 +532,10 @@ impl WhisperContextParameters { self.dtw_token_timestamps = dtw_token_timestamps; self } - pub fn dtw_aheads_preset(&mut self, dtw_aheads_preset: whisper_rs_sys::whisper_alignment_heads_preset) -> &mut Self { + pub fn dtw_aheads_preset( + &mut self, + dtw_aheads_preset: whisper_rs_sys::whisper_alignment_heads_preset, + ) -> &mut Self { self.dtw_aheads_preset = dtw_aheads_preset; self } diff --git a/sys/src/bindings.rs b/sys/src/bindings.rs index 5ed2d49..36459be 100644 --- a/sys/src/bindings.rs +++ b/sys/src/bindings.rs @@ -1,5 +1,8 @@ /* automatically generated by rust-bindgen 0.69.1 */ +pub const __bool_true_false_are_defined: u32 = 1; +pub const true_: u32 = 1; +pub const false_: u32 = 0; pub const _STDINT_H: u32 = 1; pub const _FEATURES_H: u32 = 1; pub const _DEFAULT_SOURCE: u32 = 1; @@ -26,7 +29,6 @@ pub const __USE_ATFILE: u32 = 1; pub const __USE_FORTIFY_LEVEL: u32 = 0; pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0; pub const __GLIBC_USE_DEPRECATED_SCANF: u32 = 0; -pub const __GLIBC_USE_C2X_STRTOL: u32 = 0; pub const _STDC_PREDEF_H: u32 = 1; pub const __STDC_IEC_559__: u32 = 1; pub const __STDC_IEC_60559_BFP__: u32 = 201404; @@ -35,7 +37,7 @@ pub const __STDC_IEC_60559_COMPLEX__: u32 = 201404; pub const __STDC_ISO_10646__: u32 = 201706; pub const __GNU_LIBRARY__: u32 = 6; pub const __GLIBC__: u32 = 2; -pub const __GLIBC_MINOR__: u32 = 38; +pub const __GLIBC_MINOR__: u32 = 35; pub const _SYS_CDEFS_H: u32 = 1; pub const __glibc_c99_flexarr_available: u32 = 1; pub const __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI: u32 = 0; @@ -96,9 +98,47 @@ pub const SIG_ATOMIC_MAX: u32 = 2147483647; pub const SIZE_MAX: i32 = -1; pub const WINT_MIN: u32 = 0; pub const WINT_MAX: u32 = 4294967295; -pub const __bool_true_false_are_defined: u32 = 1; -pub const true_: u32 = 1; -pub const false_: u32 = 0; +pub const _STDIO_H: u32 = 1; +pub const _____fpos_t_defined: u32 = 1; +pub const ____mbstate_t_defined: u32 = 1; +pub const _____fpos64_t_defined: u32 = 1; +pub const ____FILE_defined: u32 = 1; +pub const __FILE_defined: u32 = 1; +pub const __struct_FILE_defined: u32 = 1; +pub const _IO_EOF_SEEN: u32 = 16; +pub const _IO_ERR_SEEN: u32 = 32; +pub const _IO_USER_LOCK: u32 = 32768; +pub const _IOFBF: u32 = 0; +pub const _IOLBF: u32 = 1; +pub const _IONBF: u32 = 2; +pub const BUFSIZ: u32 = 8192; +pub const EOF: i32 = -1; +pub const SEEK_SET: u32 = 0; +pub const SEEK_CUR: u32 = 1; +pub const SEEK_END: u32 = 2; +pub const P_tmpdir: &[u8; 5] = b"/tmp\0"; +pub const _BITS_STDIO_LIM_H: u32 = 1; +pub const L_tmpnam: u32 = 20; +pub const TMP_MAX: u32 = 238328; +pub const FILENAME_MAX: u32 = 4096; +pub const L_ctermid: u32 = 9; +pub const FOPEN_MAX: u32 = 16; +pub const __HAVE_FLOAT128: u32 = 0; +pub const __HAVE_DISTINCT_FLOAT128: u32 = 0; +pub const __HAVE_FLOAT64X: u32 = 1; +pub const __HAVE_FLOAT64X_LONG_DOUBLE: u32 = 1; +pub const __HAVE_FLOAT16: u32 = 0; +pub const __HAVE_FLOAT32: u32 = 1; +pub const __HAVE_FLOAT64: u32 = 1; +pub const __HAVE_FLOAT32X: u32 = 1; +pub const __HAVE_FLOAT128X: u32 = 0; +pub const __HAVE_DISTINCT_FLOAT16: u32 = 0; +pub const __HAVE_DISTINCT_FLOAT32: u32 = 0; +pub const __HAVE_DISTINCT_FLOAT64: u32 = 0; +pub const __HAVE_DISTINCT_FLOAT32X: u32 = 0; +pub const __HAVE_DISTINCT_FLOAT64X: u32 = 0; +pub const __HAVE_DISTINCT_FLOAT128X: u32 = 0; +pub const __HAVE_FLOATN_NOT_TYPEDEF: u32 = 0; pub const GGML_FILE_MAGIC: u32 = 1734831468; pub const GGML_FILE_VERSION: u32 = 1; pub const GGML_QNT_VERSION: u32 = 2; @@ -117,11 +157,56 @@ pub const GGML_EXIT_ABORTED: u32 = 1; pub const GGUF_MAGIC: &[u8; 5] = b"GGUF\0"; pub const GGUF_VERSION: u32 = 3; pub const GGUF_DEFAULT_ALIGNMENT: u32 = 32; +pub const GGML_KQ_MASK_PAD: u32 = 32; pub const GGML_N_TASKS_MAX: i32 = -1; pub const WHISPER_SAMPLE_RATE: u32 = 16000; pub const WHISPER_N_FFT: u32 = 400; pub const WHISPER_HOP_LENGTH: u32 = 160; pub const WHISPER_CHUNK_SIZE: u32 = 30; +pub type wchar_t = ::std::os::raw::c_int; +#[repr(C)] +#[repr(align(16))] +#[derive(Debug, Copy, Clone)] +pub struct max_align_t { + pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, + pub __bindgen_padding_0: u64, + pub __clang_max_align_nonce2: u128, +} +#[test] +fn bindgen_test_layout_max_align_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(max_align_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(max_align_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce1) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce2) + ) + ); +} pub type __u_char = ::std::os::raw::c_uchar; pub type __u_short = ::std::os::raw::c_ushort; pub type __u_int = ::std::os::raw::c_uint; @@ -161,133 +246,1111 @@ pub type __pid_t = ::std::os::raw::c_int; pub struct __fsid_t { pub __val: [::std::os::raw::c_int; 2usize], } -#[test] -fn bindgen_test_layout___fsid_t() { - const UNINIT: ::std::mem::MaybeUninit<__fsid_t> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<__fsid_t>(), - 8usize, - concat!("Size of: ", stringify!(__fsid_t)) - ); - assert_eq!( - ::std::mem::align_of::<__fsid_t>(), - 4usize, - concat!("Alignment of ", stringify!(__fsid_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__fsid_t), - "::", - stringify!(__val) - ) - ); +#[test] +fn bindgen_test_layout___fsid_t() { + const UNINIT: ::std::mem::MaybeUninit<__fsid_t> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<__fsid_t>(), + 8usize, + concat!("Size of: ", stringify!(__fsid_t)) + ); + assert_eq!( + ::std::mem::align_of::<__fsid_t>(), + 4usize, + concat!("Alignment of ", stringify!(__fsid_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__fsid_t), + "::", + stringify!(__val) + ) + ); +} +pub type __clock_t = ::std::os::raw::c_long; +pub type __rlim_t = ::std::os::raw::c_ulong; +pub type __rlim64_t = ::std::os::raw::c_ulong; +pub type __id_t = ::std::os::raw::c_uint; +pub type __time_t = ::std::os::raw::c_long; +pub type __useconds_t = ::std::os::raw::c_uint; +pub type __suseconds_t = ::std::os::raw::c_long; +pub type __suseconds64_t = ::std::os::raw::c_long; +pub type __daddr_t = ::std::os::raw::c_int; +pub type __key_t = ::std::os::raw::c_int; +pub type __clockid_t = ::std::os::raw::c_int; +pub type __timer_t = *mut ::std::os::raw::c_void; +pub type __blksize_t = ::std::os::raw::c_long; +pub type __blkcnt_t = ::std::os::raw::c_long; +pub type __blkcnt64_t = ::std::os::raw::c_long; +pub type __fsblkcnt_t = ::std::os::raw::c_ulong; +pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt_t = ::std::os::raw::c_ulong; +pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; +pub type __fsword_t = ::std::os::raw::c_long; +pub type __ssize_t = ::std::os::raw::c_long; +pub type __syscall_slong_t = ::std::os::raw::c_long; +pub type __syscall_ulong_t = ::std::os::raw::c_ulong; +pub type __loff_t = __off64_t; +pub type __caddr_t = *mut ::std::os::raw::c_char; +pub type __intptr_t = ::std::os::raw::c_long; +pub type __socklen_t = ::std::os::raw::c_uint; +pub type __sig_atomic_t = ::std::os::raw::c_int; +pub type int_least8_t = __int_least8_t; +pub type int_least16_t = __int_least16_t; +pub type int_least32_t = __int_least32_t; +pub type int_least64_t = __int_least64_t; +pub type uint_least8_t = __uint_least8_t; +pub type uint_least16_t = __uint_least16_t; +pub type uint_least32_t = __uint_least32_t; +pub type uint_least64_t = __uint_least64_t; +pub type int_fast8_t = ::std::os::raw::c_schar; +pub type int_fast16_t = ::std::os::raw::c_long; +pub type int_fast32_t = ::std::os::raw::c_long; +pub type int_fast64_t = ::std::os::raw::c_long; +pub type uint_fast8_t = ::std::os::raw::c_uchar; +pub type uint_fast16_t = ::std::os::raw::c_ulong; +pub type uint_fast32_t = ::std::os::raw::c_ulong; +pub type uint_fast64_t = ::std::os::raw::c_ulong; +pub type intmax_t = __intmax_t; +pub type uintmax_t = __uintmax_t; +pub type __gnuc_va_list = __builtin_va_list; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct __mbstate_t { + pub __count: ::std::os::raw::c_int, + pub __value: __mbstate_t__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union __mbstate_t__bindgen_ty_1 { + pub __wch: ::std::os::raw::c_uint, + pub __wchb: [::std::os::raw::c_char; 4usize], +} +#[test] +fn bindgen_test_layout___mbstate_t__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit<__mbstate_t__bindgen_ty_1> = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<__mbstate_t__bindgen_ty_1>(), + 4usize, + concat!("Size of: ", stringify!(__mbstate_t__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::<__mbstate_t__bindgen_ty_1>(), + 4usize, + concat!("Alignment of ", stringify!(__mbstate_t__bindgen_ty_1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__wch) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__mbstate_t__bindgen_ty_1), + "::", + stringify!(__wch) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__wchb) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__mbstate_t__bindgen_ty_1), + "::", + stringify!(__wchb) + ) + ); +} +#[test] +fn bindgen_test_layout___mbstate_t() { + const UNINIT: ::std::mem::MaybeUninit<__mbstate_t> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<__mbstate_t>(), + 8usize, + concat!("Size of: ", stringify!(__mbstate_t)) + ); + assert_eq!( + ::std::mem::align_of::<__mbstate_t>(), + 4usize, + concat!("Alignment of ", stringify!(__mbstate_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__count) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__mbstate_t), + "::", + stringify!(__count) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__value) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(__mbstate_t), + "::", + stringify!(__value) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _G_fpos_t { + pub __pos: __off_t, + pub __state: __mbstate_t, +} +#[test] +fn bindgen_test_layout__G_fpos_t() { + const UNINIT: ::std::mem::MaybeUninit<_G_fpos_t> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<_G_fpos_t>(), + 16usize, + concat!("Size of: ", stringify!(_G_fpos_t)) + ); + assert_eq!( + ::std::mem::align_of::<_G_fpos_t>(), + 8usize, + concat!("Alignment of ", stringify!(_G_fpos_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__pos) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_G_fpos_t), + "::", + stringify!(__pos) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__state) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(_G_fpos_t), + "::", + stringify!(__state) + ) + ); +} +pub type __fpos_t = _G_fpos_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct _G_fpos64_t { + pub __pos: __off64_t, + pub __state: __mbstate_t, +} +#[test] +fn bindgen_test_layout__G_fpos64_t() { + const UNINIT: ::std::mem::MaybeUninit<_G_fpos64_t> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<_G_fpos64_t>(), + 16usize, + concat!("Size of: ", stringify!(_G_fpos64_t)) + ); + assert_eq!( + ::std::mem::align_of::<_G_fpos64_t>(), + 8usize, + concat!("Alignment of ", stringify!(_G_fpos64_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__pos) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_G_fpos64_t), + "::", + stringify!(__pos) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__state) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(_G_fpos64_t), + "::", + stringify!(__state) + ) + ); +} +pub type __fpos64_t = _G_fpos64_t; +pub type __FILE = _IO_FILE; +pub type FILE = _IO_FILE; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _IO_marker { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _IO_codecvt { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _IO_wide_data { + _unused: [u8; 0], +} +pub type _IO_lock_t = ::std::os::raw::c_void; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _IO_FILE { + pub _flags: ::std::os::raw::c_int, + pub _IO_read_ptr: *mut ::std::os::raw::c_char, + pub _IO_read_end: *mut ::std::os::raw::c_char, + pub _IO_read_base: *mut ::std::os::raw::c_char, + pub _IO_write_base: *mut ::std::os::raw::c_char, + pub _IO_write_ptr: *mut ::std::os::raw::c_char, + pub _IO_write_end: *mut ::std::os::raw::c_char, + pub _IO_buf_base: *mut ::std::os::raw::c_char, + pub _IO_buf_end: *mut ::std::os::raw::c_char, + pub _IO_save_base: *mut ::std::os::raw::c_char, + pub _IO_backup_base: *mut ::std::os::raw::c_char, + pub _IO_save_end: *mut ::std::os::raw::c_char, + pub _markers: *mut _IO_marker, + pub _chain: *mut _IO_FILE, + pub _fileno: ::std::os::raw::c_int, + pub _flags2: ::std::os::raw::c_int, + pub _old_offset: __off_t, + pub _cur_column: ::std::os::raw::c_ushort, + pub _vtable_offset: ::std::os::raw::c_schar, + pub _shortbuf: [::std::os::raw::c_char; 1usize], + pub _lock: *mut _IO_lock_t, + pub _offset: __off64_t, + pub _codecvt: *mut _IO_codecvt, + pub _wide_data: *mut _IO_wide_data, + pub _freeres_list: *mut _IO_FILE, + pub _freeres_buf: *mut ::std::os::raw::c_void, + pub __pad5: usize, + pub _mode: ::std::os::raw::c_int, + pub _unused2: [::std::os::raw::c_char; 20usize], +} +#[test] +fn bindgen_test_layout__IO_FILE() { + const UNINIT: ::std::mem::MaybeUninit<_IO_FILE> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<_IO_FILE>(), + 216usize, + concat!("Size of: ", stringify!(_IO_FILE)) + ); + assert_eq!( + ::std::mem::align_of::<_IO_FILE>(), + 8usize, + concat!("Alignment of ", stringify!(_IO_FILE)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._flags) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_flags) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_read_ptr) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_read_ptr) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_read_end) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_read_end) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_read_base) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_read_base) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_write_base) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_write_base) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_write_ptr) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_write_ptr) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_write_end) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_write_end) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_buf_base) as usize - ptr as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_buf_base) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_buf_end) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_buf_end) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_save_base) as usize - ptr as usize }, + 72usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_save_base) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_backup_base) as usize - ptr as usize }, + 80usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_backup_base) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._IO_save_end) as usize - ptr as usize }, + 88usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_IO_save_end) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._markers) as usize - ptr as usize }, + 96usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_markers) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._chain) as usize - ptr as usize }, + 104usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_chain) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._fileno) as usize - ptr as usize }, + 112usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_fileno) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._flags2) as usize - ptr as usize }, + 116usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_flags2) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._old_offset) as usize - ptr as usize }, + 120usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_old_offset) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._cur_column) as usize - ptr as usize }, + 128usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_cur_column) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._vtable_offset) as usize - ptr as usize }, + 130usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_vtable_offset) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._shortbuf) as usize - ptr as usize }, + 131usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_shortbuf) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._lock) as usize - ptr as usize }, + 136usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_lock) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._offset) as usize - ptr as usize }, + 144usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_offset) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._codecvt) as usize - ptr as usize }, + 152usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_codecvt) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._wide_data) as usize - ptr as usize }, + 160usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_wide_data) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._freeres_list) as usize - ptr as usize }, + 168usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_freeres_list) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._freeres_buf) as usize - ptr as usize }, + 176usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_freeres_buf) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__pad5) as usize - ptr as usize }, + 184usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(__pad5) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._mode) as usize - ptr as usize }, + 192usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_mode) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._unused2) as usize - ptr as usize }, + 196usize, + concat!( + "Offset of field: ", + stringify!(_IO_FILE), + "::", + stringify!(_unused2) + ) + ); +} +pub type va_list = __gnuc_va_list; +pub type off_t = __off_t; +pub type fpos_t = __fpos_t; +extern "C" { + pub static mut stdin: *mut FILE; +} +extern "C" { + pub static mut stdout: *mut FILE; +} +extern "C" { + pub static mut stderr: *mut FILE; +} +extern "C" { + pub fn remove(__filename: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn rename( + __old: *const ::std::os::raw::c_char, + __new: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn renameat( + __oldfd: ::std::os::raw::c_int, + __old: *const ::std::os::raw::c_char, + __newfd: ::std::os::raw::c_int, + __new: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fclose(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn tmpfile() -> *mut FILE; +} +extern "C" { + pub fn tmpnam(arg1: *mut ::std::os::raw::c_char) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn tmpnam_r(__s: *mut ::std::os::raw::c_char) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn tempnam( + __dir: *const ::std::os::raw::c_char, + __pfx: *const ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn fflush(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fflush_unlocked(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fopen( + __filename: *const ::std::os::raw::c_char, + __modes: *const ::std::os::raw::c_char, + ) -> *mut FILE; +} +extern "C" { + pub fn freopen( + __filename: *const ::std::os::raw::c_char, + __modes: *const ::std::os::raw::c_char, + __stream: *mut FILE, + ) -> *mut FILE; +} +extern "C" { + pub fn fdopen(__fd: ::std::os::raw::c_int, __modes: *const ::std::os::raw::c_char) + -> *mut FILE; +} +extern "C" { + pub fn fmemopen( + __s: *mut ::std::os::raw::c_void, + __len: usize, + __modes: *const ::std::os::raw::c_char, + ) -> *mut FILE; +} +extern "C" { + pub fn open_memstream( + __bufloc: *mut *mut ::std::os::raw::c_char, + __sizeloc: *mut usize, + ) -> *mut FILE; +} +extern "C" { + pub fn setbuf(__stream: *mut FILE, __buf: *mut ::std::os::raw::c_char); +} +extern "C" { + pub fn setvbuf( + __stream: *mut FILE, + __buf: *mut ::std::os::raw::c_char, + __modes: ::std::os::raw::c_int, + __n: usize, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn setbuffer(__stream: *mut FILE, __buf: *mut ::std::os::raw::c_char, __size: usize); +} +extern "C" { + pub fn setlinebuf(__stream: *mut FILE); +} +extern "C" { + pub fn fprintf( + __stream: *mut FILE, + __format: *const ::std::os::raw::c_char, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn printf(__format: *const ::std::os::raw::c_char, ...) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sprintf( + __s: *mut ::std::os::raw::c_char, + __format: *const ::std::os::raw::c_char, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn vfprintf( + __s: *mut FILE, + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn vprintf( + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn vsprintf( + __s: *mut ::std::os::raw::c_char, + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn snprintf( + __s: *mut ::std::os::raw::c_char, + __maxlen: ::std::os::raw::c_ulong, + __format: *const ::std::os::raw::c_char, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn vsnprintf( + __s: *mut ::std::os::raw::c_char, + __maxlen: ::std::os::raw::c_ulong, + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn vdprintf( + __fd: ::std::os::raw::c_int, + __fmt: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn dprintf( + __fd: ::std::os::raw::c_int, + __fmt: *const ::std::os::raw::c_char, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fscanf( + __stream: *mut FILE, + __format: *const ::std::os::raw::c_char, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn scanf(__format: *const ::std::os::raw::c_char, ...) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn sscanf( + __s: *const ::std::os::raw::c_char, + __format: *const ::std::os::raw::c_char, + ... + ) -> ::std::os::raw::c_int; +} +pub type _Float32 = f32; +pub type _Float64 = f64; +pub type _Float32x = f64; +pub type _Float64x = u128; +extern "C" { + #[link_name = "\u{1}__isoc99_fscanf"] + pub fn fscanf1( + __stream: *mut FILE, + __format: *const ::std::os::raw::c_char, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}__isoc99_scanf"] + pub fn scanf1(__format: *const ::std::os::raw::c_char, ...) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}__isoc99_sscanf"] + pub fn sscanf1( + __s: *const ::std::os::raw::c_char, + __format: *const ::std::os::raw::c_char, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn vfscanf( + __s: *mut FILE, + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn vscanf( + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn vsscanf( + __s: *const ::std::os::raw::c_char, + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}__isoc99_vfscanf"] + pub fn vfscanf1( + __s: *mut FILE, + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}__isoc99_vscanf"] + pub fn vscanf1( + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}__isoc99_vsscanf"] + pub fn vsscanf1( + __s: *const ::std::os::raw::c_char, + __format: *const ::std::os::raw::c_char, + __arg: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fgetc(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn getc(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn getchar() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn getc_unlocked(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn getchar_unlocked() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fgetc_unlocked(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fputc(__c: ::std::os::raw::c_int, __stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn putc(__c: ::std::os::raw::c_int, __stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn putchar(__c: ::std::os::raw::c_int) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fputc_unlocked(__c: ::std::os::raw::c_int, __stream: *mut FILE) + -> ::std::os::raw::c_int; +} +extern "C" { + pub fn putc_unlocked(__c: ::std::os::raw::c_int, __stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn putchar_unlocked(__c: ::std::os::raw::c_int) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn getw(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn putw(__w: ::std::os::raw::c_int, __stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fgets( + __s: *mut ::std::os::raw::c_char, + __n: ::std::os::raw::c_int, + __stream: *mut FILE, + ) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn __getdelim( + __lineptr: *mut *mut ::std::os::raw::c_char, + __n: *mut usize, + __delimiter: ::std::os::raw::c_int, + __stream: *mut FILE, + ) -> __ssize_t; +} +extern "C" { + pub fn getdelim( + __lineptr: *mut *mut ::std::os::raw::c_char, + __n: *mut usize, + __delimiter: ::std::os::raw::c_int, + __stream: *mut FILE, + ) -> __ssize_t; +} +extern "C" { + pub fn getline( + __lineptr: *mut *mut ::std::os::raw::c_char, + __n: *mut usize, + __stream: *mut FILE, + ) -> __ssize_t; +} +extern "C" { + pub fn fputs(__s: *const ::std::os::raw::c_char, __stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn puts(__s: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn ungetc(__c: ::std::os::raw::c_int, __stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fread( + __ptr: *mut ::std::os::raw::c_void, + __size: ::std::os::raw::c_ulong, + __n: ::std::os::raw::c_ulong, + __stream: *mut FILE, + ) -> ::std::os::raw::c_ulong; +} +extern "C" { + pub fn fwrite( + __ptr: *const ::std::os::raw::c_void, + __size: ::std::os::raw::c_ulong, + __n: ::std::os::raw::c_ulong, + __s: *mut FILE, + ) -> ::std::os::raw::c_ulong; +} +extern "C" { + pub fn fread_unlocked( + __ptr: *mut ::std::os::raw::c_void, + __size: usize, + __n: usize, + __stream: *mut FILE, + ) -> usize; +} +extern "C" { + pub fn fwrite_unlocked( + __ptr: *const ::std::os::raw::c_void, + __size: usize, + __n: usize, + __stream: *mut FILE, + ) -> usize; +} +extern "C" { + pub fn fseek( + __stream: *mut FILE, + __off: ::std::os::raw::c_long, + __whence: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn ftell(__stream: *mut FILE) -> ::std::os::raw::c_long; +} +extern "C" { + pub fn rewind(__stream: *mut FILE); +} +extern "C" { + pub fn fseeko( + __stream: *mut FILE, + __off: __off_t, + __whence: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn ftello(__stream: *mut FILE) -> __off_t; +} +extern "C" { + pub fn fgetpos(__stream: *mut FILE, __pos: *mut fpos_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fsetpos(__stream: *mut FILE, __pos: *const fpos_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clearerr(__stream: *mut FILE); +} +extern "C" { + pub fn feof(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn ferror(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clearerr_unlocked(__stream: *mut FILE); +} +extern "C" { + pub fn feof_unlocked(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn ferror_unlocked(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn perror(__s: *const ::std::os::raw::c_char); +} +extern "C" { + pub fn fileno(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn fileno_unlocked(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn pclose(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn popen( + __command: *const ::std::os::raw::c_char, + __modes: *const ::std::os::raw::c_char, + ) -> *mut FILE; +} +extern "C" { + pub fn ctermid(__s: *mut ::std::os::raw::c_char) -> *mut ::std::os::raw::c_char; +} +extern "C" { + pub fn flockfile(__stream: *mut FILE); +} +extern "C" { + pub fn ftrylockfile(__stream: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn funlockfile(__stream: *mut FILE); +} +extern "C" { + pub fn __uflow(arg1: *mut FILE) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn __overflow(arg1: *mut FILE, arg2: ::std::os::raw::c_int) -> ::std::os::raw::c_int; +} +pub const ggml_status_GGML_STATUS_ALLOC_FAILED: ggml_status = -2; +pub const ggml_status_GGML_STATUS_FAILED: ggml_status = -1; +pub const ggml_status_GGML_STATUS_SUCCESS: ggml_status = 0; +pub const ggml_status_GGML_STATUS_ABORTED: ggml_status = 1; +pub type ggml_status = ::std::os::raw::c_int; +extern "C" { + pub fn ggml_status_to_string(status: ggml_status) -> *const ::std::os::raw::c_char; +} +pub type ggml_fp16_t = u16; +extern "C" { + pub fn ggml_fp16_to_fp32(arg1: ggml_fp16_t) -> f32; +} +extern "C" { + pub fn ggml_fp32_to_fp16(arg1: f32) -> ggml_fp16_t; +} +extern "C" { + pub fn ggml_fp16_to_fp32_row(arg1: *const ggml_fp16_t, arg2: *mut f32, arg3: i64); +} +extern "C" { + pub fn ggml_fp32_to_fp16_row(arg1: *const f32, arg2: *mut ggml_fp16_t, arg3: i64); } -pub type __clock_t = ::std::os::raw::c_long; -pub type __rlim_t = ::std::os::raw::c_ulong; -pub type __rlim64_t = ::std::os::raw::c_ulong; -pub type __id_t = ::std::os::raw::c_uint; -pub type __time_t = ::std::os::raw::c_long; -pub type __useconds_t = ::std::os::raw::c_uint; -pub type __suseconds_t = ::std::os::raw::c_long; -pub type __suseconds64_t = ::std::os::raw::c_long; -pub type __daddr_t = ::std::os::raw::c_int; -pub type __key_t = ::std::os::raw::c_int; -pub type __clockid_t = ::std::os::raw::c_int; -pub type __timer_t = *mut ::std::os::raw::c_void; -pub type __blksize_t = ::std::os::raw::c_long; -pub type __blkcnt_t = ::std::os::raw::c_long; -pub type __blkcnt64_t = ::std::os::raw::c_long; -pub type __fsblkcnt_t = ::std::os::raw::c_ulong; -pub type __fsblkcnt64_t = ::std::os::raw::c_ulong; -pub type __fsfilcnt_t = ::std::os::raw::c_ulong; -pub type __fsfilcnt64_t = ::std::os::raw::c_ulong; -pub type __fsword_t = ::std::os::raw::c_long; -pub type __ssize_t = ::std::os::raw::c_long; -pub type __syscall_slong_t = ::std::os::raw::c_long; -pub type __syscall_ulong_t = ::std::os::raw::c_ulong; -pub type __loff_t = __off64_t; -pub type __caddr_t = *mut ::std::os::raw::c_char; -pub type __intptr_t = ::std::os::raw::c_long; -pub type __socklen_t = ::std::os::raw::c_uint; -pub type __sig_atomic_t = ::std::os::raw::c_int; -pub type int_least8_t = __int_least8_t; -pub type int_least16_t = __int_least16_t; -pub type int_least32_t = __int_least32_t; -pub type int_least64_t = __int_least64_t; -pub type uint_least8_t = __uint_least8_t; -pub type uint_least16_t = __uint_least16_t; -pub type uint_least32_t = __uint_least32_t; -pub type uint_least64_t = __uint_least64_t; -pub type int_fast8_t = ::std::os::raw::c_schar; -pub type int_fast16_t = ::std::os::raw::c_long; -pub type int_fast32_t = ::std::os::raw::c_long; -pub type int_fast64_t = ::std::os::raw::c_long; -pub type uint_fast8_t = ::std::os::raw::c_uchar; -pub type uint_fast16_t = ::std::os::raw::c_ulong; -pub type uint_fast32_t = ::std::os::raw::c_ulong; -pub type uint_fast64_t = ::std::os::raw::c_ulong; -pub type intmax_t = __intmax_t; -pub type uintmax_t = __uintmax_t; -pub type wchar_t = ::std::os::raw::c_int; #[repr(C)] -#[repr(align(16))] #[derive(Debug, Copy, Clone)] -pub struct max_align_t { - pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, - pub __bindgen_padding_0: u64, - pub __clang_max_align_nonce2: u128, +pub struct ggml_bf16_t { + pub bits: u16, } #[test] -fn bindgen_test_layout_max_align_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_ggml_bf16_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(max_align_t)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(ggml_bf16_t)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(max_align_t)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(ggml_bf16_t)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr).bits) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), + stringify!(ggml_bf16_t), "::", - stringify!(__clang_max_align_nonce2) + stringify!(bits) ) ); } -pub type ggml_fp16_t = u16; extern "C" { - pub fn ggml_fp16_to_fp32(x: ggml_fp16_t) -> f32; + pub fn ggml_fp32_to_bf16(arg1: f32) -> ggml_bf16_t; } extern "C" { - pub fn ggml_fp32_to_fp16(x: f32) -> ggml_fp16_t; + pub fn ggml_bf16_to_fp32(arg1: ggml_bf16_t) -> f32; } extern "C" { - pub fn ggml_fp16_to_fp32_row(x: *const ggml_fp16_t, y: *mut f32, n: ::std::os::raw::c_int); + pub fn ggml_bf16_to_fp32_row(arg1: *const ggml_bf16_t, arg2: *mut f32, arg3: i64); } extern "C" { - pub fn ggml_fp32_to_fp16_row(x: *const f32, y: *mut ggml_fp16_t, n: ::std::os::raw::c_int); + pub fn ggml_fp32_to_bf16_row(arg1: *const f32, arg2: *mut ggml_bf16_t, arg3: i64); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -308,17 +1371,29 @@ pub const ggml_type_GGML_TYPE_Q4_K: ggml_type = 12; pub const ggml_type_GGML_TYPE_Q5_K: ggml_type = 13; pub const ggml_type_GGML_TYPE_Q6_K: ggml_type = 14; pub const ggml_type_GGML_TYPE_Q8_K: ggml_type = 15; -pub const ggml_type_GGML_TYPE_I8: ggml_type = 16; -pub const ggml_type_GGML_TYPE_I16: ggml_type = 17; -pub const ggml_type_GGML_TYPE_I32: ggml_type = 18; -pub const ggml_type_GGML_TYPE_COUNT: ggml_type = 19; +pub const ggml_type_GGML_TYPE_IQ2_XXS: ggml_type = 16; +pub const ggml_type_GGML_TYPE_IQ2_XS: ggml_type = 17; +pub const ggml_type_GGML_TYPE_IQ3_XXS: ggml_type = 18; +pub const ggml_type_GGML_TYPE_IQ1_S: ggml_type = 19; +pub const ggml_type_GGML_TYPE_IQ4_NL: ggml_type = 20; +pub const ggml_type_GGML_TYPE_IQ3_S: ggml_type = 21; +pub const ggml_type_GGML_TYPE_IQ2_S: ggml_type = 22; +pub const ggml_type_GGML_TYPE_IQ4_XS: ggml_type = 23; +pub const ggml_type_GGML_TYPE_I8: ggml_type = 24; +pub const ggml_type_GGML_TYPE_I16: ggml_type = 25; +pub const ggml_type_GGML_TYPE_I32: ggml_type = 26; +pub const ggml_type_GGML_TYPE_I64: ggml_type = 27; +pub const ggml_type_GGML_TYPE_F64: ggml_type = 28; +pub const ggml_type_GGML_TYPE_IQ1_M: ggml_type = 29; +pub const ggml_type_GGML_TYPE_BF16: ggml_type = 30; +pub const ggml_type_GGML_TYPE_COUNT: ggml_type = 31; pub type ggml_type = ::std::os::raw::c_uint; pub const ggml_prec_GGML_PREC_DEFAULT: ggml_prec = 0; pub const ggml_prec_GGML_PREC_F32: ggml_prec = 1; pub type ggml_prec = ::std::os::raw::c_uint; -pub const ggml_backend_type_GGML_BACKEND_CPU: ggml_backend_type = 0; -pub const ggml_backend_type_GGML_BACKEND_GPU: ggml_backend_type = 10; -pub const ggml_backend_type_GGML_BACKEND_GPU_SPLIT: ggml_backend_type = 20; +pub const ggml_backend_type_GGML_BACKEND_TYPE_CPU: ggml_backend_type = 0; +pub const ggml_backend_type_GGML_BACKEND_TYPE_GPU: ggml_backend_type = 10; +pub const ggml_backend_type_GGML_BACKEND_TYPE_GPU_SPLIT: ggml_backend_type = 20; pub type ggml_backend_type = ::std::os::raw::c_uint; pub const ggml_ftype_GGML_FTYPE_UNKNOWN: ggml_ftype = -1; pub const ggml_ftype_GGML_FTYPE_ALL_F32: ggml_ftype = 0; @@ -334,6 +1409,16 @@ pub const ggml_ftype_GGML_FTYPE_MOSTLY_Q3_K: ggml_ftype = 11; pub const ggml_ftype_GGML_FTYPE_MOSTLY_Q4_K: ggml_ftype = 12; pub const ggml_ftype_GGML_FTYPE_MOSTLY_Q5_K: ggml_ftype = 13; pub const ggml_ftype_GGML_FTYPE_MOSTLY_Q6_K: ggml_ftype = 14; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ2_XXS: ggml_ftype = 15; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ2_XS: ggml_ftype = 16; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ3_XXS: ggml_ftype = 17; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ1_S: ggml_ftype = 18; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ4_NL: ggml_ftype = 19; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ3_S: ggml_ftype = 20; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ2_S: ggml_ftype = 21; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ4_XS: ggml_ftype = 22; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_IQ1_M: ggml_ftype = 23; +pub const ggml_ftype_GGML_FTYPE_MOSTLY_BF16: ggml_ftype = 24; pub type ggml_ftype = ::std::os::raw::c_int; pub const ggml_op_GGML_OP_NONE: ggml_op = 0; pub const ggml_op_GGML_OP_DUP: ggml_op = 1; @@ -378,36 +1463,40 @@ pub const ggml_op_GGML_OP_SOFT_MAX: ggml_op = 39; pub const ggml_op_GGML_OP_SOFT_MAX_BACK: ggml_op = 40; pub const ggml_op_GGML_OP_ROPE: ggml_op = 41; pub const ggml_op_GGML_OP_ROPE_BACK: ggml_op = 42; -pub const ggml_op_GGML_OP_ALIBI: ggml_op = 43; -pub const ggml_op_GGML_OP_CLAMP: ggml_op = 44; -pub const ggml_op_GGML_OP_CONV_TRANSPOSE_1D: ggml_op = 45; -pub const ggml_op_GGML_OP_IM2COL: ggml_op = 46; -pub const ggml_op_GGML_OP_CONV_TRANSPOSE_2D: ggml_op = 47; -pub const ggml_op_GGML_OP_POOL_1D: ggml_op = 48; -pub const ggml_op_GGML_OP_POOL_2D: ggml_op = 49; -pub const ggml_op_GGML_OP_UPSCALE: ggml_op = 50; -pub const ggml_op_GGML_OP_PAD: ggml_op = 51; -pub const ggml_op_GGML_OP_ARGSORT: ggml_op = 52; -pub const ggml_op_GGML_OP_LEAKY_RELU: ggml_op = 53; -pub const ggml_op_GGML_OP_FLASH_ATTN: ggml_op = 54; -pub const ggml_op_GGML_OP_FLASH_FF: ggml_op = 55; -pub const ggml_op_GGML_OP_FLASH_ATTN_BACK: ggml_op = 56; -pub const ggml_op_GGML_OP_WIN_PART: ggml_op = 57; -pub const ggml_op_GGML_OP_WIN_UNPART: ggml_op = 58; -pub const ggml_op_GGML_OP_GET_REL_POS: ggml_op = 59; -pub const ggml_op_GGML_OP_ADD_REL_POS: ggml_op = 60; -pub const ggml_op_GGML_OP_UNARY: ggml_op = 61; -pub const ggml_op_GGML_OP_MAP_UNARY: ggml_op = 62; -pub const ggml_op_GGML_OP_MAP_BINARY: ggml_op = 63; -pub const ggml_op_GGML_OP_MAP_CUSTOM1_F32: ggml_op = 64; -pub const ggml_op_GGML_OP_MAP_CUSTOM2_F32: ggml_op = 65; -pub const ggml_op_GGML_OP_MAP_CUSTOM3_F32: ggml_op = 66; -pub const ggml_op_GGML_OP_MAP_CUSTOM1: ggml_op = 67; -pub const ggml_op_GGML_OP_MAP_CUSTOM2: ggml_op = 68; -pub const ggml_op_GGML_OP_MAP_CUSTOM3: ggml_op = 69; -pub const ggml_op_GGML_OP_CROSS_ENTROPY_LOSS: ggml_op = 70; -pub const ggml_op_GGML_OP_CROSS_ENTROPY_LOSS_BACK: ggml_op = 71; -pub const ggml_op_GGML_OP_COUNT: ggml_op = 72; +pub const ggml_op_GGML_OP_CLAMP: ggml_op = 43; +pub const ggml_op_GGML_OP_CONV_TRANSPOSE_1D: ggml_op = 44; +pub const ggml_op_GGML_OP_IM2COL: ggml_op = 45; +pub const ggml_op_GGML_OP_CONV_TRANSPOSE_2D: ggml_op = 46; +pub const ggml_op_GGML_OP_POOL_1D: ggml_op = 47; +pub const ggml_op_GGML_OP_POOL_2D: ggml_op = 48; +pub const ggml_op_GGML_OP_UPSCALE: ggml_op = 49; +pub const ggml_op_GGML_OP_PAD: ggml_op = 50; +pub const ggml_op_GGML_OP_ARANGE: ggml_op = 51; +pub const ggml_op_GGML_OP_TIMESTEP_EMBEDDING: ggml_op = 52; +pub const ggml_op_GGML_OP_ARGSORT: ggml_op = 53; +pub const ggml_op_GGML_OP_LEAKY_RELU: ggml_op = 54; +pub const ggml_op_GGML_OP_FLASH_ATTN: ggml_op = 55; +pub const ggml_op_GGML_OP_FLASH_ATTN_EXT: ggml_op = 56; +pub const ggml_op_GGML_OP_FLASH_FF: ggml_op = 57; +pub const ggml_op_GGML_OP_FLASH_ATTN_BACK: ggml_op = 58; +pub const ggml_op_GGML_OP_SSM_CONV: ggml_op = 59; +pub const ggml_op_GGML_OP_SSM_SCAN: ggml_op = 60; +pub const ggml_op_GGML_OP_WIN_PART: ggml_op = 61; +pub const ggml_op_GGML_OP_WIN_UNPART: ggml_op = 62; +pub const ggml_op_GGML_OP_GET_REL_POS: ggml_op = 63; +pub const ggml_op_GGML_OP_ADD_REL_POS: ggml_op = 64; +pub const ggml_op_GGML_OP_UNARY: ggml_op = 65; +pub const ggml_op_GGML_OP_MAP_UNARY: ggml_op = 66; +pub const ggml_op_GGML_OP_MAP_BINARY: ggml_op = 67; +pub const ggml_op_GGML_OP_MAP_CUSTOM1_F32: ggml_op = 68; +pub const ggml_op_GGML_OP_MAP_CUSTOM2_F32: ggml_op = 69; +pub const ggml_op_GGML_OP_MAP_CUSTOM3_F32: ggml_op = 70; +pub const ggml_op_GGML_OP_MAP_CUSTOM1: ggml_op = 71; +pub const ggml_op_GGML_OP_MAP_CUSTOM2: ggml_op = 72; +pub const ggml_op_GGML_OP_MAP_CUSTOM3: ggml_op = 73; +pub const ggml_op_GGML_OP_CROSS_ENTROPY_LOSS: ggml_op = 74; +pub const ggml_op_GGML_OP_CROSS_ENTROPY_LOSS_BACK: ggml_op = 75; +pub const ggml_op_GGML_OP_COUNT: ggml_op = 76; pub type ggml_op = ::std::os::raw::c_uint; pub const ggml_unary_op_GGML_UNARY_OP_ABS: ggml_unary_op = 0; pub const ggml_unary_op_GGML_UNARY_OP_SGN: ggml_unary_op = 1; @@ -416,20 +1505,27 @@ pub const ggml_unary_op_GGML_UNARY_OP_STEP: ggml_unary_op = 3; pub const ggml_unary_op_GGML_UNARY_OP_TANH: ggml_unary_op = 4; pub const ggml_unary_op_GGML_UNARY_OP_ELU: ggml_unary_op = 5; pub const ggml_unary_op_GGML_UNARY_OP_RELU: ggml_unary_op = 6; -pub const ggml_unary_op_GGML_UNARY_OP_GELU: ggml_unary_op = 7; -pub const ggml_unary_op_GGML_UNARY_OP_GELU_QUICK: ggml_unary_op = 8; -pub const ggml_unary_op_GGML_UNARY_OP_SILU: ggml_unary_op = 9; -pub const ggml_unary_op_GGML_UNARY_OP_COUNT: ggml_unary_op = 10; +pub const ggml_unary_op_GGML_UNARY_OP_SIGMOID: ggml_unary_op = 7; +pub const ggml_unary_op_GGML_UNARY_OP_GELU: ggml_unary_op = 8; +pub const ggml_unary_op_GGML_UNARY_OP_GELU_QUICK: ggml_unary_op = 9; +pub const ggml_unary_op_GGML_UNARY_OP_SILU: ggml_unary_op = 10; +pub const ggml_unary_op_GGML_UNARY_OP_HARDSWISH: ggml_unary_op = 11; +pub const ggml_unary_op_GGML_UNARY_OP_HARDSIGMOID: ggml_unary_op = 12; +pub const ggml_unary_op_GGML_UNARY_OP_COUNT: ggml_unary_op = 13; pub type ggml_unary_op = ::std::os::raw::c_uint; -pub const ggml_object_type_GGML_OBJECT_TENSOR: ggml_object_type = 0; -pub const ggml_object_type_GGML_OBJECT_GRAPH: ggml_object_type = 1; -pub const ggml_object_type_GGML_OBJECT_WORK_BUFFER: ggml_object_type = 2; +pub const ggml_object_type_GGML_OBJECT_TYPE_TENSOR: ggml_object_type = 0; +pub const ggml_object_type_GGML_OBJECT_TYPE_GRAPH: ggml_object_type = 1; +pub const ggml_object_type_GGML_OBJECT_TYPE_WORK_BUFFER: ggml_object_type = 2; pub type ggml_object_type = ::std::os::raw::c_uint; pub const ggml_log_level_GGML_LOG_LEVEL_ERROR: ggml_log_level = 2; pub const ggml_log_level_GGML_LOG_LEVEL_WARN: ggml_log_level = 3; pub const ggml_log_level_GGML_LOG_LEVEL_INFO: ggml_log_level = 4; pub const ggml_log_level_GGML_LOG_LEVEL_DEBUG: ggml_log_level = 5; pub type ggml_log_level = ::std::os::raw::c_uint; +pub const ggml_tensor_flag_GGML_TENSOR_FLAG_INPUT: ggml_tensor_flag = 1; +pub const ggml_tensor_flag_GGML_TENSOR_FLAG_OUTPUT: ggml_tensor_flag = 2; +pub const ggml_tensor_flag_GGML_TENSOR_FLAG_PARAM: ggml_tensor_flag = 4; +pub type ggml_tensor_flag = ::std::os::raw::c_uint; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ggml_object { @@ -515,7 +1611,7 @@ pub struct ggml_tensor { pub nb: [usize; 4usize], pub op: ggml_op, pub op_params: [i32; 16usize], - pub is_param: bool, + pub flags: i32, pub grad: *mut ggml_tensor, pub src: [*mut ggml_tensor; 10usize], pub perf_runs: ::std::os::raw::c_int, @@ -613,13 +1709,13 @@ fn bindgen_test_layout_ggml_tensor() { ) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).is_param) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize }, 148usize, concat!( "Offset of field: ", stringify!(ggml_tensor), "::", - stringify!(is_param) + stringify!(flags) ) ); assert_eq!( @@ -734,14 +1830,15 @@ fn bindgen_test_layout_ggml_tensor() { ); } pub const GGML_TENSOR_SIZE: usize = 368; +pub type ggml_abort_callback = + ::std::option::Option bool>; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ggml_cplan { pub work_size: usize, pub work_data: *mut u8, pub n_threads: ::std::os::raw::c_int, - pub abort_callback: - ::std::option::Option bool>, + pub abort_callback: ggml_abort_callback, pub abort_callback_data: *mut ::std::os::raw::c_void, } #[test] @@ -1098,9 +2195,9 @@ fn bindgen_test_layout_ggml_init_params() { ) ); } -pub const ggml_task_type_GGML_TASK_INIT: ggml_task_type = 0; -pub const ggml_task_type_GGML_TASK_COMPUTE: ggml_task_type = 1; -pub const ggml_task_type_GGML_TASK_FINALIZE: ggml_task_type = 2; +pub const ggml_task_type_GGML_TASK_TYPE_INIT: ggml_task_type = 0; +pub const ggml_task_type_GGML_TASK_TYPE_COMPUTE: ggml_task_type = 1; +pub const ggml_task_type_GGML_TASK_TYPE_FINALIZE: ggml_task_type = 2; pub type ggml_task_type = ::std::os::raw::c_uint; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -1176,6 +2273,18 @@ fn bindgen_test_layout_ggml_compute_params() { ) ); } +pub const ggml_numa_strategy_GGML_NUMA_STRATEGY_DISABLED: ggml_numa_strategy = 0; +pub const ggml_numa_strategy_GGML_NUMA_STRATEGY_DISTRIBUTE: ggml_numa_strategy = 1; +pub const ggml_numa_strategy_GGML_NUMA_STRATEGY_ISOLATE: ggml_numa_strategy = 2; +pub const ggml_numa_strategy_GGML_NUMA_STRATEGY_NUMACTL: ggml_numa_strategy = 3; +pub const ggml_numa_strategy_GGML_NUMA_STRATEGY_MIRROR: ggml_numa_strategy = 4; +pub const ggml_numa_strategy_GGML_NUMA_STRATEGY_COUNT: ggml_numa_strategy = 5; +pub type ggml_numa_strategy = ::std::os::raw::c_uint; +pub type ggml_guid = [u8; 16usize]; +pub type ggml_guid_t = *mut ggml_guid; +extern "C" { + pub fn ggml_guid_matches(guid_a: ggml_guid_t, guid_b: ggml_guid_t) -> bool; +} extern "C" { pub fn ggml_time_init(); } @@ -1195,7 +2304,13 @@ extern "C" { pub fn ggml_print_backtrace(); } extern "C" { - pub fn ggml_numa_init(); + pub fn ggml_fopen( + fname: *const ::std::os::raw::c_char, + mode: *const ::std::os::raw::c_char, + ) -> *mut FILE; +} +extern "C" { + pub fn ggml_numa_init(numa: ggml_numa_strategy); } extern "C" { pub fn ggml_is_numa() -> bool; @@ -1263,6 +2378,9 @@ extern "C" { extern "C" { pub fn ggml_is_permuted(tensor: *const ggml_tensor) -> bool; } +extern "C" { + pub fn ggml_is_empty(tensor: *const ggml_tensor) -> bool; +} extern "C" { pub fn ggml_is_scalar(tensor: *const ggml_tensor) -> bool; } @@ -1281,9 +2399,19 @@ extern "C" { extern "C" { pub fn ggml_are_same_shape(t0: *const ggml_tensor, t1: *const ggml_tensor) -> bool; } +extern "C" { + pub fn ggml_are_same_stride(t0: *const ggml_tensor, t1: *const ggml_tensor) -> bool; +} extern "C" { pub fn ggml_tensor_overhead() -> usize; } +extern "C" { + pub fn ggml_validate_row_data( + type_: ggml_type, + data: *const ::std::os::raw::c_void, + nbytes: usize, + ) -> bool; +} extern "C" { pub fn ggml_init(params: ggml_init_params) -> *mut ggml_context; } @@ -1681,6 +2809,12 @@ extern "C" { extern "C" { pub fn ggml_relu_inplace(ctx: *mut ggml_context, a: *mut ggml_tensor) -> *mut ggml_tensor; } +extern "C" { + pub fn ggml_sigmoid(ctx: *mut ggml_context, a: *mut ggml_tensor) -> *mut ggml_tensor; +} +extern "C" { + pub fn ggml_sigmoid_inplace(ctx: *mut ggml_context, a: *mut ggml_tensor) -> *mut ggml_tensor; +} extern "C" { pub fn ggml_gelu(ctx: *mut ggml_context, a: *mut ggml_tensor) -> *mut ggml_tensor; } @@ -1707,6 +2841,12 @@ extern "C" { b: *mut ggml_tensor, ) -> *mut ggml_tensor; } +extern "C" { + pub fn ggml_hardswish(ctx: *mut ggml_context, a: *mut ggml_tensor) -> *mut ggml_tensor; +} +extern "C" { + pub fn ggml_hardsigmoid(ctx: *mut ggml_context, a: *mut ggml_tensor) -> *mut ggml_tensor; +} extern "C" { pub fn ggml_norm(ctx: *mut ggml_context, a: *mut ggml_tensor, eps: f32) -> *mut ggml_tensor; } @@ -1763,11 +2903,9 @@ extern "C" { extern "C" { pub fn ggml_mul_mat_id( ctx: *mut ggml_context, - as_: *const *mut ggml_tensor, - n_as: ::std::os::raw::c_int, - ids: *mut ggml_tensor, - id: ::std::os::raw::c_int, + as_: *mut ggml_tensor, b: *mut ggml_tensor, + ids: *mut ggml_tensor, ) -> *mut ggml_tensor; } extern "C" { @@ -1851,18 +2989,15 @@ extern "C" { ) -> *mut ggml_tensor; } extern "C" { - pub fn ggml_cpy_inplace( + pub fn ggml_cast( ctx: *mut ggml_context, a: *mut ggml_tensor, - b: *mut ggml_tensor, + type_: ggml_type, ) -> *mut ggml_tensor; } extern "C" { pub fn ggml_cont(ctx: *mut ggml_context, a: *mut ggml_tensor) -> *mut ggml_tensor; } -extern "C" { - pub fn ggml_cont_inplace(ctx: *mut ggml_context, a: *mut ggml_tensor) -> *mut ggml_tensor; -} extern "C" { pub fn ggml_cont_1d(ctx: *mut ggml_context, a: *mut ggml_tensor, ne0: i64) -> *mut ggml_tensor; } @@ -2049,6 +3184,7 @@ extern "C" { a: *mut ggml_tensor, mask: *mut ggml_tensor, scale: f32, + max_bias: f32, ) -> *mut ggml_tensor; } extern "C" { @@ -2158,15 +3294,6 @@ extern "C" { xpos_down: bool, ) -> *mut ggml_tensor; } -extern "C" { - pub fn ggml_alibi( - ctx: *mut ggml_context, - a: *mut ggml_tensor, - n_past: ::std::os::raw::c_int, - n_head: ::std::os::raw::c_int, - bias_max: f32, - ) -> *mut ggml_tensor; -} extern "C" { pub fn ggml_clamp( ctx: *mut ggml_context, @@ -2187,6 +3314,20 @@ extern "C" { d0: ::std::os::raw::c_int, d1: ::std::os::raw::c_int, is_2D: bool, + dst_type: ggml_type, + ) -> *mut ggml_tensor; +} +extern "C" { + pub fn ggml_conv_depthwise_2d( + ctx: *mut ggml_context, + a: *mut ggml_tensor, + b: *mut ggml_tensor, + s0: ::std::os::raw::c_int, + s1: ::std::os::raw::c_int, + p0: ::std::os::raw::c_int, + p1: ::std::os::raw::c_int, + d0: ::std::os::raw::c_int, + d1: ::std::os::raw::c_int, ) -> *mut ggml_tensor; } extern "C" { @@ -2297,8 +3438,16 @@ extern "C" { p3: ::std::os::raw::c_int, ) -> *mut ggml_tensor; } -pub const ggml_sort_order_GGML_SORT_ASC: ggml_sort_order = 0; -pub const ggml_sort_order_GGML_SORT_DESC: ggml_sort_order = 1; +extern "C" { + pub fn ggml_timestep_embedding( + ctx: *mut ggml_context, + timesteps: *mut ggml_tensor, + dim: ::std::os::raw::c_int, + max_period: ::std::os::raw::c_int, + ) -> *mut ggml_tensor; +} +pub const ggml_sort_order_GGML_SORT_ORDER_ASC: ggml_sort_order = 0; +pub const ggml_sort_order_GGML_SORT_ORDER_DESC: ggml_sort_order = 1; pub type ggml_sort_order = ::std::os::raw::c_uint; extern "C" { pub fn ggml_argsort( @@ -2307,6 +3456,14 @@ extern "C" { order: ggml_sort_order, ) -> *mut ggml_tensor; } +extern "C" { + pub fn ggml_arange( + ctx: *mut ggml_context, + start: f32, + stop: f32, + step: f32, + ) -> *mut ggml_tensor; +} extern "C" { pub fn ggml_top_k( ctx: *mut ggml_context, @@ -2323,6 +3480,20 @@ extern "C" { masked: bool, ) -> *mut ggml_tensor; } +extern "C" { + pub fn ggml_flash_attn_ext( + ctx: *mut ggml_context, + q: *mut ggml_tensor, + k: *mut ggml_tensor, + v: *mut ggml_tensor, + mask: *mut ggml_tensor, + scale: f32, + max_bias: f32, + ) -> *mut ggml_tensor; +} +extern "C" { + pub fn ggml_flash_attn_ext_set_prec(a: *mut ggml_tensor, prec: ggml_prec); +} extern "C" { pub fn ggml_flash_attn_back( ctx: *mut ggml_context, @@ -2343,6 +3514,27 @@ extern "C" { c1: *mut ggml_tensor, ) -> *mut ggml_tensor; } +extern "C" { + pub fn ggml_ssm_conv( + ctx: *mut ggml_context, + s: *mut ggml_tensor, + x: *mut ggml_tensor, + c: *mut ggml_tensor, + sq: *mut ggml_tensor, + ) -> *mut ggml_tensor; +} +extern "C" { + pub fn ggml_ssm_scan( + ctx: *mut ggml_context, + s: *mut ggml_tensor, + x: *mut ggml_tensor, + dt: *mut ggml_tensor, + A: *mut ggml_tensor, + B: *mut ggml_tensor, + C: *mut ggml_tensor, + sq: *mut ggml_tensor, + ) -> *mut ggml_tensor; +} extern "C" { pub fn ggml_win_part( ctx: *mut ggml_context, @@ -2659,22 +3851,19 @@ extern "C" { } extern "C" { pub fn ggml_graph_plan( - cgraph: *mut ggml_cgraph, + cgraph: *const ggml_cgraph, n_threads: ::std::os::raw::c_int, ) -> ggml_cplan; } extern "C" { - pub fn ggml_graph_compute( - cgraph: *mut ggml_cgraph, - cplan: *mut ggml_cplan, - ) -> ::std::os::raw::c_int; + pub fn ggml_graph_compute(cgraph: *mut ggml_cgraph, cplan: *mut ggml_cplan) -> ggml_status; } extern "C" { pub fn ggml_graph_compute_with_ctx( ctx: *mut ggml_context, cgraph: *mut ggml_cgraph, n_threads: ::std::os::raw::c_int, - ); + ) -> ggml_status; } extern "C" { pub fn ggml_graph_get_tensor( @@ -2712,20 +3901,20 @@ extern "C" { n_checkpoints: ::std::os::raw::c_int, ); } -pub const ggml_opt_type_GGML_OPT_ADAM: ggml_opt_type = 0; -pub const ggml_opt_type_GGML_OPT_LBFGS: ggml_opt_type = 1; +pub const ggml_opt_type_GGML_OPT_TYPE_ADAM: ggml_opt_type = 0; +pub const ggml_opt_type_GGML_OPT_TYPE_LBFGS: ggml_opt_type = 1; pub type ggml_opt_type = ::std::os::raw::c_uint; pub const ggml_linesearch_GGML_LINESEARCH_DEFAULT: ggml_linesearch = 1; pub const ggml_linesearch_GGML_LINESEARCH_BACKTRACKING_ARMIJO: ggml_linesearch = 0; pub const ggml_linesearch_GGML_LINESEARCH_BACKTRACKING_WOLFE: ggml_linesearch = 1; pub const ggml_linesearch_GGML_LINESEARCH_BACKTRACKING_STRONG_WOLFE: ggml_linesearch = 2; pub type ggml_linesearch = ::std::os::raw::c_uint; -pub const ggml_opt_result_GGML_OPT_OK: ggml_opt_result = 0; -pub const ggml_opt_result_GGML_OPT_DID_NOT_CONVERGE: ggml_opt_result = 1; -pub const ggml_opt_result_GGML_OPT_NO_CONTEXT: ggml_opt_result = 2; -pub const ggml_opt_result_GGML_OPT_INVALID_WOLFE: ggml_opt_result = 3; -pub const ggml_opt_result_GGML_OPT_FAIL: ggml_opt_result = 4; -pub const ggml_opt_result_GGML_OPT_CANCEL: ggml_opt_result = 5; +pub const ggml_opt_result_GGML_OPT_RESULT_OK: ggml_opt_result = 0; +pub const ggml_opt_result_GGML_OPT_RESULT_DID_NOT_CONVERGE: ggml_opt_result = 1; +pub const ggml_opt_result_GGML_OPT_RESULT_NO_CONTEXT: ggml_opt_result = 2; +pub const ggml_opt_result_GGML_OPT_RESULT_INVALID_WOLFE: ggml_opt_result = 3; +pub const ggml_opt_result_GGML_OPT_RESULT_FAIL: ggml_opt_result = 4; +pub const ggml_opt_result_GGML_OPT_RESULT_CANCEL: ggml_opt_result = 5; pub const ggml_opt_result_GGML_LINESEARCH_FAIL: ggml_opt_result = -128; pub const ggml_opt_result_GGML_LINESEARCH_MINIMUM_STEP: ggml_opt_result = -127; pub const ggml_opt_result_GGML_LINESEARCH_MAXIMUM_STEP: ggml_opt_result = -126; @@ -3595,103 +4784,29 @@ extern "C" { ) -> ggml_opt_result; } extern "C" { - pub fn ggml_quantize_q4_0( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; -} -extern "C" { - pub fn ggml_quantize_q4_1( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; -} -extern "C" { - pub fn ggml_quantize_q5_0( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; -} -extern "C" { - pub fn ggml_quantize_q5_1( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; -} -extern "C" { - pub fn ggml_quantize_q8_0( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; -} -extern "C" { - pub fn ggml_quantize_q2_K( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; + pub fn ggml_set_input(tensor: *mut ggml_tensor); } extern "C" { - pub fn ggml_quantize_q3_K( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; + pub fn ggml_set_output(tensor: *mut ggml_tensor); } extern "C" { - pub fn ggml_quantize_q4_K( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; + pub fn ggml_quantize_init(type_: ggml_type); } extern "C" { - pub fn ggml_quantize_q5_K( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; + pub fn ggml_quantize_free(); } -extern "C" { - pub fn ggml_quantize_q6_K( - src: *const f32, - dst: *mut ::std::os::raw::c_void, - n: ::std::os::raw::c_int, - k: ::std::os::raw::c_int, - hist: *mut i64, - ) -> usize; +extern "C" { + pub fn ggml_quantize_requires_imatrix(type_: ggml_type) -> bool; } extern "C" { pub fn ggml_quantize_chunk( type_: ggml_type, src: *const f32, dst: *mut ::std::os::raw::c_void, - start: ::std::os::raw::c_int, - n: ::std::os::raw::c_int, - hist: *mut i64, + start: i64, + nrows: i64, + n_per_row: i64, + imatrix: *const f32, ) -> usize; } pub const gguf_type_GGUF_TYPE_UINT8: gguf_type = 0; @@ -3888,6 +5003,9 @@ extern "C" { extern "C" { pub fn gguf_get_tensor_type(ctx: *const gguf_context, i: ::std::os::raw::c_int) -> ggml_type; } +extern "C" { + pub fn gguf_remove_key(ctx: *mut gguf_context, key: *const ::std::os::raw::c_char); +} extern "C" { pub fn gguf_set_val_u8(ctx: *mut gguf_context, key: *const ::std::os::raw::c_char, val: u8); } @@ -4022,11 +5140,17 @@ extern "C" { pub fn ggml_cpu_has_blas() -> ::std::os::raw::c_int; } extern "C" { - pub fn ggml_cpu_has_cublas() -> ::std::os::raw::c_int; + pub fn ggml_cpu_has_cuda() -> ::std::os::raw::c_int; } extern "C" { pub fn ggml_cpu_has_clblast() -> ::std::os::raw::c_int; } +extern "C" { + pub fn ggml_cpu_has_vulkan() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn ggml_cpu_has_kompute() -> ::std::os::raw::c_int; +} extern "C" { pub fn ggml_cpu_has_gpublas() -> ::std::os::raw::c_int; } @@ -4036,21 +5160,31 @@ extern "C" { extern "C" { pub fn ggml_cpu_has_ssse3() -> ::std::os::raw::c_int; } +extern "C" { + pub fn ggml_cpu_has_sycl() -> ::std::os::raw::c_int; +} extern "C" { pub fn ggml_cpu_has_vsx() -> ::std::os::raw::c_int; } +extern "C" { + pub fn ggml_cpu_has_matmul_int8() -> ::std::os::raw::c_int; +} pub type ggml_to_float_t = ::std::option::Option< - unsafe extern "C" fn(x: *const ::std::os::raw::c_void, y: *mut f32, k: ::std::os::raw::c_int), + unsafe extern "C" fn(x: *const ::std::os::raw::c_void, y: *mut f32, k: i64), >; pub type ggml_from_float_t = ::std::option::Option< - unsafe extern "C" fn(x: *const f32, y: *mut ::std::os::raw::c_void, k: ::std::os::raw::c_int), + unsafe extern "C" fn(x: *const f32, y: *mut ::std::os::raw::c_void, k: i64), >; pub type ggml_vec_dot_t = ::std::option::Option< unsafe extern "C" fn( n: ::std::os::raw::c_int, s: *mut f32, + bs: usize, x: *const ::std::os::raw::c_void, + bx: usize, y: *const ::std::os::raw::c_void, + by: usize, + nrc: ::std::os::raw::c_int, ), >; #[repr(C)] @@ -4065,6 +5199,7 @@ pub struct ggml_type_traits_t { pub from_float_reference: ggml_from_float_t, pub vec_dot: ggml_vec_dot_t, pub vec_dot_type: ggml_type, + pub nrows: i64, } #[test] fn bindgen_test_layout_ggml_type_traits_t() { @@ -4072,7 +5207,7 @@ fn bindgen_test_layout_ggml_type_traits_t() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 72usize, + 80usize, concat!("Size of: ", stringify!(ggml_type_traits_t)) ); assert_eq!( @@ -4170,6 +5305,16 @@ fn bindgen_test_layout_ggml_type_traits_t() { stringify!(vec_dot_type) ) ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).nrows) as usize - ptr as usize }, + 72usize, + concat!( + "Offset of field: ", + stringify!(ggml_type_traits_t), + "::", + stringify!(nrows) + ) + ); } extern "C" { pub fn ggml_internal_get_type_traits(type_: ggml_type) -> ggml_type_traits_t; @@ -4187,10 +5332,120 @@ pub struct whisper_state { pub type whisper_pos = i32; pub type whisper_token = i32; pub type whisper_seq_id = i32; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_NONE: whisper_alignment_heads_preset = 0; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_N_TOP_MOST: whisper_alignment_heads_preset = + 1; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_CUSTOM: whisper_alignment_heads_preset = 2; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_TINY_EN: whisper_alignment_heads_preset = 3; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_TINY: whisper_alignment_heads_preset = 4; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_BASE_EN: whisper_alignment_heads_preset = 5; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_BASE: whisper_alignment_heads_preset = 6; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_SMALL_EN: whisper_alignment_heads_preset = + 7; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_SMALL: whisper_alignment_heads_preset = 8; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_MEDIUM_EN: whisper_alignment_heads_preset = + 9; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_MEDIUM: whisper_alignment_heads_preset = 10; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V1: whisper_alignment_heads_preset = + 11; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V2: whisper_alignment_heads_preset = + 12; +pub const whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V3: whisper_alignment_heads_preset = + 13; +pub type whisper_alignment_heads_preset = ::std::os::raw::c_uint; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct whisper_ahead { + pub n_text_layer: ::std::os::raw::c_int, + pub n_head: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_whisper_ahead() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(whisper_ahead)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(whisper_ahead)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).n_text_layer) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whisper_ahead), + "::", + stringify!(n_text_layer) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).n_head) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(whisper_ahead), + "::", + stringify!(n_head) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct whisper_aheads { + pub n_heads: usize, + pub heads: *const whisper_ahead, +} +#[test] +fn bindgen_test_layout_whisper_aheads() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(whisper_aheads)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(whisper_aheads)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).n_heads) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whisper_aheads), + "::", + stringify!(n_heads) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).heads) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(whisper_aheads), + "::", + stringify!(heads) + ) + ); +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct whisper_context_params { pub use_gpu: bool, + pub flash_attn: bool, + pub gpu_device: ::std::os::raw::c_int, + pub dtw_token_timestamps: bool, + pub dtw_aheads_preset: whisper_alignment_heads_preset, + pub dtw_n_top: ::std::os::raw::c_int, + pub dtw_aheads: whisper_aheads, + pub dtw_mem_size: usize, } #[test] fn bindgen_test_layout_whisper_context_params() { @@ -4199,12 +5454,12 @@ fn bindgen_test_layout_whisper_context_params() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 1usize, + 48usize, concat!("Size of: ", stringify!(whisper_context_params)) ); assert_eq!( ::std::mem::align_of::(), - 1usize, + 8usize, concat!("Alignment of ", stringify!(whisper_context_params)) ); assert_eq!( @@ -4217,6 +5472,76 @@ fn bindgen_test_layout_whisper_context_params() { stringify!(use_gpu) ) ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).flash_attn) as usize - ptr as usize }, + 1usize, + concat!( + "Offset of field: ", + stringify!(whisper_context_params), + "::", + stringify!(flash_attn) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).gpu_device) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(whisper_context_params), + "::", + stringify!(gpu_device) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dtw_token_timestamps) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(whisper_context_params), + "::", + stringify!(dtw_token_timestamps) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dtw_aheads_preset) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(whisper_context_params), + "::", + stringify!(dtw_aheads_preset) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dtw_n_top) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(whisper_context_params), + "::", + stringify!(dtw_n_top) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dtw_aheads) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(whisper_context_params), + "::", + stringify!(dtw_aheads) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dtw_mem_size) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(whisper_context_params), + "::", + stringify!(dtw_mem_size) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -4229,6 +5554,7 @@ pub struct whisper_token_data { pub ptsum: f32, pub t0: i64, pub t1: i64, + pub t_dtw: i64, pub vlen: f32, } #[test] @@ -4237,7 +5563,7 @@ fn bindgen_test_layout_whisper_token_data() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 48usize, + 56usize, concat!("Size of: ", stringify!(whisper_token_data)) ); assert_eq!( @@ -4326,8 +5652,18 @@ fn bindgen_test_layout_whisper_token_data() { ) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlen) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr).t_dtw) as usize - ptr as usize }, 40usize, + concat!( + "Offset of field: ", + stringify!(whisper_token_data), + "::", + stringify!(t_dtw) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).vlen) as usize - ptr as usize }, + 48usize, concat!( "Offset of field: ", stringify!(whisper_token_data), @@ -4637,6 +5973,12 @@ extern "C" { n_max_tokens: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn whisper_token_count( + ctx: *mut whisper_context, + text: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn whisper_lang_max_id() -> ::std::os::raw::c_int; } @@ -4803,8 +6145,6 @@ pub type whisper_encoder_begin_callback = ::std::option::Option< user_data: *mut ::std::os::raw::c_void, ) -> bool, >; -pub type whisper_abort_callback = - ::std::option::Option bool>; pub type whisper_logits_filter_callback = ::std::option::Option< unsafe extern "C" fn( ctx: *mut whisper_context, @@ -4841,6 +6181,7 @@ pub struct whisper_full_params { pub debug_mode: bool, pub audio_ctx: ::std::os::raw::c_int, pub tdrz_enable: bool, + pub suppress_regex: *const ::std::os::raw::c_char, pub initial_prompt: *const ::std::os::raw::c_char, pub prompt_tokens: *const whisper_token, pub prompt_n_tokens: ::std::os::raw::c_int, @@ -4863,7 +6204,7 @@ pub struct whisper_full_params { pub progress_callback_user_data: *mut ::std::os::raw::c_void, pub encoder_begin_callback: whisper_encoder_begin_callback, pub encoder_begin_callback_user_data: *mut ::std::os::raw::c_void, - pub abort_callback: whisper_abort_callback, + pub abort_callback: ggml_abort_callback, pub abort_callback_user_data: *mut ::std::os::raw::c_void, pub logits_filter_callback: whisper_logits_filter_callback, pub logits_filter_callback_user_data: *mut ::std::os::raw::c_void, @@ -4957,7 +6298,7 @@ fn bindgen_test_layout_whisper_full_params() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 256usize, + 264usize, concat!("Size of: ", stringify!(whisper_full_params)) ); assert_eq!( @@ -5196,8 +6537,18 @@ fn bindgen_test_layout_whisper_full_params() { ) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).initial_prompt) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr).suppress_regex) as usize - ptr as usize }, 64usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(suppress_regex) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).initial_prompt) as usize - ptr as usize }, + 72usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5207,7 +6558,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).prompt_tokens) as usize - ptr as usize }, - 72usize, + 80usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5217,7 +6568,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).prompt_n_tokens) as usize - ptr as usize }, - 80usize, + 88usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5227,7 +6578,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).language) as usize - ptr as usize }, - 88usize, + 96usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5237,7 +6588,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).detect_language) as usize - ptr as usize }, - 96usize, + 104usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5247,7 +6598,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).suppress_blank) as usize - ptr as usize }, - 97usize, + 105usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5257,7 +6608,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).suppress_non_speech_tokens) as usize - ptr as usize }, - 98usize, + 106usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5267,7 +6618,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).temperature) as usize - ptr as usize }, - 100usize, + 108usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5277,7 +6628,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).max_initial_ts) as usize - ptr as usize }, - 104usize, + 112usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5287,7 +6638,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).length_penalty) as usize - ptr as usize }, - 108usize, + 116usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5297,7 +6648,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).temperature_inc) as usize - ptr as usize }, - 112usize, + 120usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5307,7 +6658,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).entropy_thold) as usize - ptr as usize }, - 116usize, + 124usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5317,7 +6668,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).logprob_thold) as usize - ptr as usize }, - 120usize, + 128usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5327,7 +6678,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).no_speech_thold) as usize - ptr as usize }, - 124usize, + 132usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5337,7 +6688,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).greedy) as usize - ptr as usize }, - 128usize, + 136usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5347,7 +6698,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).beam_search) as usize - ptr as usize }, - 132usize, + 140usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5357,7 +6708,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).new_segment_callback) as usize - ptr as usize }, - 144usize, + 152usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5369,7 +6720,7 @@ fn bindgen_test_layout_whisper_full_params() { unsafe { ::std::ptr::addr_of!((*ptr).new_segment_callback_user_data) as usize - ptr as usize }, - 152usize, + 160usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5379,7 +6730,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).progress_callback) as usize - ptr as usize }, - 160usize, + 168usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5389,7 +6740,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).progress_callback_user_data) as usize - ptr as usize }, - 168usize, + 176usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5399,7 +6750,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).encoder_begin_callback) as usize - ptr as usize }, - 176usize, + 184usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5411,7 +6762,7 @@ fn bindgen_test_layout_whisper_full_params() { unsafe { ::std::ptr::addr_of!((*ptr).encoder_begin_callback_user_data) as usize - ptr as usize }, - 184usize, + 192usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5421,7 +6772,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).abort_callback) as usize - ptr as usize }, - 192usize, + 200usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5431,7 +6782,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).abort_callback_user_data) as usize - ptr as usize }, - 200usize, + 208usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5441,7 +6792,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).logits_filter_callback) as usize - ptr as usize }, - 208usize, + 216usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5453,7 +6804,7 @@ fn bindgen_test_layout_whisper_full_params() { unsafe { ::std::ptr::addr_of!((*ptr).logits_filter_callback_user_data) as usize - ptr as usize }, - 216usize, + 224usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5463,7 +6814,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).grammar_rules) as usize - ptr as usize }, - 224usize, + 232usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5473,7 +6824,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).n_grammar_rules) as usize - ptr as usize }, - 232usize, + 240usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5483,7 +6834,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i_start_rule) as usize - ptr as usize }, - 240usize, + 248usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5493,7 +6844,7 @@ fn bindgen_test_layout_whisper_full_params() { ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).grammar_penalty) as usize - ptr as usize }, - 248usize, + 256usize, concat!( "Offset of field: ", stringify!(whisper_full_params), @@ -5690,6 +7041,70 @@ extern "C" { extern "C" { pub fn whisper_log_set(log_callback: ggml_log_callback, user_data: *mut ::std::os::raw::c_void); } +pub type __builtin_va_list = [__va_list_tag; 1usize]; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __va_list_tag { + pub gp_offset: ::std::os::raw::c_uint, + pub fp_offset: ::std::os::raw::c_uint, + pub overflow_arg_area: *mut ::std::os::raw::c_void, + pub reg_save_area: *mut ::std::os::raw::c_void, +} +#[test] +fn bindgen_test_layout___va_list_tag() { + const UNINIT: ::std::mem::MaybeUninit<__va_list_tag> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<__va_list_tag>(), + 24usize, + concat!("Size of: ", stringify!(__va_list_tag)) + ); + assert_eq!( + ::std::mem::align_of::<__va_list_tag>(), + 8usize, + concat!("Alignment of ", stringify!(__va_list_tag)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).gp_offset) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__va_list_tag), + "::", + stringify!(gp_offset) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).fp_offset) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(__va_list_tag), + "::", + stringify!(fp_offset) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).overflow_arg_area) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(__va_list_tag), + "::", + stringify!(overflow_arg_area) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).reg_save_area) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(__va_list_tag), + "::", + stringify!(reg_save_area) + ) + ); +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ggml_backend_buffer { From da6b410439c7c18ff1c494c2f5f53b4e0ad606ae Mon Sep 17 00:00:00 2001 From: arizhih Date: Thu, 16 May 2024 18:58:48 +0200 Subject: [PATCH 4/8] Add safe wrapper for raw dtw parameters --- examples/audio_transcription.rs | 2 +- examples/basic_use.rs | 2 +- src/lib.rs | 2 + src/whisper_ctx.rs | 178 +++++++++++++++++++++++--------- src/whisper_ctx_wrapper.rs | 2 +- 5 files changed, 135 insertions(+), 51 deletions(-) diff --git a/examples/audio_transcription.rs b/examples/audio_transcription.rs index 7661e04..c31aa0e 100644 --- a/examples/audio_transcription.rs +++ b/examples/audio_transcription.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), &'static str> { // Load a context and model. let ctx = WhisperContext::new_with_params( "example/path/to/model/whisper.cpp/models/ggml-base.en.bin", - WhisperContextParameters::default(), + &mut WhisperContextParameters::default(), ) .expect("failed to load model"); // Create a state diff --git a/examples/basic_use.rs b/examples/basic_use.rs index 8627473..2bc75a6 100644 --- a/examples/basic_use.rs +++ b/examples/basic_use.rs @@ -7,7 +7,7 @@ use whisper_rs::{FullParams, SamplingStrategy, WhisperContext, WhisperContextPar // more dependencies than the base library. pub fn usage() -> Result<(), &'static str> { // load a context and model - let ctx = WhisperContext::new_with_params("path/to/model", WhisperContextParameters::default()) + let ctx = WhisperContext::new_with_params("path/to/model", &mut WhisperContextParameters::default()) .expect("failed to load model"); // make a state let mut state = ctx.create_state().expect("failed to create state"); diff --git a/src/lib.rs b/src/lib.rs index 42109bc..c1ef2b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,8 @@ pub use whisper_state::WhisperState; pub use whisper_sys_log::install_whisper_log_trampoline; #[cfg(feature = "whisper-cpp-tracing")] pub use whisper_sys_tracing::install_whisper_tracing_trampoline; +pub use whisper_ctx::DtwParameters; +pub use whisper_ctx::DtwPredefinedModels; pub type WhisperSysContext = whisper_rs_sys::whisper_context; pub type WhisperSysState = whisper_rs_sys::whisper_state; diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index 3857bcc..92f9b6a 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -26,7 +26,7 @@ impl WhisperInnerContext { /// `struct whisper_context * whisper_init_from_file_with_params_no_state(const char * path_model, struct whisper_context_params params);` pub fn new_with_params( path: &str, - parameters: WhisperContextParameters, + parameters: &mut WhisperContextParameters, ) -> Result { let path_cstr = CString::new(path)?; let ctx = unsafe { @@ -476,22 +476,13 @@ pub struct WhisperContextParameters { /// (in that case, GPU is always enabled). pub use_gpu: bool, /// Enable flash attention, default false + /// + /// **Warning** Can't be used with DTW. DTW will be disabled if flash_attn is true pub flash_attn: bool, /// GPU device id, default 0 pub gpu_device: c_int, - /// [EXPERIMENTAL] Enable Token-level timestamps with DTW, default 0 - pub dtw_token_timestamps: bool, - /// Preset id for DTW, default whisper_alignment_heads_preset_WHISPER_AHEADS_NONE - pub dtw_aheads_preset: whisper_rs_sys::whisper_alignment_heads_preset, - /// Number of top text layers used from model. Only with whisper_alignment_heads_preset_WHISPER_AHEADS_N_TOP_MOST preset. - pub dtw_n_top: c_int, - /// Custom aheads, only with whisper_alignment_heads_preset_WHISPER_AHEADS_CUSTOM preset - /// See details https://github.com/ggerganov/whisper.cpp/pull/1485#discussion_r1519681143 - pub dtw_aheads: whisper_rs_sys::whisper_aheads, - /// Memory size for DTW - /// - /// **Warning**: Might be removed in next version of whisper.cpp - pub dtw_mem_size: usize, + /// DTW token level timestamp parameters + pub dtw_parameters: DtwParameters, } #[allow(clippy::derivable_impls)] // this impl cannot be derived @@ -501,14 +492,7 @@ impl Default for WhisperContextParameters { use_gpu: cfg!(feature = "_gpu"), flash_attn: false, gpu_device: 0, - dtw_token_timestamps: false, - dtw_aheads_preset: whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_NONE, - dtw_n_top: -1, - dtw_aheads: whisper_rs_sys::whisper_aheads { - n_heads: 0, - heads: std::ptr::null(), - }, - dtw_mem_size: 1024 * 1024 * 128, + dtw_parameters: DtwParameters::default(), } } } @@ -528,43 +512,141 @@ impl WhisperContextParameters { self.gpu_device = gpu_device; self } - pub fn dtw_token_timestamps(&mut self, dtw_token_timestamps: bool) -> &mut Self { - self.dtw_token_timestamps = dtw_token_timestamps; - self - } - pub fn dtw_aheads_preset( - &mut self, - dtw_aheads_preset: whisper_rs_sys::whisper_alignment_heads_preset, - ) -> &mut Self { - self.dtw_aheads_preset = dtw_aheads_preset; - self - } - pub fn dtw_n_top(&mut self, dtw_n_top: c_int) -> &mut Self { - self.dtw_n_top = dtw_n_top; - self - } - pub fn dtw_aheads(&mut self, dtw_aheads: whisper_rs_sys::whisper_aheads) -> &mut Self { - self.dtw_aheads = dtw_aheads; - self - } - pub fn dtw_mem_size(&mut self, dtw_mem_size: usize) -> &mut Self { - self.dtw_mem_size = dtw_mem_size; + pub fn dtw_parameters(&mut self, dtw_parameters: DtwParameters) -> &mut Self { + self.dtw_parameters = dtw_parameters; self } + fn to_c_struct(&self) -> whisper_rs_sys::whisper_context_params { + let dtw_token_timestamps = !matches!(self.dtw_parameters, DtwParameters::Disabled); + let mut dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_NONE; + let mut dtw_n_top: c_int = -1; + let mut dtw_aheads = whisper_rs_sys::whisper_aheads { + n_heads: 0, + heads: std::ptr::null(), + }; + + let dtw_mem_size = 1024 * 1024 * 128; + + match &self.dtw_parameters { + DtwParameters::Disabled => {} + DtwParameters::TopMost { n_top } => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_N_TOP_MOST; + dtw_n_top = *n_top; + } + DtwParameters::Custom { aheads } => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_CUSTOM; + + dtw_aheads = whisper_rs_sys::whisper_aheads { + n_heads: aheads.len(), + heads: aheads.as_ptr(), + }; + } + DtwParameters::Predefined { model_preset } => match model_preset { + DtwPredefinedModels::TinyEn => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_TINY_EN; + } + DtwPredefinedModels::Tiny => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_TINY; + } + DtwPredefinedModels::BaseEn => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_BASE_EN; + } + DtwPredefinedModels::Base => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_BASE; + } + DtwPredefinedModels::SmallEn => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_SMALL_EN; + } + DtwPredefinedModels::Small => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_SMALL; + } + DtwPredefinedModels::MediumEn => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_MEDIUM_EN; + } + DtwPredefinedModels::Medium => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_MEDIUM; + } + DtwPredefinedModels::LargeV1 => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V1; + } + DtwPredefinedModels::LargeV2 => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V2; + } + DtwPredefinedModels::LargeV3 => { + dtw_aheads_preset = + whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V3; + } + }, + } + whisper_rs_sys::whisper_context_params { use_gpu: self.use_gpu, flash_attn: self.flash_attn, gpu_device: self.gpu_device, - dtw_token_timestamps: self.dtw_token_timestamps, - dtw_aheads_preset: self.dtw_aheads_preset, - dtw_n_top: self.dtw_n_top, - dtw_aheads: self.dtw_aheads, - dtw_mem_size: self.dtw_mem_size, + dtw_token_timestamps, + dtw_aheads_preset, + dtw_n_top, + dtw_aheads, + dtw_mem_size, } } } +/// [EXPERIMENTAL] Enable Token-level timestamps with DTW, default Disabled +#[derive(Debug, Clone)] +pub enum DtwParameters { + /// DTW token level timestamps disabled + Disabled, + /// Use N Top Most layers from loaded model + TopMost { + /// Number of top text layers used from model, should be 0 < n_top <= model n_text_layer + n_top: c_int, + }, + /// Use custom aheads, non-empty list of whisper_ahead. + /// 0 < n_text_layer < model n_text_layer, 0 < n_head < model n_text_head for each element + /// See details https://github.com/ggerganov/whisper.cpp/pull/1485#discussion_r1519681143 + Custom { + aheads: Vec, + }, + /// Use predefined preset for standard models + Predefined { model_preset: DtwPredefinedModels }, +} + +impl Default for DtwParameters { + fn default() -> Self { + Self::Disabled + } +} + +#[derive(Debug, Clone)] +pub enum DtwPredefinedModels { + TinyEn, + Tiny, + BaseEn, + Base, + SmallEn, + Small, + MediumEn, + Medium, + LargeV1, + LargeV2, + LargeV3, +} + #[cfg(test)] #[cfg(feature = "test-with-tiny-model")] mod test_with_tiny_model { diff --git a/src/whisper_ctx_wrapper.rs b/src/whisper_ctx_wrapper.rs index ff3caff..87d062c 100644 --- a/src/whisper_ctx_wrapper.rs +++ b/src/whisper_ctx_wrapper.rs @@ -27,7 +27,7 @@ impl WhisperContext { /// `struct whisper_context * whisper_init_from_file_with_params_no_state(const char * path_model, struct whisper_context_params params);` pub fn new_with_params( path: &str, - parameters: WhisperContextParameters, + parameters: &mut WhisperContextParameters, ) -> Result { let ctx = WhisperInnerContext::new_with_params(path, parameters)?; Ok(Self::wrap(ctx)) From 482860d0d6f5cdf35d9c1fa2d89a9d05cca87187 Mon Sep 17 00:00:00 2001 From: arizhih Date: Fri, 17 May 2024 02:05:12 +0200 Subject: [PATCH 5/8] Pass aheads by reference, add dtw_mem_size param, rustfmt --- examples/audio_transcription.rs | 2 +- examples/basic_use.rs | 2 +- src/lib.rs | 5 ++- src/whisper_ctx.rs | 71 ++++++++++++++++++--------------- src/whisper_ctx_wrapper.rs | 2 +- 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/examples/audio_transcription.rs b/examples/audio_transcription.rs index c31aa0e..7661e04 100644 --- a/examples/audio_transcription.rs +++ b/examples/audio_transcription.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), &'static str> { // Load a context and model. let ctx = WhisperContext::new_with_params( "example/path/to/model/whisper.cpp/models/ggml-base.en.bin", - &mut WhisperContextParameters::default(), + WhisperContextParameters::default(), ) .expect("failed to load model"); // Create a state diff --git a/examples/basic_use.rs b/examples/basic_use.rs index 2bc75a6..8627473 100644 --- a/examples/basic_use.rs +++ b/examples/basic_use.rs @@ -7,7 +7,7 @@ use whisper_rs::{FullParams, SamplingStrategy, WhisperContext, WhisperContextPar // more dependencies than the base library. pub fn usage() -> Result<(), &'static str> { // load a context and model - let ctx = WhisperContext::new_with_params("path/to/model", &mut WhisperContextParameters::default()) + let ctx = WhisperContext::new_with_params("path/to/model", WhisperContextParameters::default()) .expect("failed to load model"); // make a state let mut state = ctx.create_state().expect("failed to create state"); diff --git a/src/lib.rs b/src/lib.rs index c1ef2b8..1822174 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,9 @@ pub use standalone::*; #[cfg(any(feature = "whisper-cpp-log", feature = "whisper-cpp-tracing"))] use std::sync::Once; pub use utilities::*; +pub use whisper_ctx::DtwMode; +pub use whisper_ctx::DtwModelPreset; +pub use whisper_ctx::DtwParameters; pub use whisper_ctx::WhisperContextParameters; use whisper_ctx::WhisperInnerContext; pub use whisper_ctx_wrapper::WhisperContext; @@ -34,8 +37,6 @@ pub use whisper_state::WhisperState; pub use whisper_sys_log::install_whisper_log_trampoline; #[cfg(feature = "whisper-cpp-tracing")] pub use whisper_sys_tracing::install_whisper_tracing_trampoline; -pub use whisper_ctx::DtwParameters; -pub use whisper_ctx::DtwPredefinedModels; pub type WhisperSysContext = whisper_rs_sys::whisper_context; pub type WhisperSysState = whisper_rs_sys::whisper_state; diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index 92f9b6a..5ab7e21 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -26,7 +26,7 @@ impl WhisperInnerContext { /// `struct whisper_context * whisper_init_from_file_with_params_no_state(const char * path_model, struct whisper_context_params params);` pub fn new_with_params( path: &str, - parameters: &mut WhisperContextParameters, + parameters: WhisperContextParameters, ) -> Result { let path_cstr = CString::new(path)?; let ctx = unsafe { @@ -518,7 +518,7 @@ impl WhisperContextParameters { } fn to_c_struct(&self) -> whisper_rs_sys::whisper_context_params { - let dtw_token_timestamps = !matches!(self.dtw_parameters, DtwParameters::Disabled); + let dtw_token_timestamps = !matches!(self.dtw_parameters.mode, DtwMode::None); let mut dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_NONE; let mut dtw_n_top: c_int = -1; @@ -527,16 +527,14 @@ impl WhisperContextParameters { heads: std::ptr::null(), }; - let dtw_mem_size = 1024 * 1024 * 128; - - match &self.dtw_parameters { - DtwParameters::Disabled => {} - DtwParameters::TopMost { n_top } => { + match &self.dtw_parameters.mode { + DtwMode::None => {} + DtwMode::TopMost { n_top } => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_N_TOP_MOST; dtw_n_top = *n_top; } - DtwParameters::Custom { aheads } => { + DtwMode::Custom { aheads } => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_CUSTOM; @@ -545,48 +543,48 @@ impl WhisperContextParameters { heads: aheads.as_ptr(), }; } - DtwParameters::Predefined { model_preset } => match model_preset { - DtwPredefinedModels::TinyEn => { + DtwMode::ModelPreset { model_preset } => match model_preset { + DtwModelPreset::TinyEn => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_TINY_EN; } - DtwPredefinedModels::Tiny => { + DtwModelPreset::Tiny => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_TINY; } - DtwPredefinedModels::BaseEn => { + DtwModelPreset::BaseEn => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_BASE_EN; } - DtwPredefinedModels::Base => { + DtwModelPreset::Base => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_BASE; } - DtwPredefinedModels::SmallEn => { + DtwModelPreset::SmallEn => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_SMALL_EN; } - DtwPredefinedModels::Small => { + DtwModelPreset::Small => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_SMALL; } - DtwPredefinedModels::MediumEn => { + DtwModelPreset::MediumEn => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_MEDIUM_EN; } - DtwPredefinedModels::Medium => { + DtwModelPreset::Medium => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_MEDIUM; } - DtwPredefinedModels::LargeV1 => { + DtwModelPreset::LargeV1 => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V1; } - DtwPredefinedModels::LargeV2 => { + DtwModelPreset::LargeV2 => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V2; } - DtwPredefinedModels::LargeV3 => { + DtwModelPreset::LargeV3 => { dtw_aheads_preset = whisper_rs_sys::whisper_alignment_heads_preset_WHISPER_AHEADS_LARGE_V3; } @@ -601,16 +599,31 @@ impl WhisperContextParameters { dtw_aheads_preset, dtw_n_top, dtw_aheads, - dtw_mem_size, + dtw_mem_size: self.dtw_parameters.dtw_mem_size, } } } /// [EXPERIMENTAL] Enable Token-level timestamps with DTW, default Disabled #[derive(Debug, Clone)] -pub enum DtwParameters { +pub struct DtwParameters { + pub mode: DtwMode, + pub dtw_mem_size: usize, +} + +impl Default for DtwParameters { + fn default() -> Self { + Self { + mode: DtwMode::None, + dtw_mem_size: 1024 * 1024 * 128, + } + } +} + +#[derive(Debug, Clone)] +pub enum DtwMode { /// DTW token level timestamps disabled - Disabled, + None, /// Use N Top Most layers from loaded model TopMost { /// Number of top text layers used from model, should be 0 < n_top <= model n_text_layer @@ -620,20 +633,14 @@ pub enum DtwParameters { /// 0 < n_text_layer < model n_text_layer, 0 < n_head < model n_text_head for each element /// See details https://github.com/ggerganov/whisper.cpp/pull/1485#discussion_r1519681143 Custom { - aheads: Vec, + aheads: &'static [whisper_rs_sys::whisper_ahead], }, /// Use predefined preset for standard models - Predefined { model_preset: DtwPredefinedModels }, -} - -impl Default for DtwParameters { - fn default() -> Self { - Self::Disabled - } + ModelPreset { model_preset: DtwModelPreset }, } #[derive(Debug, Clone)] -pub enum DtwPredefinedModels { +pub enum DtwModelPreset { TinyEn, Tiny, BaseEn, diff --git a/src/whisper_ctx_wrapper.rs b/src/whisper_ctx_wrapper.rs index 87d062c..ff3caff 100644 --- a/src/whisper_ctx_wrapper.rs +++ b/src/whisper_ctx_wrapper.rs @@ -27,7 +27,7 @@ impl WhisperContext { /// `struct whisper_context * whisper_init_from_file_with_params_no_state(const char * path_model, struct whisper_context_params params);` pub fn new_with_params( path: &str, - parameters: &mut WhisperContextParameters, + parameters: WhisperContextParameters, ) -> Result { let ctx = WhisperInnerContext::new_with_params(path, parameters)?; Ok(Self::wrap(ctx)) From 0c8798c986db2238f002f260b8f69bd3cb013eef Mon Sep 17 00:00:00 2001 From: arizhih Date: Fri, 17 May 2024 14:47:58 +0200 Subject: [PATCH 6/8] Use proper lifetimes, add DTW usage example --- examples/audio_transcription.rs | 50 +++++++++++++++++++++++++++++++-- src/whisper_ctx.rs | 20 ++++++------- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/examples/audio_transcription.rs b/examples/audio_transcription.rs index 7661e04..2a8499b 100644 --- a/examples/audio_transcription.rs +++ b/examples/audio_transcription.rs @@ -9,9 +9,37 @@ use whisper_rs::{FullParams, SamplingStrategy, WhisperContext, WhisperContextPar /// Loads a context and model, processes an audio file, and prints the resulting transcript to stdout. fn main() -> Result<(), &'static str> { // Load a context and model. + let mut context_param = WhisperContextParameters::default(); + + // Enable DTW token level timestamp for known model by using model preset + context_param.dtw_parameters.mode = whisper_rs::DtwMode::ModelPreset { + model_preset: whisper_rs::DtwModelPreset::BaseEn, + }; + + // Enable DTW token level timestamp for unknown model by providing custom aheads + // see details https://github.com/ggerganov/whisper.cpp/pull/1485#discussion_r1519681143 + // values corresponds to ggml-base.en.bin, result will be the same as with DtwModelPreset::BaseEn + let custom_aheads = [ + (3, 1), + (4, 2), + (4, 3), + (4, 7), + (5, 1), + (5, 2), + (5, 4), + (5, 6), + ] + .map(|(n_text_layer, n_head)| whisper_rs_sys::whisper_ahead { + n_text_layer, + n_head, + }); + context_param.dtw_parameters.mode = whisper_rs::DtwMode::Custom { + aheads: &custom_aheads, + }; + let ctx = WhisperContext::new_with_params( "example/path/to/model/whisper.cpp/models/ggml-base.en.bin", - WhisperContextParameters::default(), + context_param, ) .expect("failed to load model"); // Create a state @@ -33,6 +61,8 @@ fn main() -> Result<(), &'static str> { params.set_print_progress(false); params.set_print_realtime(false); params.set_print_timestamps(false); + // Enable token level timestamps + params.set_token_timestamps(true); // Open the audio file. let reader = hound::WavReader::open("audio.wav").expect("failed to open file"); @@ -87,8 +117,24 @@ fn main() -> Result<(), &'static str> { .full_get_segment_t1(i) .expect("failed to get end timestamp"); + let first_token_dtw_ts = if let Ok(token_count) = state.full_n_tokens(i) { + if token_count > 0 { + if let Ok(token_data) = state.full_get_token_data(i, 0) { + token_data.t_dtw + } else { + -1i64 + } + } else { + -1i64 + } + } else { + -1i64 + }; // Print the segment to stdout. - println!("[{} - {}]: {}", start_timestamp, end_timestamp, segment); + println!( + "[{} - {} ({})]: {}", + start_timestamp, end_timestamp, first_token_dtw_ts, segment + ); // Format the segment information as a string. let line = format!("[{} - {}]: {}\n", start_timestamp, end_timestamp, segment); diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index 5ab7e21..1a0f0fc 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -469,7 +469,7 @@ impl Drop for WhisperInnerContext { unsafe impl Send for WhisperInnerContext {} unsafe impl Sync for WhisperInnerContext {} -pub struct WhisperContextParameters { +pub struct WhisperContextParameters<'a> { /// Use GPU if available. /// /// **Warning**: Does not have an effect if OpenCL is selected as GPU backend @@ -482,11 +482,11 @@ pub struct WhisperContextParameters { /// GPU device id, default 0 pub gpu_device: c_int, /// DTW token level timestamp parameters - pub dtw_parameters: DtwParameters, + pub dtw_parameters: DtwParameters<'a>, } #[allow(clippy::derivable_impls)] // this impl cannot be derived -impl Default for WhisperContextParameters { +impl<'a> Default for WhisperContextParameters<'a> { fn default() -> Self { Self { use_gpu: cfg!(feature = "_gpu"), @@ -496,7 +496,7 @@ impl Default for WhisperContextParameters { } } } -impl WhisperContextParameters { +impl<'a> WhisperContextParameters<'a> { pub fn new() -> Self { Self::default() } @@ -512,7 +512,7 @@ impl WhisperContextParameters { self.gpu_device = gpu_device; self } - pub fn dtw_parameters(&mut self, dtw_parameters: DtwParameters) -> &mut Self { + pub fn dtw_parameters(&mut self, dtw_parameters: DtwParameters<'a>) -> &mut Self { self.dtw_parameters = dtw_parameters; self } @@ -606,12 +606,12 @@ impl WhisperContextParameters { /// [EXPERIMENTAL] Enable Token-level timestamps with DTW, default Disabled #[derive(Debug, Clone)] -pub struct DtwParameters { - pub mode: DtwMode, +pub struct DtwParameters<'a> { + pub mode: DtwMode<'a>, pub dtw_mem_size: usize, } -impl Default for DtwParameters { +impl Default for DtwParameters<'_> { fn default() -> Self { Self { mode: DtwMode::None, @@ -621,7 +621,7 @@ impl Default for DtwParameters { } #[derive(Debug, Clone)] -pub enum DtwMode { +pub enum DtwMode<'a> { /// DTW token level timestamps disabled None, /// Use N Top Most layers from loaded model @@ -633,7 +633,7 @@ pub enum DtwMode { /// 0 < n_text_layer < model n_text_layer, 0 < n_head < model n_text_head for each element /// See details https://github.com/ggerganov/whisper.cpp/pull/1485#discussion_r1519681143 Custom { - aheads: &'static [whisper_rs_sys::whisper_ahead], + aheads: &'a [whisper_rs_sys::whisper_ahead], }, /// Use predefined preset for standard models ModelPreset { model_preset: DtwModelPreset }, From ce17f9a441266369f6a0eea7238f514787c68796 Mon Sep 17 00:00:00 2001 From: arizhih Date: Sat, 18 May 2024 00:06:53 +0200 Subject: [PATCH 7/8] Re-export whisper_ahead --- examples/audio_transcription.rs | 2 +- src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/audio_transcription.rs b/examples/audio_transcription.rs index 2a8499b..60e5ea9 100644 --- a/examples/audio_transcription.rs +++ b/examples/audio_transcription.rs @@ -29,7 +29,7 @@ fn main() -> Result<(), &'static str> { (5, 4), (5, 6), ] - .map(|(n_text_layer, n_head)| whisper_rs_sys::whisper_ahead { + .map(|(n_text_layer, n_head)| whisper_rs::DtwAhead { n_text_layer, n_head, }); diff --git a/src/lib.rs b/src/lib.rs index 1822174..afd1996 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,3 +49,4 @@ pub type WhisperProgressCallback = whisper_rs_sys::whisper_progress_callback; pub type WhisperLogitsFilterCallback = whisper_rs_sys::whisper_logits_filter_callback; pub type WhisperAbortCallback = whisper_rs_sys::ggml_abort_callback; pub type WhisperLogCallback = whisper_rs_sys::ggml_log_callback; +pub type DtwAhead = whisper_rs_sys::whisper_ahead; From ecd2b613db0c8749448b83631f68178ef9c55e35 Mon Sep 17 00:00:00 2001 From: arizhih Date: Mon, 27 May 2024 12:16:41 +0200 Subject: [PATCH 8/8] Update whisper.cpp version to 1.6.2 --- sys/whisper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/whisper.cpp b/sys/whisper.cpp index 08981d1..c7b6988 160000 --- a/sys/whisper.cpp +++ b/sys/whisper.cpp @@ -1 +1 @@ -Subproject commit 08981d1bacbe494ff1c943af6c577c669a2d9f4d +Subproject commit c7b6988678779901d02ceba1a8212d2c9908956e