pub trait Backend {
// Required method
fn device(&self) -> Device;
}Expand description
The execution backend a Model runs its tensor ops on.
§Why this trait exists with exactly one implementation
Today every Model impl computes directly against
kopitiam_tensor::Tensor’s plain-CPU f32 kernels — there is no
dispatch through this trait yet, and adding one purely to satisfy this
task brief’s ask for a Backend seam, without a second backend that
would use it, is exactly the unnecessary abstraction CLAUDE.md warns
against. So this trait is deliberately minimal: it names the seam (what
a caller would ask a backend for — its Device) without inventing a
dispatch mechanism no code calls yet. A real second backend (a
SIMD-tuned kernel set, a threaded scheduler — see the parent epic’s
Phase 2/3) is expected to grow this trait’s surface and wire Model
impls to route their tensor ops through it; until then, CpuBackend
exists so crate::model::QwenModel has something concrete to report
through Model’s eventual device() accessor rather than hardcoding
Device::Cpu as a bare literal at every call site.
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".