sim_lib_compute_wgpu/materialization.rs
1//! Stable host materialization cache for resident wgpu tensors.
2
3use std::sync::{Arc, OnceLock};
4
5/// Caches exactly one synchronized host materialization result.
6#[derive(Debug, Default)]
7pub struct WgpuMaterializationCache {
8 cells: OnceLock<Result<Arc<[u8]>, String>>,
9}
10
11impl WgpuMaterializationCache {
12 /// Returns the cached materialization or records the first result.
13 pub fn get_or_try_init(
14 &self,
15 materialize: impl FnOnce() -> Result<Arc<[u8]>, String>,
16 ) -> Result<Arc<[u8]>, String> {
17 self.cells.get_or_init(materialize).clone()
18 }
19}