cubecl_runtime/tune/util.rs
1use core::cmp::min;
2
3/// Anchor a number to a power of 2.
4///
5/// Useful when creating autotune keys.
6pub fn anchor(x: usize, max: Option<usize>) -> usize {
7 let exp = f32::ceil(f32::log2(x as f32)) as u32;
8 let power_of_2 = 2_u32.pow(exp) as usize;
9 if let Some(max) = max {
10 min(power_of_2, max)
11 } else {
12 power_of_2
13 }
14}
15
16/// Tune the operation set with these benchmark inputs
17#[macro_export]
18macro_rules! tune_with {
19 ($($args:expr),*) => {
20 ($($args),*)
21 };
22 ($($args:expr,)*) => {
23 ($($args),*)
24 };
25}