Raw File
cuda.ac
# ----------------------------------------------------------------
# CUDA support
#
# Here we define and process a `--with-cuda[=PREFIX]` option.  By default CUDA
# support is disabled: no automatic search for for the nVidia CUDA toolkit is
# done.
#
# If the option is given without an argument or with an argument of "yes", we
# search for CUDA 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`.
#
#
# 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.)
ENABLE_CUDA="no"

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=""])

# If CUDA_DIR is set, it's because the user gave the --with-cuda option in at
# least _one_ of the valid forms.
if test -n "$CUDA_DIR"; then
    ENABLE_CUDA="yes"
fi

# Interpret "--with-cuda" (i.e. no argument) as "enable CUDA support, please."
# We also support using the argument "auto" for this purpose.
if test "$CUDA_DIR" = "yes" || test "$CUDA_DIR" = "auto"; then
    CUDA_DIR=""
fi

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

# 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_DIR])
AC_SUBST([CUDA_SDK_DIR])
AC_SUBST([NVCC_PATH])

AC_CONFIG_FILES([cuda.mk])
back to top