Skip to main content

cubecl_runtime/tune/
key_generator.rs

1use super::TuneInputs;
2
3/// Produces an autotune key from a borrowed view of the tuning inputs.
4#[diagnostic::on_unimplemented(
5    message = "`{Self}` is not a valid key generator",
6    label = "invalid key generator"
7)]
8pub trait KeyGenerator<K, I: TuneInputs>: Send + Sync + 'static {
9    /// Generate a key from a set of inputs.
10    fn generate(&self, inputs: &I::At<'_>) -> K;
11}
12
13/// Any `for<'a> Fn(&I::At<'a>) -> K` is a [`KeyGenerator`].
14impl<K, I, Func> KeyGenerator<K, I> for Func
15where
16    I: TuneInputs,
17    Func: Send + Sync + 'static,
18    for<'a> Func: Fn(&I::At<'a>) -> K,
19{
20    #[inline]
21    fn generate<'a>(&self, inputs: &I::At<'a>) -> K {
22        (self)(inputs)
23    }
24}