-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.sh
executable file
·195 lines (170 loc) · 5.75 KB
/
compile.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
#!/bin/bash
# =================================================
# compile.sh
# =================================================
HARDWARE=""
SYCL_IMPL=""
BENCHMARK_DIR=""
RUN_TESTS=false
ONEAPI_COMPILER="icpx"
INTELLLVM_COMPILER="clang++"
ACPP_COMPILER="syclcc"
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|x86_64>] [--sycl <intel-llvm|acpp|oneapi>] [--benchmark_BUILD_DIR=<directory>] [--build-tests] [--run-tests]"
echo "Compilers must be present in PATH:"
echo " intel-llvm : ${INTELLLVM_COMPILER}"
echo " acpp : ${ACPP_COMPILER}"
echo " oneapi : ${ONEAPI_COMPILER}"
exit 1
}
# =================================================
# Argument parsing
# =================================================
BUILD_TESTS=false # Initialize the boolean variable
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_BUILD_DIR=*)
BENCHMARK_DIR="${1#*=}"
shift 1 # Remove --benchmark_BUILD_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
;;
*)
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" == "intel-llvm" ]; then
CMAKE_OPTIONS+=" -DCMAKE_CXX_COMPILER=${INTELLLVM_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" == "intel-llvm" ]; 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
# Add options for a100 and different SYCL implementations
if [ "$SYCL_IMPL" == "intel-llvm" ]; 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" == "x86_64" ]; then
# Add options for x86_64 and different SYCL implementations
if [ "$SYCL_IMPL" == "intel-llvm" ]; 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
else
echo $ERR_SYCL_UNKNOWN
usage
fi
else
echo $ERR_HW_UNKNOWN
usage
fi
# Add benchmark directory option if specified
if [ -n "$BENCHMARK_DIR" ]; then
CMAKE_OPTIONS+=" -DCMAKE_PREFIX_PATH=${BENCHMARK_DIR}"
CMAKE_OPTIONS+=" -DADVECTION_BUILD_BENCHMARKS=ON"
fi
# Add tests compilation if specified
if $BUILD_TESTS; then
CMAKE_OPTIONS+=" -DADVECTION_BUILD_TESTS=ON"
fi
# =================================================
# Configure
# =================================================
BUILD_DIR=build_${SYCL_IMPL}_${HARDWARE}
# 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 24
# 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