Browse Source

Add a --with-magma option to the configure script to specify whether the MAGMA
lib should be used or not. It is possible to specify that MAGMA is installed in
a specific directory foo with --with-magma=foo .

Cédric Augonnet 15 years ago
parent
commit
210585a32e
5 changed files with 88 additions and 1 deletions
  1. 64 0
      configure.ac
  2. 6 0
      examples/lu/double.h
  3. 8 0
      examples/lu/float.h
  4. 8 1
      examples/mult/sgemm_kernels.c
  5. 2 0
      include/starpu_config.h.in

+ 64 - 0
configure.ac

@@ -220,9 +220,73 @@ if test x$enable_cuda = xyes; then
 		NVCCFLAGS="${NVCCFLAGS} -m64"
 		AC_SUBST(NVCCFLAGS)
 	fi
+fi
+
+enable_magma=no
+if test x$enable_cuda = xyes; then
+	# Should we use the MAGMA library (instead or in addition to CUBLAS)
+	magma_dir=/usr/local # default
+	enable_magma=maybe
+
+	AC_ARG_WITH(magma, [AS_HELP_STRING([--with-magma=<path>],
+			[specify that MAGMA should be used and its installation directory])],
+			[
+				if test x$withval = xyes; then
+					# No path was specified but MAGMA is explicitely enabled
+					enable_magma=yes
+				else
+				if test x$withval = xno; then
+					# MAGMA is explicitely disabled
+					enable_magma=no
+				else
+					# MAGMA is enabled and the PATH is given in $withval
+					enable_magma=yes
+					magma_dir=$withval
+				fi
+				fi
+			], [])
+
+	# Do we have a valid MAGMA setup ?
+	if test x$enable_magma = xyes -o x$enable_magma = xmaybe; then
+		SAVED_LDFLAGS="${LDFLAGS}"
+		SAVED_CPPFLAGS="${CPPFLAGS}"
+		if test -d "$magma_dir/lib/"; then
+			LDFLAGS="${SAVED_LDFLAGS} -L$magma_dir/lib/ "
+			have_valid_magma=yes
+			AC_CHECK_LIB(magmablas, main,,[have_valid_magma=no])
+			AC_CHECK_LIB(magma, magmablas_sgemm,,[have_valid_magma=no])
+		fi
+	
+		if test -d "$magma_dir/include/"; then
+			CPPFLAGS="${SAVED_CPPFLAGS} -I$magma_dir/include/ "
+			AC_CHECK_HEADER([magmablas.h],,[have_valid_magma=no])
+			#AC_CHECK_HEADER([magma.h],,[have_valid_magma=no])
+		fi
 
+		if test x$have_valid_magma = xno; then
+			# If MAGMA was explicitely required, this is an error
+			if test x$enable_magma = xyes; then
+				AC_MSG_ERROR([cannot find MAGMA])
+			fi
+	
+			# Restore old flags and don't use MAGMA
+			LDFLAGS="${SAVED_LDFLAGS}"
+			CPPFLAGS="${SAVED_CPPFLAGS}"
+			enable_magma=no
+		else
+			enable_magma=yes
+		fi
+
+	else
+		have_valid_magma=no
+		enable_magma=no
+	fi
 fi
 
+AC_MSG_CHECKING(whether MAGMA should be used)
+AC_MSG_RESULT($enable_magma)
+AC_DEFINE(STARPU_HAVE_MAGMA, [1], [use MAGMA library])
+
 # cufftDoubleComplex may not be available on an old CUDA setup
 AC_CHECK_TYPE(cufftDoubleComplex,
 	[have_cufftdoublecomplex=yes],

+ 6 - 0
examples/lu/double.h

@@ -18,8 +18,14 @@
 
 #define STARPU_LU(name)       starpu_dlu_##name
 
+#ifdef STARPU_HAVE_MAGMA
+#include <magmablas.h>
+#define CUBLAS_GEMM	magmablas_dgemm
+#define CUBLAS_TRSM	magmablas_dtrsm
+#else
 #define CUBLAS_GEMM	cublasDgemm
 #define CUBLAS_TRSM	cublasDtrsm
+#endif
 #define CUBLAS_SCAL	cublasDscal
 #define CUBLAS_GER	cublasDger
 #define CUBLAS_SWAP	cublasDswap

+ 8 - 0
examples/lu/float.h

@@ -14,12 +14,20 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
 
+
 #define TYPE float
 
 #define STARPU_LU(name)       starpu_slu_##name
 
+#ifdef STARPU_HAVE_MAGMA
+#include <magmablas.h>
+#define CUBLAS_GEMM	magmablas_sgemm
+#define CUBLAS_TRSM	magmablas_strsm
+#else
 #define CUBLAS_GEMM	cublasSgemm
 #define CUBLAS_TRSM	cublasStrsm
+#endif
+
 #define CUBLAS_SCAL	cublasSscal
 #define CUBLAS_GER	cublasSger
 #define CUBLAS_SWAP	cublasSswap

+ 8 - 1
examples/mult/sgemm_kernels.c

@@ -40,13 +40,20 @@
 
 
 #ifdef STARPU_USE_CUDA
+
+#ifdef STARPU_HAVE_MAGMA
+#define GPU_SGEMM magmablas_sgemm
+#else
+#define GPU_SGEMM cublasSgemm
+#endif
+
 void cublas_mult(void *descr[], __attribute__((unused)) void *arg)
 {
 	COMMON_CODE
 
 	starpu_trace_user_event(0x42);
 
-	cublasSgemm('n', 'n', nxC, nyC, nyA, 1.0f, subA, ldA, subB, ldB, 
+	GPU_SGEMM('n', 'n', nxC, nyC, nyA, 1.0f, subA, ldA, subB, ldB, 
 					     0.0f, subC, ldC);
 	cublasStatus st;
 	st = cublasGetError();

+ 2 - 0
include/starpu_config.h.in

@@ -9,6 +9,8 @@
 #undef STARPU_GOTO
 #undef STARPU_SYSTEM_BLAS
 
+#undef STARPU_HAVE_MAGMA
+
 #undef STARPU_DIR
 
 #undef STARPU_OPENGL_RENDER