guard_runs.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //! Time structurisation only; the synthetic programs need no title files or GPU.
  2. use std::hint::black_box;
  3. use std::time::Instant;
  4. use victory_shader::{ir, structure::structure};
  5. fn program(masks: u32, run: usize) -> ir::Program {
  6. let mut words = Vec::new();
  7. for i in 0..masks.max(1) {
  8. if masks != 0 {
  9. // v_cmpx_eq_u32 exec, 0, v[i]: each comparison narrows EXEC.
  10. words.push(0x7DA4_0080 | (i << 9));
  11. }
  12. words.extend(std::iter::repeat_n(0x4A00_0081, run)); // v_add_nc_u32 v0, 1, v0
  13. }
  14. words.push(0xBF81_0000); // s_endpgm
  15. let code = words
  16. .into_iter()
  17. .flat_map(u32::to_le_bytes)
  18. .collect::<Vec<_>>();
  19. ir::build(&code, true, 256).unwrap()
  20. }
  21. fn main() {
  22. const BATCH: u32 = 64;
  23. for (label, masks, run) in [
  24. ("unmasked", 0, 512),
  25. ("short runs", 8, 1),
  26. ("long runs", 8, 64),
  27. ] {
  28. let p = program(masks, run);
  29. black_box(structure(&p).unwrap());
  30. let mut samples = [std::time::Duration::ZERO; 9];
  31. for sample in &mut samples {
  32. let start = Instant::now();
  33. for _ in 0..BATCH {
  34. black_box(structure(black_box(&p)).unwrap());
  35. }
  36. *sample = start.elapsed() / BATCH;
  37. }
  38. samples.sort_unstable();
  39. println!(
  40. "{label}: {:?} per program (median)",
  41. samples[samples.len() / 2]
  42. );
  43. }
  44. }