rename `FullyGenericMaterial` -> `GenericMaterial`

this naming was an artifact from the separate CPU/GPU material implementations.
This commit is contained in:
colin 2022-12-07 09:46:33 +00:00
parent 6d73150fb6
commit 859a7f8b18
10 changed files with 61 additions and 61 deletions

View File

@ -20,7 +20,7 @@ here's an excerpt from the [wavefront](crates/applications/wavefront/src/main.rs
```rust
// use a general-purpose material, capable of representing vacuum, conductors, and magnetic materials.
type Mat = mat::FullyGenericMaterial<f32>;
type Mat = mat::GenericMaterial<f32>;
// simulate a volume of 401x401x1 discrete grid cells.
let (width, height, depth) = (401, 401, 1);
@ -224,7 +224,7 @@ pub trait Material<R: Real>: Sized {
```
to add a new material:
- for `CpuBackend` simulations: just implement this trait on your own type and instantiate a `SpirvSim` specialized over that material instead of `FullyGenericMaterial`.
- for `CpuBackend` simulations: just implement this trait on your own type and instantiate a `SpirvSim` specialized over that material instead of `GenericMaterial`.
- for `WgpuBackend` simulations, do the above and add a spirv entry-point specialized to your material. scroll to the bottom of `crates/spirv_backend/src/lib.rs` and follow the examples.
as can be seen, the Material trait is fairly restrictive. its methods are immutable, and it doesn't even have access to the entire cell state (only the cell's M value, during `move_b_vec`). i'd be receptive to a PR or request that exposes more cell state or mutability: this is just an artifact of me tailoring this specifically to the class of materials i intended to use it for.

View File

@ -59,7 +59,7 @@ fn main() {
let coupling_region = Torus::new_xz(Meters::new(0.5*(ferro1_center + ferro2_center), ferro_center_y, half_depth), wire_coupling_major, wire_minor);
let sense_region = Torus::new_xz(Meters::new(ferro2_center + ferro_major, ferro_center_y, half_depth), wire_major, wire_minor);
let mut driver = Driver::new(SpirvSim::<f32, mat::FullyGenericMaterial<f32>, WgpuBackend>::new(
let mut driver = Driver::new(SpirvSim::<f32, mat::GenericMaterial<f32>, WgpuBackend>::new(
Meters::new(width, height, depth).to_index(feat_size), feat_size
));

View File

@ -14,7 +14,7 @@ use coremem::sim::spirv::{self, SpirvSim};
use coremem::stim::{Fields, ModulatedVectorField, Pulse, RegionGated};
use coremem::cross::vec::Vec3;
type Mat = mat::FullyGenericMaterial<f32>;
type Mat = mat::GenericMaterial<f32>;
fn main() {
coremem::init_logging();

View File

@ -1,12 +1,12 @@
use coremem::Driver;
use coremem::geom::Index;
use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr, FullyGenericMaterial};
use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr, GenericMaterial};
use coremem::sim::spirv::{SpirvSim, WgpuBackend};
use criterion::{BenchmarkId, criterion_group, criterion_main, Criterion};
pub fn bench_step_spirv(c: &mut Criterion) {
type Mat = FullyGenericMaterial<f32>;
type Mat = GenericMaterial<f32>;
for size in &[10, 20, 40, 80, 160] {
let sim = SpirvSim::<f32, Mat, WgpuBackend>::new(Index::new(*size, *size, *size), 1e-5);
c.bench_with_input(BenchmarkId::new("Driver::step_spirv", size), &sim, |b, sim| {

View File

@ -1,7 +1,7 @@
use coremem::{self, Driver, AbstractSim};
use coremem::sim::spirv::{SpirvSim, WgpuBackend};
use coremem::sim::units::Frame;
use coremem::cross::mat::FullyGenericMaterial;
use coremem::cross::mat::GenericMaterial;
use coremem::geom::Index;
use std::time::{Instant, Duration};
@ -25,16 +25,16 @@ fn measure_steps<S: AbstractSim + Clone + Default + Send + 'static>(name: &str,
fn main() {
coremem::init_logging();
measure_steps("spirv/80", 1, Driver::new(
SpirvSim::<f32, FullyGenericMaterial<f32>, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3)
SpirvSim::<f32, GenericMaterial<f32>, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3)
));
measure_steps("spirv/80 step(2)", 2, Driver::new(
SpirvSim::<f32, FullyGenericMaterial<f32>, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3)
SpirvSim::<f32, GenericMaterial<f32>, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3)
));
measure_steps("spirv/80 step(10)", 10, Driver::new(
SpirvSim::<f32, FullyGenericMaterial<f32>, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3)
SpirvSim::<f32, GenericMaterial<f32>, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3)
));
measure_steps("spirv/80 step(100)", 100, Driver::new(
SpirvSim::<f32, FullyGenericMaterial<f32>, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3)
SpirvSim::<f32, GenericMaterial<f32>, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3)
));
}

View File

@ -1,6 +1,6 @@
use crate::diagnostics::SyncDiagnostics;
use crate::geom::{Coord, Cube, Index, InvertedRegion, Region};
use crate::cross::mat::{FullyGenericMaterial, Material};
use crate::cross::mat::{GenericMaterial, Material};
use crate::cross::real::Real;
use crate::cross::step::SimMeta;
use crate::cross::vec::{Vec3, Vec3u};
@ -14,7 +14,7 @@ pub mod units;
use spirv::{CpuBackend, SpirvSim};
pub type GenericSim<R> = SpirvSim<R, FullyGenericMaterial<R>, CpuBackend>;
pub type GenericSim<R> = SpirvSim<R, GenericMaterial<R>, CpuBackend>;
/// Conceptually, one cell looks like this (in 2d):

View File

@ -8,7 +8,7 @@ use crate::geom::Index;
use crate::real::Real;
use crate::sim::{AbstractSim, Fields, GenericSim};
use crate::stim::{RenderedStimulus, Stimulus};
use coremem_cross::mat::{FullyGenericMaterial, Material};
use coremem_cross::mat::{GenericMaterial, Material};
use coremem_cross::step::SimMeta;
use coremem_cross::vec::Vec3;
@ -41,7 +41,7 @@ pub trait SimBackend<R, M> {
/// Wrapper around an inner state object which offloads stepping onto a spirv backend (e.g. GPU).
#[derive(Default, Serialize, Deserialize)]
// TODO: remove default R/M
pub struct SpirvSim<R=f32, M=FullyGenericMaterial<R>, B=WgpuBackend>
pub struct SpirvSim<R=f32, M=GenericMaterial<R>, B=WgpuBackend>
where M: 'static
{
meta: SimMeta<R>,
@ -78,7 +78,7 @@ impl<R: Clone, M: Clone, B: Default> Clone for SpirvSim<R, M, B> {
impl<R, M, B> AbstractSim for SpirvSim<R, M, B>
where
R: Real,
M: Send + Sync + Material<R> + Clone + Into<FullyGenericMaterial<R>>,
M: Send + Sync + Material<R> + Clone + Into<GenericMaterial<R>>,
B: Send + Sync + SimBackend<R, M>,
{
type Real = R;
@ -204,7 +204,7 @@ impl<R, M, B> SpirvSim<R, M, B> {
impl<R, M, B> SpirvSim<R, M, B>
where
R: Real,
M: Send + Sync + Material<R> + Clone + Into<FullyGenericMaterial<R>>,
M: Send + Sync + Material<R> + Clone + Into<GenericMaterial<R>>,
B: Send + Sync + SimBackend<R, M>,
{
fn eval_stimulus<'a, S: Stimulus<R>>(&self, stim: &'a S)
@ -366,7 +366,7 @@ mod test {
#[test]
fn accessors() {
let size = Index::new(15, 17, 19);
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(size, 1e-6);
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(size, 1e-6);
assert_eq!(state.width(), 15);
assert_eq!(state.height(), 17);
assert_eq!(state.depth(), 19);
@ -379,7 +379,7 @@ mod test {
#[test]
fn energy_conservation_over_time() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index((2001, 1, 1).into()), 1e-6
);
let stim = smooth_pulse_at(state.timestep(), state.feature_size(), Index::new(1000, 0, 0), 100);
@ -393,7 +393,7 @@ mod test {
#[test]
fn sane_boundary_conditions() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index((21, 21, 21).into()), 1e-6
);
let stim = smooth_pulse_at(state.timestep(), state.feature_size(), Index::new(10, 10, 10), 40);
@ -410,8 +410,8 @@ mod test {
/// Fill the world with the provided material and a stimulus.
/// Measure energy at the start, and then again after advancing many steps.
/// Return these two measurements (energy(t=0), energy(t=~=1000))
fn conductor_test<M: Into<FullyGenericMaterial<R32>>>(mat: M) -> (f32, f32) {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
fn conductor_test<M: Into<GenericMaterial<R32>>>(mat: M) -> (f32, f32) {
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(201, 1, 1), 1e-6
);
state.fill_region(&WorldRegion, mat.into());
@ -458,56 +458,56 @@ mod test {
#[test]
fn smoke_small() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(8, 8, 8), 1e-3
);
state.step();
}
#[test]
fn smoke_med_7bit() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(124, 124, 124), 1e-3
);
state.step();
}
#[test]
fn smoke_med128() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(128, 128, 128), 1e-3
);
state.step();
}
#[test]
fn smoke_med_23bit() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(127, 256, 256), 1e-3
);
state.step();
}
#[test]
fn smoke_med_0x800000_indexing() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(128, 256, 256), 1e-3
);
state.step();
}
#[test]
fn smoke_med_0x800000_address_space() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(170, 256, 256), 1e-3
);
state.step();
}
#[test]
fn smoke_large() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(326, 252, 160), 1e-3
);
state.step();
}
#[test]
fn smoke_not_multiple_of_4() {
let mut state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(
let mut state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(
Index::new(3, 2, 5), 1e-3
);
state.step();
@ -519,7 +519,7 @@ mod test {
// XXX This doesn't do anything, except make sure we don't crash!
use rand::{Rng as _, SeedableRng as _};
let mut rng = rand::rngs::StdRng::seed_from_u64(seed);
let mut dut_state = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(size, 1e-3);
let mut dut_state = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(size, 1e-3);
for z in 0..size.z() {
for y in 0..size.y() {
@ -561,7 +561,7 @@ mod test {
/// returns the (E, H) value of the first cycle of a rightward-traveling ray at a given point in space/time.
/// E amplitude of the ray is assumed to be 1; H is scaled appropriately to ensure that.
fn ray(z_origin: i32, wavelength_cells: u32, sim: &SpirvSim<R32, FullyGenericMaterial<R32>, $backend>, z: u32, frame: u32) -> (R32, R32) {
fn ray(z_origin: i32, wavelength_cells: u32, sim: &SpirvSim<R32, GenericMaterial<R32>, $backend>, z: u32, frame: u32) -> (R32, R32) {
let time_step = sim.timestep().cast::<R32>();
let feat_size = sim.feature_size().cast::<R32>();
@ -580,7 +580,7 @@ mod test {
/// inject one cycle of a rightward-traveling ray with the provided parameters into
/// the sim.
fn inject_ray(z_origin: i32, wavelength_cells: u32, sim: &mut SpirvSim<R32, FullyGenericMaterial<R32>, $backend>) {
fn inject_ray(z_origin: i32, wavelength_cells: u32, sim: &mut SpirvSim<R32, GenericMaterial<R32>, $backend>) {
// inject the wave at t=0
for z in 0..sim.size().z() {
let (e, h) = ray(z_origin, wavelength_cells, &sim, z, 0);
@ -600,7 +600,7 @@ mod test {
fn ray_propagation() {
let size = Index::new(1, 1, 1536);
let feat_size = 1e-3;
let mut sim = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(size, feat_size);
let mut sim = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(size, feat_size);
inject_ray(512, 512, &mut sim);
@ -627,7 +627,7 @@ mod test {
fn conductor_reflection() {
let size = Index::new(1, 1, 2048);
let feat_size = 1e-3;
let mut sim = SpirvSim::<R32, FullyGenericMaterial<R32>, $backend>::new(size, feat_size);
let mut sim = SpirvSim::<R32, GenericMaterial<R32>, $backend>::new(size, feat_size);
inject_ray(512, 512, &mut sim);
@ -672,8 +672,8 @@ mod test {
use super::*;
use crate::stim::{NoopStimulus, RngStimulus};
fn test_same_explicit<S: Stimulus<R32>>(
mut cpu_state: SpirvSim<R32, FullyGenericMaterial<R32>, CpuBackend>,
mut wgpu_state: SpirvSim<R32, FullyGenericMaterial<R32>, WgpuBackend>,
mut cpu_state: SpirvSim<R32, GenericMaterial<R32>, CpuBackend>,
mut wgpu_state: SpirvSim<R32, GenericMaterial<R32>, WgpuBackend>,
stim: &S,
step_iters: u64,
steps_per_iter: u32
@ -810,9 +810,9 @@ mod test {
#[test]
fn step_multiple_with_stim() {
let size = Index::new(4, 12, 8);
let mut cpu_state: SpirvSim<R32, FullyGenericMaterial<R32>, CpuBackend> =
let mut cpu_state: SpirvSim<R32, GenericMaterial<R32>, CpuBackend> =
SpirvSim::new(size, 1e-3);
let mut wgpu_state: SpirvSim<R32, FullyGenericMaterial<R32>, WgpuBackend> =
let mut wgpu_state: SpirvSim<R32, GenericMaterial<R32>, WgpuBackend> =
SpirvSim::new(size, 1e-3);
let stim = stim::Fields::new_e(Vec3::new(1.0e15, 2.0e15, -3.0e15).cast::<R32>());
for _ in 0..5 {

View File

@ -65,12 +65,12 @@ impl<P: Peano, T: Into<I>, I> Visitor<P, T, I> for IntoDispatcher {
}
}
impl<R, M0, M1> Into<FullyGenericMaterial<R>> for DiscrMat2<M0, M1>
impl<R, M0, M1> Into<GenericMaterial<R>> for DiscrMat2<M0, M1>
where
M0: DiscriminantCodable<P2> + Into<FullyGenericMaterial<R>> + Copy,
M1: Into<FullyGenericMaterial<R>> + Copy,
M0: DiscriminantCodable<P2> + Into<GenericMaterial<R>> + Copy,
M1: Into<GenericMaterial<R>> + Copy,
{
fn into(self) -> FullyGenericMaterial<R> {
fn into(self) -> GenericMaterial<R> {
self.0.dispatch(IntoDispatcher)
}
}
@ -88,13 +88,13 @@ where
}
}
impl<R, M0, M1, M2> Into<FullyGenericMaterial<R>> for DiscrMat3<M0, M1, M2>
impl<R, M0, M1, M2> Into<GenericMaterial<R>> for DiscrMat3<M0, M1, M2>
where
M0: DiscriminantCodable<P3> + Into<FullyGenericMaterial<R>> + Copy,
M1: Into<FullyGenericMaterial<R>> + Copy,
M2: Into<FullyGenericMaterial<R>> + Copy,
M0: DiscriminantCodable<P3> + Into<GenericMaterial<R>> + Copy,
M1: Into<GenericMaterial<R>> + Copy,
M2: Into<GenericMaterial<R>> + Copy,
{
fn into(self) -> FullyGenericMaterial<R> {
fn into(self) -> GenericMaterial<R> {
self.0.dispatch(IntoDispatcher)
}
}
@ -195,38 +195,38 @@ impl<R: Real> From<Vacuum> for GenericMagnetic<R> {
/// "Fully Generic" in that one can set both the conductivity,
/// and set any of the well-known magnetic materials, simultaneously.
pub type FullyGenericMaterial<R> = DualMaterial<
pub type GenericMaterial<R> = DualMaterial<
AnisomorphicConductor<R>,
GenericMagnetic<R>,
>;
impl<R: Real> From<AnisomorphicConductor<R>> for FullyGenericMaterial<R> {
impl<R: Real> From<AnisomorphicConductor<R>> for GenericMaterial<R> {
fn from(mat: AnisomorphicConductor<R>) -> Self {
Self::new(mat, Default::default())
}
}
impl<R: Real> From<MBPgram<R>> for FullyGenericMaterial<R> {
impl<R: Real> From<MBPgram<R>> for GenericMaterial<R> {
fn from(mat: MBPgram<R>) -> Self {
Self::new(Default::default(), mat.into())
}
}
impl<R: Real> From<MHPgram<R>> for FullyGenericMaterial<R> {
impl<R: Real> From<MHPgram<R>> for GenericMaterial<R> {
fn from(mat: MHPgram<R>) -> Self {
Self::new(Default::default(), mat.into())
}
}
impl<R: Real> From<Vacuum> for FullyGenericMaterial<R> {
impl<R: Real> From<Vacuum> for GenericMaterial<R> {
fn from(mat: Vacuum) -> Self {
Self::new(Default::default(), mat.into())
}
}
impl<R: Real> From<IsomorphicConductor<R>> for FullyGenericMaterial<R> {
impl<R: Real> From<IsomorphicConductor<R>> for GenericMaterial<R> {
fn from(mat: IsomorphicConductor<R>) -> Self {
let mat: AnisomorphicConductor<R> = mat.into();
mat.into()
}
}
impl<R: Real> From<Ferroxcube3R1MH> for FullyGenericMaterial<R> {
impl<R: Real> From<Ferroxcube3R1MH> for GenericMaterial<R> {
fn from(mat: Ferroxcube3R1MH) -> Self {
let mat: MHPgram<R> = mat.into();
mat.into()

View File

@ -5,7 +5,7 @@ mod compound;
mod conductor;
mod mb_pgram;
mod mh_pgram;
pub use compound::{FullyGenericMaterial, IsoConductorOr};
pub use compound::{GenericMaterial, IsoConductorOr};
pub use conductor::{AnisomorphicConductor, IsomorphicConductor};
pub use mb_pgram::MBPgram;
pub use mh_pgram::{Ferroxcube3R1MH, MHPgram};

View File

@ -15,7 +15,7 @@ use spirv_std::macros::spirv;
mod adapt;
mod support;
use coremem_cross::mat::{Ferroxcube3R1MH, FullyGenericMaterial, IsoConductorOr};
use coremem_cross::mat::{Ferroxcube3R1MH, GenericMaterial, IsoConductorOr};
use coremem_cross::real::R32;
use coremem_cross::step::SimMeta;
use coremem_cross::vec::{Vec3, Vec3u};
@ -80,15 +80,15 @@ macro_rules! steps {
};
}
steps!(f32, FullyGenericMaterial<f32>, step_h_generic_material_f32, step_e_generic_material_f32);
steps!(f32, GenericMaterial<f32>, step_h_generic_material_f32, step_e_generic_material_f32);
steps!(f32, Iso3R1<f32>, step_h_iso_3r1_f32, step_e_iso_3r1_f32);
steps!(R32, FullyGenericMaterial<R32>, step_h_generic_material_r32, step_e_generic_material_r32);
steps!(R32, GenericMaterial<R32>, step_h_generic_material_r32, step_e_generic_material_r32);
steps!(R32, Iso3R1<R32>, step_h_iso_3r1_r32, step_e_iso_3r1_r32);
// these should work, but require OpCapability Float64
// we disable them for compatibility concerns: use the Cpu if you need f64 or temporarily uncomment
// this and add the capability to the WgpuBackend driver.
// steps!(f64, FullyGenericMaterial<f64>, step_h_generic_material_f64, step_e_generic_material_f64);
// steps!(f64, GenericMaterial<f64>, step_h_generic_material_f64, step_e_generic_material_f64);
// steps!(f64, Iso3R1<f64>, step_h_iso_3r1_f64, step_e_iso_3r1_f64);
// steps!(R64, FullyGenericMaterial<R64>, step_h_generic_material_r64, step_e_generic_material_r64);
// steps!(R64, GenericMaterial<R64>, step_h_generic_material_r64, step_e_generic_material_r64);
// steps!(R64, Iso3R1<R64>, step_h_iso_3r1_r64, step_e_iso_3r1_r64);