cubecl_runtime/tune/
util.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use core::cmp::min;

/// Anchor a number to a power of 2.
///
/// Useful when creating autotune keys.
pub fn anchor(x: usize, max: Option<usize>) -> usize {
    let exp = f32::ceil(f32::log2(x as f32)) as u32;
    let power_of_2 = 2_u32.pow(exp) as usize;
    if let Some(max) = max {
        min(power_of_2, max)
    } else {
        power_of_2
    }
}

/// Tune the operation set with these benchmark inputs
#[macro_export]
macro_rules! tune_with {
    ($($args:expr),*) => {
        ($($args),*)
    };
    ($($args:expr,)*) => {
        ($($args),*)
    };
}