Skip to content

Commit

Permalink
update wgpu perf wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
bastibl committed Mar 24, 2024
1 parent 779fe77 commit 2806f56
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 157 deletions.
2 changes: 2 additions & 0 deletions perf/wgpu/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# [build]
# target = "wasm32-unknown-unknown"
3 changes: 2 additions & 1 deletion perf/wgpu/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
perf-data
wgpu.pdf
*.log
*.log
dist
10 changes: 3 additions & 7 deletions perf/wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
futuresdr = { path = "../..", features = ["wgpu"] }
json = "0.12"
log = { version = "0.4", features = ["release_max_level_off"] }
rand = "0.8"
instant = { version = "0.1", features = [ "wasm-bindgen" ] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
getrandom = { version = "0.2", features = ["js"] }
instant = { version = "0.1", features = [ "wasm-bindgen" ] }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = ["Location"] }
console_log = "1"
leptos = { version = "0.6", features = ["csr", "nightly"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap = { version = "4", features = ["derive"] }
instant = { version = "0.1" }
21 changes: 0 additions & 21 deletions perf/wgpu/Gulpfile.js

This file was deleted.

8 changes: 1 addition & 7 deletions perf/wgpu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,5 @@ perf-data/fs%.csv:
@echo SAMPLES=$(SAMPLES)
@echo BUFFER_SIZE=$(BUFFER_SIZE)

cset shield --userset=sdr --exec -- cargo run --release -- --run=$(RUN) --scheduler=smol1 --samples=$(SAMPLES) --buffer_size=$(BUFFER_SIZE) | grep -v cset > $@

.PHONY: build

build:
RUSTFLAGS='--cfg=web_sys_unstable_apis' wasm-pack build --target web --out-name wasm --out-dir ./dist --release #--dev
./gulp default serve
cset shield --userset=sdr --exec -- cargo run --release -- --run=$(RUN) --scheduler=smol1 --samples=$(SAMPLES) --buffer-size=$(BUFFER_SIZE) | grep -v cset > $@

3 changes: 3 additions & 0 deletions perf/wgpu/Trunk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
target = "index.html"
dist = "dist"
Binary file added perf/wgpu/assets/favicon.ico
Binary file not shown.
Binary file removed perf/wgpu/assets/static/favicon.png
Binary file not shown.
39 changes: 0 additions & 39 deletions perf/wgpu/assets/static/index.html

This file was deleted.

1 change: 0 additions & 1 deletion perf/wgpu/gulp

This file was deleted.

11 changes: 11 additions & 0 deletions perf/wgpu/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link data-trunk rel="icon" href="assets/favicon.ico"/>
<link data-trunk rel="rust" data-bin="perf" data-wasm-opt="4" data-weak-refs data-reference-types/>
<title>FutureSDR :: WGPU Perf</title>
</head>
<body>
</body>
</html>
14 changes: 0 additions & 14 deletions perf/wgpu/package.json

This file was deleted.

13 changes: 0 additions & 13 deletions perf/wgpu/server.py

This file was deleted.

64 changes: 64 additions & 0 deletions perf/wgpu/src/bin/perf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use futuresdr::anyhow::Result;

#[cfg(not(target_arch = "wasm32"))]
mod foo {
use clap::Parser;
use futuresdr::anyhow::Result;

#[derive(Parser, Debug)]
struct Args {
#[clap(short, long, default_value_t = 0)]
run: u64,
#[clap(short = 'S', long, default_value = "smol1")]
scheduler: String,
#[clap(short, long, default_value_t = 1000000)]
samples: u64,
#[clap(short, long, default_value_t = 4096)]
buffer_size: u64,
}

pub fn main() -> Result<()> {
let Args {
run,
scheduler,
samples,
buffer_size,
} = Args::parse();

futuresdr::async_io::block_on(perf_wgpu::run(run, scheduler, samples, buffer_size))?;
Ok(())
}
}

#[cfg(target_arch = "wasm32")]
mod foo {
use futuresdr::anyhow::Result;
use leptos::*;

#[component]
/// Main GUI
fn Gui() -> impl IntoView {
let start = move |_| {
leptos::spawn_local(async {
perf_wgpu::run(0, "wasm".to_string(), 1000000, 32768)
.await
.unwrap();
});
};
view! {
<h1>"FutureSDR WGPU Perf"</h1>
<button on:click=start type="button" class="bg-fs-blue hover:brightness-75 text-slate-200 font-bold py-2 px-4 rounded">Start</button>
}
}

pub fn main() -> Result<()> {
_ = console_log::init_with_level(futuresdr::log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|| view! { <Gui /> });
Ok(())
}
}

fn main() -> Result<()> {
foo::main()
}
36 changes: 7 additions & 29 deletions perf/wgpu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
use std::iter::repeat_with;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

use futuresdr::anyhow::{Context, Result};
use futuresdr::blocks::VectorSink;
use futuresdr::blocks::VectorSource;
use futuresdr::blocks::Wgpu;
use futuresdr::log::info;
use futuresdr::runtime::buffer::wgpu;
use futuresdr::runtime::Flowgraph;
use futuresdr::runtime::Runtime;

#[cfg(not(target_arch = "wasm32"))]
use futuresdr::runtime::scheduler::SmolScheduler;

#[cfg(target_arch = "wasm32")]
use web_sys::console;

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub async fn run_fg(run: u64, samples: u64, buffer_size: u64) {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
crate::run(run, "wasm".to_string(), samples, buffer_size)
.await
.unwrap();
}

pub async fn run(run: u64, scheduler: String, samples: u64, buffer_size: u64) -> Result<()> {
info!("start flowgraph");

let orig: Vec<f32> = repeat_with(rand::random::<f32>)
.take(samples as usize)
.collect();
Expand All @@ -47,8 +30,6 @@ pub async fn run(run: u64, scheduler: String, samples: u64, buffer_size: u64) ->
fg.connect_stream_with_type(src, "out", mul, "in", wgpu::H2D::new())?;
fg.connect_stream_with_type(mul, "out", snk, "in", wgpu::D2H::new())?;

info!("start flowgraph");

let runtime;

#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -82,16 +63,13 @@ pub async fn run(run: u64, scheduler: String, samples: u64, buffer_size: u64) ->

#[cfg(target_arch = "wasm32")]
{
console::log_1(
&format!(
"{},{},{},{},{}",
run,
scheduler,
samples,
buffer_size,
elapsed.as_secs_f64()
)
.into(),
leptos::logging::log!(
"{},{},{},{},{}",
run,
scheduler,
samples,
buffer_size,
elapsed.as_secs_f64()
);
}

Expand Down
25 changes: 0 additions & 25 deletions perf/wgpu/src/main.rs

This file was deleted.

0 comments on commit 2806f56

Please sign in to comment.