Przeglądaj źródła

mlr: cleaning the code and configuration

Luka Stanisic 9 lat temu
rodzic
commit
a7bf2f2698
2 zmienionych plików z 66 dodań i 35 usunięć
  1. 30 25
      configure.ac
  2. 36 10
      src/core/perfmodel/multiple_regression.c

+ 30 - 25
configure.ac

@@ -1131,35 +1131,40 @@ fi
 #			 Multiple linear regression			      #
 #                                                                             #
 ###############################################################################
-STARPU_SEARCH_LIBS(LAPACK,[dgels_],[lapack],use_system_lapack=yes,,)
-if test x$use_system_lapack = xyes; then
-        AC_DEFINE(STARPU_SYSTEM_LAPACK, [1], [use reflapack library])
-	LDFLAGS="-llapack $LDFLAGS"
-else
-	AC_MSG_CHECKING(whether min-dgels is linked)
-	if test x"$DGELS_LIBS" != x; then
-	   	AC_MSG_RESULT(yes)
-        	AC_DEFINE(STARPU_MIN_DGELS, [1], [use user defined library])
-		LDFLAGS="$DGELS_LIBS $LDFLAGS"
-		AC_ARG_VAR([DGELS_LIBS], [linker flags for lapack dgels])
+AC_ARG_ENABLE(mlr, [AS_HELP_STRING([--disable-mlr],
+			[Disable multiple linear regression models])],
+			enable_mlr=$enableval, enable_mlr=yes)
+
+if test x$enable_mlr = xyes; then
+   	STARPU_SEARCH_LIBS(LAPACK,[dgels_],[lapack],use_system_lapack=yes,,)
+	if test x$use_system_lapack = xyes; then
+	        AC_DEFINE(STARPU_MLR_MODEL, [1], [use reflapack library])
+		LDFLAGS="-llapack $LDFLAGS"
 	else
-		AC_MSG_RESULT(no-need to install LAPACK or min-dgels library)
-		AC_MSG_CHECKING(installation of min-dgels)
-		wget https://github.com/stanisic/min-dgels/raw/master/min-dgels-src.tar.gz 1> min-dgels.out 2> min-dgels.err
-		mkdir -p min-dgels
-		tar xvzf min-dgels-src.tar.gz --strip-components=1 -C min-dgels 1> min-dgels.out 2> min-dgels.err
-		cd min-dgels
-		make 1> ../min-dgels.out 2> ../min-dgels.err
-		cd ..
-		AC_MSG_RESULT(done)
-		DGELS_LIBS="-Wl,--start-group $PWD/min-dgels/build/*.a -Wl,--end-group"
-		AC_DEFINE(STARPU_MIN_DGELS, [1], [use user defined library])
-		LDFLAGS="$DGELS_LIBS $LDFLAGS"
-		AC_ARG_VAR([DGELS_LIBS], [linker flags for lapack dgels])
+		AC_MSG_CHECKING(whether min-dgels is linked)
+		if test x"$DGELS_LIBS" != x; then
+		   	AC_MSG_RESULT(yes)
+        		AC_DEFINE(STARPU_MLR_MODEL, [1], [use user defined library])
+			LDFLAGS="$DGELS_LIBS $LDFLAGS"
+			AC_ARG_VAR([DGELS_LIBS], [linker flags for lapack dgels])
+		else
+			AC_MSG_RESULT(no-need to install LAPACK or min-dgels library)
+			AC_MSG_CHECKING(installation of min-dgels)
+			wget https://github.com/stanisic/min-dgels/raw/master/min-dgels-src.tar.gz 1> min-dgels.out 2> min-dgels.err
+			mkdir -p min-dgels
+			tar xvzf min-dgels-src.tar.gz --strip-components=1 -C min-dgels 1> min-dgels.out 2> min-dgels.err
+			cd min-dgels
+			make 1> ../min-dgels.out 2> ../min-dgels.err
+			cd ..
+			AC_MSG_RESULT(done)
+			DGELS_LIBS="-Wl,--start-group $PWD/min-dgels/build/*.a -Wl,--end-group"
+			AC_DEFINE(STARPU_MLR_MODEL, [1], [use user defined library])
+			LDFLAGS="$DGELS_LIBS $LDFLAGS"
+			AC_ARG_VAR([DGELS_LIBS], [linker flags for lapack dgels])
+		fi
 	fi
 fi
 
-
 ###############################################################################
 #                                                                             #
 #                                 MIC settings                                #

+ 36 - 10
src/core/perfmodel/multiple_regression.c

@@ -22,8 +22,9 @@
 typedef long int integer;
 typedef double doublereal;
 
+#ifdef STARPU_MLR_MODEL
 int dgels_(char *trans, integer *m, integer *n, integer *nrhs, doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *work, integer *lwork, integer *info);
-
+#endif //STARPU_MLR_MODEL
 
 static long count_file_lines(FILE *f)
 {
@@ -56,12 +57,16 @@ static void dump_multiple_regression_list(double *mpar, double *my, int start, u
 
 }
 
-static void load_old_calibration(double *mx, double *my, unsigned nparameters, FILE *f)
+static void load_old_calibration(double *mx, double *my, unsigned nparameters, char *filepath)
 {
 	char buffer[1024];
 	char *record,*line;
 	int i=0,j=0;
 
+	FILE *f=NULL;
+	f = fopen(filepath, "a+");
+	STARPU_ASSERT_MSG(f, "Could not save performance model into the file %s\n", filepath);
+
 	line=fgets(buffer,sizeof(buffer),f);//skipping first line
 	while((line=fgets(buffer,sizeof(buffer),f))!=NULL)
 	{
@@ -77,6 +82,8 @@ static void load_old_calibration(double *mx, double *my, unsigned nparameters, F
 		}
 		++i ;
 	}
+
+	fclose(f);
 }
 
 static long find_long_list_size(struct starpu_perfmodel_history_list *list_history)
@@ -93,6 +100,7 @@ static long find_long_list_size(struct starpu_perfmodel_history_list *list_histo
 	return cnt;
 }
 
+#ifdef STARPU_MLR_MODEL
 int dgels_multiple_reg_coeff(double *mpar, double *my, long nn, unsigned ncoeff, unsigned nparameters, double *coeff, unsigned **combinations)
 {	
  /*  Arguments */
@@ -226,6 +234,7 @@ int dgels_multiple_reg_coeff(double *mpar, double *my, long nn, unsigned ncoeff,
 
 	return 0;
 }
+#endif //STARPU_MLR_MODEL
 
 /*
    Validating the accuracy of the coefficients.
@@ -243,6 +252,13 @@ void validate(double *coeff, unsigned ncoeff)
 	
 int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, double *coeff, unsigned ncoeff, unsigned nparameters, unsigned **combinations, const char *codelet_name)
 {
+#ifndef STARPU_MLR_MODEL
+	_STARPU_DISP("Warning: StarPU was compiled with '--disable-mlr' option, thus multiple linear regression model will not be computed.\n");
+	for(int i=0; i<ncoeff; i++)
+		coeff[i] = 0.;
+	return 1;
+#endif //STARPU_MLR_MODEL
+	
 	/* Computing number of rows */
 	long n=find_long_list_size(ptr);
 	STARPU_ASSERT(n);
@@ -269,6 +285,8 @@ int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, doubl
 		//STARPU_ASSERT(old_lines);
 
 		n+=old_lines;
+
+		fclose(f);
 	}
 
 	/* Allocating X and Y matrices */
@@ -279,27 +297,35 @@ int _starpu_multiple_regression(struct starpu_perfmodel_history_list *ptr, doubl
 
 	/* Loading old calibration */
 	if (calibrate==1)
-		load_old_calibration(mpar, my, nparameters, f);
+		load_old_calibration(mpar, my, nparameters, filepath);
 
 	/* Filling X and Y matrices with measured values */
 	dump_multiple_regression_list(mpar, my, old_lines, nparameters, ptr);
-	
+
+#ifdef STARPU_MLR_MODEL
 	/* Computing coefficients using multiple linear regression */
 	if(dgels_multiple_reg_coeff(mpar, my, n, ncoeff, nparameters, coeff, combinations))
 		return 1;
+#endif //STARPU_MLR_MODEL
 
 	/* Basic validation of the model accuracy */
 	validate(coeff, ncoeff);
 	
 	/* Preparing new output calibration file */
-	if (calibrate==2)
+	if (calibrate==1 || calibrate==2)
 	{
-		f = fopen(filepath, "w+");
-		STARPU_ASSERT_MSG(f, "Could not save performance model into the file %s\n", filepath);
-		fprintf(f, "Duration");
-		for(int k=0; k < nparameters; k++)
+		if (old_lines > 0)
 		{
-			fprintf(f, ", P%d", k);
+			f = fopen(filepath, "a+");
+			STARPU_ASSERT_MSG(f, "Could not save performance model into the file %s\n", filepath);
+		}
+		else
+		{
+			f = fopen(filepath, "w+");
+			STARPU_ASSERT_MSG(f, "Could not save performance model into the file %s\n", filepath);
+			fprintf(f, "Duration");
+			for(int k=0; k < nparameters; k++)
+				fprintf(f, ", P%d", k);
 		}
 	}