From 8df001773fc0970a5e41b55d239d85f78511fffd Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 19 Aug 2022 04:26:58 -0700 Subject: [PATCH] eval_into: remove the `scale` parameter this actually seems to drop perf from 637 -> 595 ish? i suppose the compiler was able to fold the time multiplier in with the scale multipler? idk, somewhat surprised. --- crates/coremem/src/sim/spirv/mod.rs | 8 ++++---- crates/coremem/src/stim.rs | 25 ++++++++++++------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/coremem/src/sim/spirv/mod.rs b/crates/coremem/src/sim/spirv/mod.rs index ae7207e..cde1694 100644 --- a/crates/coremem/src/sim/spirv/mod.rs +++ b/crates/coremem/src/sim/spirv/mod.rs @@ -233,7 +233,7 @@ where let dim_len = dim.product_sum_usize(); let feature_size = self.feature_size(); let t_sec = self.time(); - let timestep = self.meta.time_step.cast(); + let timestep = self.meta.time_step; // we'll evaluate in parallel each row (const y/z) of the stimulus. let mut backing = Vec::new(); @@ -246,7 +246,7 @@ where let this_slice; (this_slice, undispatched_backing) = undispatched_backing.split_at_mut(dim.x() as usize); let view = OffsetDimSlice::new(Vec3u::new(0, y, z), Vec3u::new(this_slice.len() as u32, 1, 1), this_slice); - s.spawn(move |_| stim.eval_into(t_sec, feature_size, timestep, view)); + s.spawn(move |_| stim.eval_into(t_sec, feature_size, view)); } } }); @@ -258,8 +258,8 @@ where h.reserve(dim_len); for field in backing { - e.push(field.e.cast::()); - h.push(field.h.cast::()); + e.push(field.e.cast::() * timestep); + h.push(field.h.cast::() * timestep); } (e, h) diff --git a/crates/coremem/src/stim.rs b/crates/coremem/src/stim.rs index 47cdeb7..7e961ac 100644 --- a/crates/coremem/src/stim.rs +++ b/crates/coremem/src/stim.rs @@ -113,7 +113,7 @@ pub trait Stimulus: Sync { /// Return the (E, H) field which should be added PER-SECOND to the provided position/time. fn at(&self, t_sec: f32, feat_size: f32, loc: Index) -> Fields { let mut dat = OffsetDimSlice::new(loc.into(), Vec3u::new(1, 1, 1), [Fields::default()]); - self.eval_into(t_sec, feat_size, 1.0, dat.as_mut()); + self.eval_into(t_sec, feat_size, dat.as_mut()); let [fields] = dat.into_inner(); fields } @@ -121,9 +121,9 @@ pub trait Stimulus: Sync { // TODO: could remove the `scale` param if we parameterized this array over some `F: FnMut(Fields)` instead `Fields`. // that would also allow easier unzipping in the SpirvSim code. /// bulk version of at. evaluate several positions at once and populate the output region. - fn eval_into(&self, t_sec: f32, feat_size: f32, scale: f32, into: OffsetDimSlice<&mut [Fields]>) { + fn eval_into(&self, t_sec: f32, feat_size: f32, into: OffsetDimSlice<&mut [Fields]>) { for (idx, out) in into.enumerated() { - *out += self.at(t_sec, feat_size, Index::from(idx)) * scale; + *out += self.at(t_sec, feat_size, Index::from(idx)); } } } @@ -214,12 +214,11 @@ struct StimEvalInto<'a> { into: OffsetDimSlice<&'a mut [Fields]>, t_sec: f32, feat_size: f32, - scale: f32, } impl<'a, S: Stimulus> Visitor<&S> for StimEvalInto<'a> { fn visit(&mut self, next: &S) { - next.eval_into(self.t_sec, self.feat_size, self.scale, self.into.as_mut()); + next.eval_into(self.t_sec, self.feat_size, self.into.as_mut()); } } @@ -227,8 +226,8 @@ impl Stimulus for L where for<'a, 'b> &'a L: Visit>, { - fn eval_into(&self, t_sec: f32, feat_size: f32, scale: f32, into: OffsetDimSlice<&mut [Fields]>) { - let ev = StimEvalInto { t_sec, feat_size, scale, into }; + fn eval_into(&self, t_sec: f32, feat_size: f32, into: OffsetDimSlice<&mut [Fields]>) { + let ev = StimEvalInto { t_sec, feat_size, into }; self.visit(ev); } } @@ -274,9 +273,9 @@ impl Stimulus for StimuliVec { self.0.iter().map(|i| i.at(t_sec, feat_size, loc)) .fold(Fields::default(), core::ops::Add::add) } - fn eval_into(&self, t_sec: f32, feat_size: f32, scale: f32, mut into: OffsetDimSlice<&mut [Fields]>) { + fn eval_into(&self, t_sec: f32, feat_size: f32, mut into: OffsetDimSlice<&mut [Fields]>) { for i in &self.0 { - i.eval_into(t_sec, feat_size, scale, into.as_mut()); + i.eval_into(t_sec, feat_size, into.as_mut()); } } } @@ -558,9 +557,9 @@ impl Stimulus for Gated { Default::default() } } - fn eval_into(&self, t_sec: f32, feat_size: f32, scale: f32, into: OffsetDimSlice<&mut [Fields]>) { + fn eval_into(&self, t_sec: f32, feat_size: f32, into: OffsetDimSlice<&mut [Fields]>) { if self.active.contains(t_sec) { - self.inner.eval_into(t_sec, feat_size, scale, into); + self.inner.eval_into(t_sec, feat_size, into); } } } @@ -587,8 +586,8 @@ impl Stimulus for Shifted { fn at(&self, t_sec: f32, feat_size: f32, loc: Index) -> Fields { self.inner.at(t_sec - self.start_at, feat_size, loc) } - fn eval_into(&self, t_sec: f32, feat_size: f32, scale: f32, into: OffsetDimSlice<&mut [Fields]>) { - self.inner.eval_into(t_sec - self.start_at, feat_size, scale, into) + fn eval_into(&self, t_sec: f32, feat_size: f32, into: OffsetDimSlice<&mut [Fields]>) { + self.inner.eval_into(t_sec - self.start_at, feat_size, into) } }