summaryrefslogtreecommitdiffstats
path: root/tools/cuda-ab/ab.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/cuda-ab/ab.sh')
-rwxr-xr-xtools/cuda-ab/ab.sh32
1 files changed, 27 insertions, 5 deletions
diff --git a/tools/cuda-ab/ab.sh b/tools/cuda-ab/ab.sh
index 5a290e4..d0326f8 100755
--- a/tools/cuda-ab/ab.sh
+++ b/tools/cuda-ab/ab.sh
@@ -11,7 +11,13 @@
# tools/cuda-ab/ab.sh guest # push the binary + run in the running VM
# tools/cuda-ab/ab.sh compare # diff the stable result lines
# tools/cuda-ab/ab.sh all # host + guest + compare
+# tools/cuda-ab/ab.sh push # push $WORKLOAD (default vector_add) to the VM
# tools/cuda-ab/ab.sh victory # push victory_mail to the VM (runner executes it)
+# tools/cuda-ab/ab.sh smiley # push smiley (== WORKLOAD=smiley ./ab.sh push)
+#
+# WORKLOAD selects the program (<name>.cu -> run/<name>); guest execution uses
+# AB_GUEST_TIMEOUT seconds (default 300) because the first emulated CUDA call
+# can be much slower than a bare-metal launch.
#
# The binary links the CUDA runtime statically, so the guest needs no CUDA
# toolkit - only the guest driver's libcuda.so.
@@ -24,6 +30,7 @@ RUN="$HERE/run"
WORKLOAD="${WORKLOAD:-vector_add}"
SRC="$HERE/$WORKLOAD.cu"
BIN="$RUN/$WORKLOAD"
+AB_GUEST_TIMEOUT="${AB_GUEST_TIMEOUT:-300}"
mkdir -p "$RUN"
@@ -39,8 +46,13 @@ run_host() {
}
push_bin() {
- [ -x "$BIN" ] || build_host
- local b64 chunk off total size
+ [ -f "$SRC" ] || { echo "no source for WORKLOAD=$WORKLOAD ($SRC)"; exit 1; }
+ # Rebuild when missing or older than the source, so a pushed binary is
+ # never stale relative to its .cu.
+ if [ ! -x "$BIN" ] || [ "$SRC" -nt "$BIN" ]; then
+ build_host
+ fi
+ local b64 chunk off total size out
b64=$(base64 -w0 "$BIN")
total=${#b64}
off=0
@@ -52,13 +64,18 @@ push_bin() {
"$VMEXEC" exec "echo -n '$chunk' >> /tmp/$WORKLOAD.b64" >/dev/null 2>&1
off=$((off + size))
done
- "$VMEXEC" exec "base64 -d /tmp/$WORKLOAD.b64 > /tmp/$WORKLOAD && chmod +x /tmp/$WORKLOAD && rm -f /tmp/$WORKLOAD.b64 && echo PUSH_OK"
+ out=$("$VMEXEC" exec "base64 -d /tmp/$WORKLOAD.b64 > /tmp/$WORKLOAD && chmod +x /tmp/$WORKLOAD && rm -f /tmp/$WORKLOAD.b64 && echo PUSH_OK" 2>&1) || true
+ printf '%s\n' "$out"
+ case "$out" in
+ *PUSH_OK*) ;;
+ *) echo "push failed (no PUSH_OK)" >&2; exit 1 ;;
+ esac
}
run_guest() {
push_bin
echo "[*] guest run (emulated vGPU)"
- "$VMEXEC" exec "/tmp/$WORKLOAD" 2>&1 | tee "$RUN/guest.txt"
+ "$VMEXEC" exec --timeout "$AB_GUEST_TIMEOUT" "/tmp/$WORKLOAD" 2>&1 | tee "$RUN/guest.txt"
}
compare() {
@@ -92,5 +109,10 @@ victory)
SRC="$HERE/$WORKLOAD.cu"
BIN="$RUN/$WORKLOAD"
push_bin ;;
-*) echo "usage: $0 [host|guest|compare|all|victory]"; exit 1 ;;
+smiley)
+ WORKLOAD=smiley
+ SRC="$HERE/$WORKLOAD.cu"
+ BIN="$RUN/$WORKLOAD"
+ push_bin ;;
+*) echo "usage: $0 [host|guest|compare|all|push|victory|smiley]"; exit 1 ;;
esac