Debian Codegraph @

install

raw
1 #!/bin/bash
2
3
4 # #################################################
5 # helper functions
6 # #################################################
7 function display_help()
8 {
9 echo "hipCUB build & installation helper script"
10 echo "./install [-h|--help] "
11 echo " [-h|--help] prints this help message"
12 echo " [-i|--install] install after build"
13 echo " [-p|--package build package"
14 echo " [-r]--relocatable] create a package to support relocatable ROCm"
15 echo " [-b|--benchmark] builds and runs benchmark"
16 echo " [-d|--dependencies] install build dependencies"
17 echo " [-c|--clients] build library clients too (combines with -i & -d)"
18 echo " [-g|--debug] -DCMAKE_BUILD_TYPE=Debug (default is =Release)"
19 echo " [--hip-clang] build library for amdgpu backend using hip-clang"
20 echo " [--address-sanitizer] build with address sanitizer enabled"
21 echo " [--rm-legacy-include-dir] Remove legacy include dir Packaging added for file/folder reorg backward compatibility"
22 }
23
24
25 # #################################################
26 # global variables
27 # #################################################
28 install_package=false
29 build_package=false
30 build_clients=false
31 build_release=true
32 build_hip_clang=false
33 run_tests=false
34 rocm_path=/opt/rocm
35 build_relocatable=false
36 install_dependencies=false
37 build_address_sanitizer=false
38 build_benchmark=false
39 build_freorg_bkwdcomp=false
40
41 # #################################################
42 # Parameter parsing
43 # #################################################
44
45 # check if we have a modern version of getopt that can handle whitespace and long parameters
46 getopt -T
47 if [[ $? -eq 4 ]]; then
48 GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,debug,hip-clang,test,benchmark,package,relocatable,dependencies,address-sanitizer,rm-legacy-include-dir --options hicdtbpr -- "$@")
49 else
50 echo "Need a new version of getopt"
51 exit 1
52 fi
53
54 if [[ $? -ne 0 ]]; then
55 echo "getopt invocation failed; could not parse the command line";
56 exit 1
57 fi
58
59 eval set -- "${GETOPT_PARSE}"
60
61 check_exit_code( )
62 {
63 if (( $1 != 0 )); then
64 exit $1
65 fi
66 }
67
68 while true; do
69 case "${1}" in
70 -h|--help)
71 display_help
72 exit 0
73 ;;
74 -i|--install)
75 install_package=true
76 shift ;;
77 -p|--package)
78 build_package=true
79 shift ;;
80 -c|--clients)
81 build_clients=true
82 shift ;;
83 -r|--relocatable)
84 build_relocatable=true
85 shift ;;
86 -g|--debug)
87 build_release=false
88 shift ;;
89 -t|--test)
90 run_tests=true
91 shift ;;
92 -b|--benchmark)
93 build_benchmark=true
94 shift ;;
95 -d|--dependencies)
96 install_dependencies=true
97 shift ;;
98 --hip-clang)
99 build_hip_clang=true
100 shift ;;
101 --address-sanitizer)
102 build_address_sanitizer=true
103 shift ;;
104 --rm-legacy-include-dir)
105 build_freorg_bkwdcomp=false
106 shift ;;
107 --) shift ; break ;;
108 *) echo "Unexpected command line parameter received; aborting";
109 exit 1
110 ;;
111 esac
112 done
113
114 if [[ "${build_relocatable}" == true ]]; then
115 if ! [ -z ${ROCM_PATH+x} ]; then
116 rocm_path=${ROCM_PATH}
117 fi
118 fi
119
120 # Install the pre-commit hook
121 bash .githooks/install
122
123
124 # Create and go to the build directory.
125 mkdir -p build; cd build
126
127 if ($build_release); then
128 mkdir -p release; cd release
129 build_type="-DCMAKE_BUILD_TYPE=Release"
130 else
131 mkdir -p debug; cd debug
132 build_type="-DCMAKE_BUILD_TYPE=Debug"
133 fi
134
135 # Configure hipCUB, setup options for your system.
136 # Build options:
137 # BUILD_TEST - off by default,
138 # BUILD_BENCHMARK - off by default.
139 #
140 cmake_executable="cmake"
141
142 cmake_common_options="--toolchain=toolchain-linux.cmake"
143
144 if [[ "${build_benchmark}" == true ]]; then
145 build_benchmarks="-DBUILD_BENCHMARK=ON"
146 fi
147
148 if [[ "${build_clients}" == true ]]; then
149 build_tests="-DBUILD_TEST=ON"
150 else
151 build_tests="-DBUILD_TEST=OFF"
152 fi
153
154 if [[ "${build_address_sanitizer}" == true ]]; then
155 cmake_common_options="$cmake_common_options -DBUILD_ADDRESS_SANITIZER=ON"
156 fi
157
158 if ($install_dependencies); then
159 cmake_common_options="${cmake_common_options} -DDEPENDENCIES_FORCE_DOWNLOAD=ON"
160 fi
161
162 if [[ "${build_relocatable}" == true ]]; then
163 ${cmake_executable} \
164 -DCMAKE_INSTALL_PREFIX=${rocm_path} \
165 -DCMAKE_MODULE_PATH="${rocm_path}/lib/cmake/hip ${rocm_path}/hip/cmake" \
166 -Drocprim_DIR=${rocm_path}/rocprim \
167 ${cmake_common_options} \
168 ${build_tests} ${build_benchmarks} ${build_type} ../../. # or cmake-gui ../.
169 else
170 ${cmake_executable} ${build_tests} ${build_benchmarks} ${build_type} ${cmake_common_options} ../../. # or cmake-gui ../.
171 fi
172 check_exit_code "$?"
173
174 # Build
175 make -j$(nproc)
176 check_exit_code "$?"
177
178 if ($run_tests); then
179 # Optionally, run tests if they're enabled.
180 ctest --output-on-failure
181 fi
182
183 if ($install_package); then
184 # Install
185 make install
186 check_exit_code "$?"
187 fi
188
189 if ($build_package); then
190 # Package
191 make package -j$(nproc)
192 check_exit_code "$?"
193 fi