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