cubecl_runtime/tune/mod.rs
1//! # Autotuning
2//!
3//! Autotuning runs several candidate kernels on reference inputs and caches the fastest
4//! one per key.
5//!
6//! ```ignore
7//! #[derive(AutotuneKey)]
8//! struct KernelKey { size: u32 }
9//!
10//! fn run_kernel_tuned(lhs: Tensor, rhs: Tensor) -> Tensor {
11//! static TUNER: LocalTuner<String, KernelKey> = local_tuner!();
12//!
13//! let tunables = TUNER.init(|| {
14//! TunableSet::new(KernelKey::new, |_key, (lhs, rhs)| (lhs.clone(), rhs.clone()))
15//! .with(Tunable::new("k1", |(lhs, rhs)| kernel_1(lhs, rhs)))
16//! .with(Tunable::new("k2", |(lhs, rhs)| kernel_2(lhs, rhs)))
17//! });
18//!
19//! TUNER.execute(&device_id, &lhs.client, tunables, (lhs, rhs));
20//! }
21//! ```
22//!
23//! Kernels are closures returning `Result<Out, impl Into<String>>`. Multi-input kernels
24//! take a single tuple argument and destructure: `|(lhs, rhs, out)| body`.
25//!
26//! See [`TuneInputs`] for the borrowed-inputs story, and [`Tunable::new`] for why its
27//! HRTB bound is spelled out directly (closure inference).
28
29mod base;
30mod bounds_generator;
31mod input_generator;
32mod key_generator;
33mod local;
34mod log;
35mod operation;
36// Both are the adaptive strategy, which only the native driver can run.
37#[cfg(not(target_family = "wasm"))]
38mod sampler;
39#[cfg(not(target_family = "wasm"))]
40mod schedule;
41mod tune_benchmark;
42mod tune_cache;
43mod tune_inputs;
44mod tuner;
45mod util;
46
47pub use base::*;
48pub use bounds_generator::*;
49pub use input_generator::*;
50pub use key_generator::*;
51pub use local::*;
52pub use log::*;
53pub use operation::*;
54pub use tune_benchmark::*;
55pub use tune_cache::*;
56pub use tune_inputs::*;
57pub use tuner::*;
58pub use util::*;