Skip to content

blake3 difftest #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 57 additions & 6 deletions tests/difftests/tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion tests/difftests/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace]
resolver = "2"
members = [
"simple-compute/simple-compute-rust",
"blake3/blake3-rust",
"blake3/blake3-rust-gpu",
"simple-compute/simple-compute-wgsl",
]

Expand All @@ -21,6 +22,8 @@ spirv-std = { path = "../../../crates/spirv-std", version = "=0.9.0" }
spirv-std-types = { path = "../../../crates/spirv-std/shared", version = "=0.9.0" }
spirv-std-macros = { path = "../../../crates/spirv-std/macros", version = "=0.9.0" }
difftest = { path = "../../../tests/difftests/lib" }
anyhow = "1.0.98"
bytemuck = "1.21.0"
# External dependencies that need to be mentioned more than once.
num-traits = { version = "0.2.15", default-features = false }
glam = { version = ">=0.22, <=0.29", default-features = false }
Expand Down
20 changes: 20 additions & 0 deletions tests/difftests/tests/blake3/blake3-rust-gpu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "blake3-rust-gpu"
edition.workspace = true

[lints]
workspace = true

[lib]
crate-type = ["rlib", "dylib"]

# Common deps
[dependencies]

# GPU deps
spirv-std.workspace = true
blake3 = {version = "1.8.2", default-features = false}

# CPU deps
[target.'cfg(not(target_arch = "spirv"))'.dependencies]
difftest.workspace = true
13 changes: 13 additions & 0 deletions tests/difftests/tests/blake3/blake3-rust-gpu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![no_std]

use spirv_std::spirv;

#[spirv(compute(threads(1)))]
pub fn main_cs(#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] output: &mut [u32]) {
let hash = blake3::Hasher::new().finalize();
let bytes = hash.as_bytes();

for i in 0..8 {
output[i] = u32::from_le_bytes([bytes[i], bytes[i + 1], bytes[i + 2], bytes[i + 3]]);
}
}
13 changes: 13 additions & 0 deletions tests/difftests/tests/blake3/blake3-rust-gpu/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use difftest::config::Config;
use difftest::scaffold::compute::{RustComputeShader, WgpuComputeTest};

fn main() {
// Load the config from the harness.
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();

// Define test parameters, loading the rust shader from the current crate.
let test = WgpuComputeTest::new(RustComputeShader::default(), [1, 1, 1], 1024);

// Run the test and write the output to a file.
test.run_test(&config).unwrap();
}
12 changes: 12 additions & 0 deletions tests/difftests/tests/blake3/blake3-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "blake3-rust"
edition.workspace = true

[lints]
workspace = true

[dependencies]
difftest.workspace = true
anyhow.workspace = true
bytemuck.workspace = true
blake3-rust-gpu = {path = "../blake3-rust-gpu"}
16 changes: 16 additions & 0 deletions tests/difftests/tests/blake3/blake3-rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use difftest::config::Config;
use std::fs::File;
use std::io::Write;

fn main() {
let mut buf = [0u32; 256];
blake3_rust_gpu::main_cs(&mut buf);
write_cpu_test(bytemuck::bytes_of(&buf)).unwrap();
}

fn write_cpu_test(output: &[u8]) -> anyhow::Result<()> {
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
let mut f = File::create(&config.output_path)?;
f.write_all(&output)?;
Ok(())
}
Loading