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