use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt::{Debug, Display};
use core::hash::Hash;
#[cfg(autotune_persistent_cache)]
pub fn compute_checksum<Out>(autotunables: &[Box<dyn AutotuneOperation<Out>>]) -> String {
let mut checksum = String::new();
autotunables.iter().for_each(|op| {
checksum += op.name();
});
format!("{:x}", md5::compute(checksum))
}
pub trait AutotuneOperationSet<K, Output = ()>: Send {
fn key(&self) -> K;
fn autotunables(&self) -> Vec<Box<dyn AutotuneOperation<Output>>>;
fn fastest(self: Box<Self>, fastest_index: usize) -> Box<dyn AutotuneOperation<Output>>;
#[cfg(autotune_persistent_cache)]
fn compute_checksum(&self) -> String {
compute_checksum(&self.autotunables())
}
}
pub trait AutotuneOperation<Output = ()> {
fn execute(self: Box<Self>) -> Output;
fn name(&self) -> &str {
core::any::type_name::<Self>()
}
fn clone(&self) -> Box<dyn AutotuneOperation<Output>>;
}
#[cfg(autotune_persistent_cache)]
pub trait AutotuneKey:
Clone
+ Debug
+ PartialEq
+ Eq
+ Hash
+ Display
+ serde::Serialize
+ serde::de::DeserializeOwned
+ Send
+ Sync
{
}
#[cfg(not(autotune_persistent_cache))]
pub trait AutotuneKey: Clone + Debug + PartialEq + Eq + Hash + Display {}
impl AutotuneKey for String {}