Debian Codegraph @

install

raw
1 #!/bin/bash
2
3
4 # #################################################
5 # helper functions
6 # #################################################
7 function display_help()
8 {
9 echo "hipRAND 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 " [-d|--dependencies] install build dependencies"
16 echo " [-c|--clients] build library clients too (combines with -i & -d)"
17 echo " [-g|--debug] -DCMAKE_BUILD_TYPE=Debug (default is =Release)"
18 echo " [--hip-clang] build library for amdgpu backend using hip-clang"
19 echo " [--address-sanitizer] build with address sanitizer enabled"
20 }
21
22
23 # #################################################
24 # global variables
25 # #################################################
26 install_package=false
27 build_package=false
28 build_clients=false
29 build_release=true
30 run_tests=false
31 build_hip_clang=false
32 rocm_path=/opt/rocm
33 build_relocatable=false
34 install_dependencies=false
35 build_address_sanitizer=false
36
37 # #################################################
38 # Parameter parsing
39 # #################################################
40
41 # check if we have a modern version of getopt that can handle whitespace and long parameters
42 getopt -T
43 if [[ $? -eq 4 ]]; then
44 GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,debug,hip-clang,test,package,relocatable,dependencies,address-sanitizer --options hicgtprd -- "$@")
45 else
46 echo "Need a new version of getopt"
47 exit 1
48 fi
49
50 if [[ $? -ne 0 ]]; then
51 echo "getopt invocation failed; could not parse the command line";
52 exit 1
53 fi
54
55 eval set -- "${GETOPT_PARSE}"
56
57 check_exit_code( )
58 {
59 if (( $1 != 0 )); then
60 exit $1
61 fi
62 }
63
64 while true; do
65 case "${1}" in
66 -h|--help)
67 display_help
68 exit 0
69 ;;
70 -i|--install)
71 install_package=true
72 shift ;;
73 -p|--package)
74 build_package=true
75 shift ;;
76 -r|--relocatable)
77 build_relocatable=true
78 shift ;;
79 -d|--dependencies)
80 install_dependencies=true
81 shift ;;
82 -c|--clients)
83 build_clients=true
84 shift ;;
85 -g|--debug)
86 build_release=false
87 shift ;;
88 -t|--test)
89 run_tests=true
90 shift ;;
91 --hip-clang)
92 build_hip_clang=true
93 shift ;;
94 --address-sanitizer)
95 build_address_sanitizer=true
96 shift ;;
97 --) shift ; break ;;
98 *) echo "Unexpected command line parameter received; aborting";
99 exit 1
100 ;;
101 esac
102 done
103
104 if [[ "${build_relocatable}" == true ]]; then
105 if ! [ -z ${ROCM_PATH+x} ]; then
106 rocm_path=${ROCM_PATH}
107 fi
108
109 rocm_rpath=" -Wl,--enable-new-dtags -Wl,--rpath,/opt/rocm/lib:/opt/rocm/lib64"
110 if ! [ -z ${ROCM_RPATH+x} ]; then
111 rocm_rpath=" -Wl,--enable-new-dtags -Wl,--rpath,${ROCM_RPATH}"
112 fi
113 fi
114
115 # Instal the pre-commit hook
116 #bash .githooks/install
117
118
119 # Create and go to the build directory.
120 mkdir -p build; cd build
121
122 if ($build_release); then
123 mkdir -p release; cd release
124 else
125 mkdir -p debug; cd debug
126 fi
127
128 # build type
129 if [[ "${build_release}" == true ]]; then
130 cmake_common_options="${cmake_common_options} -DCMAKE_BUILD_TYPE=Release"
131 else
132 cmake_common_options="${cmake_common_options} -DCMAKE_BUILD_TYPE=Debug"
133 fi
134
135 # Configure hipCUB, setup options for your system.
136 # Build options:
137 # BUILD_TEST - on by default,
138 # BUILD_BENCHMARK - off by default.
139 #
140 # ! IMPORTANT !
141 # On ROCm software set C++ compiler to HIPCC. You can do it by adding 'CXX=<path-to-hipcc>'
142 # before 'cmake' or setting cmake option 'CMAKE_CXX_COMPILER' to path to the HIPCC compiler.
143 #
144
145 compiler="hipcc"
146
147 cmake_executable="cmake"
148
149 if($build_clients); then
150 clients=" -DBUILD_TEST=ON -DBUILD_BENCHMARK=ON "
151 fi
152
153 if ($build_address_sanitizer); then
154 cmake_common_options="$cmake_common_options -DBUILD_ADDRESS_SANITIZER=ON"
155 fi
156
157 if($install_dependencies); then
158 cmake_common_options="${cmake_common_options} -DDEPENDENCIES_FORCE_DOWNLOAD=ON"
159 fi
160
161 if [[ "${build_relocatable}" == true ]]; then
162 CXX=${rocm_path}/bin/$compiler ${cmake_executable} -DCMAKE_INSTALL_PREFIX="${rocm_path}" \
163 -DBUILD_TEST=ON -DBUILD_BENCHMARK=ON ${cmake_common_options} \
164 -DCMAKE_PREFIX_PATH="${rocm_path} ${rocm_path}/hip" \
165 -DCMAKE_SHARED_LINKER_FLAGS="${rocm_rpath}" \
166 -DROCM_DISABLE_LDCONFIG=ON \
167 -DCMAKE_MODULE_PATH="${rocm_path}/hip/cmake" \
168 ../../. # or cmake-gui ../.
169 else
170 CXX=${rocm_path}/bin/$compiler ${cmake_executable} ${clients} ${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