use crate::MemoryScope;
use cubecl_runtime::{client::Client, runtime::Runtime};
const SIZE: usize = 1024;
pub fn a_new_threads_first_allocation_honors_its_allocation_mode<R: Runtime>(client: Client) {
std::thread::spawn(move || {
let persistent = client.memory_persistent_allocation((), |_| client.empty(SIZE));
let after_window = client.empty(SIZE);
let report = client.memory_report(MemoryScope::CurrentStream);
let stream = report
.streams
.first()
.expect("the thread's stream exists once it allocated");
assert_eq!(
stream.pools.persistent.usage.number_allocs, 1,
"the allocation made inside the window, and only that one, is persistent"
);
assert!(
stream.pools.persistent.usage.bytes_in_use >= SIZE as u64,
"the persistent allocation holds its bytes"
);
drop((persistent, after_window));
})
.join()
.expect("the allocation-mode test thread panicked");
}
#[allow(missing_docs)]
#[macro_export]
macro_rules! testgen_allocation_mode {
() => {
mod allocation_mode {
use super::*;
#[cfg(not(target_family = "wasm"))]
#[$crate::runtime_tests::test_log::test]
fn a_new_threads_first_allocation_honors_its_allocation_mode() {
let client = TestRuntime::client(&Default::default());
cubecl_core::runtime_tests::allocation_mode::a_new_threads_first_allocation_honors_its_allocation_mode::<
TestRuntime,
>(client);
}
}
};
}