I put together a working autotools example to start the creation of some opensource frameworks using CUDA.
I have autotools running on my Mac OS X 10.6.7, automake 1.10. The CUDA release I used was 3.1.
I will need to verify that it works with CUDA 4.0 after I get it installed.
Best,
Owen
configure.ac file
------------------------------------------------------------------------------
AC_PREREQ([2.65])
AC_INIT([cuAutotools], [3.1.0], )
Config initialization
AC_CONFIG_SRCDIR([m4/ct_check_cuda.m4])
AC_CONFIG_AUX_DIR(m4)
AC_CONFIG_HEADER(config.h)
automake initialization
AM_INIT_AUTOMAKE([cuAutotools], [3.1.0])
Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O
Checks for
Checks for libraries.
AC_CHECK_LIB([m], [pow])
Checks for header files.
AC_CHECK_HEADERS([limits.h stdlib.h string.h])
check for CUDA
CT_CHECK_CUDA_API
check for CUDA SDK
CT_CHECK_CUDA_SDK
Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
Checks for library functions.
AC_CHECK_FUNCS([pow])
AC_CONFIG_FILES([Makefile
src/Makefile])
AC_OUTPUT
top level Makefile.am
AUTOMAKE_OPTIONS = 1.4 no-dependencies foreign
-------------------
-------------------
ACLOCAL_AMFLAGS = -I m4
SUBDIRS=src
dist_data_DATA=cudalt.py autogen.sh
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
./src/Makefile.am
.cu.o:
$(NVCC) -o $@ -c {:content:}lt; $(NVCCFLAGS)
.cu.lo:
$(top_srcdir)/cudalt.py $@ $(NVCC) $(NVCC_CFLAGS) --compiler-options="$(CFLAGS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)" -c {:content:}lt;
CCLD=$(CC)
bin_PROGRAMS=cuAutotools
cuAutotools_SOURCES = main.cu
template_gold.cpp
template_kernel.cu
cuAutotools_CFLAGS = $(CUDA_CFLAGS)
cuAutotools_LDADD = $(CUDA_LIBS)
cuAutotools_LDFLAGS =
m4 script for checking out CUDA
SYNOPSIS
CT_CHECK_CUDA_API
DESCRIPTION
This macro tries to find the headers and libraries for the
CUDA API to build client applications.
If includes are found, the variable CDINCPATH will be set. If
libraries are found, the variable CDLIBPATH will be set. if no check
was successful, the script exits with a error message.
LAST MODIFICATION
2011-01-04
COPYLEFT
Copyright © 2011 <www.platos-cave.org>
Copying and distribution of this file, with or without
modification, are permitted in any medium without royalty provided
the copyright notice and this notice are preserved.
AC_DEFUN([CT_CHECK_CUDA_API], [
AC_ARG_WITH(cuda,
[ --with-cuda=PREFIX Prefix of your CUDA installation],
[cd_prefix=$withval], [cd_prefix=“”])
AC_SUBST(CDINCPATH)
AC_SUBST(CDLIBPATH)
AC_SUBST(NVCC)
AC_CANONICAL_HOST
#find out what version we are running
ARCH=uname -m
if [[ $ARCH == “x86_64” ]];
then
SUFFIX=“64”
else
SUFFIX=“”
fi
AC_MSG_NOTICE([$cd_prefix, $withval])
cd_prefix will be set to “yes” if --with-cuda is passed in with no value
if test “$cd_prefix” == “yes”; then
if test “$withval” == “yes”; then
cd_prefix=“/usr/local/cuda”
fi
fi
if test “$cd_prefix” != “”; then
AC_MSG_CHECKING([for CUDA compiler in $cd_prefix/bin])
if test -f “$cd_prefix/bin/nvcc” ; then
NVCC=“$cd_prefix/bin/nvcc”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(nvcc not found)
fi
AC_MSG_CHECKING([for CUDA includes in $cd_prefix/include])
if test -f “$cd_prefix/include/cuda.h” ; then
CDINCPATH=“-I$cd_prefix/include”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(cuda.h not found)
fi
AC_MSG_CHECKING([for CUDA libraries in $cd_prefix/lib$SUFFIX])
case $host_os in
darwin*)
if test -f “$cd_prefix/lib$SUFFIX/libcudart.dylib” ; then
CDLIBPATH=“-L$cd_prefix/lib$SUFFIX”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(libcublas.dylib not found)
fi
;;
linux*)
if test -f “$cd_prefix/lib$SUFFIX/libcudart.so” ; then
CDLIBPATH=“-L$cd_prefix/lib$SUFFIX”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(libcudart.so not found)
fi
;;
*)
#Default Case
AC_MSG_ERROR([Your platform is not currently supported]) ;;
esac
fi
if test “$CDINCPATH” = “” ; then
AC_CHECK_HEADER([cuda.h], , AC_MSG_ERROR(cuda.h not found))
fi
if test “$CDLIBPATH” = “” ; then
AC_CHECK_LIB(cublas, cudaSetDevice, , AC_MSG_ERROR(libcublas.so not found))
AC_CHECK_LIB([cudart], [cudaMalloc])
fi
])
m4 script for checking out CUDA SDK
SYNOPSIS
CT_CHECK_CUDA_SDK
DESCRIPTION
This macro tries to find the headers and libraries for the
CUDA SDK to build client applications.
If includes are found, the variable CDSDKINCPATH will be set. If
libraries are found, the variable CDSDKLIBPATH will be set. if no check
was successful, the script exits with a error message.
LAST MODIFICATION
2011-01-04
COPYLEFT
Copyright © 2011 <www.platos-cave.org>
Copying and distribution of this file, with or without
modification, are permitted in any medium without royalty provided
the copyright notice and this notice are preserved.
AC_DEFUN([CT_CHECK_CUDA_SDK], [
AC_ARG_WITH([cudasdk],
[AS_HELP_STRING([–with-cudasdk],
[Prefix of your CUDA SDK installation])],
[cdsdk_prefix=$withval],
[cdsdk_prefix=yes])
AC_CANONICAL_HOST
AC_SUBST(CDSDK_COMMON_INCPATH)
AC_SUBST(CDSDK_COMMON_LIBPATH)
AC_SUBST(CDSDK_SHARED_INCPATH)
AC_SUBST(CDSDK_SHARED_LIBPATH)
AC_MSG_NOTICE([$cdsdk_prefix, $withval])
cd_prefix will be set to “yes” if --with-cudasdk is passed in with no value
if test “$cdsdk_prefix” == “yes”; then
if test “$withval” == “yes”; then
case $host_os in
darwin*)
cdsdk_prefix=“/Developer/GPU Computing”
;;
linux*)
cdsdk_prefix=“/usr/local/cuda/NVIDIA_GPU_COMPUTING_SDK”
;;
*)
#Default Case
AC_MSG_ERROR([Your platform is not currently supported]) ;;
esac
fi
fi
if test “$cdsdk_prefix” != “”; then
#########################
common
AC_MSG_CHECKING([for CUDA SDK common includes in $cdsdk_prefix/C/common/inc])
if test -f “$cdsdk_prefix/C/common/inc/cutil.h” ; then
CDSDK_COMMON_INCPATH=“-I$cdsdk_prefix/C/common/inc”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(cutil.h not found)
fi
AC_MSG_CHECKING([for CUDA SDK common libraries in $cdsdk_prefix/C/common/lib])
case $host_os in
darwin*)
if test -f “$cdsdk_prefix/C/common/lib/darwin/libcudpp_i386.a” ; then
CDSDK_COMMON_LIBPATH=“-L$cdsdk_prefix/C/common/lib/darwin/”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(libcudpp_i386.a not found)
fi
;;
linux*)
if test -f “$cdsdk_prefix/C/common/lib/linux/libnvcuvid.dylib” ; then
CDSDK_COMMON_LIBPATH=“-L$cdsdk_prefix/C/common/lib/linux/”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(libcudpp_i386.a not found)
fi
;;
*)
#Default Case
AC_MSG_ERROR([Your platform is not currently supported]) ;;
esac
#########################
shared
AC_MSG_CHECKING([for CUDA SDK shared includes in $cdsdk_prefix/shared/inc])
if test -f “$cdsdk_prefix/shared/inc/shrUtils.h” ; then
CDSDK_SHARED_INCPATH=“-I$cdsdk_prefix/shared/inc”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(shrUtils.h not found)
fi
AC_MSG_CHECKING([for CUDA SDK shared libraries in $cdsdk_prefix/shared/lib])
if test -f “$cdsdk_prefix/shared/lib/libshrutil_i386.a” ; then
CDSDK_SHARED_LIBPATH=“-I$cdsdk_prefix/shared/lib”
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR(libshrutil_i386.a not found)
fi
else
#Default Case
AC_MSG_ERROR([cdsdk_prefix is NULL])
fi
if test “$CDSDK_COMMON_INCPATH” = “” ; then
AC_CHECK_HEADER([cutil.h], , AC_MSG_ERROR(cuda.h not found))
fi
if test “$CDSDK_COMMON_LIBPATH” = “” ; then
AC_CHECK_LIB(cudpp_i386, cutilCheckError, , AC_MSG_ERROR(libcudpp_i386.a not found))
fi
if test “$CDSDK_SHARED_INCPATH” = “” ; then
AC_CHECK_HEADER([shrUtils.h], , AC_MSG_ERROR(cuda.h not found))
fi
if test “$CDSDK_SHARED_LIBPATH” = “” ; then
AC_CHECK_LIB(shrutil_i386, __shrExitEX, , AC_MSG_ERROR(libshrutil_i386.a not found))
fi
])