Skip to content

Commit 4e70037

Browse files
committed
Pull newer nvcc_wrapper for GPU builds
1 parent 6291359 commit 4e70037

File tree

1 file changed

+56
-32
lines changed

1 file changed

+56
-32
lines changed

utils/nvcc_wrapper

+56-32
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
# or g++ as their back-end compiler. The defaults can be overwritten
1313
# by using the usual arguments (e.g., -arch=sm_30 -ccbin icpc).
1414

15-
#######
16-
# This file was copied from the Trilinos project on May 15, 2019
17-
# Please see https://github.com/trilinos/trilinos for more details
18-
#######
15+
############
16+
# This file was copied from the Trilinos project on Feb. 18, 2020
17+
# See https://github.com/Trilinos/trilinos.git for more details
18+
# Git SHA-ID: c7e9205e6e68360fb78821a719ef60a736881f4f
19+
############
1920

20-
default_arch="sm_35"
21+
default_arch="sm_70"
2122
#default_arch="sm_50"
2223

2324
#
@@ -90,11 +91,11 @@ first_xcompiler_arg=1
9091

9192
temp_dir=${TMPDIR:-/tmp}
9293

93-
# Check if we have an optimization argument already
94-
optimization_applied=0
94+
# optimization flag added as a command-line argument
95+
optimization_flag=""
9596

96-
# Check if we have -std=c++X or --std=c++X already
97-
stdcxx_applied=0
97+
# std standard flag added as a command-line argument
98+
std_flag=""
9899

99100
# Run nvcc a second time to generate dependencies if needed
100101
depfile_separate=0
@@ -104,6 +105,10 @@ depfile_target_arg=""
104105
# Option to remove duplicate libraries and object files
105106
remove_duplicate_link_files=0
106107

108+
function warn_std_flag() {
109+
echo "nvcc_wrapper - *warning* you have set multiple standard flags (-std=c++1* or --std=c++1*), only the last is used because nvcc can only accept a single std setting" > /dev/null
110+
}
111+
107112
#echo "Arguments: $# $@"
108113

109114
while [ $# -gt 0 ]
@@ -135,12 +140,16 @@ do
135140
;;
136141
# Ensure we only have one optimization flag because NVCC doesn't allow muliple
137142
-O*)
138-
if [ $optimization_applied -eq 1 ]; then
139-
echo "nvcc_wrapper - *warning* you have set multiple optimization flags (-O*), only the first is used because nvcc can only accept a single optimization setting." > /dev/null
143+
if [ -n "$optimization_flag" ]; then
144+
echo "nvcc_wrapper - *warning* you have set multiple optimization flags (-O*), only the last is used because nvcc can only accept a single optimization setting." > /dev/null
145+
shared_args=${shared_args/ $optimization_flag/}
146+
fi
147+
if [ "$1" = "-O" ]; then
148+
optimization_flag="-O2"
140149
else
141-
shared_args="$shared_args $1"
142-
optimization_applied=1
150+
optimization_flag=$1
143151
fi
152+
shared_args="$shared_args $optimization_flag"
144153
;;
145154
#Handle shared args (valid for both nvcc and the host compiler)
146155
-D*)
@@ -176,29 +185,51 @@ do
176185
shift
177186
;;
178187
#Handle known nvcc args
179-
--dryrun|--verbose|--keep|--keep-dir*|-G|--relocatable-device-code*|-lineinfo|-expt-extended-lambda|--resource-usage|-Xptxas*)
188+
--dryrun|--verbose|--keep|--keep-dir*|-G|--relocatable-device-code*|-lineinfo|-expt-extended-lambda|--resource-usage|-Xptxas*|--fmad*)
180189
cuda_args="$cuda_args $1"
181190
;;
182191
#Handle more known nvcc args
183192
--expt-extended-lambda|--expt-relaxed-constexpr)
184193
cuda_args="$cuda_args $1"
185194
;;
186195
#Handle known nvcc args that have an argument
187-
-rdc|-maxrregcount|--default-stream)
196+
-rdc|-maxrregcount|--default-stream|-Xnvlink|--fmad)
188197
cuda_args="$cuda_args $1 $2"
189198
shift
190199
;;
191200
-rdc=*|-maxrregcount*|--maxrregcount*)
192201
cuda_args="$cuda_args $1"
193202
;;
194-
#Handle c++11
195-
--std=c++11|-std=c++11|--std=c++14|-std=c++14|--std=c++1y|-std=c++1y|--std=c++17|-std=c++17|--std=c++1z|-std=c++1z)
196-
if [ $stdcxx_applied -eq 1 ]; then
197-
echo "nvcc_wrapper - *warning* you have set multiple optimization flags (-std=c++1* or --std=c++1*), only the first is used because nvcc can only accept a single std setting" > /dev/null
198-
else
199-
shared_args="$shared_args $1"
200-
stdcxx_applied=1
203+
#Handle unsupported standard flags
204+
--std=c++1y|-std=c++1y|--std=c++1z|-std=c++1z|--std=gnu++1y|-std=gnu++1y|--std=gnu++1z|-std=gnu++1z|--std=c++2a|-std=c++2a|--std=c++17|-std=c++17)
205+
fallback_std_flag="-std=c++14"
206+
# this is hopefully just occurring in a downstream project during CMake feature tests
207+
# we really have no choice here but to accept the flag and change to an accepted C++ standard
208+
echo "nvcc_wrapper does not accept standard flags $1 since partial standard flags and standards after C++14 are not supported. nvcc_wrapper will use $fallback_std_flag instead. It is undefined behavior to use this flag. This should only be occurring during CMake configuration."
209+
if [ -n "$std_flag" ]; then
210+
warn_std_flag
211+
shared_args=${shared_args/ $std_flag/}
212+
fi
213+
std_flag=$fallback_std_flag
214+
shared_args="$shared_args $std_flag"
215+
;;
216+
-std=gnu*)
217+
corrected_std_flag=${1/gnu/c}
218+
echo "nvcc_wrapper has been given GNU extension standard flag $1 - reverting flag to $corrected_std_flag"
219+
if [ -n "$std_flag" ]; then
220+
warn_std_flag
221+
shared_args=${shared_args/ $std_flag/}
222+
fi
223+
std_flag=$corrected_std_flag
224+
shared_args="$shared_args $std_flag"
225+
;;
226+
--std=c++11|-std=c++11|--std=c++14|-std=c++14)
227+
if [ -n "$std_flag" ]; then
228+
warn_std_flag
229+
shared_args=${shared_args/ $std_flag/}
201230
fi
231+
std_flag=$1
232+
shared_args="$shared_args $std_flag"
202233
;;
203234

204235
#strip of -std=c++98 due to nvcc warnings and Tribits will place both -std=c++11 and -std=c++98
@@ -313,16 +344,6 @@ do
313344
shift
314345
done
315346

316-
#Check if nvcc exists
317-
if [ $host_only -ne 1 ]; then
318-
var=$(which nvcc )
319-
if [ $? -gt 0 ]; then
320-
echo "Could not find nvcc in PATH"
321-
exit $?
322-
fi
323-
fi
324-
325-
326347
# Only print host compiler version
327348
if [ $get_host_version -eq 1 ]; then
328349
$host_compiler --version
@@ -377,6 +398,9 @@ if [ $first_xcompiler_arg -eq 0 ]; then
377398
nvcc_command="$nvcc_command -Xcompiler $xcompiler_args"
378399
fi
379400

401+
#Replace all commas in xcompiler_args with a space for the host only command
402+
xcompiler_args=${xcompiler_args//,/" "}
403+
380404
#Compose host only command
381405
host_command="$host_compiler $shared_args $host_only_args $compile_arg $output_arg $xcompiler_args $host_linker_args $shared_versioned_libraries_host"
382406

0 commit comments

Comments
 (0)