Skip to content

Commit f2cd9b8

Browse files
committed
blake3 difftest
1 parent de24a89 commit f2cd9b8

File tree

7 files changed

+135
-7
lines changed

7 files changed

+135
-7
lines changed

tests/difftests/tests/Cargo.lock

Lines changed: 57 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/difftests/tests/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[workspace]
22
resolver = "2"
33
members = [
4-
"simple-compute/simple-compute-rust",
4+
"blake3/blake3-rust",
5+
"blake3/blake3-rust-gpu",
56
"simple-compute/simple-compute-wgsl",
67
]
78

@@ -21,6 +22,8 @@ spirv-std = { path = "../../../crates/spirv-std", version = "=0.9.0" }
2122
spirv-std-types = { path = "../../../crates/spirv-std/shared", version = "=0.9.0" }
2223
spirv-std-macros = { path = "../../../crates/spirv-std/macros", version = "=0.9.0" }
2324
difftest = { path = "../../../tests/difftests/lib" }
25+
anyhow = "1.0.98"
26+
bytemuck = "1.21.0"
2427
# External dependencies that need to be mentioned more than once.
2528
num-traits = { version = "0.2.15", default-features = false }
2629
glam = { version = ">=0.22, <=0.29", default-features = false }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "blake3-rust-gpu"
3+
edition.workspace = true
4+
5+
[lints]
6+
workspace = true
7+
8+
[lib]
9+
crate-type = ["rlib", "dylib"]
10+
11+
# Common deps
12+
[dependencies]
13+
14+
# GPU deps
15+
spirv-std.workspace = true
16+
blake3 = {version = "1.8.2", default-features = false}
17+
18+
# CPU deps
19+
[target.'cfg(not(target_arch = "spirv"))'.dependencies]
20+
difftest.workspace = true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![no_std]
2+
3+
use spirv_std::spirv;
4+
5+
#[spirv(compute(threads(1)))]
6+
pub fn main_cs(#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] output: &mut [u32]) {
7+
let hash = blake3::Hasher::new().finalize();
8+
let bytes = hash.as_bytes();
9+
10+
for i in 0..8 {
11+
output[i] = u32::from_le_bytes([bytes[i], bytes[i + 1], bytes[i + 2], bytes[i + 3]]);
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use difftest::config::Config;
2+
use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTest};
3+
4+
fn main() {
5+
// Load the config from the harness.
6+
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
7+
8+
// Define test parameters, loading the rust shader from the current crate.
9+
let test = WgpuComputeTest::new(RustComputeShader::default(), [1, 1, 1], 1024);
10+
11+
// Run the test and write the output to a file.
12+
test.run_test(&config).unwrap();
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "blake3-rust"
3+
edition.workspace = true
4+
5+
[lints]
6+
workspace = true
7+
8+
[dependencies]
9+
difftest.workspace = true
10+
anyhow.workspace = true
11+
bytemuck.workspace = true
12+
blake3-rust-gpu = {path = "../blake3-rust-gpu"}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use difftest::config::Config;
2+
use std::fs::File;
3+
use std::io::Write;
4+
5+
fn main() {
6+
let mut buf = [0u32; 256];
7+
blake3_rust_gpu::main_cs(&mut buf);
8+
write_cpu_test(bytemuck::bytes_of(&buf)).unwrap();
9+
}
10+
11+
fn write_cpu_test(output: &[u8]) -> anyhow::Result<()> {
12+
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
13+
let mut f = File::create(&config.output_path)?;
14+
f.write_all(&output)?;
15+
Ok(())
16+
}

0 commit comments

Comments
 (0)