Skip to main content

qualia_core_db/inference/
cuda_lane_stub.rs

1//! Stub when CUDA feature is off — CUDA lane APIs return false / no-op.
2
3#![cfg(any(target_arch = "wasm32", not(feature = "cuda")))]
4
5pub const MAX_DENSE_ELEMS: usize = 0;
6
7/// Returns 0 — no weight fingerprinting without CUDA (feature `cuda` off or wasm).
8pub fn weight_fingerprint(_raw: &[u8], _n_in: usize, _n_out: usize) -> u64 {
9    0
10}
11
12/// No-op — no device weight cache exists without CUDA.
13pub fn cache_dense_weight(_key: u64, _n_in: usize, _n_out: usize, _data: Vec<f32>) {}
14
15/// Returns `false` — nothing is ever cached without CUDA.
16pub fn dense_weight_cached(_key: u64) -> bool {
17    false
18}
19
20/// Returns 0 — no device weight preloading without CUDA.
21pub fn preload_q4k_soa_weights(_weights: &[(&[u8], usize, usize)]) -> usize {
22    0
23}
24
25/// Returns `false` — CUDA GEMV unavailable; caller falls back to CPU.
26pub fn try_cuda_batch_gemv(
27    _hidden: &[f32],
28    _batch: usize,
29    _n_in: usize,
30    _n_out: usize,
31    _weight: &[f32],
32    _out: &mut [f32],
33) -> bool {
34    false
35}
36
37/// Returns `false` — no cached device weights exist without CUDA.
38pub fn try_cuda_batch_gemv_cached_only(
39    _key: u64,
40    _hidden: &[f32],
41    _batch: usize,
42    _out: &mut [f32],
43) -> bool {
44    false
45}
46
47/// Returns `false` — CUDA GEMV unavailable; caller falls back to CPU.
48pub fn try_cuda_batch_gemv_cached(
49    _key: u64,
50    _hidden: &[f32],
51    _batch: usize,
52    _n_in: usize,
53    _n_out: usize,
54    _weight: &[f32],
55    _out: &mut [f32],
56) -> bool {
57    false
58}
59
60/// Returns 0 — the weight cache is empty by definition without CUDA.
61pub fn weight_cache_len() -> usize {
62    0
63}
64
65/// No-op — no cache to clear without CUDA.
66pub fn clear_weight_cache() {}
67
68/// Returns `false` — Q4K device GEMV unavailable without CUDA.
69pub fn try_q4k_soa_gemv(
70    _n_in: usize,
71    _n_out: usize,
72    _x: &[f32],
73    _weight_raw: &[u8],
74    _out: &mut [f32],
75) -> bool {
76    false
77}
78
79/// Returns `false` — fused QKV projection unavailable without CUDA.
80pub fn try_q4k_soa_qkv(
81    _n_in: usize,
82    _n_q: usize,
83    _n_kv: usize,
84    _x: &[f32],
85    _q_raw: &[u8],
86    _k_raw: &[u8],
87    _v_raw: &[u8],
88    _q_out: &mut [f32],
89    _k_out: &mut [f32],
90    _v_out: &mut [f32],
91) -> bool {
92    false
93}
94
95/// Returns `false` — fused SwiGLU unavailable without CUDA.
96pub fn try_q4k_soa_fused_swiglu(
97    _n_in: usize,
98    _n_out: usize,
99    _x: &[f32],
100    _gate_raw: &[u8],
101    _up_raw: &[u8],
102    _out: &mut [f32],
103) -> bool {
104    false
105}
106
107/// Returns `false` — fused residual FFN block unavailable without CUDA.
108pub fn try_q4k_soa_ffn_block_residual(
109    _n_embd: usize,
110    _n_ffn: usize,
111    _x_normed: &[f32],
112    _residual: &[f32],
113    _gate_raw: &[u8],
114    _up_raw: &[u8],
115    _down_raw: &[u8],
116    _out: &mut [f32],
117) -> bool {
118    false
119}
120
121/// Returns `false` — fused FFN block unavailable without CUDA.
122pub fn try_q4k_soa_ffn_block(
123    _n_embd: usize,
124    _n_ffn: usize,
125    _x: &[f32],
126    _gate_raw: &[u8],
127    _up_raw: &[u8],
128    _down_raw: &[u8],
129    _out: &mut [f32],
130) -> bool {
131    false
132}
133
134/// Returns 0 — no Q4K weights are resident on-device without CUDA.
135pub fn q4k_device_weight_count() -> usize {
136    0
137}
138
139/// Returns `false` — no CUDA context to warm.
140pub fn warm_cuda_context() -> bool {
141    false
142}
143
144/// Returns `false` — no device KV cache can be allocated without CUDA.
145pub fn ensure_device_kv_cache(
146    _max_context: u32,
147    _n_layer: u32,
148    _n_kv_head: u32,
149    _head_dim: u32,
150    _slot_kv_elems: u32,
151    _layer_stride: u32,
152    _total_f32_elems: usize,
153) -> bool {
154    false
155}
156
157/// Returns `false` — device KV cache never exists without CUDA.
158pub fn device_kv_ready() -> bool {
159    false
160}
161
162/// Returns `false` — device-side attention unavailable without CUDA.
163pub fn try_q4k_soa_attention_device(
164    _n_embd: usize,
165    _n_head: usize,
166    _n_kv: usize,
167    _head_dim: usize,
168    _layer: u32,
169    _token_idx: u32,
170    _max_context: u32,
171    _layer_stride: u32,
172    _slot_kv_elems: u32,
173    _rope_base: f32,
174    _rope_scale: f32,
175    _x_normed: &[f32],
176    _q_raw: &[u8],
177    _k_raw: &[u8],
178    _v_raw: &[u8],
179    _o_raw: &[u8],
180    _host_kv: Option<&mut [f32]>,
181    _out_delta: &mut [f32],
182) -> bool {
183    false
184}
185
186pub struct MegaPassLayerWeights<'a> {
187    pub attn_norm: &'a [f32],
188    pub q_raw: &'a [u8],
189    pub k_raw: &'a [u8],
190    pub v_raw: &'a [u8],
191    pub o_raw: &'a [u8],
192    pub ffn_norm: &'a [f32],
193    pub gate_raw: &'a [u8],
194    pub up_raw: &'a [u8],
195    pub down_raw: &'a [u8],
196}
197
198pub struct MegaPassLayerDims {
199    pub q_in: usize,
200    pub q_out: usize,
201    pub kv_in: usize,
202    pub kv_out: usize,
203    pub o_in: usize,
204    pub o_out: usize,
205    pub gate_in: usize,
206    pub gate_out: usize,
207    pub up_in: usize,
208    pub up_out: usize,
209    pub down_in: usize,
210    pub down_out: usize,
211}
212
213/// Returns `None` — the fused mega-pass is unavailable without CUDA.
214pub fn try_cuda_mega_pass(
215    _n_embd: usize,
216    _n_head: usize,
217    _n_kv: usize,
218    _head_dim: usize,
219    _n_layer: u32,
220    _token_idx: u32,
221    _max_context: u32,
222    _layer_stride: u32,
223    _slot_kv_elems: u32,
224    _rope_base: f32,
225    _rope_scale: f32,
226    _rms_eps: f32,
227    _hidden: &mut [f32],
228    _layers: &[MegaPassLayerWeights<'_>],
229    _layer_dims: &[MegaPassLayerDims],
230    _output_norm: Option<&[f32]>,
231    _lm_head_raw: Option<&[u8]>,
232    _lm_head_in: usize,
233    _lm_head_out: usize,
234) -> Option<u32> {
235    None
236}