-
Notifications
You must be signed in to change notification settings - Fork 2
/
cuda.ac
189 lines (176 loc) · 6.89 KB
/
cuda.ac
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
# ----------------------------------------------------------------
# CUDA support
#
# Here we define and process several `--with-cuda`-prefixed `configure`
# options. By default CUDA support is disabled: no automatic search for for
# the nVidia CUDA toolkit or SDK is done, and ENABLE_CUDA is set to "no".
#
# The option `--with-cuda` can be used to specify the location of nVidia's CUDA
# toolkit; if the option is given without an argument or with an argument of
# "yes", we search for the CUDA toolkit in the following locations:
#
# /usr/local/cuda standard CUDA install directory
#
# /usr/lib/nvidia-cuda-toolkit install directory for the system-
# installed CUDA toolkit package on Debian
# and Debian-based systems
#
# On successful search, these variables are set in the generated cuda.mk:
#
# * HAVE_CUDA and ENABLE_CUDA: set to "yes"
# * CUDA_DIR: set to the found CUDA toolkit directory
# * NVCC: set to the location of the `nvcc` binary in the CUDA toolkit
# directory
#
# We also define a `--with-cuda-sdk=PATH` option, which allows the user to
# specify the install location of nVidia's CUDA SDK. Unlike the `--with-cuda`
# option, `--with-cuda-sdk` does no automatic search and requires an argument.
# If the argument exists and is a directory, the following variables are set in
# the generated cuda.mk.
#
# * HAVE_CUDA_SDK: set to "yes"
# * CUDA_SDK_DIR: set to the path given as an argument to `--with-cuda-sdk`.
#
# Note that `ENABLE_CUDA` and all `HAVE_*` variables that are set to "no"
# (which is the default) by configure are set to the empty string prior to
# substitution into cuda.mk[.in].
#
# The final option we define is `--with-cuda-level`, which takes a mandatory
# argument. This can be used to specify the CUDA compute capability of the
# target device(s) when the nVidia CUDA compiler is invoked; the argument
# should be an integer value equal to ten times the documented compute
# capability for the target device(s). This one sets the following variable in
# the generated cuda.mk.
#
# * CUDA_LEVEL: set to the argument give to `--with-cuda-level` (default 10).
#
# There are some arguments to AC_MSG_* with ugly formatting here; the formatting
# is intentional (it produces nice, readable output in the generated `configure`
# script, and keeps lines under 80 characters in length).
#
# To enable automatic "use" of CUDA (i.e., setting ENABLE_CUDA to "yes" if the
# CUDA toolkit is found), change the assigned value of `ENABLE_CUDA` in the
# line directly below this comment to "auto". (You should also change the
# default-argument value in the docstring passed to `AS_HELP_STRING` for
# `--with-cuda` to match.)
HAVE_CUDA="no"
HAVE_CUDA_SDK="no"
AC_ARG_VAR([CUDA_DIR], [CUDA toolkit install directory])
AC_ARG_WITH([cuda],
[AS_HELP_STRING([--with-cuda@<:@=PATH@:>@],
[use CUDA (installed in PATH) @<:@no@:>@])],
[CUDA_DIR=$withval],[CUDA_DIR="no"])
# Interpret "--with-cuda" (i.e. no argument) as "enable CUDA support, please."
# We also support using the argument "auto" for this purpose.
ENABLE_CUDA=yes
case x$(echo $CUDA_DIR | awk '{print tolower($0)}') in
xno)
ENABLE_CUDA=no
;;
x|xauto|xyes)
ENABLE_CUDA=yes
CUDA_DIR=
;;
*)
ENABLE_CUDA=yes
;;
esac
if test "$ENABLE_CUDA" != "no"; then
AC_MSG_CHECKING([for CUDA toolkit directory])
if test -z "$CUDA_DIR"; then
CUDA_DIR_AUTOMATIC=yes
CUDA_CANDIDATE_DIRS="/usr/local/cuda /usr/lib/nvidia-cuda-toolkit"
for dir in $CUDA_CANDIDATE_DIRS; do
if test -d "$dir"; then
CUDA_DIR="$dir"
HAVE_CUDA="yes"
AC_MSG_RESULT($CUDA_DIR)
break
fi
done
if test -z "$CUDA_DIR"; then
if test "$ENABLE_CUDA" = "yes"; then
# User explicitly requested CUDA support but did not provide a
# directory argument; being unable to find a toolkit directory
# is an error.
AC_MSG_RESULT(not found)
AC_MSG_ERROR(\
[CUDA support explicitly enabled but the toolkit was not found by automatic path
search. Specify CUDA toolkit location with `--with-cuda=PATH`.])
else
AC_MSG_RESULT([not found. CUDA support will be disabled.])
ENABLE_CUDA="no"
HAVE_CUDA="no"
fi
fi
else # User gave explicit toolkit location.
if test -d "$CUDA_DIR"; then
AC_MSG_RESULT($CUDA_DIR)
HAVE_CUDA="yes"
else
AC_MSG_RESULT(not found)
AC_MSG_ERROR([specified CUDA toolkit directory not found.])
fi
fi
fi
# Make sure we have the nVidia CUDA compiler available. We give different
# messages depending on how the `--with-cuda` option was passed to configure.
if test "$ENABLE_CUDA" != "no"; then
AC_PATH_PROG([NVCC_PATH],nvcc,[],[$CUDA_DIR/bin])
if test -z "$NVCC_PATH" ; then
if test "$ENABLE_CUDA" = "yes"; then
if test "$CUDA_DIR_AUTOMATIC" = "yes"; then
AC_MSG_ERROR(\
[`bin/nvcc` not found in automatically-selected CUDA toolkit directory. Specify
CUDA toolkit location with `--with-cuda=PATH`.])
else
AC_MSG_ERROR(\
[`bin/nvcc` not found in specified CUDA toolkit install prefix.])
fi
else # ENABLE_CUDA is "auto"
AC_MSG_NOTICE(\
[`bin/nvcc` not found in automatically-selected CUDA toolkit directory; CUDA
support will be disabled. If this is not what you want, try specifying a
valid CUDA toolkit install prefix using `--with-cuda=PATH`.])
ENABLE_CUDA="no"
HAVE_CUDA="no"
fi
fi
fi
# Check for the CUDA SDK.
AC_ARG_VAR([CUDA_SDK_DIR], [CUDA SDK install directory])
AC_ARG_WITH([cuda-sdk],
[AS_HELP_STRING([--with-cuda-sdk=PATH],
[specify the CUDA SDK install directory])],
[CUDA_SDK_DIR=$withval],[CUDA_SDK_DIR=""])
if test -n "$CUDA_SDK_DIR"; then
AC_MSG_CHECKING([for CUDA SDK directory])
if test -d "$CUDA_SDK_DIR"; then
AC_MSG_RESULT($CUDA_SDK_DIR)
HAVE_CUDA_SDK=yes
else
AC_MSG_RESULT(not found)
AC_MSG_ERROR([specified CUDA SDK directory not found.])
fi
fi
# Allow setting CUDA compute capability at `configure`-time.
AC_ARG_WITH([cuda-level],
[AS_HELP_STRING([--with-cuda-level=LEVEL],[use CUDA compute capability LEVEL])],
[CUDA_LEVEL=$withval],[CUDA_LEVEL=35])
# Set up boolean AC_SUBST variables for use in Make.
for var in HAVE_CUDA HAVE_CUDA_SDK ENABLE_CUDA; do
eval value='$'"$var"
if test "$value" = "no"; then
eval "$var=''"
fi
done
AC_SUBST([ENABLE_CUDA])
AC_SUBST([HAVE_CUDA])
AC_SUBST([HAVE_CUDA_SDK])
AC_SUBST([CUDA_LEVEL])
AC_SUBST([CUDA_DIR])
AC_SUBST([CUDA_SDK_DIR])
AC_SUBST([NVCC_PATH])
if test -n "$ENABLE_CUDA"; then
AC_CONFIG_FILES([cuda.mk])
fi