-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtask1.sh
More file actions
144 lines (123 loc) · 3.73 KB
/
Copy pathtask1.sh
File metadata and controls
144 lines (123 loc) · 3.73 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
# task1.sh — replaces the Makefile targets with a single bash CLI
# Usage:
# ./task1.sh <command> [--float f32|f16] [--ver N]
# FLOAT=f16 VER=2 ./task1.sh run
# Commands: build | run | debug | profile | clean | clean-logs | help
set -euo pipefail
# -------- defaults (can be overridden by env or CLI) --------
FLOAT="${FLOAT:-f32}"
VER="${VER:-1}"
# -------- tiny args parser (flags override env) -------------
cmd="${1:-help}"
shift || true
while [[ $# -gt 0 ]]; do
case "$1" in
-f|--float) FLOAT="$2"; shift 2;;
-v|--ver) VER="$2"; shift 2;;
-h|--help) cmd="help"; shift;;
*) echo "Unknown arg: $1" >&2; exit 2;;
esac
done
# -------- derived values -----------------------------------
if [[ "$FLOAT" == "f16" ]]; then
FLOAT_TYPE="float16"
FLOAT_FLAG="-f16"
else
FLOAT_TYPE="float32"
FLOAT_FLAG="-f32"
fi
BUILD_DIR="./build/src"
BINARY_NAME="task1_${FLOAT_TYPE}_v${VER}"
BINARY_PATH="${BUILD_DIR}/${BINARY_NAME}"
LOGS_DIR="logs"
# -------- helpers ------------------------------------------
timestamp() { date +"%Y%m%d_%H%M%S"; }
ensure_exec() {
# ensure a script is executable; if missing, fail with a clear msg
local p="$1"
[[ -f "$p" ]] || { echo "Required script not found: $p" >&2; exit 1; }
[[ -x "$p" ]] || chmod +x "$p" || true
}
do_build() {
echo "=== Building with FLOAT=${FLOAT} VERSION=${VER} ==="
ensure_exec "scripts/build-task1.sh"
bash scripts/build-task1.sh "${FLOAT_FLAG}" "-v${VER}"
}
do_run() {
do_build
echo "=== Running ${BINARY_NAME} ==="
mkdir -p "${LOGS_DIR}"
local ts; ts="$(timestamp)"
local log="${LOGS_DIR}/${BINARY_NAME}_${ts}.log"
{
echo "Run started at: $(date)"
echo "FLOAT_TYPE: ${FLOAT_TYPE}"
echo "VERSION: ${VER}"
echo "======================================"
} > "${log}"
# run binary, tee to log
"${BINARY_PATH}" 2>&1 | tee -a "${log}"
{
echo "======================================"
echo "Run completed at: $(date)"
echo "Log saved to: ${log}"
} >> "${log}"
}
do_debug() {
echo "=== Building Debug version with FLOAT=${FLOAT} VERSION=${VER} ==="
ensure_exec "scripts/build-task1.sh"
bash scripts/build-task1.sh "${FLOAT_FLAG}" "-v${VER}" "RD"
}
do_profile() {
do_debug
echo "=== Profiling ${BINARY_NAME} with Nsight Compute ==="
mkdir -p "${LOGS_DIR}/profiles"
ensure_exec "scripts/nsight-profile.sh"
local ts; ts="$(timestamp)"
local out="${LOGS_DIR}/profiles/${BINARY_NAME}_${ts}.ncu-rep"
bash scripts/nsight-profile.sh -t "${BINARY_PATH}" -o "${out}"
echo "Profile saved to: ${out}"
}
do_clean() {
rm -rf "${BUILD_DIR}"
echo "Build directory cleaned"
}
do_clean_logs() {
rm -rf "${LOGS_DIR}"
echo "Logs directory cleaned"
}
do_help() {
cat <<EOF
task1.sh — build & run helper (Bash version of your Makefile)
Usage:
./task1.sh <command> [--float f32|f16] [--ver N]
FLOAT=f16 VER=2 ./task1.sh run
Commands:
build Build code with specified FLOAT and VERSION
run Build and run code, save output to logs
debug Build with debug symbols (RelWithDebInfo via 'RD')
profile Run Nsight Compute profiling
clean Clean build directory (${BUILD_DIR})
clean-logs Clean logs directory (${LOGS_DIR})
help Show this help
Parameters:
--float f32|f16 Data type (default: ${FLOAT})
--ver N Version number (default: ${VER})
Examples:
./task1.sh build --float f16 --ver 2
FLOAT=f32 VER=1 ./task1.sh run
./task1.sh debug --float f16 --ver 3
./task1.sh profile --float f32 --ver 1
EOF
}
# -------- dispatch -----------------------------------------
case "$cmd" in
build) do_build;;
run) do_run;;
debug) do_debug;;
profile) do_profile;;
clean) do_clean;;
clean-logs) do_clean_logs;;
help|*) do_help;;
esac