driver: remove new_spirv method

This commit is contained in:
2022-07-28 01:52:09 -07:00
parent 50af5927df
commit 7a6bbf06a5
5 changed files with 33 additions and 32 deletions

View File

@@ -2,13 +2,14 @@
//! to couple them. i parameterize the entire setup over a bunch of different factors in order to //! to couple them. i parameterize the entire setup over a bunch of different factors in order to
//! search for the conditions which maximize energy transfer from the one core to the other. //! search for the conditions which maximize energy transfer from the one core to the other.
use coremem::{Driver, mat, meas, SpirvDriver}; use coremem::{Driver, mat, meas};
use coremem::geom::{region, Cube, Dilate, Memoize, Meters, Spiral, SwapYZ, Torus, Translate, Wrap}; use coremem::geom::{region, Cube, Dilate, Memoize, Meters, Spiral, SwapYZ, Torus, Translate, Wrap};
use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr}; use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr};
use coremem::real::{R32, Real as _}; use coremem::real::{R32, Real as _};
use coremem::render::CsvRenderer; use coremem::render::CsvRenderer;
use coremem::stim::{CurlStimulus, Exp1, Gated, Sinusoid1, TimeVarying as _}; use coremem::sim::spirv::{SpirvSim, WgpuBackend};
use coremem::sim::units::{Seconds, Time as _}; use coremem::sim::units::{Seconds, Time as _};
use coremem::stim::{CurlStimulus, Exp1, Gated, Sinusoid1, TimeVarying as _};
use coremem::util::cache::DiskCache; use coremem::util::cache::DiskCache;
use log::{error, info, warn}; use log::{error, info, warn};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -389,7 +390,9 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
p.clock_type, p.clock_type,
); );
let mut driver: SpirvDriver<f32, Mat> = Driver::new_spirv(g.dim, p.geom.feat_size); let mut driver = Driver::new_with_state(SpirvSim::<f32, Mat, WgpuBackend>::new(
g.dim.to_index(p.geom.feat_size), p.geom.feat_size
));
driver.set_steps_per_stim(1000); driver.set_steps_per_stim(1000);
if !driver.add_state_file(&*format!("{}/state.bc", prefix), 16000) { if !driver.add_state_file(&*format!("{}/state.bc", prefix), 16000) {
// mu_r=881.33, starting at H=25 to H=75. // mu_r=881.33, starting at H=25 to H=75.
@@ -414,7 +417,7 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
info!("loaded state file: skipping geometry calculations"); info!("loaded state file: skipping geometry calculations");
} }
let add_drive_sine_pulse = |driver: &mut SpirvDriver<f32, Mat>, region: &Torus, start: f32, duration: f32, amp: f32| { let add_drive_sine_pulse = |driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| {
let wave = Sinusoid1::from_wavelength(amp, duration * 2.0) let wave = Sinusoid1::from_wavelength(amp, duration * 2.0)
.half_cycle() .half_cycle()
.shifted(start); .shifted(start);
@@ -426,7 +429,7 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
)); ));
}; };
let add_drive_square_pulse = |driver: &mut SpirvDriver<f32, Mat>, region: &Torus, start: f32, duration: f32, amp: f32| { let add_drive_square_pulse = |driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| {
let wave = Gated::new(amp, start, start+duration); let wave = Gated::new(amp, start, start+duration);
driver.add_stimulus(CurlStimulus::new( driver.add_stimulus(CurlStimulus::new(
region.clone(), region.clone(),
@@ -436,7 +439,7 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
)); ));
}; };
let add_drive_exp_pulse = |driver: &mut SpirvDriver<f32, Mat>, region: &Torus, start: f32, duration: f32, amp: f32| { let add_drive_exp_pulse = |driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| {
let wave = Exp1::new_at(amp, start, 0.5*duration); let wave = Exp1::new_at(amp, start, 0.5*duration);
driver.add_stimulus(CurlStimulus::new( driver.add_stimulus(CurlStimulus::new(
region.clone(), region.clone(),
@@ -447,11 +450,11 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
}; };
// step function: "permanently" increase the current by `amp`. // step function: "permanently" increase the current by `amp`.
let _add_drive_step = |driver: &mut SpirvDriver<f32, Mat>, region: &Torus, start: f32, amp: f32| { let _add_drive_step = |driver: &mut Driver<_>, region: &Torus, start: f32, amp: f32| {
add_drive_square_pulse(driver, region, start, 1.0 /* effectively infinite duration */, amp); add_drive_square_pulse(driver, region, start, 1.0 /* effectively infinite duration */, amp);
}; };
let add_drive_pulse = |ty: PulseType, driver: &mut SpirvDriver<f32, Mat>, region: &Torus, start: f32, duration: f32, amp: f32| { let add_drive_pulse = |ty: PulseType, driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| {
match ty { match ty {
PulseType::Square => add_drive_square_pulse(driver, region, start, duration, amp), PulseType::Square => add_drive_square_pulse(driver, region, start, duration, amp),
PulseType::Sine => add_drive_sine_pulse(driver, region, start, duration, amp), PulseType::Sine => add_drive_sine_pulse(driver, region, start, duration, amp),

View File

@@ -36,10 +36,11 @@
//! $ pushd crates/coremem; cargo run --release --bin viewer ../../out/applications/multi_core_inverter/0/ ; popd //! $ pushd crates/coremem; cargo run --release --bin viewer ../../out/applications/multi_core_inverter/0/ ; popd
//! ``` //! ```
use coremem::geom::{Meters, Torus}; use coremem::geom::{Coord as _, Meters, Torus};
use coremem::sim::spirv::{SpirvSim, WgpuBackend};
use coremem::sim::units::Seconds; use coremem::sim::units::Seconds;
use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr, IsomorphicConductor}; use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr, IsomorphicConductor};
use coremem::{Driver, SpirvDriver}; use coremem::Driver;
type Mat = IsoConductorOr<f32, Ferroxcube3R1MH>; type Mat = IsoConductorOr<f32, Ferroxcube3R1MH>;
@@ -76,7 +77,9 @@ fn main() {
let ferro_mat = wire_mat; let ferro_mat = wire_mat;
// let ferro_mat = Ferroxcube3R1MH::new(); // uncomment when ready to simulate for real // let ferro_mat = Ferroxcube3R1MH::new(); // uncomment when ready to simulate for real
let mut driver: SpirvDriver<f32, Mat> = Driver::new_spirv(sim_bounds, feat_size); let mut driver = Driver::new_with_state(SpirvSim::<f32, Mat, WgpuBackend>::new(
sim_bounds.to_index(feat_size), feat_size,
));
driver.add_classical_boundary(sim_padding); driver.add_classical_boundary(sim_padding);
driver.fill_region(&drive0, wire_mat); driver.fill_region(&drive0, wire_mat);
driver.fill_region(&sense3, wire_mat); driver.fill_region(&sense3, wire_mat);

View File

@@ -3,8 +3,9 @@
/// the SR latch in this example is wired to a downstream latch, mostly to show that it's /// the SR latch in this example is wired to a downstream latch, mostly to show that it's
/// possible to transfer the state (with some limitation) from one latch to another. /// possible to transfer the state (with some limitation) from one latch to another.
use coremem::{Driver, mat, meas, SpirvDriver}; use coremem::{Driver, mat, meas};
use coremem::geom::{Meters, Torus}; use coremem::geom::{Coord as _, Meters, Torus};
use coremem::sim::spirv::{SpirvSim, WgpuBackend};
use coremem::sim::units::Seconds; use coremem::sim::units::Seconds;
use coremem::stim::{CurlStimulus, Sinusoid1, TimeVarying as _}; use coremem::stim::{CurlStimulus, Sinusoid1, TimeVarying as _};
@@ -58,7 +59,9 @@ 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 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 sense_region = Torus::new_xz(Meters::new(ferro2_center + ferro_major, ferro_center_y, half_depth), wire_major, wire_minor);
let mut driver: SpirvDriver<f32, mat::FullyGenericMaterial<f32>> = Driver::new_spirv(Meters::new(width, height, depth), feat_size); let mut driver = Driver::new_with_state(SpirvSim::<f32, mat::FullyGenericMaterial<f32>, WgpuBackend>::new(
Meters::new(width, height, depth).to_index(feat_size), feat_size
));
// mu_r=881.33, starting at H=25 to H=75. // mu_r=881.33, starting at H=25 to H=75.
driver.fill_region(&ferro1_region, mat::MHPgram::new(25.0, 881.33, 44000.0)); driver.fill_region(&ferro1_region, mat::MHPgram::new(25.0, 881.33, 44000.0));

View File

@@ -7,12 +7,15 @@
//! with something that absorbs energy. since this example doesn't, it lets you see what //! with something that absorbs energy. since this example doesn't, it lets you see what
//! happens when you just use the default boundary conditions. //! happens when you just use the default boundary conditions.
use coremem::{mat, driver}; use coremem::{mat, Driver};
use coremem::geom::{Coord as _, Cube, Index}; use coremem::geom::{Coord as _, Cube, Index};
use coremem::units::Seconds; use coremem::units::Seconds;
use coremem::sim::spirv::{self, SpirvSim};
use coremem::stim::{Stimulus, TimeVarying as _, UniformStimulus}; use coremem::stim::{Stimulus, TimeVarying as _, UniformStimulus};
use coremem::types::vec::Vec3; use coremem::types::vec::Vec3;
type Mat = mat::FullyGenericMaterial<f32>;
fn main() { fn main() {
coremem::init_logging(); coremem::init_logging();
// create a 2d simulation with so many grid cells // create a 2d simulation with so many grid cells
@@ -23,13 +26,12 @@ fn main() {
let feature_size = 1e-6; let feature_size = 1e-6;
// create the simulation "driver". // create the simulation "driver".
// by default all the computations are done with R32: a f32 which panics on NaN/Inf. // the first parameter is the float type to use: f32 for unchecked math, coremem::real::R32
// you can parameterize it to use R64, or unchecked f32 -- see src/driver.rs for definition. // to guard against NaN/Inf (useful for debugging).
let mut driver: driver::SpirvDriver = driver::Driver::new_spirv(size, feature_size); // to run this on the gpu instead of the gpu, replace `CpuBackend` with `WgpuBackend`.
let mut driver = Driver::new_with_state(SpirvSim::<f32, Mat, spirv::CpuBackend>::new(
// uncomment to use the Spirv/GPU driver. this one is restricted to unchecked f32. size, feature_size
// note: this won't have better perf unless you reduce the y4m/term renderer framerate below. ));
// let mut driver: driver::SpirvDriver = driver::Driver::new_spirv(size, feature_size);
// create a conductor on the left side. // create a conductor on the left side.
let conductor = Cube::new( let conductor = Cube::new(

View File

@@ -38,16 +38,6 @@ pub struct Driver<S=SpirvDriver> {
sim_end_time: Option<Frame>, sim_end_time: Option<Frame>,
} }
impl<R: Real, M: Default + Send + Sync> SpirvDriver<R, M>
{
pub fn new_spirv<C: Coord>(size: C, feature_size: f32) -> Self {
Self::new_with_state(SpirvSim::new(
size.to_index(feature_size),
feature_size,
))
}
}
impl<S> Driver<S> { impl<S> Driver<S> {
pub fn new_with_state(state: S) -> Self { pub fn new_with_state(state: S) -> Self {
Self { Self {