Skip to main content

BackendTimer

Trait BackendTimer 

Source
pub trait BackendTimer<B: Backend>: Send {
    // Required methods
    fn new() -> Self
       where Self: Sized;
    fn record_start(&mut self, ctx: &mut B::Context);
    fn record_end(&mut self, ctx: &mut B::Context);
    fn elapsed_ms(&self) -> f64;
}
Expand description

GPU-side timer scoped to a single Backend context.

Required Methods§

Source

fn new() -> Self
where Self: Sized,

Allocate timer state. On CUDA this creates two cuEvent_t handles; on Metal it’s a no-op; on CPU it’s two Option<Instant>.

Source

fn record_start(&mut self, ctx: &mut B::Context)

Record the “start” timestamp on the current ctx’s stream/command buffer. Returns immediately on CUDA (async); on Metal forces a sync to flush any pending work first.

Source

fn record_end(&mut self, ctx: &mut B::Context)

Record the “end” timestamp.

Source

fn elapsed_ms(&self) -> f64

Synchronize on the recorded events and return the elapsed time in milliseconds. Blocks the calling thread on CUDA; instant on CPU/Metal.

Calling elapsed_ms before both record_start + record_end have fired returns 0.0.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§