Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·117 lines (99 loc) · 2.66 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·117 lines (99 loc) · 2.66 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
#!/bin/bash
set -e
# === Configuration ===
BUILD_DIR="build"
CORES_COUNT=$(($(nproc) - 2))
BACKEND=""
OPTION=""
# === Functions ===
print_help() {
echo "Usage: ./build.sh [f|c] [--backend=HIP|CUDA]"
echo
echo "Options:"
echo " -f Full rebuild (clean + build)"
echo " -c Clean build directory"
echo " --backend=HIP Build HIP benchmarks"
echo " --backend=CUDA Build CUDA benchmarks"
echo " -h, --help Show this help message"
exit 0
}
detect_backend() {
if [[ -n "$BACKEND" ]]; then return; fi
if command -v nvidia-smi &> /dev/null; then
BACKEND="CUDA"
echo "🟦 Detected NVIDIA GPU: Using CUDA backend"
elif command -v rocminfo &> /dev/null; then
BACKEND="HIP"
echo "🟥 Detected AMD GPU: Using HIP backend"
else
echo "❌ Could not detect supported GPU backend (NVIDIA or AMD)."
echo "Use --backend=HIP or --backend=CUDA to specify manually."
exit 1
fi
}
clean() {
echo "🧹 Cleaning build directory..."
rm -rf "$BUILD_DIR" build.log
echo "✅ Cleaning completed."
}
duration() {
local duration=$((end - start))
echo | tee -a build.log
echo "################################################################################" | tee -a build.log
echo "Build time: ${duration}s" | tee -a build.log
echo "################################################################################" | tee -a build.log
echo | tee -a build.log
}
build() {
detect_backend
echo "🚀 Starting build for backend: $BACKEND"
start=$(date +%s)
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
touch ".${BACKEND}"
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_CUDA=$([[ "$BACKEND" == "CUDA" ]] && echo ON || echo OFF) \
-DENABLE_HIP=$([[ "$BACKEND" == "HIP" ]] && echo ON || echo OFF) \
2>&1 | tee ../build.log
make -j "$CORES_COUNT" 2>&1 | tee -a ../build.log
end=$(date +%s)
cd ..
duration
}
parse_args() {
for arg in "$@"; do
case $arg in
-c)
OPTION="CLEAN"
;;
-f)
OPTION="FULL"
;;
--backend=*)
BACKEND="${arg#*=}"
;;
-h|--help)
print_help
;;
*)
echo "❌ Unknown argument: $arg"
print_help
;;
esac
done
}
# === Main Execution ===
parse_args "$@"
case "$OPTION" in
"CLEAN")
clean
;;
"FULL")
clean
build
;;
*)
build
;;
esac