/
find_cuda_libs.sh
executable file
·65 lines (60 loc) · 2.46 KB
/
find_cuda_libs.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
#!/bin/sh
# We do not use nvcc to link CUDA programs, because we may be linking
# against MPI libraries also, and prefer to allow the MPI compiler
# drivers to handle the link.
#
# This requires us to determine which libraries are needed to link CUDA
# programs. We use nvcc -dryrun to determine which libraries are
# needed to link CUDA programs. Prior to the release of CUDA version 6.0,
# the output of nvcc -dryrun included a line of the form LIBRARIES=...
# that indicated all libraries needed to link as -llib flags.
# The nvcc distributed with CUDA 6.0 no longer lists the libraries
# in the LIBRARIES line itself, but only as part of the actual
# command that would have been executed to link the executable.
#
# For CUDA < 6.0, we just use the output of the LIBRARIES line.
# For CUDA 6.0, we determine the libraries to use by:
#
# Running nvcc -dryrun and saving the LIBRARIES line from the output.
# Re-running nvcc -dryrun and parsing the link line to remove
# everything before the LIBRARIES contents and possibly a -Wl,--end-group
# specification.
#
if [ "$#" -ne 1 ]
then
echo "Usage: $0 <nvcc>" >&2
echo " where <nvcc> is the filename or path to the nvcc executable to use." >&2
exit 1
fi
NVCC=$1
#echo "Using NVCC=$NVCC"
cudart_flag_supported=0
$NVCC -dryrun -cudart shared bogus.cu > /dev/null 2>&1
if [ $? -eq 0 ]
then
cudart_flag_supported=1
fi
#echo "cudart_flag_supported=$cudart_flag_supported"
libspec=`$NVCC -dryrun bogus.cu 2>&1 | grep LIBRARIES | sed 's/^.*LIBRARIES=//'`
#echo "libspec=$libspec"
if [ $cudart_flag_supported -eq 1 ]
then
arch=$(uname -i)
if [ "$arch" = "x86_64" ]
then
cudalibs=`$NVCC -dryrun bogus.cu 2>&1 | tail -1 | sed "s#^.*-o \"a.out\"##" | sed 's#"[a-zA-Z0-9./_-]*\.o"##g' | sed 's/-Wl,--start-group//' | sed 's/-Wl,--end-group//'`
# this is a hotfix for newer CUDA because the a.out appearred at the beginning
# instead of the end. Temporery fix
if [ *"$arch"* != "$cudalibs" ]
then
cudalibs=`$NVCC -dryrun bogus.cu 2>&1 | tail -1 | sed 's#"[a-zA-Z0-9/_-]*\.o"##g' | sed 's#-o "a.out"##g' | sed 's/#$ g++ -m64 -Wl,--start-group//g' | sed 's/-Wl,--end-group//'`
fi
elif [ "$arch" = "ppc64le" ]
then
cudalibs=`$NVCC -dryrun bogus.cu 2>&1 | tail -1 | sed 's#^.*"[a-zA-Z0-9/_-]*\.o"##g' | sed 's/-Wl,--start-group//' | sed 's/-Wl,--end-group//' | sed "s#-o \"a.out\"##"`
fi
else
cudalibs=$libspec
echo cudalibs
fi
echo $cudalibs