-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.sh
More file actions
executable file
·238 lines (214 loc) · 6.88 KB
/
Copy pathcompile.sh
File metadata and controls
executable file
·238 lines (214 loc) · 6.88 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
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
#!/bin/bash
# =================================================
# compile.sh
# =================================================
HARDWARE=""
SYCL_IMPL=""
BENCHMARK_DIR=""
RUN_TESTS=false
ONEAPI_COMPILER="icpx"
DPCPP_COMPILER="clang++"
ACPP_COMPILER="acpp"
CMAKE_OPTIONS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
usage() {
echo "Simple compilation script. Automatically builds the project for a combination (hw, sycl)."
echo "For multiple devices compilation flows, please compile manually."
echo "Usage: $0 [--hw <mi250|a100|cpu|mi300|pvc|h100>] [--sycl <dpcpp|acpp|oneapi>] [--benchmark_DIR=<directory>] [--build-tests] [--run-tests] [--debug]"
echo "Compilers must be present in PATH:"
echo " dpcpp : ${DPCPP_COMPILER}"
echo " acpp : ${ACPP_COMPILER}"
echo " oneapi : ${ONEAPI_COMPILER}"
exit 1
}
# =================================================
# Argument parsing
# =================================================
BUILD_TESTS=false # Initialize the boolean variable
BUILD_DEBUG=false
while [ "$#" -gt 0 ]; do
case $1 in
--hw)
HARDWARE="$2"
shift 2 # Remove --hw and its argument from the list
;;
--sycl)
SYCL_IMPL="$2"
shift 2 # Remove --sycl and its argument from the list
;;
--benchmark_DIR=*)
BENCHMARK_DIR="${1#*=}"
shift 1 # Remove --benchmark_DIR=path from the list
;;
--build-tests)
BUILD_TESTS=true
shift 1 # Remove --build-tests from the list
;;
--run-tests)
RUN_TESTS=true
shift 1 # Remove --run-tests from the list
;;
--debug)
BUILD_DEBUG=true
shift 1
;;
*)
usage # Handle unknown options
;;
esac
done
if [ -z "$HARDWARE" ] || [ -z "$SYCL_IMPL" ]; then
echo "Error: Both --hw and --sycl options are required."
usage
fi
if $RUN_TESTS && ! $BUILD_TESTS; then
echo "Error: --run-tests option requires --build-tests option to be set."
usage
fi
ERR_SYCL_UNKNOWN="### Error: Unsupported SYCL implementation specified."
ERR_HW_UNKNOWN="### Error: Unsupported hardware architecture specified."
# =================================================
# Set right CXX compiler (must be in PATH)
# =================================================
if [ "$SYCL_IMPL" == "dpcpp" ]; then
CMAKE_OPTIONS+=" -DCMAKE_CXX_COMPILER=${DPCPP_COMPILER}"
elif [ "$SYCL_IMPL" == "acpp" ]; then
CMAKE_OPTIONS+=" -DCMAKE_CXX_COMPILER=${ACPP_COMPILER}"
elif [ "$SYCL_IMPL" == "oneapi" ]; then
CMAKE_OPTIONS+=" -DCMAKE_CXX_COMPILER=${ONEAPI_COMPILER}"
else
echo $ERR_SYCL_UNKNOWN
usage
fi
# =================================================
# Set CMake options based on hardware and compiler
# =================================================
if [ "$HARDWARE" == "mi250" ]; then
if [ "$SYCL_IMPL" == "dpcpp" ]; then
CMAKE_OPTIONS+=" -DDPCPP_FSYCL_TARGETS='-fsycl-targets=amd_gpu_gfx90a'"
elif [ "$SYCL_IMPL" == "acpp" ]; then
export ACPP_TARGETS="hip:gfx90a"
elif [ "$SYCL_IMPL" == "oneapi" ]; then
echo "### Warning: Combination not tested: ${SYCL_IMPL} - ${HARDWARE}"
else
echo $ERR_SYCL_UNKNOWN
usage
fi
elif [ "$HARDWARE" == "a100" ]; then
if [ "$SYCL_IMPL" == "dpcpp" ]; then
CMAKE_OPTIONS+=" -DDPCPP_FSYCL_TARGETS='-fsycl-targets=nvidia_gpu_sm_80'"
elif [ "$SYCL_IMPL" == "acpp" ]; then
export ACPP_TARGETS="cuda:sm_80"
elif [ "$SYCL_IMPL" == "oneapi" ]; then
echo "### Warning: Combination not tested: ${SYCL_IMPL} - ${HARDWARE}"
else
echo $ERR_SYCL_UNKNOWN
usage
fi
elif [ "$HARDWARE" == "cpu" ]; then
if [ "$SYCL_IMPL" == "dpcpp" ]; then
CMAKE_OPTIONS+=" -DDPCPP_FSYCL_TARGETS='-fsycl-targets=spir64_x86_64'"
elif [ "$SYCL_IMPL" == "acpp" ]; then
export ACPP_TARGETS="omp"
elif [ "$SYCL_IMPL" == "oneapi" ]; then
# do nothing
CMAKE_OPTIONS+=""
else
echo $ERR_SYCL_UNKNOWN
usage
fi
elif [ "$HARDWARE" == "mi300" ]; then
if [ "$SYCL_IMPL" == "dpcpp" ]; then
CMAKE_OPTIONS+=" -DDPCPP_FSYCL_TARGETS='-fsycl-targets=amd_gpu_gfx942'"
elif [ "$SYCL_IMPL" == "acpp" ]; then
export ACPP_TARGETS="generic"
elif [ "$SYCL_IMPL" == "oneapi" ]; then
#do nothing
CMAKE_OPTIONS+=""
else
echo $ERR_SYCL_UNKNOWN
usage
fi
elif [ "$HARDWARE" == "pvc" ]; then
if [ "$SYCL_IMPL" == "dpcpp" ]; then
CMAKE_OPTIONS+=" -DBUILD_WITH_INTEL_LLVM=ON"
elif [ "$SYCL_IMPL" == "acpp" ]; then
export ACPP_TARGETS="generic"
elif [ "$SYCL_IMPL" == "oneapi" ]; then
#do nothing
CMAKE_OPTIONS+=""
else
echo $ERR_SYCL_UNKNOWN
usage
fi
elif [ "$HARDWARE" == "h100" ]; then
if [ "$SYCL_IMPL" == "dpcpp" ]; then
CMAKE_OPTIONS+=" -DDPCPP_FSYCL_TARGETS='-fsycl-targets=nvidia_gpu_sm_90'"
elif [ "$SYCL_IMPL" == "acpp" ]; then
export ACPP_TARGETS="generic"
elif [ "$SYCL_IMPL" == "oneapi" ]; then
#do nothing
CMAKE_OPTIONS+=""
else
echo $ERR_SYCL_UNKNOWN
usage
fi
else
echo $ERR_HW_UNKNOWN
usage
fi
if [ -n "$BENCHMARK_DIR" ]; then
if [ "$BENCHMARK_DIR" = "default" ]; then
BENCHMARK_DIR="`pwd`/thirdparty/benchmark/build"
fi
CMAKE_OPTIONS+=" -Dbenchmark_DIR=${BENCHMARK_DIR}"
fi
if $BUILD_TESTS; then
CMAKE_OPTIONS+=" -DADVECTION_BUILD_TESTS=ON"
fi
# =================================================
# Configure
# =================================================
BUILD_DIR=build_${SYCL_IMPL}_${HARDWARE}
if $BUILD_DEBUG; then
CMAKE_OPTIONS+=" -DCMAKE_BUILD_TYPE=Debug"
BUILD_DIR+="_debug"
fi
# Check if the build directory exists
if [ -d "${BUILD_DIR}" ]; then
echo "### Removing existing build directory: ${BUILD_DIR}"
rm -r "${BUILD_DIR}"
fi
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
echo "### Configuring project..."
cmake $CMAKE_OPTIONS ..
# Check the exit status of the CMake configuration
if [ $? -ne 0 ]; then
echo "### Error: CMake configuration failed. Deleting the build directory."
rm -r "$BUILD_DIR"
exit 1
fi
echo "### CMake configuration complete in `pwd`."
echo "# CMake options: ${CMAKE_OPTIONS}"
echo ""
# =================================================
# Build
# =================================================
echo "### Building project..."
cmake --build . --parallel 16
# Check the exit status of the build
if [ $? -ne 0 ]; then
echo "### Error: Build failed."
exit 1
fi
echo "### Build complete in `pwd`."
echo ""
# =================================================
# Run tests if specified
# =================================================
if $RUN_TESTS; then
echo "### Running tests..."
ctest --output-on-failure
echo "### Tests complete."
echo ""
fi