Skip to main content

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 eviction;
32mod input_generator;
33mod key_generator;
34mod local;
35mod log;
36mod operation;
37// What a tune leaves in the environment beside its answer.
38#[cfg(persistence)]
39mod record;
40// Both are the adaptive strategy, which only the native driver can run.
41#[cfg(not(target_family = "wasm"))]
42mod sampler;
43#[cfg(not(target_family = "wasm"))]
44mod schedule;
45mod tune_benchmark;
46mod tune_cache;
47mod tune_inputs;
48mod tuner;
49mod util;
50
51pub use base::*;
52pub use bounds_generator::*;
53pub use eviction::*;
54pub use input_generator::*;
55pub use key_generator::*;
56pub use local::*;
57pub use log::*;
58pub use operation::*;
59#[cfg(persistence)]
60pub use record::{Trial, TuneRecord};
61pub use tune_benchmark::*;
62pub use tune_cache::*;
63pub use tune_inputs::*;
64pub use tuner::*;
65pub use util::*;