blob: 85dd11e49f5c8c36f0ba4d99b3dc5b42a55d3b94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#!/usr/bin/env bash
# run_sim.sh -- run a CUDA binary on the GreenEye-GPGPU-Sim TU104 scaffold.
#
# Substitutes the CUDA runtime with GPGPU-Sim's libcudart.so via
# LD_LIBRARY_PATH (the mechanism documented in the upstream README, "Step 3:
# Run"), points the simulator at the tracked TU104 scaffold config, and
# executes the binary from a dedicated run directory so simulator output does
# not pollute the source tree.
#
# Development-only tooling: it simulates; it never touches GPU hardware,
# kernel modules, mdev, or a guest.
#
# Usage:
# ./run_sim.sh [--workdir DIR] [--build-type release|debug] <cuda-binary> [args...]
#
# Prerequisites: ./setup.sh has completed a build, and the binary was linked
# with `--cudart shared` so it resolves libcudart.so dynamically.
#
# Outputs (in the work directory, default gpgpu-sim/build/run/):
# gpgpusim.config -> symlink to the tracked TU104 config
# config_turing_islip.icnt -> symlink to the tracked interconnect config
# gpgpusim_out.txt, gpgpu_inst_stats.txt, ... (upstream simulator outputs)
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
UPSTREAM="$HERE/upstream"
DEFAULT_CONFIG_DIR="$HERE/configs/turing-tu104-2080super"
CONFIG_NAME="gpgpusim.config"
ICNT_NAME="config_turing_islip.icnt"
BUILD_TYPE="${GPGPUSIM_BUILD_TYPE:-release}"
WORKDIR="${GPGPUSIM_RUN_DIR:-$HERE/build/run}"
CONFIG_DIR="$DEFAULT_CONFIG_DIR"
die() { echo "run_sim.sh: ERROR: $*" >&2; exit 1; }
usage() {
cat <<'EOF'
Usage: run_sim.sh [--workdir DIR] [--build-type release|debug] \
[--config-dir DIR] <cuda-binary> [args...]
--workdir DIR directory the binary runs in (default gpgpu-sim/build/run)
--build-type TYPE release (default) or debug
--config-dir DIR config directory to use (default configs/turing-tu104-2080super)
-h, --help this help
The binary must be dynamically linked against libcudart (link with
"--cudart shared"); LD_LIBRARY_PATH is replaced with the GPGPU-Sim runtime
so no recompilation for the simulator is needed.
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--workdir) WORKDIR="${2:-}"; shift ;;
--build-type) BUILD_TYPE="${2:-}"; shift ;;
--config-dir) CONFIG_DIR="${2:-}"; shift ;;
-h|--help) usage; exit 0 ;;
--) shift; break ;;
-*) usage >&2; exit 2 ;;
*) break ;;
esac
shift
done
[ $# -ge 1 ] || { usage >&2; exit 2; }
[ -n "$WORKDIR" ] || die "--workdir requires a value"
[ -n "$CONFIG_DIR" ] || die "--config-dir requires a value"
case "$BUILD_TYPE" in release|debug) ;; *) die "unknown build type '$BUILD_TYPE'" ;; esac
BIN="$1"; shift
case "$BIN" in
*/*)
[ -e "$BIN" ] || die "binary not found: $BIN"
BIN="$(cd "$(dirname "$BIN")" && pwd)/$(basename "$BIN")"
;;
*)
resolved="$(command -v "$BIN" || true)"
[ -n "$resolved" ] || die "binary '$BIN' not found in PATH"
BIN="$resolved"
;;
esac
[ -d "$CONFIG_DIR" ] || die "config dir not found: $CONFIG_DIR"
[ -f "$CONFIG_DIR/$CONFIG_NAME" ] || die "missing $CONFIG_DIR/$CONFIG_NAME"
LIBDIR="$(find "$UPSTREAM/lib" -maxdepth 3 -type d -name "$BUILD_TYPE" 2>/dev/null | sort | head -n 1 || true)"
[ -n "$LIBDIR" ] || die "no GPGPU-Sim runtime library dir under $UPSTREAM/lib; run ./setup.sh first"
if ! ls "$LIBDIR"/libcudart.so* >/dev/null 2>&1; then
echo "run_sim.sh: WARNING: no libcudart.so in $LIBDIR; the binary may load the system CUDA runtime" >&2
fi
mkdir -p "$WORKDIR"
ln -sfn "$CONFIG_DIR/$CONFIG_NAME" "$WORKDIR/$CONFIG_NAME"
if [ -f "$CONFIG_DIR/$ICNT_NAME" ]; then
ln -sfn "$CONFIG_DIR/$ICNT_NAME" "$WORKDIR/$ICNT_NAME"
fi
export GPGPUSIM_ROOT="$UPSTREAM"
export LD_LIBRARY_PATH="$LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export CUDA_INSTALL_PATH="${CUDA_INSTALL_PATH:-/usr/local/cuda}"
echo "run_sim.sh: binary : $BIN"
echo "run_sim.sh: config : $CONFIG_DIR/$CONFIG_NAME"
echo "run_sim.sh: workdir : $WORKDIR"
echo "run_sim.sh: runtime libs: $LIBDIR"
cd "$WORKDIR"
exec "$BIN" "$@"
|