Kaynağa Gözat

- In case we have a non standard CUDA setup, we can specify both include and
lib dirs for CUDA.
- The pi_redux example only use CUDA if the CURAND library is available.

Cédric Augonnet 14 yıl önce
ebeveyn
işleme
f90e00fa9f
3 değiştirilmiş dosya ile 81 ekleme ve 38 silme
  1. 58 25
      configure.ac
  2. 21 13
      examples/pi/pi_redux.c
  3. 2 0
      include/starpu_config.h.in

+ 58 - 25
configure.ac

@@ -174,24 +174,47 @@ AC_DEFINE_UNQUOTED(STARPU_MAXCUDADEVS, [$nmaxcudadev],
 AC_ARG_ENABLE(cuda, [AS_HELP_STRING([--disable-cuda],
 		[do not use CUDA device(s)])],, [enable_cuda=maybe])
 
-if test x$enable_cuda = xyes -o x$enable_cuda = xmaybe; then
-	#AC_MSG_CHECKING(whether CUDA is available)
-	AC_ARG_WITH(cuda-dir, 
-		[AS_HELP_STRING([--with-cuda-dir=<path>],
-		[specify CUDA installation directory (default is /usr/local/cuda/)])],
-		[
-			cuda_dir=$withval
-			# in case this was not explicit yet
-			enable_cuda=yes
-		], cuda_dir=/usr/local/cuda/)
+#AC_MSG_CHECKING(whether CUDA is available)
+AC_ARG_WITH(cuda-dir, 
+	[AS_HELP_STRING([--with-cuda-dir=<path>],
+	[specify CUDA installation directory (default is /usr/local/cuda/)])],
+	[
+		cuda_dir=$withval
+		# in case this was not explicit yet
+		enable_cuda=yes
+	], cuda_dir=/usr/local/cuda/)
+
+AC_ARG_WITH(cuda-include-dir, 
+	[AS_HELP_STRING([--with-cuda-include-dir=<path>],
+	[specify where CUDA headers are installed])],
+	[
+		cuda_include_dir=$withval
+		# in case this was not explicit yet
+		enable_cuda=yes
+	], [cuda_include_dir=no])
+
+AC_ARG_WITH(cuda-lib-dir, 
+	[AS_HELP_STRING([--with-cuda-lib-dir=<path>],
+	[specify where CUDA libraries are installed])],
+	[
+		cuda_lib_dir=$withval
+		# in case this was not explicit yet
+		enable_cuda=yes
+	], [cuda_lib_dir=no])
+
 
+if test x$enable_cuda = xyes -o x$enable_cuda = xmaybe; then
 	! test -d "$cuda_dir" && test -d "/c/cuda" && cuda_dir=/c/cuda
 	! test -d "$cuda_dir" && test -d "/cygdrive/c/cuda" && cuda_dir=/cygdrive/c/cuda
 
-	if test -d "$cuda_dir/include/"; then
-		CPPFLAGS="${CPPFLAGS} -I$cuda_dir/include/ "
-                STARPU_CUDA_CPPFLAGS="-I$cuda_dir/include/"
-		NVCCFLAGS="${NVCCFLAGS} -I$cuda_dir/include/ "
+	if test x$cuda_include_dir = xno; then
+		cuda_include_dir="$cuda_dir/include/"
+	fi
+
+	if test -d "$cuda_include_dir"; then
+		CPPFLAGS="${CPPFLAGS} -I$cuda_include_dir "
+                STARPU_CUDA_CPPFLAGS="-I$cuda_include_dir"
+		NVCCFLAGS="${NVCCFLAGS} -I$cuda_include_dir "
 	fi
 
 	# do we have a valid CUDA setup ?
@@ -203,16 +226,23 @@ if test x$enable_cuda = xyes -o x$enable_cuda = xmaybe; then
 	# restore it in case it's not working.
 	SAVED_LDFLAGS="${LDFLAGS}"
 
-	found_cudalib=no
-	if test -d "$cuda_dir/lib/"; then
-		LDFLAGS="${SAVED_LDFLAGS} -L$cuda_dir/lib/ "
-                STARPU_CUDA_LDFLAGS="-L$cuda_dir/lib/"
-		AC_HAVE_LIBRARY([cuda],[found_cudalib=yes],[found_cudalib=no])
-	fi
-
-	if test x$found_cudalib=xno -a -d "$cuda_dir/lib64/"; then
-		LDFLAGS="${SAVED_LDFLAGS} -L$cuda_dir/lib64/ "
-                STARPU_CUDA_LDFLAGS="-L$cuda_dir/lib64/"
+	if test x$cuda_lib_dir = xno; then
+		found_cudalib=no
+		if test -d "$cuda_dir/lib/"; then
+			LDFLAGS="${SAVED_LDFLAGS} -L$cuda_dir/lib/ "
+	                STARPU_CUDA_LDFLAGS="-L$cuda_dir/lib/"
+			AC_HAVE_LIBRARY([cuda],[found_cudalib=yes],[found_cudalib=no])
+		fi
+	
+		if test x$found_cudalib=xno -a -d "$cuda_dir/lib64/"; then
+			LDFLAGS="${SAVED_LDFLAGS} -L$cuda_dir/lib64/ "
+	                STARPU_CUDA_LDFLAGS="-L$cuda_dir/lib64/"
+		fi
+	else
+		if test -d "$cuda_lib_dir"; then
+			LDFLAGS="${LDFLAGS} -L$cuda_lib_dir "
+	                STARPU_CUDA_LDFLAGS="-L$cuda_lib_dir "
+		fi
 	fi
 
 	AC_HAVE_LIBRARY([cuda],[],[have_valid_cuda=no])
@@ -341,7 +371,10 @@ if test x$enable_cuda = xyes; then
 fi
 AC_MSG_CHECKING(whether CURAND is available)
 AC_MSG_RESULT($have_curand)
-AC_SUBST(STARPU_HAVE_CURAND, $have_curand) 
+if test x$have_curand = xyes; then
+AC_DEFINE(STARPU_HAVE_CURAND,[1], [CURAND is available])
+fi
+
 
 ###############################################################################
 #                                                                             #

+ 21 - 13
examples/pi/pi_redux.c

@@ -15,19 +15,19 @@
  */
 
 #include <starpu.h>
-#include <starpu_cuda.h>
 #include <stdlib.h>
 #include <sys/time.h>
 
 #define PI	3.14159265358979323846
 
-#if defined(STARPU_USE_CUDA) && defined(STARPU_HAVE_CURAND)
-#error CURAND is required to run that example on CUDA devices
+#if defined(STARPU_USE_CUDA) && !defined(STARPU_HAVE_CURAND)
+#warning CURAND is required to run that example on CUDA devices
 #endif
 
-#ifdef STARPU_USE_CUDA
+#ifdef STARPU_HAVE_CURAND
 #include <cuda.h>
 #include <curand.h>
+#include <starpu_cuda.h>
 #endif
 
 #define NSHOT_PER_TASK	(1024*1024)
@@ -39,7 +39,7 @@ static unsigned long ntasks = 1024;
  *	Initialization of the Random Number Generators (RNG)
  */
 
-#ifdef STARPU_USE_CUDA
+#ifdef STARPU_HAVE_CURAND
 /* RNG for the CURAND library */
 static curandGenerator_t curandgens[STARPU_NMAXWORKERS];
 #endif 
@@ -50,7 +50,7 @@ static unsigned short xsubi[3*STARPU_NMAXWORKERS];
 /* Function to initialize the random number generator in the current worker */
 static void init_rng(void *arg __attribute__((unused)))
 {
-#ifdef STARPU_USE_CUDA
+#ifdef STARPU_HAVE_CURAND
 	curandStatus_t res;
 #endif
 
@@ -63,7 +63,7 @@ static void init_rng(void *arg __attribute__((unused)))
 			xsubi[1 + 3*workerid] = (unsigned short)workerid;
 			xsubi[2 + 3*workerid] = (unsigned short)workerid;
 			break;
-#ifdef STARPU_USE_CUDA
+#ifdef STARPU_HAVE_CURAND
 		case STARPU_CUDA_WORKER:
 
 			/* Create a RNG */
@@ -126,7 +126,7 @@ static void pi_func_cpu(void *descr[], void *cl_arg __attribute__ ((unused)))
 
 extern void pi_redux_cuda_kernel(float *x, float *y, unsigned n, unsigned long *shot_cnt);
 
-#ifdef STARPU_USE_CUDA
+#ifdef STARPU_HAVE_CURAND
 static void pi_func_cuda(void *descr[], void *cl_arg __attribute__ ((unused)))
 {
 	cudaError_t cures;
@@ -155,9 +155,13 @@ static void pi_func_cuda(void *descr[], void *cl_arg __attribute__ ((unused)))
 #endif
 
 static struct starpu_codelet_t pi_cl = {
-	.where = STARPU_CPU|STARPU_CUDA,
+	.where =
+#ifdef STARPU_HAVE_CURAND
+		STARPU_CUDA|
+#endif
+		STARPU_CPU,
 	.cpu_func = pi_func_cpu,
-#ifdef STARPU_USE_CUDA
+#ifdef STARPU_HAVE_CURAND
 	.cuda_func = pi_func_cuda,
 #endif
 	.nbuffers = 2,
@@ -174,7 +178,7 @@ static void init_cpu_func(void *descr[], void *cl_arg)
         *val = 0;
 }
 
-#ifdef STARPU_USE_CUDA
+#ifdef STARPU_HAVE_CURAND
 static void init_cuda_func(void *descr[], void *cl_arg)
 {
         unsigned long *val = (unsigned long *)STARPU_VARIABLE_GET_PTR(descr[0]);
@@ -184,9 +188,13 @@ static void init_cuda_func(void *descr[], void *cl_arg)
 #endif
 
 static struct starpu_codelet_t init_codelet = {
-        .where = STARPU_CPU|STARPU_CUDA,
+	.where =
+#ifdef STARPU_HAVE_CURAND
+		STARPU_CUDA|
+#endif
+		STARPU_CPU,
         .cpu_func = init_cpu_func,
-#ifdef STARPU_USE_CUDA
+#ifdef STARPU_HAVE_CURAND
         .cuda_func = init_cuda_func,
 #endif
         .nbuffers = 1

+ 2 - 0
include/starpu_config.h.in

@@ -39,6 +39,8 @@
 #undef STARPU_HAVE_FFTWF
 #undef STARPU_HAVE_FFTWL
 
+#undef STARPU_HAVE_CURAND
+
 #undef STARPU_NMAXBUFS
 #undef STARPU_MAXCUDADEVS
 #undef STARPU_MAXOPENCLDEVS