mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
Merge pull request #264 from MacosPorters/archive/pull/340/head
benchmarks: measure gfx1030 metadata identification
This commit is contained in:
6 files changed
+174
No files matched your search
@@ -38,6 +38,8 @@ remains unsupported.
|
||||
- Added a Python 3 fallback for `timeout` in `scripts/test-gpu.sh`, so the native Metal suite runs on stock macOS without GNU coreutils while preserving bounded execution and the usual timeout exit status.
|
||||
|
||||
### Added
|
||||
- The gfx1030 identification benchmark fixture now runs as an ordinary integration test, so workspace tests check LLVM-derived names, families, lengths and byte boundaries without invoking a timing run.
|
||||
- Added a CPU benchmark for gfx1030 metadata identification (#173). It verifies instruction boundaries on a mixed-family stream assembled with LLVM and reports first-pass and repeated-pass throughput.
|
||||
- Added a Win64 ABI regression showing that a service may write the caller-allocated shadow space. Existing negative controls cover nonvolatile XMM-register corruption; the unchanged-home-slot test now describes its handler rather than implying an ABI preservation requirement.
|
||||
- Added a BetterXen development phase plan based on current source, pending PRs and existing acceptance records, linked from both contributor entry points. It separates baseline reconciliation, hosted C execution, guest threading, translated rendering, application integration and measured optimization; no new runtime or compatibility acceptance is claimed.
|
||||
- Added `tests/runtime_clock.rs`, which reads the performance counter, its frequency, both tick counts, the unbiased interrupt time and the system time from one injected clock and checks that they report the same elapsed time in their own units, after a host advance and after a guest `Sleep`, and that none of them decreases up to and past the end of the clock (#204). Expected values are worked out by hand from the documented units. Timed waits still return without consuming clock time.
|
||||
|
||||
Generated
+1
@@ -166,6 +166,7 @@ dependencies = [
|
||||
name = "xenora-benchmarks"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"xenora-isa",
|
||||
"xenora-metal",
|
||||
"xenora-ref",
|
||||
"xenora-shader",
|
||||
|
||||
@@ -17,3 +17,10 @@ path = "src/main.rs"
|
||||
xenora-shader = { path = "../crates/shader" }
|
||||
xenora-ref = { path = "../crates/ref" }
|
||||
xenora-metal = { path = "../crates/metal" }
|
||||
|
||||
[dev-dependencies]
|
||||
xenora-isa = { path = "../crates/isa" }
|
||||
|
||||
[[bench]]
|
||||
name = "gfx1030_identify"
|
||||
harness = false
|
||||
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Original gfx1030 Wave32 instruction stream for metadata identification.
|
||||
s_mov_b32 s12, 0x89abcdef
|
||||
v_add_f32_e32 v4, v5, v9
|
||||
s_cmp_lt_u32 s12, s13
|
||||
ds_read_b32 v8, v2 offset:12
|
||||
v_mov_b32_dpp v9, v6 quad_perm:[2,3,0,1] row_mask:0xf bank_mask:0xf
|
||||
s_add_u32 s16, s17, s18
|
||||
buffer_store_dword v7, off, s[4:7], 0
|
||||
v_fma_f32 v5, v8, v10, 0x3f800003
|
||||
s_movk_i32 s19, 0x2345
|
||||
global_load_dword v3, v[10:11], off
|
||||
v_cmp_lt_u32_e32 vcc_lo, v3, v7
|
||||
s_load_dword s20, s[22:23], 0x20
|
||||
v_pk_add_f16 v3, v4, v6
|
||||
s_waitcnt vmcnt(0)
|
||||
@@ -0,0 +1,143 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! CPU-only gfx1030 metadata benchmark.
|
||||
//!
|
||||
//! Run `cargo bench --locked -p xenora-benchmarks --bench gfx1030_identify`
|
||||
//! from the repository root. Repeat the command to collect independent
|
||||
//! first-pass samples. The first pass is the first identification in a fresh
|
||||
//! process with the input already in memory. It does not measure process
|
||||
//! startup or guarantee cold hardware caches. Repeated passes use the same
|
||||
//! stream after the untimed correctness check.
|
||||
//!
|
||||
//! To verify the fixture bytes and instruction lengths independently, run:
|
||||
//! ```sh
|
||||
//! llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx1030 -mattr=+wavefrontsize32 \
|
||||
//! -show-encoding benchmarks/benches/fixtures/gfx1030_mixed.s
|
||||
//! ```
|
||||
|
||||
use std::hint::black_box;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use xenora_isa::meta::{EncodingFamily, Identified, identify};
|
||||
|
||||
const COPIES: usize = 4096;
|
||||
const WARM_PASSES: usize = 9;
|
||||
|
||||
// Encodings and lengths come from llvm-mc, one row per instruction in
|
||||
// fixtures/gfx1030_mixed.s. Each word is stored in little-endian order.
|
||||
const FIXTURE: &[(&str, EncodingFamily, &[u32])] = {
|
||||
use EncodingFamily::*;
|
||||
&[
|
||||
("S_MOV_B32", Sop1, &[0xbe8c03ff, 0x89abcdef]),
|
||||
("V_ADD_F32", Vop2, &[0x06081305]),
|
||||
("S_CMP_LT_U32", Sopc, &[0xbf0a0d0c]),
|
||||
("DS_READ_B32", Ds, &[0xd8d8000c, 0x08000002]),
|
||||
("V_MOV_B32", Vop1, &[0x7e1202fa, 0xff004e06]),
|
||||
("S_ADD_U32", Sop2, &[0x80101211]),
|
||||
("BUFFER_STORE_DWORD", Mubuf, &[0xe0700000, 0x80010700]),
|
||||
("V_FMA_F32", Vop3, &[0xd54b0005, 0x03fe1508, 0x3f800003]),
|
||||
("S_MOVK_I32", Sopk, &[0xb0132345]),
|
||||
("GLOBAL_LOAD_DWORD", Global, &[0xdc308000, 0x037d000a]),
|
||||
("V_CMP_LT_U32", Vopc, &[0x7d820f03]),
|
||||
("S_LOAD_DWORD", Smem, &[0xf400050b, 0xfa000020]),
|
||||
("V_PK_ADD_F16", Vop3p, &[0xcc0f4003, 0x1a020d04]),
|
||||
("S_WAITCNT", Sopp, &[0xbf8c3f70]),
|
||||
]
|
||||
};
|
||||
|
||||
fn walk(stream: &[u8], mut observe: impl FnMut(usize, Identified)) -> usize {
|
||||
let mut offset = 0;
|
||||
let mut count = 0;
|
||||
while offset < stream.len() {
|
||||
let identified = identify(&stream[offset..])
|
||||
.unwrap_or_else(|error| panic!("identification failed at byte {offset}: {error}"));
|
||||
observe(offset, identified);
|
||||
offset += identified.len;
|
||||
count += 1;
|
||||
}
|
||||
count
|
||||
}
|
||||
|
||||
fn verify(stream: &[u8]) {
|
||||
let mut expected_offset = 0;
|
||||
let mut expected = FIXTURE.iter().cycle();
|
||||
let count = walk(stream, |offset, identified| {
|
||||
let &(name, family, words) = expected.next().expect("fixture is nonempty");
|
||||
let len = std::mem::size_of_val(words);
|
||||
assert_eq!(offset, expected_offset, "byte boundary for {name}");
|
||||
assert_eq!(identified.len, len, "length of {name} at byte {offset}");
|
||||
assert_eq!(identified.form.name, name, "mnemonic at byte {offset}");
|
||||
assert_eq!(identified.form.family, family, "family at byte {offset}");
|
||||
expected_offset += len;
|
||||
});
|
||||
assert_eq!(expected_offset, stream.len());
|
||||
assert_eq!(count, COPIES * FIXTURE.len());
|
||||
}
|
||||
|
||||
fn measure(stream: &[u8]) -> Duration {
|
||||
let start = Instant::now();
|
||||
let count = walk(black_box(stream), |_, identified| {
|
||||
black_box(identified);
|
||||
});
|
||||
let elapsed = start.elapsed();
|
||||
assert_eq!(count, COPIES * FIXTURE.len());
|
||||
elapsed
|
||||
}
|
||||
|
||||
fn report(label: &str, elapsed: Duration, byte_count: usize) {
|
||||
let seconds = elapsed.as_secs_f64();
|
||||
let count = (COPIES * FIXTURE.len()) as f64;
|
||||
println!(
|
||||
"{label}: {:.3} ms, {:.2} ns/instruction, {:.2} MiB/s",
|
||||
seconds * 1e3,
|
||||
seconds * 1e9 / count,
|
||||
byte_count as f64 / (1024.0 * 1024.0) / seconds
|
||||
);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let block: Vec<u8> = FIXTURE
|
||||
.iter()
|
||||
.flat_map(|(_, _, words)| words.iter().flat_map(|word| word.to_le_bytes()))
|
||||
.collect();
|
||||
let stream = block.repeat(COPIES);
|
||||
|
||||
// 'cargo test --all-targets' checks the fixture without timing it.
|
||||
if !std::env::args().any(|arg| arg == "--bench") {
|
||||
verify(&stream);
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep the first pass ahead of any metadata lookups. Validate the entire
|
||||
// stream before reporting any timings. That validation also warms the path.
|
||||
let first = measure(&stream);
|
||||
verify(&stream);
|
||||
let mut warm = [Duration::ZERO; WARM_PASSES];
|
||||
for sample in &mut warm {
|
||||
*sample = measure(&stream);
|
||||
}
|
||||
warm.sort_unstable();
|
||||
|
||||
println!(
|
||||
"gfx1030 metadata identification: {} instructions, {} bytes, {} repeated passes",
|
||||
COPIES * FIXTURE.len(),
|
||||
stream.len(),
|
||||
WARM_PASSES
|
||||
);
|
||||
report("First pass in a fresh process", first, stream.len());
|
||||
report("Repeated minimum", warm[0], stream.len());
|
||||
report("Repeated median", warm[WARM_PASSES / 2], stream.len());
|
||||
report("Repeated maximum", warm[WARM_PASSES - 1], stream.len());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn mixed_llvm_fixture_preserves_names_families_lengths_and_boundaries() {
|
||||
let block: Vec<u8> = super::FIXTURE
|
||||
.iter()
|
||||
.flat_map(|(_, _, words)| words.iter().flat_map(|word| word.to_le_bytes()))
|
||||
.collect();
|
||||
super::verify(&block.repeat(super::COPIES));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Exercise the benchmark's LLVM-derived fixture during ordinary workspace tests.
|
||||
#[allow(dead_code)]
|
||||
#[path = "../benches/gfx1030_identify.rs"]
|
||||
mod benchmark;
|
||||
Reference in new issue
Block a user