spirv sim: port rgpu smoke tests to test both Gpu and Cpu backend generically
This commit is contained in:
@@ -5,7 +5,7 @@ use coremem_types::vec::{Vec3, Vec3u};
|
||||
|
||||
use super::SimBackend;
|
||||
|
||||
struct CpuBackend;
|
||||
pub struct CpuBackend;
|
||||
|
||||
impl<R: Real, M: Material<R>> SimBackend<R, M> for CpuBackend {
|
||||
fn new(_volume: u64) -> Self {
|
||||
|
@@ -13,7 +13,8 @@ use coremem_types::step::SimMeta;
|
||||
|
||||
mod cpu;
|
||||
mod gpu;
|
||||
use gpu::WgpuBackend;
|
||||
pub use cpu::CpuBackend;
|
||||
pub use gpu::WgpuBackend;
|
||||
|
||||
pub trait SimBackend<R, M> {
|
||||
fn new(volume: u64) -> Self;
|
||||
@@ -349,6 +350,100 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
mod backend_agnostic {
|
||||
use super::*;
|
||||
pub fn do_smoke_small<B: SimBackend<f32, FullyGenericMaterial<f32>> + Send + Sync>() {
|
||||
let mut state: SpirvSim<f32, FullyGenericMaterial<f32>, B> =
|
||||
SpirvSim::new(Index::new(8, 8, 8), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
pub fn do_smoke_med_7bit<B: SimBackend<f32, FullyGenericMaterial<f32>> + Send + Sync>() {
|
||||
let mut state: SpirvSim<f32, FullyGenericMaterial<f32>, B> =
|
||||
SpirvSim::new(Index::new(124, 124, 124), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
pub fn do_smoke_med128<B: SimBackend<f32, FullyGenericMaterial<f32>> + Send + Sync>() {
|
||||
let mut state: SpirvSim<f32, FullyGenericMaterial<f32>, B> =
|
||||
SpirvSim::new(Index::new(128, 128, 128), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
pub fn do_smoke_med_23bit<B: SimBackend<f32, FullyGenericMaterial<f32>> + Send + Sync>() {
|
||||
let mut state: SpirvSim<f32, FullyGenericMaterial<f32>, B> =
|
||||
SpirvSim::new(Index::new(127, 256, 256), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
pub fn do_smoke_med_0x800000_indexing<B: SimBackend<f32, FullyGenericMaterial<f32>> + Send + Sync>() {
|
||||
let mut state: SpirvSim<f32, FullyGenericMaterial<f32>, B> =
|
||||
SpirvSim::new(Index::new(128, 256, 256), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
pub fn do_smoke_med_0x800000_address_space<B: SimBackend<f32, FullyGenericMaterial<f32>> + Send + Sync>() {
|
||||
let mut state: SpirvSim<f32, FullyGenericMaterial<f32>, B> =
|
||||
SpirvSim::new(Index::new(170, 256, 256), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
pub fn do_smoke_large<B: SimBackend<f32, FullyGenericMaterial<f32>> + Send + Sync>() {
|
||||
let mut state: SpirvSim<f32, FullyGenericMaterial<f32>, B> =
|
||||
SpirvSim::new(Index::new(326, 252, 160), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
pub fn do_smoke_not_multiple_of_4<B: SimBackend<f32, FullyGenericMaterial<f32>> + Send + Sync>() {
|
||||
let mut state: SpirvSim<f32, FullyGenericMaterial<f32>, B> =
|
||||
SpirvSim::new(Index::new(3, 2, 5), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! test_backend {
|
||||
($shortname:ident, $backend:ty) => {
|
||||
mod $shortname {
|
||||
use super::backend_agnostic::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_smoke_small() {
|
||||
do_smoke_small::<$backend>();
|
||||
}
|
||||
#[test]
|
||||
fn test_smoke_med_7bit() {
|
||||
do_smoke_med_7bit::<$backend>();
|
||||
}
|
||||
#[test]
|
||||
fn smoke_med128() {
|
||||
do_smoke_med128::<$backend>();
|
||||
}
|
||||
#[test]
|
||||
fn smoke_med_23bit() {
|
||||
do_smoke_med_23bit::<$backend>();
|
||||
}
|
||||
#[test]
|
||||
fn smoke_med_0x800000_indexing() {
|
||||
do_smoke_med_0x800000_indexing::<$backend>();
|
||||
}
|
||||
#[test]
|
||||
fn smoke_med_0x800000_address_space() {
|
||||
do_smoke_med_0x800000_address_space::<$backend>();
|
||||
}
|
||||
#[test]
|
||||
fn smoke_large() {
|
||||
do_smoke_large::<$backend>();
|
||||
}
|
||||
#[test]
|
||||
fn smoke_not_multiple_of_4() {
|
||||
do_smoke_not_multiple_of_4::<$backend>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type WgpuForTest = WgpuBackend<f32, FullyGenericMaterial<f32>>;
|
||||
test_backend!(cpu_v2, CpuBackend);
|
||||
test_backend!(gpu, WgpuForTest);
|
||||
|
||||
mod cpu {
|
||||
//! Validate the spirv_backend implementation against the reference, but
|
||||
//! invoke it natively -- not through rgpu
|
||||
@@ -648,72 +743,6 @@ mod test {
|
||||
use super::*;
|
||||
use crate::stim::{NoopStimulus, RngStimulus, UniformStimulus};
|
||||
|
||||
#[test]
|
||||
fn smoke_small() {
|
||||
let mut state: SpirvSim = SpirvSim::new(Index::new(8, 8, 8), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_med_7bit() {
|
||||
let mut state: SpirvSim = SpirvSim::new(Index::new(124, 124, 124), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_med128() {
|
||||
let mut state: SpirvSim = SpirvSim::new(Index::new(128, 128, 128), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_med_23bit() {
|
||||
let mut state: SpirvSim = SpirvSim::new(Index::new(127, 256, 256), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_med_0x800000_indexing() {
|
||||
let mut state: SpirvSim = SpirvSim::new(Index::new(128, 256, 256), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_med_0xff00000_address_space() {
|
||||
let mut state: SpirvSim = SpirvSim::new(Index::new(170, 256, 256), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn smoke_med_0x10080000_address_space() {
|
||||
// let mut state = SpirvSim::new(Index::new(171, 256, 256), 1e-3);
|
||||
// state.step();
|
||||
// }
|
||||
|
||||
// #[test]
|
||||
// fn smoke_med_0xf00000_indexing() {
|
||||
// let mut state = SpirvSim::new(Index::new(240, 256, 256), 1e-3);
|
||||
// state.step();
|
||||
// }
|
||||
|
||||
// #[test]
|
||||
// fn smoke_med252() {
|
||||
// let mut state = SpirvSim::new(Index::new(252, 252, 252), 1e-3);
|
||||
// state.step();
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn smoke_large() {
|
||||
let mut state: SpirvSim = SpirvSim::new(Index::new(326, 252, 160), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_not_multiple_of_4() {
|
||||
let mut state: SpirvSim = SpirvSim::new(Index::new(3, 2, 5), 1e-3);
|
||||
state.step();
|
||||
}
|
||||
|
||||
fn test_same_explicit(mut ref_state: SimState, mut dut_state: SpirvSim, step_iters: u64, steps_per_iter: u32) {
|
||||
for _ in 0..step_iters {
|
||||
ref_state.step_multiple(steps_per_iter, &NoopStimulus);
|
||||
@@ -732,6 +761,8 @@ mod test {
|
||||
test_same_explicit(cpu_state, spirv_state, step_iters, steps_per_iter);
|
||||
}
|
||||
|
||||
// TODO: port the rest of these tests to the test_backend macro
|
||||
|
||||
#[test]
|
||||
fn same_1_step() {
|
||||
test_same(0x1234, 1, 1, Index::new(4, 4, 4));
|
||||
|
Reference in New Issue
Block a user