Skip to content

Commit

Permalink
SIMD test in dedicated workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Aug 28, 2023
1 parent 37a5b6a commit 435337f
Show file tree
Hide file tree
Showing 9 changed files with 559 additions and 113 deletions.
216 changes: 112 additions & 104 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
[workspace]
members = ["simd_test"]

[package]
name = "breakwater"
version = "0.1.0"
edition = "2021"

[dependencies]
chrono = "0.4"
const_format = "0.2"
clap = { version = "4.3", features = ["derive"] }
rusttype = "0.9"
number_prefix = "0.4"
const_format = "0.2"
env_logger = "0.10"
lazy_static = "1.4"
log = "0.4"
number_prefix = "0.4"
prometheus_exporter = "0.8"
rusttype = "0.9"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
simple_moving_average = "0.1"
Expand Down Expand Up @@ -48,6 +51,6 @@ opt-level = 3

[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
# lto = "fat"
# codegen-units = 1
# panic = "abort" # You can enable this, but I prefer to get actual stack traces
37 changes: 37 additions & 0 deletions simd_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "simd_test"
version = "0.1.0"
edition = "2021"

[dependencies]
breakwater = { path = "../" }

# chrono = "0.4"
# clap = { version = "4.3", features = ["derive"] }
# const_format = "0.2"
# env_logger = "0.10"
# lazy_static = "1.4"
# log = "0.4"
# number_prefix = "0.4"
# prometheus_exporter = "0.8"
# rusttype = "0.9"
# serde = { version = "1.0", features = ["derive"] }
# serde_json = "1.0"
# simple_moving_average = "0.1"
# thread-priority = "0.13"
tokio = { version = "1.29", features = ["fs", "rt-multi-thread", "net", "io-util", "macros", "process", "signal", "sync", "time"] }
# vncserver = { version ="0.2", optional = true}

[dev-dependencies]
criterion = {version = "0.5", features = ["async_tokio"]}
pixelbomber = "0.4.1"
# rstest = "0.18"
# rand = "0.8"

[lib]
name = "simd_test"
path = "src/lib.rs"

[[bench]]
name = "benchmarks"
harness = false
162 changes: 162 additions & 0 deletions simd_test/benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#![feature(portable_simd)]

use breakwater::{framebuffer::FrameBuffer, parser::ParserState, test::helpers::DevNullTcpStream};
use criterion::{
BenchmarkId, Criterion, {criterion_group, criterion_main},
};
use pixelbomber::image_handler;
use pixelbomber::image_handler::ImageConfig;
use std::{sync::Arc, time::Duration};

const FRAMEBUFFER_WIDTH: usize = 1920;
const FRAMEBUFFER_HEIGHT: usize = 1080;

async fn invoke_parse_pixelflut_commands_base(
input: &[u8],
fb: &Arc<FrameBuffer>,
parser_state: ParserState,
) {
let mut stream = DevNullTcpStream::default();
breakwater::parser::parse_pixelflut_commands(input, fb, &mut stream, parser_state).await;
}

async fn invoke_parse_pixelflut_commands_simd(
input: &[u8],
fb: &Arc<FrameBuffer>,
parser_state: ParserState,
) {
let mut stream = DevNullTcpStream::default();
simd_test::parser::parse_pixelflut_commands(input, fb, &mut stream, parser_state).await;
}

fn benchmark_base(c: &mut Criterion, name: &str, file: &str, config: ImageConfig) {
let mut commands = image_handler::load(vec![file], &config);
let command = commands.pop().unwrap();
c.bench_with_input(
BenchmarkId::new(name, format!("{FRAMEBUFFER_WIDTH} x {FRAMEBUFFER_HEIGHT}")),
&command,
|b, input| {
let fb = Arc::new(FrameBuffer::new(FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT));
let parser_state = ParserState::default();
b.to_async(tokio::runtime::Runtime::new().unwrap())
.iter(|| invoke_parse_pixelflut_commands_base(input, &fb, parser_state.clone()));
},
);
}

fn benchmark_simd(c: &mut Criterion, name: &str, file: &str, config: ImageConfig) {
let mut commands = image_handler::load(vec![file], &config);
let command = commands.pop().unwrap();
c.bench_with_input(
BenchmarkId::new(name, format!("{FRAMEBUFFER_WIDTH} x {FRAMEBUFFER_HEIGHT}")),
&command,
|b, input| {
let fb = Arc::new(FrameBuffer::new(FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT));
let parser_state = ParserState::default();
b.to_async(tokio::runtime::Runtime::new().unwrap())
.iter(|| invoke_parse_pixelflut_commands_simd(input, &fb, parser_state.clone()));
},
);
}

fn add_benches(c: &mut Criterion) {
// benchmark_base(
// c,
// "parse_draw_commands_ordered",
// "benches/non-transparent.png",
// image_handler::ImageConfigBuilder::new()
// .width(FRAMEBUFFER_WIDTH as u32)
// .height(FRAMEBUFFER_HEIGHT as u32)
// .shuffle(false)
// .build(),
// );

benchmark_base(
c,
"base_parse_draw_commands_shuffled",
"benches/non-transparent.png",
image_handler::ImageConfigBuilder::new()
.width(FRAMEBUFFER_WIDTH as u32)
.height(FRAMEBUFFER_HEIGHT as u32)
.shuffle(true)
.build(),
);

// benchmark_base(
// c,
// "parse_mixed_draw_commands",
// "benches/mixed.png",
// image_handler::ImageConfigBuilder::new()
// .width(FRAMEBUFFER_WIDTH as u32)
// .height(FRAMEBUFFER_HEIGHT as u32)
// .shuffle(false)
// .gray_usage(true)
// .build(),
// );

// benchmark_base(
// c,
// "parse_draw_commands_with_offset",
// "benches/non-transparent.png",
// image_handler::ImageConfigBuilder::new()
// .width(FRAMEBUFFER_WIDTH as u32)
// .height(FRAMEBUFFER_HEIGHT as u32)
// .shuffle(false)
// .offset_usage(true)
// .build(),
// );

// benchmark_simd(
// c,
// "parse_draw_commands_ordered",
// "benches/non-transparent.png",
// image_handler::ImageConfigBuilder::new()
// .width(FRAMEBUFFER_WIDTH as u32)
// .height(FRAMEBUFFER_HEIGHT as u32)
// .shuffle(false)
// .build(),
// );

benchmark_simd(
c,
"simd_parse_draw_commands_shuffled",
"benches/non-transparent.png",
image_handler::ImageConfigBuilder::new()
.width(FRAMEBUFFER_WIDTH as u32)
.height(FRAMEBUFFER_HEIGHT as u32)
.shuffle(true)
.build(),
);

// benchmark_simd(
// c,
// "parse_mixed_draw_commands",
// "benches/mixed.png",
// image_handler::ImageConfigBuilder::new()
// .width(FRAMEBUFFER_WIDTH as u32)
// .height(FRAMEBUFFER_HEIGHT as u32)
// .shuffle(false)
// .gray_usage(true)
// .build(),
// );

// benchmark_simd(
// c,
// "parse_draw_commands_with_offset",
// "benches/non-transparent.png",
// image_handler::ImageConfigBuilder::new()
// .width(FRAMEBUFFER_WIDTH as u32)
// .height(FRAMEBUFFER_HEIGHT as u32)
// .shuffle(false)
// .offset_usage(true)
// .build(),
// );
}

criterion_group!(
name = benches;
config = Criterion::default().warm_up_time(Duration::from_secs(2)).measurement_time(Duration::from_secs(3));
targets = add_benches,
);

criterion_main!(benches);
Binary file added simd_test/benches/mixed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simd_test/benches/non-transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions simd_test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![feature(portable_simd)]

pub mod parser;
Loading

0 comments on commit 435337f

Please sign in to comment.