cubecl_runtime/tune/tune_inputs.rs
1/// Describes the set of inputs a [`TunableSet`](super::TunableSet) accepts.
2///
3/// The associated type [`At`](Self::At) gives the concrete input type at a specific
4/// lifetime. The indirection exists because [`TunableSet`](super::TunableSet) must be
5/// `'static` (to live in [`LocalTuner`](super::LocalTuner)'s `Arc<dyn Any>` cache), but
6/// some callers want to pass *borrowed* inputs. A `'static` marker type with a
7/// lifetime-parameterized works here: the set is `'static`, but every
8/// tunable function accepts `Self::At<'a>` for any `'a` via HRTB.
9///
10/// Implementing it manually is needed when the inputs genuinely borrowed. Example:
11/// burn's fusion autotune passes `TuneInput<'a, R, O>` (which wraps `&'a mut Context`)
12/// by defining a `FusionTuneInputs<R, O>` marker with
13/// `At<'a> = TuneInput<'a, R, O>`. Such a marker must not implement `Clone`, otherwise
14/// it would overlap with the blanket impl below.
15pub trait TuneInputs: Send + Sync + 'static {
16 /// The concrete input type at lifetime `'a`.
17 type At<'a>: Clone + Send;
18}
19
20impl<T: Clone + Send + Sync + 'static> TuneInputs for T {
21 type At<'a> = T;
22}