Skip to main content

cbtop/bricks/generators/
cuda.rs

1//! CUDA load generator using trueno-gpu PTX
2
3use crate::brick::{Brick, BrickAssertion, BrickBudget, BrickVerification};
4use std::any::Any;
5
6pub struct CudaLoadBrick {
7    is_running: bool,
8    intensity: f64,
9    problem_size: usize,
10}
11
12impl CudaLoadBrick {
13    pub fn new(problem_size: usize) -> Self {
14        Self {
15            is_running: false,
16            intensity: 0.0,
17            problem_size,
18        }
19    }
20
21    pub fn start(&mut self) {
22        self.is_running = true;
23    }
24
25    pub fn stop(&mut self) {
26        self.is_running = false;
27    }
28
29    pub fn is_running(&self) -> bool {
30        self.is_running
31    }
32
33    pub fn set_intensity(&mut self, intensity: f64) {
34        self.intensity = intensity.clamp(0.0, 1.0);
35    }
36
37    pub fn is_available(&self) -> bool {
38        // Would check for CUDA device
39        false
40    }
41}
42
43impl Default for CudaLoadBrick {
44    fn default() -> Self {
45        Self::new(1_048_576)
46    }
47}
48
49impl Brick for CudaLoadBrick {
50    fn brick_name(&self) -> &'static str {
51        "cuda_load"
52    }
53
54    fn assertions(&self) -> Vec<BrickAssertion> {
55        vec![
56            BrickAssertion::custom("cuda_available", |_| true),
57            BrickAssertion::max_latency_ms(10),
58        ]
59    }
60
61    fn budget(&self) -> BrickBudget {
62        BrickBudget {
63            collect_ms: 1,
64            layout_ms: 0,
65            render_ms: 0,
66        }
67    }
68
69    fn verify(&self) -> BrickVerification {
70        let mut v = BrickVerification::new();
71        for assertion in self.assertions() {
72            v.check(&assertion);
73        }
74        v
75    }
76
77    fn as_any(&self) -> &dyn Any {
78        self
79    }
80}