use super::*;
use crate::device::SubstrateType;
#[test]
fn test_tiling() {
let hierarchy = SubstrateMemoryHierarchy {
substrate_name: "Test GPU".to_string(),
substrate_type: SubstrateType::Other,
cache_levels: vec![CacheLevel {
name: "Cache",
size_bytes: 64 * 1024 * 1024, bandwidth_gbs: 1000.0,
shared: true,
}],
main_memory: MainMemory {
size_bytes: 16 * 1024 * 1024 * 1024,
bandwidth_gbs: 500.0,
},
optimal_tile_bytes: 32 * 1024 * 1024,
probed: false,
};
let tiler = CacheAwareTiler::new(hierarchy);
let config = tiler.optimal_tile_size(
1024 * 1024 * 1024,
4, 3.0, );
assert!(
config.tile_bytes < 64 * 1024 * 1024,
"Tiles should fit in cache"
);
assert!(config.num_tiles > 1, "Large workload should be tiled");
}
#[test]
fn test_cache_residency() {
let hierarchy = SubstrateMemoryHierarchy {
substrate_name: "Test GPU".to_string(),
substrate_type: SubstrateType::Other,
cache_levels: vec![CacheLevel {
name: "Cache",
size_bytes: 64 * 1024 * 1024,
bandwidth_gbs: 1000.0,
shared: true,
}],
main_memory: MainMemory {
size_bytes: 16 * 1024 * 1024 * 1024,
bandwidth_gbs: 500.0,
},
optimal_tile_bytes: 32 * 1024 * 1024,
probed: false,
};
let tiler = CacheAwareTiler::new(hierarchy);
match tiler.is_cache_resident(10 * 1024 * 1024) {
CacheResidency::Resident { .. } => {}
_ => panic!("10 MB should be cache-resident"),
}
match tiler.is_cache_resident(100 * 1024 * 1024) {
CacheResidency::DramBound { .. } => {}
_ => panic!("100 MB should be DRAM-bound"),
}
}