cubecl_runtime/
kernel_timestamps.rs1use cubecl_common::benchmark::ProfileDuration;
2use std::time::Instant;
3
4#[derive(Debug, Default)]
5pub struct KernelTimestamps {
8 start: Option<Instant>,
9}
10
11impl KernelTimestamps {
12 pub fn start(&mut self) {
14 if self.start.is_some() {
15 panic!("Recursive kernel timestamps are not supported.");
16 }
17 self.start = Some(std::time::Instant::now());
18 }
19
20 pub fn stop(&mut self) -> ProfileDuration {
22 ProfileDuration::from_duration(
23 self.start
24 .take()
25 .expect("Stopped timestamp before starting one.")
26 .elapsed(),
27 )
28 }
29}