use std::fmt;
use crate::CacheStats;
pub(crate) const DEFAULT_GEMM_ANALYSIS_CACHE_CAPACITY: usize = 1024;
#[doc(hidden)]
pub struct GemmAnalysisCache {
max_slots: usize,
clears: u64,
pub(crate) binary: crate::contraction::BinaryCache,
}
impl fmt::Debug for GemmAnalysisCache {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("GemmAnalysisCache")
.field("max_slots", &self.max_slots)
.field("binary", &self.binary)
.finish_non_exhaustive()
}
}
impl GemmAnalysisCache {
pub(crate) fn with_capacity(max_slots: usize) -> Self {
Self {
max_slots,
clears: 0,
binary: crate::contraction::BinaryCache::default(),
}
}
#[doc(hidden)]
pub fn capacity(&self) -> usize {
self.max_slots
}
#[doc(hidden)]
pub fn set_capacity(&mut self, max_slots: usize) {
self.binary.set_capacity(max_slots);
self.max_slots = max_slots;
}
}
impl Default for GemmAnalysisCache {
fn default() -> Self {
Self::with_capacity(DEFAULT_GEMM_ANALYSIS_CACHE_CAPACITY)
}
}
impl tenferro_tensor::RuntimeCacheControl for GemmAnalysisCache {
fn clear(&mut self) {
self.binary.clear();
self.clears = self.clears.saturating_add(1);
}
fn stats(&self) -> CacheStats {
let binary = self.binary.stats();
CacheStats {
clears: self.clears,
..binary
}
}
}
#[cfg(test)]
mod tests;