Newer
Older
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
# ax_cuda.m4: An m4 macro to detect and configure Cuda
#
# Copyright © 2008 Frederic Chateau <frederic.chateau@cea.fr>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
#
#
# SYNOPSIS
# AX_CUDA()
#
# DESCRIPTION
# Checks the existence of Cuda binaries and libraries.
# Options:
# --with-cuda=(path|yes|no)
# Indicates whether to use Cuda or not, and the path of a non-standard
# installation location of Cuda if necessary.
#
# This macro calls:
# AC_SUBST(CUDA_CFLAGS)
# AC_SUBST(CUDA_LIBS)
# AC_SUBST(NVCC)
Kurt A. O'Hearn
committed
# AC_SUBST(NFLAGS)
#
AC_DEFUN([AX_CUDA],
[
AC_ARG_WITH([cuda],
AS_HELP_STRING([--with-cuda@<:@=yes|no|DIR@:>@], [prefix where cuda is installed (default=yes)]),
[
with_cuda=$withval
if test "$withval" = "no"
then
want_cuda="no"
elif test "$withval" = "yes"
then
want_cuda="yes"
else
want_cuda="yes"
cuda_home_path=$withval
fi
],
[
want_cuda="yes"
])
Kurt A. O'Hearn
committed
AC_ARG_ENABLE([cuda-fast-math],
AC_HELP_STRING([--enable-cuda-fast-math], [Turn on fast, less precise math functions in CUDA]),
[case "${enableval}" in
yes) CUDA_FAST_MATH=true ;;
no) CUDA_FAST_MATH=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-cuda-fast-math]) ;;
esac],
[CUDA_FAST_MATH=false]
)
AC_ARG_ENABLE([emu],
AS_HELP_STRING([--enable-emu], [Turn on device emulation for CUDA]),
[case "${enableval}" in
yes) EMULATION=true ;;
no) EMULATION=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-emu]) ;;
esac],
[EMULATION=false]
)
Kurt A. O'Hearn
committed
#AM_CONDITIONAL(USE_CUDA, test "x${want_cuda}" = xyes)
if test "$want_cuda" = "yes"
then
# check that nvcc compiler is in the path
if test -n "$cuda_home_path"
then
nvcc_search_dirs="$PATH$PATH_SEPARATOR$cuda_home_path/bin"
else
nvcc_search_dirs=$PATH
fi
AC_PATH_PROG([NVCC], [nvcc], [], [$nvcc_search_dirs])
if test -n "$NVCC"
then
have_nvcc="yes"
else
have_nvcc="no"
fi
# test if nvcc version is >= 2.3
NVCC_VERSION=`$NVCC --version | grep release | awk 'gsub(/,/, "") {print [$]5}'`
AC_MSG_RESULT([nvcc version : $NVCC_VERSION])
Kurt A. O'Hearn
committed
#libdir=lib #NOTE: was lib, but changed to lib64 for CUDA 8.0
libdir=lib64
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
# set CUDA flags
if test -n "$cuda_home_path"
then
CUDA_CFLAGS="-I$cuda_home_path/include"
CUDA_LIBS="-L$cuda_home_path/$libdir -lcudart"
else
CUDA_CFLAGS="-I/usr/local/cuda/include"
CUDA_LIBS="-L/usr/local/cuda/$libdir -lcudart"
fi
# Env var CUDA_DRIVER_LIB_PATH can be used to set an alternate driver library path
# this is usefull when building on a host where only toolkit (nvcc) is installed
# and not driver. Driver libs must be placed in some location specified by this var.
if test -n "$CUDA_DRIVER_LIB_PATH"
then
CUDA_LIBS+=" -L$CUDA_DRIVER_LIB_PATH -lcuda"
else
CUDA_LIBS+=" -lcuda"
fi
saved_CPPFLAGS=$CPPFLAGS
saved_LIBS=$LIBS
CPPFLAGS="$CPPFLAGS $CUDA_CFLAGS"
LIBS="$LIBS $CUDA_LIBS"
AC_LANG_PUSH(C)
AC_MSG_CHECKING([for Cuda headers])
AC_COMPILE_IFELSE(
[
AC_LANG_PROGRAM([@%:@include <cuda.h>], [])
],
[
have_cuda_headers="yes"
AC_MSG_RESULT([yes])
],
[
have_cuda_headers="no"
AC_MSG_RESULT([not found])
])
AC_MSG_CHECKING([for Cuda libraries])
AC_LINK_IFELSE(
[
AC_LANG_PROGRAM([@%:@include <cuda.h>],
[
CUmodule cuModule;
CUdeviceptr devPtr;
CUfunction cuFunction;
Kurt A. O'Hearn
committed
size_t pitch, width = 250, height = 500;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
int main()
Kurt A. O'Hearn
committed
{
cuModuleLoad(&cuModule, "myModule.cubin");
cuMemAllocPitch(&devPtr, &pitch,width * sizeof(float), height, 4);
cuModuleGetFunction(&cuFunction, cuModule, "myKernel");
cuFuncSetBlockShape(cuFunction, 512, 1, 1);
cuParamSeti(cuFunction, 0, devPtr);
cuParamSetSize(cuFunction, sizeof(devPtr));
cuLaunchGrid(cuFunction, 100, 1);
Kurt A. O'Hearn
committed
return 0;
Kurt A. O'Hearn
committed
}
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
])
],
[
have_cuda_libs="yes"
AC_MSG_RESULT([yes])
],
[
have_cuda_libs="no"
AC_MSG_RESULT([not found])
])
AC_LANG_POP(C)
CPPFLAGS=$saved_CPPFLAGS
LIBS=$saved_LIBS
if test "$have_cuda_headers" = "yes" -a "$have_cuda_libs" = "yes" -a "$have_nvcc" = "yes"
then
have_cuda="yes"
else
have_cuda="no"
AC_MSG_ERROR([Cuda is requested but not available])
fi
fi
if test x$EMULATION = xtrue
then
Kurt A. O'Hearn
committed
NFLAGS+=" -deviceemu"
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
if test x$CUDA_FAST_MATH = xtrue
Kurt A. O'Hearn
committed
NFLAGS+=" -use_fast_math"
Kurt A. O'Hearn
committed
AC_MSG_NOTICE([Using NFLAGS=$NFLAGS])
AC_SUBST(CUDA_CFLAGS)
AC_SUBST(CUDA_LIBS)
AC_SUBST(NVCC)
AC_SUBST(NFLAGS)