ソースを参照

also print measures for non-linear regression

Samuel Thibault 14 年 前
コミット
ba202980af
共有1 個のファイルを変更した107 個の追加36 個の削除を含む
  1. 107 36
      tools/starpu_regression_display.c

+ 107 - 36
tools/starpu_regression_display.c

@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
+#include <limits.h>
 
 #include <starpu.h>
 #include <starpu_perfmodel.h>
@@ -30,6 +31,8 @@
 
 static struct starpu_perfmodel_t model;
 
+/* display all available models */
+static int list = 0;
 /* what kernel ? */
 static char *symbol = NULL;
 /* which architecture ? (NULL = all)*/
@@ -43,17 +46,21 @@ static long dumped_codelets_count;
 static struct starpu_fxt_options options;
 #endif
 
+#ifdef STARPU_USE_FXT
 static int archtype_is_found[STARPU_NARCH_VARIATIONS];
 
 static char data_file_name[256];
+#endif
+static char avg_file_name[256];
 static char gnuplot_file_name[256];
 
 static void usage(char **argv)
 {
 	fprintf(stderr, "Usage: %s [ options ]\n", argv[0]);
         fprintf(stderr, "\n");
-        fprintf(stderr, "One must specify a symbol with the -s option\n");
+	fprintf(stderr, "One must specify a symbol with the -s option or use -l\n");
         fprintf(stderr, "Options:\n");
+        fprintf(stderr, "   -l                  display all available models\n");
         fprintf(stderr, "   -s <symbol>         specify the symbol\n");
 	fprintf(stderr, "   -i <Fxt files>      input FxT files generated by StarPU\n");
         fprintf(stderr, "   -a <arch>           specify the architecture (e.g. cpu, cpu:k, cuda, gordon)\n");
@@ -95,6 +102,11 @@ static void parse_args(int argc, char **argv)
 			continue;
 		}
 
+		if (strcmp(argv[i], "-l") == 0) {
+			list = 1;
+			continue;
+		}
+
 		if (strcmp(argv[i], "-a") == 0) {
 			arch = argv[++i];
 			continue;
@@ -118,6 +130,17 @@ static void parse_args(int argc, char **argv)
 	}
 }
 
+static void print_comma(FILE *gnuplot_file, int *first)
+{
+	if (*first)
+	{
+		*first = 0;
+	}
+	else {
+		fprintf(gnuplot_file, ",\\\n\t");
+	}
+}
+
 static void display_perf_model(FILE *gnuplot_file, struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch, int *first)
 {
 	char arch_name[256];
@@ -126,14 +149,7 @@ static void display_perf_model(FILE *gnuplot_file, struct starpu_perfmodel_t *mo
 #ifdef STARPU_USE_FXT
 	if (!no_fxt_file && archtype_is_found[arch])
 	{
-		if (*first)
-		{
-			*first = 0;
-		}
-		else {
-			fprintf(gnuplot_file, ",\\\n\t");
-		}
-	
+		print_comma(gnuplot_file, first);
 		fprintf(gnuplot_file, "\"< grep -w \\^%d %s\" using 2:3 title \"%s\"", arch, data_file_name, arch_name);
 	}
 #endif
@@ -143,13 +159,7 @@ static void display_perf_model(FILE *gnuplot_file, struct starpu_perfmodel_t *mo
 	/* Only display the regression model if we could actually build a model */
 	if (arch_model->regression.valid)
 	{
-		if (*first)
-		{
-			*first = 0;
-		}
-		else {
-			fprintf(gnuplot_file, ",\\\n\t");
-		}
+		print_comma(gnuplot_file, first);
 	
 		fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
 		fprintf(stderr, "\t\talpha = %le\n", arch_model->regression.alpha * 0.001);
@@ -161,13 +171,7 @@ static void display_perf_model(FILE *gnuplot_file, struct starpu_perfmodel_t *mo
 
 	if (arch_model->regression.nl_valid)
 	{
-		if (*first)
-		{
-			*first = 0;
-		}
-		else {
-			fprintf(gnuplot_file, ",\\\n\t");
-		}
+		print_comma(gnuplot_file, first);
 	
 		fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
 		fprintf(stderr, "\t\ta = %le\n", arch_model->regression.a * 0.001);
@@ -179,6 +183,70 @@ static void display_perf_model(FILE *gnuplot_file, struct starpu_perfmodel_t *mo
 	}
 }
 
+static void display_history_based_perf_models(FILE *gnuplot_file, struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch1, enum starpu_perf_archtype arch2, int *first)
+{
+	FILE *datafile = fopen(avg_file_name, "w");
+	unsigned n = arch2 - arch1;
+	enum starpu_perf_archtype arch;
+	struct starpu_history_list_t *ptr[n];
+	char archname[32];
+
+	for (arch = arch1; arch < arch2; arch++) {
+		struct starpu_per_arch_perfmodel_t *arch_model = &model->per_arch[arch];
+		starpu_perfmodel_get_arch_name(arch, archname, 32);
+
+		ptr[arch-arch1] = arch_model->list;
+
+		if (ptr[arch-arch1]) {
+			print_comma(gnuplot_file, first);
+			fprintf(gnuplot_file, "\"%s\" using 1:%d with linespoint title \"Measured %s\", \"%s\" using 1:%d:%d with errorbars notitle", avg_file_name, 2*(arch-arch1)+2, archname, avg_file_name, 2*(arch-arch1)+2, 2*(arch-arch1)+3);
+		}
+	}
+
+	while (1) {
+		unsigned long minimum;
+		/* Check whether there's data left */
+		for (arch = arch1; arch < arch2; arch++) {
+			if (ptr[arch-arch1])
+				break;
+		}
+		if (arch == arch2)
+			/* finished with archs */
+			break;
+
+		/* Get the minimum x */
+		minimum = ULONG_MAX;
+		for (arch = arch1; arch < arch2; arch++) {
+			if (ptr[arch-arch1]) {
+				struct starpu_history_entry_t *entry = ptr[arch-arch1]->entry;
+				if (entry->size < minimum)
+					minimum = entry->size;
+			}
+		}
+
+		fprintf(datafile, "%-15lu ", minimum);
+		for (arch = arch1; arch < arch2; arch++) {
+			if (ptr[arch-arch1]) {
+				struct starpu_history_entry_t *entry = ptr[arch-arch1]->entry;
+				if (entry->size == minimum) {
+					fprintf(datafile, "\t%-15le\t%-15le", 0.001*entry->mean, 0.001*entry->deviation);
+					ptr[arch-arch1] = ptr[arch-arch1]->next;
+				} else
+					fprintf(datafile, "\t\"\"\t\"\"");
+			}
+		}
+		fprintf(datafile, "\n");
+	}
+}
+
+static void display_perf_models(FILE *gnuplot_file, struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch1, enum starpu_perf_archtype arch2, int *first)
+{
+	enum starpu_perf_archtype arch;
+	for (arch = arch1; arch < arch2; arch++)
+		display_perf_model(gnuplot_file, model, arch, first);
+	display_history_based_perf_models(gnuplot_file, model, arch1, arch2, first);
+}
+
 #ifdef STARPU_USE_FXT
 static void dump_data_file(FILE *data_file)
 {
@@ -226,9 +294,7 @@ static void display_selected_models(FILE *gnuplot_file, struct starpu_perfmodel_
 	if (arch == NULL)
 	{
 		/* display all architectures */
-		unsigned archid;
-		for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
-			display_perf_model(gnuplot_file, model, archid, &first);
+		display_perf_models(gnuplot_file, model, 0, STARPU_NARCH_VARIATIONS, &first);
 	}
 	else {
 		if (strcmp(arch, "cpu") == 0) {
@@ -246,18 +312,12 @@ static void display_selected_models(FILE *gnuplot_file, struct starpu_perfmodel_
 				exit(-1);
 			}
 
-			display_perf_model(gnuplot_file, model, STARPU_CPU_DEFAULT + k - 1, &first);
+			display_perf_models(gnuplot_file, model, STARPU_CPU_DEFAULT + k - 1, STARPU_CPU_DEFAULT + k - 1, &first);
 			return;
 		}
 
 		if (strcmp(arch, "cuda") == 0) {
-			unsigned archid;
-			for (archid = STARPU_CUDA_DEFAULT; archid < STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS; archid++)
-			{
-				char archname[32];
-				starpu_perfmodel_get_arch_name(archid, archname, 32);
-				display_perf_model(gnuplot_file, model, archid, &first);
-			}
+			display_perf_models(gnuplot_file, model, STARPU_CUDA_DEFAULT, STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS, &first);
 			return;
 		}
 
@@ -268,12 +328,12 @@ static void display_selected_models(FILE *gnuplot_file, struct starpu_perfmodel_
 		if (nmatched == 1)
 		{
 			unsigned archid = STARPU_CUDA_DEFAULT+ gpuid;
-			display_perf_model(gnuplot_file, model, archid, &first);
+			display_perf_models(gnuplot_file, model, archid, archid, &first);
 			return;
 		}
 
 		if (strcmp(arch, "gordon") == 0) {
-			display_perf_model(gnuplot_file, model, STARPU_GORDON_DEFAULT, &first);
+			display_perf_models(gnuplot_file, model, STARPU_GORDON_DEFAULT, STARPU_GORDON_DEFAULT, &first);
 			return;
 		}
 
@@ -293,6 +353,15 @@ int main(int argc, char **argv)
 
 	parse_args(argc, argv);
 
+        if (list) {
+                int ret = starpu_list_models();
+                if (ret) {
+                        fprintf(stderr, "The performance model directory is invalid\n");
+                        return 1;
+                }
+		return 0;
+        }
+
 	/* We need at least a symbol name */
 	if (!symbol)
 	{
@@ -325,6 +394,8 @@ int main(int argc, char **argv)
 
 	snprintf(gnuplot_file_name, 256, "starpu_%s.gp", symbol);
 
+	snprintf(avg_file_name, 256, "starpu_%s_avg.data", symbol);
+
 	FILE *gnuplot_file = fopen(gnuplot_file_name, "w+");
 	STARPU_ASSERT(gnuplot_file);
 	display_selected_models(gnuplot_file, &model);