omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / gpu / amd / gfx942 / fp8gemv / bench.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # Correctness first. Then, only when /dev/kfd exists, one process times two |
| 4 | # arms at the same shapes, each in a hot mode and a cold mode: |
| 5 | # hipblasLtMatmul, FP8 x FP8 into f32 (the library has no FP8 x FP32 GEMM) |
| 6 | # fp8gemv_stream, FP8 weights x FP32 activations plus a per-row scale, |
| 7 | # with the row-remap bit clear and with it set |
| 8 | # Hot is 10 calls on the buffers being timed, then 21 samples, in that process. |
| 9 | # Cold reads a 512 MiB device buffer in that process and then times the next |
| 10 | # call on the same operands. hipblaslt-bench is not invoked: its --flush is |
| 11 | # s_icache_inv, and its --rotating copies are initialized before one averaged |
| 12 | # interval. The kernel's y is compared to the CPU plain reference before any |
| 13 | # sample. A mismatch prints FAIL and exits non-zero. No device: exit non-zero. |
| 14 | # 5.3 TB/s is the published MI300X HBM peak, not a measurement. |
| 15 | set -eu |
| 16 | HERE=$(CDPATH= cd -- "$(dirname "$0")" && pwd) |
| 17 | ROOT=$(CDPATH= cd -- "$HERE/../../../.." && pwd) |
| 18 | OMC=$ROOT/seed/out/omc |
| 19 | QEMU=/usr/bin/qemu-aarch64-static |
| 20 | |
| 21 | "$HERE/check.sh" |
| 22 | |
| 23 | echo "shapes M in 4096 8192 14336 28672, K in 4096 8192, batch 1" |
| 24 | echo "kernel flags: bit0 row remap, bit1 residual+rmsnorm scale, bit2 bf16 store" |
| 25 | echo "peak denominator 5.3 TB/s (published MI300X HBM peak, not a measurement)" |
| 26 | echo "hipBLASLt is f8_fnuz_r x f8_fnuz_r into f32 (compute f32, D f32, scalar scales 1)." |
| 27 | echo "That is HIP_R_8F_E4M3_FNUZ. The type table has no FP8 x FP32 matmul." |
| 28 | echo "The kernel is FP8 weights x FP32 activations plus a per-row scale." |
| 29 | echo "kernel bytes are M*K+4*K+8*M. library bytes are M*K+K+4*M. Each GB/s uses its own count." |
| 30 | echo "Non-weight bytes are at most 0.293% of the kernel weight bytes and 0.122% of the library weight bytes at these shapes (both maxima at M=K=4096)." |
| 31 | echo "The library GB/s is the median of this process's hipblasLtMatmul samples and M*K+K+4*M. hipblaslt-bench is not the timer, so there is no bench_GB/s column." |
| 32 | echo "kernel_swizzle is flags bit 0. Same byte count either way. It is not --swizzleA." |
| 33 | echo "5.3 TB/s is the published peak, not a measurement." |
| 34 | echo "mode hot: 10 warmups then 21 samples, one process, no extra read. mode cold: a 512 MiB device read, then the next call on the same operands, 21 times." |
| 35 | |
| 36 | if [ ! -e /dev/kfd ]; then |
| 37 | echo "BLOCKED_HARDWARE no /dev/kfd" |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | HIPCC=$(command -v hipcc || true) |
| 42 | if [ -z "$HIPCC" ] && [ -x /opt/rocm/bin/hipcc ]; then |
| 43 | HIPCC=/opt/rocm/bin/hipcc |
| 44 | fi |
| 45 | if [ -z "$HIPCC" ]; then |
| 46 | echo "BLOCKED_HARDWARE /dev/kfd is present but hipcc is not on PATH" >&2 |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | work=$(mktemp -d) |
| 51 | trap 'rm -rf "$work"' EXIT |
| 52 | |
| 53 | echo "compile hsaco.om" |
| 54 | env -i "$QEMU" "$OMC" < "$ROOT/gpu/amd/gfx942/hsaco.om" > "$work/hsaco" 2>"$work/hsaco.err" |
| 55 | if [ -s "$work/hsaco.err" ]; then |
| 56 | cat "$work/hsaco.err" >&2 |
| 57 | exit 1 |
| 58 | fi |
| 59 | chmod +x "$work/hsaco" |
| 60 | env -i "$QEMU" "$work/hsaco" "$HERE/fp8gemv_stream.isa" > "$work/fp8gemv_stream.hsaco" 2>"$work/herr" |
| 61 | if [ -s "$work/herr" ]; then |
| 62 | cat "$work/herr" >&2 |
| 63 | exit 1 |
| 64 | fi |
| 65 | |
| 66 | echo "compile time_fp8gemv" |
| 67 | if ! "$HIPCC" -O2 -std=c++17 -ffp-contract=off -o "$work/time_fp8gemv" \ |
| 68 | "$HERE/time_fp8gemv.cpp" -lhipblaslt; then |
| 69 | echo "BLOCKED_HARDWARE hipcc could not link hipblaslt" >&2 |
| 70 | exit 1 |
| 71 | fi |
| 72 | "$work/time_fp8gemv" "$work/fp8gemv_stream.hsaco" |
| 73 | |
| 74 | echo "profiler commands this script does not run:" |
| 75 | echo "rocprof --stats --kernel fp8gemv_stream $work/time_fp8gemv $work/fp8gemv_stream.hsaco" |
| 76 | echo "omniperf profile -n fp8gemv -- $work/time_fp8gemv $work/fp8gemv_stream.hsaco" |
| 77 | |
| 78 | echo "bench.sh pass" |