forked from THU-DSP-LAB/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-ventus.sh
executable file
·306 lines (270 loc) · 8.21 KB
/
build-ventus.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!bash
DIR=$(cd "$(dirname "${0}")" &> /dev/null && (pwd -W 2> /dev/null || pwd))
VENTUS_BUILD_DIR=${DIR}/build
LIBCLC_BUILD_DIR=${DIR}/build-libclc
VENTUS_INSTALL_PREFIX=${DIR}/install
PROGRAMS_TOBUILD=(llvm ocl-icd libclc spike driver pocl rodinia test-pocl)
# Helper function
help() {
cat <<END
Build llvm, pocl, ocl-icd, libclc programs
Read ${DIR}/README.md to get started.
Usage: ${DIR}/$(basename ${0})
[--build <build programs>]
[--help | -h]
Options:
--build <build programs>
Chosen programs to build : llvm, ocl-icd, libclc, spike, driver, pocl
Option format : "llvm;pocl", string are seperated by semicolon
Default : "llvm;ocl-icd;libclc;spike;driver;pocl"
'BUILD_TYPE' is default 'Debug' which can be changed by enviroment variable
--help | -h
Print this help message and exit.
END
}
# Check the to be built program exits in file system or not
check_if_program_exits() {
if [ ! -d "$1" ]; then
echo "WARNING:*************************************************************"
echo
echo "$2 folder not found, please set or check!"
echo "Default folder is set to be $(realpath $1)"
echo
echo "WARNING:*************************************************************"
fi
}
# Parse command line options
while [ $# -gt 0 ]; do
case $1 in
-h | --help)
help
exit 0
;;
--build)
shift
if [ ! -z "${1}" ];then
PROGRAMS_TOBUILD=(${1//;/ })
fi
;;
?*)
echo "Invalid options: \"$1\" , try ${DIR}/$(basename ${0}) --help for help"
exit -1
;;
esac
# Process next command-line option
shift
done
# Need to get the pocl folder from enviroment variables
if [ -z "${POCL_DIR}" ]; then
POCL_DIR=${DIR}/../pocl
fi
check_if_program_exits $POCL_DIR "pocl"
POCL_BUILD_DIR=${POCL_DIR}/build
# Get build type from env, otherwise use default value 'Debug'
if [ -z "${BUILD_TYPE}" ]; then
BUILD_TYPE=Release
fi
# Need to get the ventus-driver folder from enviroment variables
if [ -z "${DRIVER_DIR}" ]; then
DRIVER_DIR=${DIR}/../ventus-driver
fi
check_if_program_exits ${DRIVER_DIR} "ventus-driver"
DRIVER_BUILD_DIR=${DRIVER_DIR}/build
# Need to get the ventud-driver folder from enviroment variables
if [ -z "${SPIKE_DIR}" ]; then
SPIKE_DIR=${DIR}/../ventus-gpgpu-isa-simulator
fi
check_if_program_exits ${SPIKE_DIR} "spike"
SPIKE_BUILD_DIR=${SPIKE_DIR}/build
# Need to get the icd_loader folder from enviroment variables
if [ -z "${OCL_ICD_DIR}" ]; then
OCL_ICD_DIR=${DIR}/../ocl-icd
fi
check_if_program_exits ${OCL_ICD_DIR} "ocl icd"
OCL_ICD_BUILD_DIR=${OCL_ICD_DIR}/build
# Need to get the gpu-rodinia folder from enviroment variables
if [ -z "${RODINIA_DIR}" ]; then
RODINIA_DIR=${DIR}/../gpu-rodinia
fi
check_if_program_exits ${RODINIA_DIR} "gpu-rodinia"
# Build llvm
build_llvm() {
if [ ! -d "${VENTUS_BUILD_DIR}" ]; then
mkdir ${VENTUS_BUILD_DIR}
fi
cd ${VENTUS_BUILD_DIR}
cmake -G Ninja -B ${VENTUS_BUILD_DIR} ${DIR}/llvm \
-DLLVM_CCACHE_BUILD=ON \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
-DLLVM_PARALLEL_LINK_JOBS=12 \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DLLVM_ENABLE_PROJECTS="clang;lld;libclc" \
-DLLVM_TARGETS_TO_BUILD="AMDGPU;X86;RISCV" \
-DLLVM_TARGET_ARCH=riscv32 \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DCMAKE_INSTALL_PREFIX=${VENTUS_INSTALL_PREFIX}
ninja
ninja install
}
# Build ventus driver
build_driver() {
mkdir ${DRIVER_BUILD_DIR} || true
cd ${DRIVER_DIR}
cmake -G Ninja -B ${DRIVER_BUILD_DIR} . \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DENABLE_INSTALL=ON \
-DCMAKE_INSTALL_PREFIX=${VENTUS_INSTALL_PREFIX}
ninja -C ${DRIVER_BUILD_DIR}
ninja -C ${DRIVER_BUILD_DIR} install
}
# Build spike simulator
build_spike() {
# rm -rf ${SPIKE_BUILD_DIR} || true
mkdir ${SPIKE_BUILD_DIR} ||true
cd ${SPIKE_BUILD_DIR}
../configure --prefix=${VENTUS_INSTALL_PREFIX} --enable-commitlog
make -j8
make install
}
# Build pocl from THU
build_pocl() {
mkdir ${POCL_BUILD_DIR} || true
cd ${POCL_DIR}
cmake -G Ninja -B ${POCL_BUILD_DIR} . \
-DENABLE_HOST_CPU_DEVICES=OFF \
-DENABLE_VENTUS=ON \
-DENABLE_ICD=ON \
-DDEFAULT_ENABLE_ICD=ON \
-DENABLE_TESTS=OFF \
-DSTATIC_LLVM=OFF \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_INSTALL_PREFIX=${VENTUS_INSTALL_PREFIX}
ninja -C ${POCL_BUILD_DIR}
ninja -C ${POCL_BUILD_DIR} install
}
# Build libclc for pocl
build_libclc() {
if [ ! -d "${LIBCLC_BUILD_DIR}" ]; then
mkdir ${LIBCLC_BUILD_DIR}
fi
cd ${LIBCLC_BUILD_DIR}
cmake -G Ninja -B ${LIBCLC_BUILD_DIR} ${DIR}/libclc \
-DCMAKE_CLC_COMPILER=clang \
-DCMAKE_LLAsm_COMPILER_WORKS=ON \
-DCMAKE_CLC_COMPILER_WORKS=ON \
-DCMAKE_CLC_COMPILER_FORCED=ON \
-DCMAKE_LLAsm_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -Dcl_khr_fp64 -ffunction-sections -fdata-sections" \
-DCMAKE_CLC_FLAGS="-target riscv32 -mcpu=ventus-gpgpu -cl-std=CL2.0 -I${DIR}/libclc/generic/include -Dcl_khr_fp64 -ffunction-sections -fdata-sections"\
-DLIBCLC_TARGETS_TO_BUILD="riscv32--" \
-DCMAKE_CXX_FLAGS="-I ${DIR}/llvm/include/ -std=c++17 -Dcl_khr_fp64 -ffunction-sections -fdata-sections" \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_INSTALL_PREFIX=${VENTUS_INSTALL_PREFIX} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
ninja
ninja install
# TODO: There are bugs in linking all libclc object files now
echo "************* Building riscv32 libclc object file ************"
bash ${DIR}/libclc/build_riscv32clc.sh ${DIR}/libclc ${LIBCLC_BUILD_DIR} ${VENTUS_INSTALL_PREFIX} || true
DstDir=${VENTUS_INSTALL_PREFIX}/share/pocl
if [ ! -d "${DstDir}" ]; then
mkdir -p ${DstDir}
fi
}
# Build icd_loader
build_icd_loader() {
cd ${OCL_ICD_DIR}
./bootstrap
./configure --prefix=${VENTUS_INSTALL_PREFIX}
make && make install
}
# Test the rodinia test suit
test_rodinia() {
cd ${RODINIA_DIR}
make OCL_clean
make OPENCL
}
# TODO : More test cases of the pocl will be added
test_pocl() {
cd ${POCL_BUILD_DIR}/examples
./vecadd/vecadd
./matadd/matadd
}
# Export needed path and enviroment variables
export_elements() {
export PATH=${VENTUS_INSTALL_PREFIX}/bin:$PATH
export LD_LIBRARY_PATH=${VENTUS_INSTALL_PREFIX}/lib:$LD_LIBRARY_PATH
export SPIKE_SRC_DIR=${SPIKE_DIR}
export SPIKE_TARGET_DIR=${VENTUS_INSTALL_PREFIX}
export VENTUS_INSTALL_PREFIX=${VENTUS_INSTALL_PREFIX}
export POCL_DEVICES="ventus"
export OCL_ICD_VENDORS=${VENTUS_INSTALL_PREFIX}/lib/libpocl.so
}
# When no need to build llvm, export needed elements
if [[ ! "${PROGRAMS_TOBUILD[*]}" =~ "llvm" ]];then
export_elements
fi
# Check llvm is built or not
check_if_ventus_built() {
if [ ! -d "${VENTUS_INSTALL_PREFIX}" ];then
echo "Please build llvm first!"
exit 1
fi
}
# Check isa simulator is built or not
check_if_spike_built() {
if [ ! -f "${VENTUS_INSTALL_PREFIX}/lib/libspike_main.so" ];then
if [ ! -f "${SPIKE_BUILD_DIR}/lib/libspike_main.so" ];then
echo "Please build isa-simulator first!"
exit 1
else
cp ${SPIKE_BUILD_DIR}/lib/libspike_main.so ${VENTUS_INSTALL_PREFIX}/lib
fi
fi
}
# Check ocl-icd loader is built or not
# since pocl need ocl-icd and llvm built first
check_if_ocl_icd_built() {
if [ ! -f "${VENTUS_INSTALL_PREFIX}/lib/libOpenCL.so" ];then
echo "Please build ocl-icd first!"
exit 1
fi
}
# Process build options
for program in "${PROGRAMS_TOBUILD[@]}"
do
if [ "${program}" == "llvm" ];then
build_llvm
export_elements
elif [ "${program}" == "ocl-icd" ];then
build_icd_loader
elif [ "${program}" == "libclc" ];then
check_if_ventus_built
build_libclc
elif [ "${program}" == "spike" ]; then
build_spike
elif [ "${program}" == "driver" ]; then
check_if_spike_built
build_driver
elif [ "${program}" == "pocl" ]; then
check_if_ventus_built
check_if_ocl_icd_built
build_pocl
elif [ "${program}" == "rodinia" ]; then
check_if_ventus_built
check_if_ocl_icd_built
check_if_spike_built
test_rodinia
elif [ "${program}" == "test-pocl" ]; then
check_if_ventus_built
check_if_ocl_icd_built
check_if_spike_built
test_pocl
else
echo "Invalid build options: \"${program}\" , try $0 --help for help"
exit 1
fi
done