From 859a7f8b18db96eee9d08c8efbae77f995c1e6f0 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 7 Dec 2022 09:46:33 +0000 Subject: [PATCH] rename `FullyGenericMaterial` -> `GenericMaterial` this naming was an artifact from the separate CPU/GPU material implementations. --- README.md | 4 +- crates/applications/sr_latch/src/main.rs | 2 +- crates/applications/wavefront/src/main.rs | 2 +- crates/coremem/benches/driver.rs | 4 +- crates/coremem/src/bin/bench.rs | 10 ++--- crates/coremem/src/sim/mod.rs | 4 +- crates/coremem/src/sim/spirv/mod.rs | 52 +++++++++++------------ crates/cross/src/mat/compound.rs | 32 +++++++------- crates/cross/src/mat/mod.rs | 2 +- crates/spirv_backend/src/lib.rs | 10 ++--- 10 files changed, 61 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 0942daa..8dc8886 100644 --- a/README.md +++ b/README.md @@ -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; +type Mat = mat::GenericMaterial; // simulate a volume of 401x401x1 discrete grid cells. let (width, height, depth) = (401, 401, 1); @@ -224,7 +224,7 @@ pub trait Material: 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. diff --git a/crates/applications/sr_latch/src/main.rs b/crates/applications/sr_latch/src/main.rs index f7989e4..99262fa 100644 --- a/crates/applications/sr_latch/src/main.rs +++ b/crates/applications/sr_latch/src/main.rs @@ -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::, WgpuBackend>::new( + let mut driver = Driver::new(SpirvSim::, WgpuBackend>::new( Meters::new(width, height, depth).to_index(feat_size), feat_size )); diff --git a/crates/applications/wavefront/src/main.rs b/crates/applications/wavefront/src/main.rs index 95f1350..9a1ec51 100644 --- a/crates/applications/wavefront/src/main.rs +++ b/crates/applications/wavefront/src/main.rs @@ -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; +type Mat = mat::GenericMaterial; fn main() { coremem::init_logging(); diff --git a/crates/coremem/benches/driver.rs b/crates/coremem/benches/driver.rs index 3878cb6..2810b7a 100644 --- a/crates/coremem/benches/driver.rs +++ b/crates/coremem/benches/driver.rs @@ -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; + type Mat = GenericMaterial; for size in &[10, 20, 40, 80, 160] { let sim = SpirvSim::::new(Index::new(*size, *size, *size), 1e-5); c.bench_with_input(BenchmarkId::new("Driver::step_spirv", size), &sim, |b, sim| { diff --git a/crates/coremem/src/bin/bench.rs b/crates/coremem/src/bin/bench.rs index 4852dc1..6d082aa 100644 --- a/crates/coremem/src/bin/bench.rs +++ b/crates/coremem/src/bin/bench.rs @@ -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(name: &str, fn main() { coremem::init_logging(); measure_steps("spirv/80", 1, Driver::new( - SpirvSim::, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3) + SpirvSim::, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3) )); measure_steps("spirv/80 step(2)", 2, Driver::new( - SpirvSim::, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3) + SpirvSim::, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3) )); measure_steps("spirv/80 step(10)", 10, Driver::new( - SpirvSim::, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3) + SpirvSim::, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3) )); measure_steps("spirv/80 step(100)", 100, Driver::new( - SpirvSim::, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3) + SpirvSim::, WgpuBackend>::new(Index::new(80, 80, 80), 1e-3) )); } diff --git a/crates/coremem/src/sim/mod.rs b/crates/coremem/src/sim/mod.rs index 93869cf..37125e5 100644 --- a/crates/coremem/src/sim/mod.rs +++ b/crates/coremem/src/sim/mod.rs @@ -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 = SpirvSim, CpuBackend>; +pub type GenericSim = SpirvSim, CpuBackend>; /// Conceptually, one cell looks like this (in 2d): diff --git a/crates/coremem/src/sim/spirv/mod.rs b/crates/coremem/src/sim/spirv/mod.rs index 38cebd0..cb40887 100644 --- a/crates/coremem/src/sim/spirv/mod.rs +++ b/crates/coremem/src/sim/spirv/mod.rs @@ -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 { /// 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, B=WgpuBackend> +pub struct SpirvSim, B=WgpuBackend> where M: 'static { meta: SimMeta, @@ -78,7 +78,7 @@ impl Clone for SpirvSim { impl AbstractSim for SpirvSim where R: Real, - M: Send + Sync + Material + Clone + Into>, + M: Send + Sync + Material + Clone + Into>, B: Send + Sync + SimBackend, { type Real = R; @@ -204,7 +204,7 @@ impl SpirvSim { impl SpirvSim where R: Real, - M: Send + Sync + Material + Clone + Into>, + M: Send + Sync + Material + Clone + Into>, B: Send + Sync + SimBackend, { fn eval_stimulus<'a, S: Stimulus>(&self, stim: &'a S) @@ -366,7 +366,7 @@ mod test { #[test] fn accessors() { let size = Index::new(15, 17, 19); - let mut state = SpirvSim::, $backend>::new(size, 1e-6); + let mut state = SpirvSim::, $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::, $backend>::new( + let mut state = SpirvSim::, $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::, $backend>::new( + let mut state = SpirvSim::, $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>>(mat: M) -> (f32, f32) { - let mut state = SpirvSim::, $backend>::new( + fn conductor_test>>(mat: M) -> (f32, f32) { + let mut state = SpirvSim::, $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::, $backend>::new( + let mut state = SpirvSim::, $backend>::new( Index::new(8, 8, 8), 1e-3 ); state.step(); } #[test] fn smoke_med_7bit() { - let mut state = SpirvSim::, $backend>::new( + let mut state = SpirvSim::, $backend>::new( Index::new(124, 124, 124), 1e-3 ); state.step(); } #[test] fn smoke_med128() { - let mut state = SpirvSim::, $backend>::new( + let mut state = SpirvSim::, $backend>::new( Index::new(128, 128, 128), 1e-3 ); state.step(); } #[test] fn smoke_med_23bit() { - let mut state = SpirvSim::, $backend>::new( + let mut state = SpirvSim::, $backend>::new( Index::new(127, 256, 256), 1e-3 ); state.step(); } #[test] fn smoke_med_0x800000_indexing() { - let mut state = SpirvSim::, $backend>::new( + let mut state = SpirvSim::, $backend>::new( Index::new(128, 256, 256), 1e-3 ); state.step(); } #[test] fn smoke_med_0x800000_address_space() { - let mut state = SpirvSim::, $backend>::new( + let mut state = SpirvSim::, $backend>::new( Index::new(170, 256, 256), 1e-3 ); state.step(); } #[test] fn smoke_large() { - let mut state = SpirvSim::, $backend>::new( + let mut state = SpirvSim::, $backend>::new( Index::new(326, 252, 160), 1e-3 ); state.step(); } #[test] fn smoke_not_multiple_of_4() { - let mut state = SpirvSim::, $backend>::new( + let mut state = SpirvSim::, $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::, $backend>::new(size, 1e-3); + let mut dut_state = SpirvSim::, $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, $backend>, z: u32, frame: u32) -> (R32, R32) { + fn ray(z_origin: i32, wavelength_cells: u32, sim: &SpirvSim, $backend>, z: u32, frame: u32) -> (R32, R32) { let time_step = sim.timestep().cast::(); let feat_size = sim.feature_size().cast::(); @@ -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, $backend>) { + fn inject_ray(z_origin: i32, wavelength_cells: u32, sim: &mut SpirvSim, $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::, $backend>::new(size, feat_size); + let mut sim = SpirvSim::, $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::, $backend>::new(size, feat_size); + let mut sim = SpirvSim::, $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>( - mut cpu_state: SpirvSim, CpuBackend>, - mut wgpu_state: SpirvSim, WgpuBackend>, + mut cpu_state: SpirvSim, CpuBackend>, + mut wgpu_state: SpirvSim, 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, CpuBackend> = + let mut cpu_state: SpirvSim, CpuBackend> = SpirvSim::new(size, 1e-3); - let mut wgpu_state: SpirvSim, WgpuBackend> = + let mut wgpu_state: SpirvSim, WgpuBackend> = SpirvSim::new(size, 1e-3); let stim = stim::Fields::new_e(Vec3::new(1.0e15, 2.0e15, -3.0e15).cast::()); for _ in 0..5 { diff --git a/crates/cross/src/mat/compound.rs b/crates/cross/src/mat/compound.rs index 4dc8348..93145bc 100644 --- a/crates/cross/src/mat/compound.rs +++ b/crates/cross/src/mat/compound.rs @@ -65,12 +65,12 @@ impl, I> Visitor for IntoDispatcher { } } -impl Into> for DiscrMat2 +impl Into> for DiscrMat2 where - M0: DiscriminantCodable + Into> + Copy, - M1: Into> + Copy, + M0: DiscriminantCodable + Into> + Copy, + M1: Into> + Copy, { - fn into(self) -> FullyGenericMaterial { + fn into(self) -> GenericMaterial { self.0.dispatch(IntoDispatcher) } } @@ -88,13 +88,13 @@ where } } -impl Into> for DiscrMat3 +impl Into> for DiscrMat3 where - M0: DiscriminantCodable + Into> + Copy, - M1: Into> + Copy, - M2: Into> + Copy, + M0: DiscriminantCodable + Into> + Copy, + M1: Into> + Copy, + M2: Into> + Copy, { - fn into(self) -> FullyGenericMaterial { + fn into(self) -> GenericMaterial { self.0.dispatch(IntoDispatcher) } } @@ -195,38 +195,38 @@ impl From for GenericMagnetic { /// "Fully Generic" in that one can set both the conductivity, /// and set any of the well-known magnetic materials, simultaneously. -pub type FullyGenericMaterial = DualMaterial< +pub type GenericMaterial = DualMaterial< AnisomorphicConductor, GenericMagnetic, >; -impl From> for FullyGenericMaterial { +impl From> for GenericMaterial { fn from(mat: AnisomorphicConductor) -> Self { Self::new(mat, Default::default()) } } -impl From> for FullyGenericMaterial { +impl From> for GenericMaterial { fn from(mat: MBPgram) -> Self { Self::new(Default::default(), mat.into()) } } -impl From> for FullyGenericMaterial { +impl From> for GenericMaterial { fn from(mat: MHPgram) -> Self { Self::new(Default::default(), mat.into()) } } -impl From for FullyGenericMaterial { +impl From for GenericMaterial { fn from(mat: Vacuum) -> Self { Self::new(Default::default(), mat.into()) } } -impl From> for FullyGenericMaterial { +impl From> for GenericMaterial { fn from(mat: IsomorphicConductor) -> Self { let mat: AnisomorphicConductor = mat.into(); mat.into() } } -impl From for FullyGenericMaterial { +impl From for GenericMaterial { fn from(mat: Ferroxcube3R1MH) -> Self { let mat: MHPgram = mat.into(); mat.into() diff --git a/crates/cross/src/mat/mod.rs b/crates/cross/src/mat/mod.rs index 23cdbdf..fefa40d 100644 --- a/crates/cross/src/mat/mod.rs +++ b/crates/cross/src/mat/mod.rs @@ -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}; diff --git a/crates/spirv_backend/src/lib.rs b/crates/spirv_backend/src/lib.rs index b2a0e81..83e8824 100644 --- a/crates/spirv_backend/src/lib.rs +++ b/crates/spirv_backend/src/lib.rs @@ -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, step_h_generic_material_f32, step_e_generic_material_f32); +steps!(f32, GenericMaterial, step_h_generic_material_f32, step_e_generic_material_f32); steps!(f32, Iso3R1, step_h_iso_3r1_f32, step_e_iso_3r1_f32); -steps!(R32, FullyGenericMaterial, step_h_generic_material_r32, step_e_generic_material_r32); +steps!(R32, GenericMaterial, step_h_generic_material_r32, step_e_generic_material_r32); steps!(R32, Iso3R1, 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, step_h_generic_material_f64, step_e_generic_material_f64); +// steps!(f64, GenericMaterial, step_h_generic_material_f64, step_e_generic_material_f64); // steps!(f64, Iso3R1, step_h_iso_3r1_f64, step_e_iso_3r1_f64); -// steps!(R64, FullyGenericMaterial, step_h_generic_material_r64, step_e_generic_material_r64); +// steps!(R64, GenericMaterial, step_h_generic_material_r64, step_e_generic_material_r64); // steps!(R64, Iso3R1, step_h_iso_3r1_r64, step_e_iso_3r1_r64);