Browse Source

Build sgemm when cuda is available even if blas is not

Samuel Thibault 4 years ago
parent
commit
10fa883814
4 changed files with 27 additions and 6 deletions
  1. 1 0
      configure.ac
  2. 13 6
      examples/Makefile.am
  3. 12 0
      examples/mult/xgemm.c
  4. 1 0
      include/starpu_config.h.in

+ 1 - 0
configure.ac

@@ -2778,6 +2778,7 @@ if test x$have_cblas_h = xyes; then
     AC_DEFINE(STARPU_HAVE_CBLAS_H, [1], [The blas library has blas.h])
 fi
 if test x$blas_lib != xnone; then
+    AC_DEFINE(STARPU_HAVE_BLAS, [1], [The blas library is available])
     SAVED_LIBS="$LIBS"
     LIBS="$LIBS -lblas"
     AC_CHECK_FUNCS([cblas_sgemv])

+ 13 - 6
examples/Makefile.am

@@ -309,6 +309,12 @@ endif
 endif
 endif
 
+if STARPU_USE_CUDA
+STARPU_EXAMPLES +=				\
+	mult/sgemm 				\
+	mult/dgemm
+endif
+
 if !STARPU_NO_BLAS_LIB
 STARPU_EXAMPLES +=				\
 	mult/sgemm 				\
@@ -672,22 +678,23 @@ endif
 # Mult example #
 ################
 
-if !STARPU_NO_BLAS_LIB
-
 mult_sgemm_SOURCES = 				\
-	mult/sgemm.c				\
-	common/blas.c
+	mult/sgemm.c
 
 mult_sgemm_LDADD =				\
 	$(STARPU_BLAS_LDFLAGS)
 
 mult_dgemm_SOURCES = 				\
-	mult/dgemm.c				\
-	common/blas.c
+	mult/dgemm.c
 
 mult_dgemm_LDADD =				\
 	$(STARPU_BLAS_LDFLAGS)
 
+if !STARPU_NO_BLAS_LIB
+mult_sgemm_SOURCES += 				\
+	common/blas.c
+mult_dgemm_SOURCES += 				\
+	common/blas.c
 endif
 
 ####################

+ 12 - 0
examples/mult/xgemm.c

@@ -33,7 +33,9 @@
 #include <starpu.h>
 #include <starpu_fxt.h>
 
+#ifdef STARPU_HAVE_BLAS
 #include <common/blas.h>
+#endif
 
 #ifdef STARPU_USE_CUDA
 #include <cuda.h>
@@ -68,6 +70,7 @@ static starpu_data_handle_t A_handle, B_handle, C_handle;
 #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
 #define PRINTF(fmt, ...) do { if (!getenv("STARPU_SSILENT")) {printf(fmt, ## __VA_ARGS__); fflush(stdout); }} while(0)
 
+#ifdef STARPU_HAVE_BLAS
 static int check_output(void)
 {
 	/* compute C = C - AB */
@@ -92,6 +95,7 @@ static int check_output(void)
 		return 1;
 	}
 }
+#endif
 
 static void init_problem_data(void)
 {
@@ -225,6 +229,7 @@ static void cublas_gemm(void *descr[], void *arg)
 }
 #endif
 
+#ifdef STARPU_HAVE_BLAS
 void cpu_mult(void *descr[], void *arg, TYPE beta)
 {
 	(void)arg;
@@ -273,6 +278,7 @@ void cpu_gemm(void *descr[], void *arg)
 {
 	cpu_mult(descr, arg, 1.);
 }
+#endif
 
 static struct starpu_perfmodel starpu_gemm_model =
 {
@@ -282,10 +288,12 @@ static struct starpu_perfmodel starpu_gemm_model =
 
 static struct starpu_codelet cl_gemm0 =
 {
+#ifdef STARPU_HAVE_BLAS
 	.type = STARPU_SEQ, /* changed to STARPU_SPMD if -spmd is passed */
 	.max_parallelism = INT_MAX,
 	.cpu_funcs = {cpu_gemm0},
 	.cpu_funcs_name = {"cpu_gemm0"},
+#endif
 #ifdef STARPU_USE_CUDA
 	.cuda_funcs = {cublas_gemm0},
 #elif defined(STARPU_SIMGRID)
@@ -299,10 +307,12 @@ static struct starpu_codelet cl_gemm0 =
 
 static struct starpu_codelet cl_gemm =
 {
+#ifdef STARPU_HAVE_BLAS
 	.type = STARPU_SEQ, /* changed to STARPU_SPMD if -spmd is passed */
 	.max_parallelism = INT_MAX,
 	.cpu_funcs = {cpu_gemm},
 	.cpu_funcs_name = {"cpu_gemm"},
+#endif
 #ifdef STARPU_USE_CUDA
 	.cuda_funcs = {cublas_gemm},
 #elif defined(STARPU_SIMGRID)
@@ -599,10 +609,12 @@ enodev:
 	starpu_data_unregister(B_handle);
 	starpu_data_unregister(C_handle);
 
+#ifdef STARPU_HAVE_BLAS
 #ifndef STARPU_SIMGRID
 	if (check)
 		ret = check_output();
 #endif
+#endif
 
 	starpu_free_flags(A, zdim*ydim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);
 	starpu_free_flags(B, xdim*zdim*sizeof(TYPE), STARPU_MALLOC_PINNED|STARPU_MALLOC_SIMULATION_FOLDED);

+ 1 - 0
include/starpu_config.h.in

@@ -127,6 +127,7 @@
 #undef STARPU_ARMPL
 #undef STARPU_SYSTEM_BLAS
 #undef STARPU_HAVE_CBLAS_H
+#undef STARPU_HAVE_BLAS
 
 /**
    Define the directory in which the OpenCL codelets of the