forked from rapidsai/cusignal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·262 lines (228 loc) · 9.03 KB
/
build.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
#!/bin/bash
# Copyright (c) 2019-2020, NVIDIA CORPORATION.
# cuSignal build script
# This script is used to build the component(s) in this repo from
# source, and can be called with various options to customize the
# build as needed (see the help output for details)
# Abort script on first error
set -e
NUMARGS=$#
ARGS=$*
# NOTE: ensure all dir changes are relative to the location of this
# script, and that this script resides in the repo dir!
REPODIR=$(cd $(dirname $0); pwd)
VALIDARGS="clean cusignal -c -v -g -n -p --allgpuarch -h"
HELP="$0 [clean] [cusignal] [-v] [-g] [-n] [--allgpuarch] [-h]
clean - remove all existing build artifacts and configuration (start
over)
cusignal - build the cusignal Python package
-c - ci build
-v - verbose build mode
-g - build for debug
-n - no install step
-p - Pass additional Xptxas options
--allgpuarch - build for all supported GPU architectures
-h - print this text
default action (no args) is to build and install 'cusignal' target
"
CUSIGNAL_BUILD_DIR=${REPODIR}/python/build
BUILD_DIRS="${CUSIGNAL_BUILD_DIR}"
# Set defaults for vars modified by flags to this script
VERBOSE=""
BUILD_TYPE=Release
INSTALL_TARGET=install
BUILD_ALL_GPU_ARCH=0
# Set defaults for vars that may not have been defined externally
# FIXME: if INSTALL_PREFIX is not set, check PREFIX, then check
# CONDA_PREFIX, but there is no fallback from there!
INSTALL_PREFIX=${INSTALL_PREFIX:=${PREFIX:=${CONDA_PREFIX}}}
PARALLEL_LEVEL=${PARALLEL_LEVEL:=""}
function hasArg {
(( ${NUMARGS} != 0 )) && (echo " ${ARGS} " | grep -q " $1 ")
}
function buildAll {
((${NUMARGS} == 0 )) || !(echo " ${ARGS} " | grep -q " [^-]\+ ")
}
if hasArg -h; then
echo "${HELP}"
exit 0
fi
# Check for valid usage
if (( ${NUMARGS} != 0 )); then
for a in ${ARGS}; do
if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then
echo "Invalid option: ${a}"
exit 1
fi
done
fi
# Process flags
if hasArg -v; then
VERBOSE=1
fi
if hasArg -g; then
BUILD_TYPE=Debug
fi
if hasArg -n; then
INSTALL_TARGET=""
fi
if hasArg --allgpuarch; then
BUILD_ALL_GPU_ARCH=1
fi
# If clean given, run it prior to any other steps
if hasArg clean; then
# If the dirs to clean are mounted dirs in a container, the
# contents should be removed but the mounted dirs will remain.
# The find removes all contents but leaves the dirs, the rmdir
# attempts to remove the dirs but can fail safely.
for bd in ${BUILD_DIRS}; do
if [ -d ${bd} ]; then
find ${bd} -mindepth 1 -delete
rmdir ${bd} || true
fi
done
fi
################################################################################
# Build fatbins
SRC="cpp/src"
FAT="python/cusignal"
GCC_V=$(gcc --version | grep gcc | cut -f2 -d')' | cut -f1 -d'.' | xargs)
NVCC_MAJOR=$(nvcc --version | grep "release" | awk '{print $6}' | cut -c2- | cut -f1 -d'.')
NVCC_MINOR=$(nvcc --version | grep "release" | awk '{print $6}' | cut -c2- | cut -f2 -d'.')
GET_CC(){
MAJOR=`python3 -c 'from ctypes import *; \
sms = c_int(); \
l = cdll.LoadLibrary("libcuda.so"); \
l.cuInit(0); \
l.cuDeviceGetAttribute(byref(sms), 75, '${1}'); \
print(sms.value)'`
MINOR=`python3 -c 'from ctypes import *; \
sms = c_int(); \
l = cdll.LoadLibrary("libcuda.so"); \
l.cuInit(0); \
l.cuDeviceGetAttribute(byref(sms), 76, '${1}'); \
print(sms.value)'`
}
RETURN_ALL(){
echo "Building for *ALL* supported GPU architectures..."
GPU_ARCH="--generate-code arch=compute_50,code=sm_50 \
--generate-code arch=compute_50,code=sm_52 \
--generate-code arch=compute_53,code=sm_53 \
--generate-code arch=compute_60,code=sm_60 \
--generate-code arch=compute_61,code=sm_61 \
--generate-code arch=compute_62,code=sm_62 \
--generate-code arch=compute_70,code=sm_70 \
--generate-code arch=compute_72,code=sm_72"
if [ "$NVCC_MAJOR" -lt 11 ]; then
GPU_ARCH="${GPU_ARCH} --generate-code arch=compute_75,code=[sm_75,compute_75]"
echo -e "\t including: CUDA 10.X - {50,52,53,60,61,62,70,72,75}"
else
GPU_ARCH="${GPU_ARCH} --generate-code arch=compute_75,code=sm_75"
if [ "$NVCC_MINOR" -eq 0 ]; then
GPU_ARCH="${GPU_ARCH} --generate-code arch=compute_80,code=[sm_80,compute_80]"
echo -e "\t including: CUDA 11.0 - {50,52,53,60,61,62,70,72,75,80}"
elif [ "$NVCC_MINOR" -lt 8 ]; then
GPU_ARCH="${GPU_ARCH} --generate-code arch=compute_80,code=sm_80 \
--generate-code arch=compute_86,code=[sm_86,compute_86]"
echo -e "\t including: CUDA 11.1+ - {50,52,53,60,61,62,70,72,75,80,86}"
else
GPU_ARCH="${GPU_ARCH} --generate-code arch=compute_80,code=sm_80 \
--generate-code arch=compute_86,code=[sm_86,compute_86] \
--generate-code arch=compute_90,code=[sm_90,compute_90]"
echo -e "\t including: CUDA 11.8+ - {50,52,53,60,61,62,70,72,75,80,86,90}"
fi
fi
}
if (( ${BUILD_ALL_GPU_ARCH} == 0 )); then
echo "Building for the architecture of the GPU in the system..."
DEVICES=${CUDA_VISIBLE_DEVICES}
if [ -z "${DEVICES}" ]
then
# If DEVICES is empty, retrieve all attached NVIDIA GPU
NUMGPU=`lspci | grep VGA | grep NVIDIA | wc -l`
# If now gpus can be found build all
if [ $NUMGPU -eq "0" ]
then
echo "Unable to determine GPU(s) installed..."
RETURN_ALL
else
for (( i=0; i<${NUMGPU}; i++ ))
do
GET_CC ${i}
echo -e "\tDevice ${i} - CC ${MAJOR}${MINOR}"
GPU_ARCH="${GPU_ARCH} --generate-code arch=compute_${MAJOR}${MINOR},code=sm_${MAJOR}${MINOR}"
done
fi
else
IFS=',' read -r -a arr <<< ${DEVICES}
for (( i=0; i<"${#arr[@]}"; i++ ))
do
GET_CC ${i}
echo -e "\tDevice ${i} - CC ${MAJOR}${MINOR}"
GPU_ARCH="${GPU_ARCH} --generate-code arch=compute_${MAJOR}${MINOR},code=sm_${MAJOR}${MINOR}"
done
fi
else
RETURN_ALL
fi
if [ "$NVCC_MAJOR" -ge 11 ] && [ "$NVCC_MINOR" -ge 2 ] ; then
THREADS="-t 0"
else
THREADS=
fi
# Must check GCC for Centos OS
if [ "$GCC_V" -lt 7 ] || [ "$NVCC_MAJOR" -lt 11 ]; then
FLAGS="-std=c++11"
else
FLAGS="-std=c++17"
fi
if hasArg -v; then
FLAGS="${FLAGS} -Xptxas -v"
fi
if hasArg -p; then
FLAGS="${FLAGS} -Xptxas -warn-lmem-usage -Xptxas -warn-double-usage"
fi
echo "Building Convolution kernels..."
FOLDER="convolution"
mkdir -p ${FAT}/${FOLDER}/
echo "nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_convolution.cu -odir ${FAT}/${FOLDER}/"
nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_convolution.cu -odir ${FAT}/${FOLDER}/ &
echo "Building Filtering kernels..."
FOLDER="filtering"
mkdir -p ${FAT}/${FOLDER}/
echo "nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_upfirdn.cu -odir ${FAT}/${FOLDER}/"
nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_upfirdn.cu -odir ${FAT}/${FOLDER}/ &
echo "nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_sosfilt.cu -odir ${FAT}/${FOLDER}/"
nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_sosfilt.cu -odir ${FAT}/${FOLDER}/ &
echo "nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_channelizer.cu -odir ${FAT}/${FOLDER}/"
nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_channelizer.cu -odir ${FAT}/${FOLDER}/ &
echo "Building IO kernels..."
FOLDER="io"
mkdir -p ${FAT}/${FOLDER}/
echo "nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_reader.cu -odir ${FAT}/${FOLDER}/"
nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_reader.cu -odir ${FAT}/${FOLDER}/ &
echo "nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_writer.cu -odir ${FAT}/${FOLDER}/"
nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_writer.cu -odir ${FAT}/${FOLDER}/ &
echo "Building Peak Finding kernels..."
FOLDER="peak_finding"
mkdir -p ${FAT}/${FOLDER}/
echo "nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_peak_finding.cu -odir ${FAT}/${FOLDER}/"
nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_peak_finding.cu -odir ${FAT}/${FOLDER}/ &
echo "Building Spectral kernels..."
FOLDER="spectral_analysis"
mkdir -p ${FAT}/${FOLDER}/
echo "nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_spectral.cu -odir ${FAT}/${FOLDER}/"
nvcc --fatbin ${THREADS} ${FLAGS} ${GPU_ARCH} ${SRC}/${FOLDER}/_spectral.cu -odir ${FAT}/${FOLDER}/ &
wait
################################################################################
# Build and install the cusignal Python package
if buildAll || hasArg cusignal; then
cd ${REPODIR}/python
if [[ ${INSTALL_TARGET} != "" ]]; then
if hasArg -c; then
python setup.py install --single-version-externally-managed --record record.txt
else
python setup.py install
fi
fi
fi