qualia_core_db/gguf_bridge/
native_resident_adapter.rs1use super::*;
2use etalon_inference::native_resident::{ResidentProvider, ResidentResources};
3impl ResidentProvider for QTensorEngine {
4 type Mask = [u32; KV_ATTENTION_MASK_WORDS];
5 fn resident_resources(&self) -> ResidentResources<'_> {
6 ResidentResources {
7 add_pipeline: self.elem_gpu_pipeline(ELEM_OP_ADD_RESIDUAL),
8 attention_mask_buf: self.attention_mask_buf.as_ref(),
9 attention_pipeline: &self.attention_pipeline,
10 coop_gemv_mr_pipeline: &self.coop_gemv_mr_pipeline,
11 coop_gemv_pipeline: &self.coop_gemv_pipeline,
12 coop_gemv_residual_mr_pipeline: &self.coop_gemv_residual_mr_pipeline,
13 coop_gemv_residual_pipeline: &self.coop_gemv_residual_pipeline,
14 coop_gemv_residual_warp_pipeline: &self.coop_gemv_residual_warp_pipeline,
15 coop_gemv_warp_pipeline: &self.coop_gemv_warp_pipeline,
16 dual_gemv_mr_pipeline: &self.dual_gemv_mr_pipeline,
17 dual_gemv_pipeline: &self.dual_gemv_pipeline,
18 elem_silu_mul_pipeline: &self.elem_silu_mul_pipeline,
19 ffn_fused_coop_pipeline: &self.ffn_fused_coop_pipeline,
20 ffn_fused_mr_pipeline: &self.ffn_fused_mr_pipeline,
21 ffn_fused_pipeline: &self.ffn_fused_pipeline,
22 ffn_fused_warp_pipeline: &self.ffn_fused_warp_pipeline,
23 output_topk_pipeline: self.output_topk_pipeline.as_ref(),
24 pipeline: &self.pipeline,
25 rms_pipeline: self.elem_gpu_pipeline(ELEM_OP_RMS_NORM),
26 topk_cand_idx_buf: self.topk_cand_idx_buf.as_ref(),
27 topk_cand_val_buf: self.topk_cand_val_buf.as_ref(),
28 triple_gemv_pipeline: &self.triple_gemv_pipeline,
29 }
30 }
31 fn gpu_device(&self) -> &etalon::Device {
32 QTensorEngine::gpu_device(self)
33 }
34 fn gpu_queue(&self) -> &etalon::Queue {
35 QTensorEngine::gpu_queue(self)
36 }
37 fn submit(&self, command: etalon::CommandBuffer) -> bool {
38 self.submit_commands([command]).is_some()
39 }
40 fn poll_wait(&self) -> bool {
41 let result = self
42 .gpu_device()
43 .poll(etalon::PollType::wait_indefinitely())
44 .is_ok();
45 GPU_WAIT_COUNT.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
46 result
47 }
48 fn attention_kv_mask(&self, token: u32, capacity: u32) -> (Self::Mask, u32) {
49 crate::compute_universe::attention_kv_mask_u32(token, capacity)
50 }
51 fn dual_multirow(&self) -> bool {
52 matches!(
53 super::execution_env::var("QUALIA_LLM_DUAL_MR")
54 .ok()
55 .as_deref(),
56 Some("1") | Some("true")
57 )
58 }
59 fn coop_gemv_workgroups(&self, rows: u32) -> u32 {
60 crate::llm_bench::coop_gemv_workgroups(rows)
61 }
62 fn pass_writes(&self) -> Option<etalon::ComputePassTimestampWrites<'static>> {
63 crate::llm_gpu_profiler::pass_writes_both()
64 }
65 fn resolve(&self, encoder: &mut etalon::CommandEncoder) {
66 crate::llm_gpu_profiler::resolve(encoder);
67 }
68 fn accumulate_fused(&self) {
69 crate::llm_gpu_profiler::accumulate(crate::llm_gpu_profiler::Phase::FusedBlock);
70 }
71}