-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-ventus.sh
executable file
·167 lines (147 loc) · 3.96 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
#!/usr/bin/bash
DIR=$(cd "$(dirname "${0}")" &> /dev/null && (pwd -W 2> /dev/null || pwd))
VENTUS_BUILD_DIR=${DIR}/build
VENTUS_INSTALL_PREFIX=${DIR}/install
PROGRAMS_TOBUILD=(llvm-ventus ocl-icd pocl)
# Helper function
help() {
cat <<END
Build llvm-ventus, pocl, ocl-icd, 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-ventus, pocl, ocl-icd
Option format : "llvm-ventus;pocl", string are seperated by semicolon
Default : "llvm-ventus;pocl;ocl-icd"
--help | -h
Print this help message and exit.
END
}
# 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
if [ ! -d "${POCL_DIR}" ]; then
echo "pocl folder not found, please set or check!"
echo "Default folder is set to be $(realpath ${POCL_DIR})"
exit 1
fi
POCL_BUILD_DIR=${POCL_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
if [ ! -d "${OCL_ICD_DIR}" ]; then
echo "ocl icd folder not found, please set or check"
echo "Default folder is set to be $(realpath ${OCL_ICD_DIR})"
exit 1
fi
OCL_ICD_BUILD_DIR=${OCL_ICD_DIR}/build
# Build llvm-ventus
build_ventus() {
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=Debug \
-DLLVM_ENABLE_PROJECTS="clang;lld;libclc" \
-DLLVM_TARGETS_TO_BUILD="X86;RISCV" \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DCMAKE_INSTALL_PREFIX=${VENTUS_INSTALL_PREFIX}
ninja
ninja install
}
# Build pocl from THU
build_pocl() {
rm -rf ${POCL_BUILD_DIR} || true
mkdir ${POCL_BUILD_DIR}
cd ${POCL_DIR}
cmake -G Ninja -B ${POCL_BUILD_DIR} . \
-DENABLE_HOST_CPU_DEVICES=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 icd_loader
build_icd_loader() {
cd ${OCL_ICD_DIR}
./bootstrap
./configure --prefix=${VENTUS_INSTALL_PREFIX}
make && make install
}
# Export needed path and enviroment variables
export_elements() {
export PATH=${VENTUS_INSTALL_PREFIX}/bin:$PATH
export LD_LIBRARY_PATH=${VENTUS_INSTALL_PREFIX}/lib
}
# When no need to build llvm-ventus, export needed elements
if [[ ! "${PROGRAMS_TOBUILD[*]}" =~ "llvm-ventus" ]];then
export_elements
fi
# Check llvm-ventus is built or not
check_if_ventus_built() {
if [ ! -d "${VENTUS_INSTALL_PREFIX}" ];then
echo "Please build llvm-ventus first!"
exit 1
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-ventus" ];then
build_ventus
export_elements
elif [ "${program}" == "pocl" ]; then
check_if_ventus_built
check_if_ocl_icd_built
build_pocl
elif [ "${program}" == "ocl-icd" ];then
build_icd_loader
else
echo "Invalid build options: \"${program}\" , try $0 --help for help"
exit 1
fi
done