diff --git a/configure.ac b/configure.ac index 844ad154c97..caedd046d49 100644 --- a/configure.ac +++ b/configure.ac @@ -412,41 +412,43 @@ AC_ARG_WITH([cuda], where CUDA is installed. The cuda compiler can also be specified by setting the NVCC environment variable. The CUDA library and header can be manually specified by using - CPPFLAGS, LDFLAGS and LIBS. [no]]), , - with_cuda=no) AC_MSG_RESULT($with_cuda) + CPPFLAGS, LDFLAGS and LIBS. [guess]]), , + with_cuda=guess) AC_MSG_RESULT($with_cuda) -if test x$with_cuda = xguess || test x$with_cuda = xyes; then +AS_IF([test x$with_cuda = xguess || test x$with_cuda = xyes],[ cuda_path=/usr/local/cuda -elif test x$with_cuda != xno; then +],[test x$with_cuda != xno],[ cuda_path=$with_cuda with_cuda=yes -fi +]) cuda_ok=no -if test x$with_cuda != xno; then +AS_IF([test x$with_cuda != xno],[ cuda_ok=yes + save_LIBS=$LIBS - if test x$NVCC = x; then + AS_IF([test x$NVCC = x],[ NVCC=$cuda_path/bin/nvcc - fi + ]) - if test -d $cuda_path/lib64; then + AS_IF([test -d $cuda_path/lib64],[ LDFLAGS="$LDFLAGS -L$cuda_path/lib64" - else + ],[ LDFLAGS="$LDFLAGS -L$cuda_path/lib" - fi + ]) NVCCFLAGS="$NVCCFLAGS -I$cuda_path/include" + CFLAGS="$CFLAGS -I$cuda_path/include" # NVCC AC_ARG_VAR(NVCC,[NVIDIA CUDA compiler command]) AC_ARG_VAR(NVCCFLAGS,[special compiler flags for the NVIDIA CUDA compiler]) AC_PATH_PROG(NVCC, nvcc, no) - if test x$NVCC = xno; then + AS_IF([test x$NVCC = xno],[ AC_MSG_FAILURE([CUDA compiler nvcc was not found, specify location using the NVCC variable]) - fi + ]) # libraries AC_CHECK_LIB(cudart, cudaGetDevice, [LIBS="$LIBS -lcudart"], [ @@ -470,7 +472,7 @@ if test x$with_cuda != xno; then ]) # NVCC compile check - AC_MSG_CHECKING([whether CUDA works]) + AC_MSG_CHECKING([whether CUDA compiles]) # if no other compute capability is defined by the user, we require at least 1.1 case "$NVCCFLAGS" in @@ -497,14 +499,35 @@ if test x$with_cuda != xno; then AC_MSG_WARN([cannot compile CUDA code. Some features will not be available!]) ]) ]) + + # NVCC compile check + AC_MSG_CHECKING([whether CUDA runs]) + + AC_RUN_IFELSE([AC_LANG_PROGRAM([#include ],[cudaGetDevice(0);])], [ + AC_MSG_RESULT(yes) + ],[ + cuda_ok=no + + AS_IF([test x$with_cuda = xyes],[ + AC_MSG_FAILURE([cannot run CUDA code. Look at config.log for more details.]) + ],[ + AC_MSG_WARN([cannot run CUDA code. Some features will not be available!]) + ]) + ],[ + AC_MSG_RESULT([unknown (cross-compiling)]) + ]) CC=$save_CC CFLAGS=$save_CFLAGS - AC_DEFINE(CUDA,[],[Whether CUDA is available]) -fi + AS_IF([test x$cuda_ok == xyes], [ + AC_DEFINE(CUDA,[],[Whether CUDA is available]) + ],[ + LIBS=$save_LIBS + ]) +]) -AM_CONDITIONAL(CUDA, [test x$with_cuda != xno]) +AM_CONDITIONAL(CUDA, [test x$cuda_ok == xyes]) cat <. */ -#include + + // CUDA code is always interpreted as C++, so we need the extern C interface extern "C" { @@ -25,6 +26,10 @@ extern "C" { } +#ifdef CUDA + +#include + /** \name minimally required compute capability. */ /*@{*/ static const int computeCapabilityMinMajor = 1; @@ -97,3 +102,5 @@ int cuda_get_device() else return dev; } + +#endif /* defined(CUDA) */ diff --git a/src/cuda_init.h b/src/cuda_init.h index afa259dfb07..175a098cb9b 100644 --- a/src/cuda_init.h +++ b/src/cuda_init.h @@ -19,6 +19,10 @@ #ifndef CUDA_INIT_H #define CUDA_INIT_H +#include "config.h" + +#ifdef CUDA + /** get the number of CUDA devices. @return the number of GPUs, or -1 if CUDA could not be @@ -63,4 +67,6 @@ int cuda_get_device(); /** current error message of CUDA. */ extern const char *cuda_error; +#endif /* defined(CUDA) */ + #endif diff --git a/src/lbgpu.cu b/src/lbgpu.cu index 90a5d2b6188..86aef120782 100644 --- a/src/lbgpu.cu +++ b/src/lbgpu.cu @@ -29,6 +29,7 @@ extern "C" { #include "lbgpu.h" +#include "config.h" } #ifdef LB_GPU diff --git a/src/tcl/cuda_init_tcl.c b/src/tcl/cuda_init_tcl.c index f18a4e48423..7c6235961bd 100644 --- a/src/tcl/cuda_init_tcl.c +++ b/src/tcl/cuda_init_tcl.c @@ -21,6 +21,8 @@ #include "parser.h" #include "cuda_init.h" +#ifdef CUDA + /** prints a list of the available GPUs to the result of the Tcl interpreter. Only devices with compute capability of 1.1 or higher are listed, since atomic operations are required for CUDA-LB. */ @@ -50,6 +52,7 @@ static int list_gpus(Tcl_Interp *interp) return TCL_OK; } +#endif /* defined(CUDA) */ /** returns 1 if and only if the GPU with the given id is usable for CUDA computations. Only devices with compute capability of 1.1 or @@ -58,6 +61,10 @@ static int list_gpus(Tcl_Interp *interp) int tclcommand_cuda(ClientData data, Tcl_Interp *interp, int argc, char **argv) { +#ifndef CUDA + Tcl_AppendResult(interp, "Feature CUDA required!", (char *)NULL); + return TCL_ERROR; +#else if (argc <= 1) { Tcl_AppendResult(interp, "too few arguments to the cuda command", (char *)NULL); return TCL_ERROR; @@ -110,4 +117,5 @@ int tclcommand_cuda(ClientData data, Tcl_Interp *interp, Tcl_AppendResult(interp, "unknown subcommand \"", argv[0], "\"", (char *)NULL); return TCL_ERROR; } +#endif /* defined(CUDA) */ }