qualia_core_db/inference/inference_bench/
counters.rs1use std::sync::atomic::{AtomicU64, Ordering};
7
8static TOPK_HITS: AtomicU64 = AtomicU64::new(0);
10static ARGMAX_FALLBACKS: AtomicU64 = AtomicU64::new(0);
11
12#[inline]
14pub fn record_topk_hit() {
15 TOPK_HITS.fetch_add(1, Ordering::Relaxed);
16}
17#[inline]
19pub fn record_argmax_fallback() {
20 ARGMAX_FALLBACKS.fetch_add(1, Ordering::Relaxed);
21}
22#[inline]
24pub fn output_path_counts() -> (u64, u64) {
25 (
26 TOPK_HITS.load(Ordering::Relaxed),
27 ARGMAX_FALLBACKS.load(Ordering::Relaxed),
28 )
29}
30#[inline]
32pub fn reset_output_path_counts() {
33 TOPK_HITS.store(0, Ordering::Relaxed);
34 ARGMAX_FALLBACKS.store(0, Ordering::Relaxed);
35}
36
37static RESIDENT_HITS: AtomicU64 = AtomicU64::new(0);
39static RESIDENT_FALLBACKS: AtomicU64 = AtomicU64::new(0);
40
41#[inline]
43pub fn record_resident_hit() {
44 RESIDENT_HITS.fetch_add(1, Ordering::Relaxed);
45}
46#[inline]
48pub fn record_resident_fallback() {
49 RESIDENT_FALLBACKS.fetch_add(1, Ordering::Relaxed);
50}
51#[inline]
53pub fn resident_path_counts() -> (u64, u64) {
54 (
55 RESIDENT_HITS.load(Ordering::Relaxed),
56 RESIDENT_FALLBACKS.load(Ordering::Relaxed),
57 )
58}
59#[inline]
61pub fn reset_resident_path_counts() {
62 RESIDENT_HITS.store(0, Ordering::Relaxed);
63 RESIDENT_FALLBACKS.store(0, Ordering::Relaxed);
64}
65
66static CUDA_MEGA_HITS: AtomicU64 = AtomicU64::new(0);
72static CUDA_MEGA_FALLBACKS: AtomicU64 = AtomicU64::new(0);
73
74#[inline]
76pub fn record_cuda_mega_hit() {
77 CUDA_MEGA_HITS.fetch_add(1, Ordering::Relaxed);
78}
79
80#[inline]
83pub fn record_cuda_mega_fallback() {
84 CUDA_MEGA_FALLBACKS.fetch_add(1, Ordering::Relaxed);
85}
86
87#[inline]
89pub fn cuda_mega_path_counts() -> (u64, u64) {
90 (
91 CUDA_MEGA_HITS.load(Ordering::Relaxed),
92 CUDA_MEGA_FALLBACKS.load(Ordering::Relaxed),
93 )
94}
95
96#[inline]
98pub fn reset_cuda_mega_path_counts() {
99 CUDA_MEGA_HITS.store(0, Ordering::Relaxed);
100 CUDA_MEGA_FALLBACKS.store(0, Ordering::Relaxed);
101}
102
103static SAMPLED_TOKENS: AtomicU64 = AtomicU64::new(0);
105
106#[inline]
108pub fn record_sampled_token() {
109 SAMPLED_TOKENS.fetch_add(1, Ordering::Relaxed);
110}
111#[inline]
113pub fn sampled_token_count() -> u64 {
114 SAMPLED_TOKENS.load(Ordering::Relaxed)
115}
116#[inline]
118pub fn reset_sampled_token_count() {
119 SAMPLED_TOKENS.store(0, Ordering::Relaxed);
120}
121
122static SPEC_STEPS: AtomicU64 = AtomicU64::new(0);
124static SPEC_DRAFTED: AtomicU64 = AtomicU64::new(0);
125static SPEC_ACCEPTED: AtomicU64 = AtomicU64::new(0);
126
127#[inline]
129pub fn record_spec_step(drafted: u64, accepted: u64) {
130 SPEC_STEPS.fetch_add(1, Ordering::Relaxed);
131 SPEC_DRAFTED.fetch_add(drafted, Ordering::Relaxed);
132 SPEC_ACCEPTED.fetch_add(accepted, Ordering::Relaxed);
133}
134#[inline]
136pub fn spec_decode_counts() -> (u64, u64, u64) {
137 (
138 SPEC_STEPS.load(Ordering::Relaxed),
139 SPEC_DRAFTED.load(Ordering::Relaxed),
140 SPEC_ACCEPTED.load(Ordering::Relaxed),
141 )
142}
143#[inline]
145pub fn reset_spec_decode_counts() {
146 SPEC_STEPS.store(0, Ordering::Relaxed);
147 SPEC_DRAFTED.store(0, Ordering::Relaxed);
148 SPEC_ACCEPTED.store(0, Ordering::Relaxed);
149}
150
151static RESIDENT_PREFILL_HITS: AtomicU64 = AtomicU64::new(0);
153static RESIDENT_PREFILL_FALLBACKS: AtomicU64 = AtomicU64::new(0);
154
155#[inline]
157pub fn record_resident_prefill_hit() {
158 RESIDENT_PREFILL_HITS.fetch_add(1, Ordering::Relaxed);
159}
160#[inline]
162pub fn record_resident_prefill_fallback() {
163 RESIDENT_PREFILL_FALLBACKS.fetch_add(1, Ordering::Relaxed);
164}
165#[inline]
167pub fn resident_prefill_counts() -> (u64, u64) {
168 (
169 RESIDENT_PREFILL_HITS.load(Ordering::Relaxed),
170 RESIDENT_PREFILL_FALLBACKS.load(Ordering::Relaxed),
171 )
172}
173#[inline]
175pub fn reset_resident_prefill_counts() {
176 RESIDENT_PREFILL_HITS.store(0, Ordering::Relaxed);
177 RESIDENT_PREFILL_FALLBACKS.store(0, Ordering::Relaxed);
178}