interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tools / sm121dis / corpus.sh

74 lines · 4461 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# corpus.sh <build-out-dir> <kernel-dir>: collects every kernel the library builds, without a GPU, into <kernel-dir>.
4# Each GPU test runs in its host-only (and simulator) modes with OMEGA_KERNEL_DUMP_DIR set, so every program the
5# library encodes lands as <sha16>.bin (src/omega_blackwell_codegen.c omega_kernel_dump). In CUDA++ the corpus is the
6# GPU library's kernels; the numeric kernels (DIV, SQRT, load/store, reductions, own encoder) and gpu_tern_test stay
7# in omega-mv with their producers. Run from the repo root after
8# `make OUT_DIR=<build-out-dir> sm121dis-corpus-bins` (mk/sm121dis.mk). Any failed producer invalidates the corpus.
9set -u
10OUT=$1; K=$2
11mkdir -p "$K"; K=$(cd "$K" && pwd)
12export OMEGA_KERNEL_DUMP_DIR="$K"
13# Manifest (CUDA++ C6, DRA-475): each kernel is credited to the first producer that wrote it (a later producer that
14# builds the same bytes finds the file already there); PRODUCERS.tsv counts the new kernels of each run.
15: > "$K/.seen"; : > "$K/.firstby"; printf 'producer\tnew_kernels\tkernels_so_far\n' > "$K/PRODUCERS.tsv"
16run() {
17 printf '%s' "$*: "
18 "$@" > "$K/producer.log" 2>&1; rc=$?
19 echo "exit $rc, $(ls "$K"/*.bin 2>/dev/null | wc -l) kernels so far"
20 if [ "$rc" -ne 0 ]; then
21 cat "$K/producer.log" >&2
22 echo "VERDICT FAIL: corpus producer failed: $*" >&2
23 exit "$rc"
24 fi
25 # src/omega_blackwell_codegen.c omega_kernel_dump: a kernel that could not be written whole is missing from the corpus
26 if grep -q '^omega_kernel_dump: ' "$K/producer.log"; then
27 grep '^omega_kernel_dump: ' "$K/producer.log" >&2
28 echo "VERDICT FAIL: kernels not captured whole: $*" >&2
29 exit 1
30 fi
31 rm -f "$K/producer.log"
32 p=$(basename "$1"); shift; [ $# -gt 0 ] && p="$p $*"
33 (cd "$K" && ls -1 | grep '\.bin$' | LC_ALL=C sort) > "$K/.now"
34 LC_ALL=C comm -13 "$K/.seen" "$K/.now" > "$K/.new"
35 while read -r f; do printf '%s\t%s\n' "$f" "$p" >> "$K/.firstby"; done < "$K/.new"
36 printf '%s\t%s\t%s\n' "$p" "$(wc -l < "$K/.new")" "$(wc -l < "$K/.now")" >> "$K/PRODUCERS.tsv"
37 mv "$K/.now" "$K/.seen"
38}
39for t in gpu_matmul_api_test gpu_elementwise_test gpu_reconv_test gpu_attention_test gpu_moe_window_test gpu_fp8_api_test \
40 gpu_decode_attn_test gpu_router_test gpu_bf16_gemv_test gpu_fp8gemm_test gpu_tc_probe_test \
41 gpu_tc_peak_test gpu_pf_mem_test gpu_qmma_probe_test gpu_cmdlist_test gpu_decode_graph_test; do
42 run "$OUT/$t" --host-only
43done
44run "$OUT/gpu_attention_test" --hd 128 --host-only
45for t in gpu_tcgemm_test gpu_prefill_attn_test gpu_pfgemm_test gpu_qgemm_test gpu_pfhost_test gpu_cmdlist_test; do
46 run "$OUT/$t" --host-only; run "$OUT/$t" --sim
47done
48run "$OUT/gpu_gpr_boundary_test"
49for t in gpu_gemm_test gpu_streams_test gpu_mathlibs_test; do
50 run "$OUT/$t" --host-only; run "$OUT/$t" --sim
51done
52# the scan kernels depend only on kind and mutant, so the short simulator sweep builds the same set as the full one
53run "$OUT/gpu_scan_test" --host-only; run "$OUT/gpu_scan_test" --sim --quick
54run "$OUT/gpu_isolation_test" --host-only
55# the hazard checker's sweep (every generator over its accepted shapes, patched as the launchers do): bw_hazard_test
56# --disasm reads each of these kernels through our disassembler, so each is compared with nvdisasm here
57run "$OUT/bw_hazard_test"
58# MANIFEST.tsv: one row per distinct kernel file, its full SHA-256 (the file name is its first 8 bytes), size, words and
59# first producer. Its own SHA-256 is printed, so a receipt can name the exact corpus.
60printf 'kernel\tsha256\tbytes\twords\tfirst_producer\n' > "$K/MANIFEST.tsv"
61bad=0
62for f in "$K"/*.bin; do
63 b=$(basename "$f")
64 h=$(sha256sum < "$f" | cut -c1-64)
65 [ "$(printf '%s' "$h" | cut -c1-16).bin" = "$b" ] || { echo "VERDICT FAIL: $b does not carry its content hash ($h)" >&2; bad=1; }
66 s=$(wc -c < "$f")
67 pr=$(grep -F "$b " "$K/.firstby" | head -1 | cut -f2-)
68 [ -n "$pr" ] || { echo "VERDICT FAIL: $b has no producer" >&2; bad=1; }
69 printf '%s\t%s\t%s\t%s\t%s\n' "$b" "$h" "$s" $((s / 16)) "$pr" >> "$K/MANIFEST.tsv"
70done
71rm -f "$K/.seen" "$K/.new" "$K/.firstby"
72[ "$bad" = 0 ] || exit 1
73echo "manifest: $(($(wc -l < "$K/MANIFEST.tsv") - 1)) kernels, $(awk -F'\t' 'NR>1{w+=$4} END{print w+0}' "$K/MANIFEST.tsv") words, sha256 $(sha256sum < "$K/MANIFEST.tsv" | cut -c1-64)"
74echo "corpus: $(ls "$K"/*.bin | wc -l) kernels in $K"