-
Notifications
You must be signed in to change notification settings - Fork 80
/
build_metal.sh
executable file
·285 lines (248 loc) · 8.97 KB
/
build_metal.sh
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/bin/bash
set -eo pipefail
# Function to display help
show_help() {
echo "Usage: $0 [options]..."
echo " -h, --help Show this help message."
echo " -e, --export-compile-commands Enable CMAKE_EXPORT_COMPILE_COMMANDS."
echo " -c, --enable-ccache Enable ccache for the build."
echo " -b, --build-type build_type Set the build type. Default is Release. Other options are Debug, RelWithDebInfo, and CI."
echo " -t, --trace Enable build time trace (clang only)."
echo " -a, --enable-asan Enable AddressSanitizer."
echo " -m, --enable-msan Enable MemorySanitizer."
echo " -s, --enable-tsan Enable ThreadSanitizer."
echo " -u, --enable-ubsan Enable UndefinedBehaviorSanitizer."
echo " -p, --enable-profiler Enable Tracy profiler."
echo " --install-prefix Where to install build artifacts."
echo " --build-tests Build All Testcases."
echo " --build-ttnn-tests Build ttnn Testcases."
echo " --build-metal-tests Build metal Testcases."
echo " --build-umd-tests Build umd Testcases."
echo " --build-programming-examples Build programming examples."
echo " --build-tt-train Build tt-train."
echo " --build-all Build all optional components."
echo " --release Set the build type as Release."
echo " --development Set the build type as RelWithDebInfo."
echo " --debug Set the build type as Debug."
echo " --clean Remove build workspaces."
echo " --build-static-libs Build tt_metal (not ttnn) as a static lib (BUILD_SHARED_LIBS=OFF)"
echo " --disable-unity-builds Disable Unity builds"
echo " --cxx-compiler-path Set path to C++ compiler."
echo " --c-compiler-path Set path to C++ compiler."
}
clean() {
echo "INFO: Removing build artifacts!"
rm -rf build_Release* build_Debug* build_RelWithDebInfo* build built
}
# Parse CLI options
export_compile_commands="OFF"
enable_ccache="OFF"
enable_time_trace="OFF"
enable_asan="OFF"
enable_msan="OFF"
enable_tsan="OFF"
enable_ubsan="OFF"
build_type="Release"
enable_profiler="OFF"
build_tests="OFF"
build_ttnn_tests="OFF"
build_metal_tests="OFF"
build_umd_tests="OFF"
build_programming_examples="OFF"
build_tt_train="OFF"
build_static_libs="OFF"
unity_builds="ON"
build_all="OFF"
cxx_compiler_path=""
c_compiler_path=""
declare -a cmake_args
OPTIONS=h,e,c,t,a,m,s,u,b:,p
LONGOPTIONS=help,build-all,export-compile-commands,enable-ccache,enable-time-trace,enable-asan,enable-msan,enable-tsan,enable-ubsan,build-type:,enable-profiler,install-prefix:,build-tests,build-ttnn-tests,build-metal-tests,build-umd-tests,build-programming-examples,build-tt-train,build-static-libs,disable-unity-builds,release,development,debug,clean,cxx-compiler-path:,c-compiler-path:
# Parse the options
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
# If getopt has errors
echo "INFO: Failed to parse arguments!"
show_help
exit 1
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
show_help;exit 0;;
-e|--export-compile-commands)
export_compile_commands="ON";unity_builds="OFF";;
-c|--enable-ccache)
enable_ccache="ON";;
-t|--enable-time-trace)
enable_time_trace="ON";;
-a|--enable-asan)
enable_asan="ON";;
-m|--enable-msan)
enable_msan="ON";;
-s|--enable-tsan)
enable_tsan="ON";;
-u|--enable-ubsan)
enable_ubsan="ON";;
-b|--build-type)
build_type="$2";shift;;
-p|--enable-profiler)
enable_profiler="ON";;
--install-prefix)
install_prefix="$2";shift;;
--build-tests)
build_tests="ON";;
--build-ttnn-tests)
build_ttnn_tests="ON";;
--build-metal-tests)
build_metal_tests="ON";;
--build-umd-tests)
build_umd_tests="ON";;
--build-programming-examples)
build_programming_examples="ON";;
--build-tt-train)
build_tt_train="ON";;
--build-static-libs)
build_static_libs="ON";;
--build-all)
build_all="ON";;
--disable-unity-builds)
unity_builds="OFF";;
--cxx-compiler-path)
cxx_compiler_path="$2";shift;;
--c-compiler-path)
c_compiler_path="$2";shift;;
--release)
build_type="Release";;
--development)
build_type="RelWithDebInfo";;
--debug)
build_type="Debug";;
--clean)
clean; exit 0;;
--)
shift;break;;
esac
shift
done
# Check if there are unrecognized positional arguments left
if [[ $# -gt 0 ]]; then
echo "ERROR: Unrecognized positional argument(s): $@"
show_help
exit 1
fi
# Validate the build_type
VALID_BUILD_TYPES=("Release" "Debug" "RelWithDebInfo")
if [[ ! " ${VALID_BUILD_TYPES[@]} " =~ " ${build_type} " ]]; then
echo "ERROR: Invalid build type '$build_type'. Allowed values are Release, Debug, RelWithDebInfo."
show_help
exit 1
fi
build_dir="build_$build_type"
if [ "$enable_profiler" = "ON" ]; then
build_dir="${build_dir}_tracy"
fi
install_prefix_default=$build_dir
cmake_install_prefix=${install_prefix:="${install_prefix_default}"}
# Set the python environment directory if not already set
if [ -z "$PYTHON_ENV_DIR" ]; then
PYTHON_ENV_DIR=$(pwd)/python_env
fi
# Debug output to verify parsed options
echo "INFO: Export compile commands: $export_compile_commands"
echo "INFO: Enable ccache: $enable_ccache"
echo "INFO: Build type: $build_type"
echo "INFO: Enable time trace: $enable_time_trace"
echo "INFO: Enable AddressSanitizer: $enable_asan"
echo "INFO: Enable MemorySanitizer: $enable_msan"
echo "INFO: Enable ThreadSanitizer: $enable_tsan"
echo "INFO: Enable UndefinedBehaviorSanitizer: $enable_ubsan"
echo "INFO: Build directory: $build_dir"
echo "INFO: Install Prefix: $cmake_install_prefix"
echo "INFO: Build tests: $build_tests"
echo "INFO: Enable Unity builds: $unity_builds"
# Prepare cmake arguments
cmake_args+=("-B" "$build_dir")
cmake_args+=("-G" "Ninja")
cmake_args+=("-DCMAKE_BUILD_TYPE=$build_type")
cmake_args+=("-DCMAKE_INSTALL_PREFIX=$cmake_install_prefix")
if [ "$cxx_compiler_path" != "" ]; then
echo "INFO: C++ compiler: $cxx_compiler_path"
cmake_args+=("-DCMAKE_CXX_COMPILER=$cxx_compiler_path")
fi
if [ "$c_compiler_path" != "" ]; then
echo "INFO: C compiler: $c_compiler_path"
cmake_args+=("-DCMAKE_C_COMPILER=$c_compiler_path")
fi
if [ "$enable_ccache" = "ON" ]; then
cmake_args+=("-DCMAKE_DISABLE_PRECOMPILE_HEADERS=TRUE")
cmake_args+=("-DENABLE_CCACHE=TRUE")
fi
if [ "$enable_time_trace" = "ON" ]; then
cmake_args+=("-DENABLE_BUILD_TIME_TRACE=ON")
fi
if [ "$enable_asan" = "ON" ]; then
cmake_args+=("-DENABLE_ASAN=ON")
fi
if [ "$enable_msan" = "ON" ]; then
cmake_args+=("-DENABLE_MSAN=ON")
fi
if [ "$enable_tsan" = "ON" ]; then
cmake_args+=("-DENABLE_TSAN=ON")
fi
if [ "$enable_ubsan" = "ON" ]; then
cmake_args+=("-DENABLE_UBSAN=ON")
fi
if [ "$enable_profiler" = "ON" ]; then
cmake_args+=("-DENABLE_TRACY=ON")
fi
if [ "$export_compile_commands" = "ON" ]; then
cmake_args+=("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON")
else
cmake_args+=("-DCMAKE_EXPORT_COMPILE_COMMANDS=OFF")
fi
if [ "$build_tests" = "ON" ]; then
cmake_args+=("-DTT_METAL_BUILD_TESTS=ON")
cmake_args+=("-DTTNN_BUILD_TESTS=ON")
cmake_args+=("-DTT_UMD_BUILD_TESTS=ON")
fi
if [ "$build_metal_tests" = "ON" ]; then
cmake_args+=("-DTT_METAL_BUILD_TESTS=ON")
fi
if [ "$build_ttnn_tests" = "ON" ]; then
cmake_args+=("-DTTNN_BUILD_TESTS=ON")
fi
if [ "$build_tt_umd_tests" = "ON" ]; then
cmake_args+=("-DTT_UMD_BUILD_TESTS=ON")
fi
if [ "$build_programming_examples" = "ON" ]; then
cmake_args+=("-DBUILD_PROGRAMMING_EXAMPLES=ON")
fi
if [ "$build_tt_train" = "ON" ]; then
cmake_args+=("-DBUILD_TT_TRAIN=ON")
fi
if [ "$build_static_libs" = "ON" ]; then
cmake_args+=("-DBUILD_SHARED_LIBS=OFF")
fi
if [ "$unity_builds" = "ON" ]; then
cmake_args+=("-DTT_UNITY_BUILDS=ON")
else
cmake_args+=("-DTT_UNITY_BUILDS=OFF")
fi
if [ "$build_all" = "ON" ]; then
cmake_args+=("-DTT_METAL_BUILD_TESTS=ON")
cmake_args+=("-DTTNN_BUILD_TESTS=ON")
cmake_args+=("-DTT_UMD_BUILD_TESTS=ON")
cmake_args+=("-DBUILD_PROGRAMMING_EXAMPLES=ON")
cmake_args+=("-DBUILD_TT_TRAIN=ON")
fi
# Create and link the build directory
mkdir -p $build_dir
ln -nsf $build_dir build
echo "INFO: Configuring Project"
echo "INFO: Running: cmake "${cmake_args[@]}""
cmake "${cmake_args[@]}"
# Build libraries and cpp tests
echo "INFO: Building Project"
cmake --build $build_dir --target install