| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
use everycycle_appraise::enumerate::enumerate; |
| 9 |
use everycycle_appraise::probe::{ |
| 10 |
BandwidthError, LaunchError, TimingSource, VulkanContext, VulkanContextError, |
| 11 |
measure_bandwidth, measure_launch_overhead, |
| 12 |
}; |
| 13 |
|
| 14 |
fn main() { |
| 15 |
let host = match enumerate() { |
| 16 |
Ok(h) => h, |
| 17 |
Err(e) => { |
| 18 |
eprintln!("enumeration failed: {e}"); |
| 19 |
std::process::exit(1); |
| 20 |
} |
| 21 |
}; |
| 22 |
|
| 23 |
let Some(device) = host.devices.first() else { |
| 24 |
eprintln!("no discrete-compute devices found"); |
| 25 |
std::process::exit(1); |
| 26 |
}; |
| 27 |
|
| 28 |
eprintln!("host: {}", host.host.hostname); |
| 29 |
eprintln!("device: {} @ {}", device.device_name, device.bus_address); |
| 30 |
eprintln!("driver: {}", device.driver_version); |
| 31 |
eprintln!(); |
| 32 |
|
| 33 |
let ctx = match VulkanContext::new(&device.bus_address) { |
| 34 |
Ok(c) => c, |
| 35 |
Err(e) => { |
| 36 |
eprintln!("vulkan context bring-up failed: {}", render_ctx_err(&e)); |
| 37 |
std::process::exit(1); |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
eprintln!("running launch-overhead probe ..."); |
| 42 |
match measure_launch_overhead(&ctx) { |
| 43 |
Ok(r) => { |
| 44 |
eprintln!(" null launch: {:>10.1} ns", r.null_launch_ns); |
| 45 |
eprintln!(" memcpy 1MiB: {:>10.1} ns", r.memcpy_1mib_ns); |
| 46 |
} |
| 47 |
Err(e) => eprintln!(" failed: {}", render_launch_err(&e)), |
| 48 |
} |
| 49 |
eprintln!(); |
| 50 |
|
| 51 |
eprintln!("running bandwidth probe ..."); |
| 52 |
match measure_bandwidth(&ctx) { |
| 53 |
Ok(r) => { |
| 54 |
eprintln!(" read: {:>7.1} GB/s", r.read_bps / 1e9); |
| 55 |
eprintln!(" write: {:>7.1} GB/s", r.write_bps / 1e9); |
| 56 |
eprintln!(" clock: {}", timing_label(r.timing)); |
| 57 |
} |
| 58 |
Err(e) => eprintln!(" failed: {}", render_bw_err(&e)), |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
fn timing_label(t: TimingSource) -> &'static str { |
| 63 |
match t { |
| 64 |
TimingSource::DeviceTimestamps => "device timestamps", |
| 65 |
TimingSource::HostWallClock => "host wall clock (lower bound)", |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
fn render_ctx_err(e: &VulkanContextError) -> String { |
| 70 |
format!("{e:?}") |
| 71 |
} |
| 72 |
|
| 73 |
fn render_launch_err(e: &LaunchError) -> String { |
| 74 |
format!("{e:?}") |
| 75 |
} |
| 76 |
|
| 77 |
fn render_bw_err(e: &BandwidthError) -> String { |
| 78 |
format!("{e:?}") |
| 79 |
} |
| 80 |
|