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
//! 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::mat::{Ferroxcube3R1MH, IsoConductorOr};
use coremem::real::{R32, Real as _};
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::stim::{CurlStimulus, Exp1, Gated, Sinusoid1, TimeVarying as _};
use coremem::util::cache::DiskCache;
use log::{error, info, warn};
use serde::{Deserialize, Serialize};
@@ -389,7 +390,9 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
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);
if !driver.add_state_file(&*format!("{}/state.bc", prefix), 16000) {
// 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");
}
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)
.half_cycle()
.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);
driver.add_stimulus(CurlStimulus::new(
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);
driver.add_stimulus(CurlStimulus::new(
region.clone(),
@@ -447,11 +450,11 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
};
// 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);
};
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 {
PulseType::Square => add_drive_square_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
//! ```
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::mat::{Ferroxcube3R1MH, IsoConductorOr, IsomorphicConductor};
use coremem::{Driver, SpirvDriver};
use coremem::Driver;
type Mat = IsoConductorOr<f32, Ferroxcube3R1MH>;
@@ -76,7 +77,9 @@ fn main() {
let ferro_mat = wire_mat;
// 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.fill_region(&drive0, 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
/// possible to transfer the state (with some limitation) from one latch to another.
use coremem::{Driver, mat, meas, SpirvDriver};
use coremem::geom::{Meters, Torus};
use coremem::{Driver, mat, meas};
use coremem::geom::{Coord as _, Meters, Torus};
use coremem::sim::spirv::{SpirvSim, WgpuBackend};
use coremem::sim::units::Seconds;
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 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.
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
//! 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::units::Seconds;
use coremem::sim::spirv::{self, SpirvSim};
use coremem::stim::{Stimulus, TimeVarying as _, UniformStimulus};
use coremem::types::vec::Vec3;
type Mat = mat::FullyGenericMaterial<f32>;
fn main() {
coremem::init_logging();
// create a 2d simulation with so many grid cells
@@ -23,13 +26,12 @@ fn main() {
let feature_size = 1e-6;
// create the simulation "driver".
// by default all the computations are done with R32: a f32 which panics on NaN/Inf.
// you can parameterize it to use R64, or unchecked f32 -- see src/driver.rs for definition.
let mut driver: driver::SpirvDriver = driver::Driver::new_spirv(size, feature_size);
// uncomment to use the Spirv/GPU driver. this one is restricted to unchecked f32.
// 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);
// the first parameter is the float type to use: f32 for unchecked math, coremem::real::R32
// to guard against NaN/Inf (useful for debugging).
// 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(
size, feature_size
));
// create a conductor on the left side.
let conductor = Cube::new(