Explorar o código

Add starpu_tasks_rec_complete tool to add estimation times in tasks.rec files

Samuel Thibault %!s(int64=8) %!d(string=hai) anos
pai
achega
7bd115a084

+ 3 - 0
ChangeLog

@@ -27,7 +27,10 @@ Changes:
 
 StarPU 1.2.1 (svn revision xxx)
 ==============================================
+New features:
   * Add starpu_fxt_trace_user_event_string.
+  * Add starpu_tasks_rec_complete tool to add estimation times in tasks.rec
+    files.
 
 StarPU 1.2.0 (svn revision 18521)
 ==============================================

+ 10 - 3
doc/doxygen/chapters/380_offline_performance_tools.doxy

@@ -182,9 +182,16 @@ $ starpu_fxt_tool -i /tmp/prof_file_something
 This will create a <c>tasks.rec</c> file in the current directory.  This file
 is in the recutils format, i.e. <c>Field: value</c> lines, and empty lines to
 separate each task.  This can be used as a convenient input for various ad-hoc
-analysis tools.  The performance models can be opened for instance by using
-starpu_perfmodel_load_symbol() and then using
-starpu_perfmodel_history_based_expected_perf().
+analysis tools. By default it only contains information about the actual
+execution. Performance models can be obtained by running
+<c>starpu_tasks_rec_complete</c> on it:
+
+\verbatim
+$ starpu_tasks_rec_complete tasks.rec tasks2.rec
+\endverbatim
+
+which will add <c>EstimatedTime</c> lines which contain the performance
+model-estimated time (in µs) for each worker starting from 0.
 
 \subsection MonitoringActivity Monitoring Activity
 

+ 4 - 0
doc/doxygen/chapters/api/performance_model.doxy

@@ -246,6 +246,10 @@ todo
 \ingroup API_Performance_Model
 todo
 
+\fn int starpu_perfmodel_print_estimations(struct starpu_perfmodel *model, uint32_t footprint, FILE *output)
+\ingroup API_Performance_Model
+todo
+
 \fn void starpu_bus_print_bandwidth(FILE *f)
 \ingroup API_Performance_Model
 prints a matrix of bus bandwidths on \p f.

+ 1 - 0
include/starpu_perfmodel.h

@@ -168,6 +168,7 @@ double starpu_perfmodel_history_based_expected_perf(struct starpu_perfmodel *mod
 int starpu_perfmodel_list(FILE *output);
 void starpu_perfmodel_print(struct starpu_perfmodel *model, struct starpu_perfmodel_arch *arch, unsigned nimpl, char *parameter, uint32_t *footprint, FILE *output);
 int starpu_perfmodel_print_all(struct starpu_perfmodel *model, char *arch, char *parameter, uint32_t *footprint, FILE *output);
+int starpu_perfmodel_print_estimations(struct starpu_perfmodel *model, uint32_t footprint, FILE *output);
 
 int starpu_perfmodel_list_combs(FILE *output, struct starpu_perfmodel *model);
 

+ 28 - 1
src/core/perfmodel/perfmodel_print.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2011, 2013-2015  Université de Bordeaux
+ * Copyright (C) 2011, 2013-2016  Université de Bordeaux
  * Copyright (C) 2011, 2012, 2013, 2014, 2015  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  *
@@ -288,3 +288,30 @@ int starpu_perfmodel_print_all(struct starpu_perfmodel *model, char *arch, char
 	return 0;
 }
 
+int starpu_perfmodel_print_estimations(struct starpu_perfmodel *model, uint32_t footprint, FILE *output)
+{
+	unsigned workerid;
+	for (workerid = 0; workerid < starpu_worker_get_count(); workerid++)
+	{
+		struct starpu_perfmodel_arch* arch = starpu_worker_get_perf_archtype(workerid, STARPU_NMAX_SCHED_CTXS);
+		int comb = starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices);
+		struct starpu_perfmodel_per_arch *arch_model = &model->state->per_arch[comb][0];
+		struct starpu_perfmodel_history_list *ptr;
+
+		for (ptr = arch_model->list; ptr; ptr = ptr->next)
+		{
+			struct starpu_perfmodel_history_entry *entry = ptr->entry;
+			if (entry->footprint == footprint)
+			{
+				fprintf(output, "%s%e", workerid?" ":"", entry->mean);
+				break;
+			}
+		}
+		if (!ptr)
+		{
+			/* Didn't find any entry :/ */
+			fprintf(output, "%sNaN", workerid?" ":"");
+		}
+	}
+	return 0;
+}

+ 4 - 0
tools/Makefile.am

@@ -220,6 +220,7 @@ bin_PROGRAMS += 			\
 	starpu_calibrate_bus		\
 	starpu_machine_display		\
 	starpu_sched_display		\
+	starpu_tasks_rec_complete	\
 	starpu_lp2paje
 
 starpu_perfmodel_plot_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) $(FXT_CFLAGS)
@@ -267,6 +268,8 @@ starpu_perfmodel_display.1: starpu_perfmodel_display$(EXEEXT)
 	help2man --no-discard-stderr -N --output=$@ ./$<
 starpu_perfmodel_plot.1: starpu_perfmodel_plot$(EXEEXT)
 	help2man --no-discard-stderr -N --output=$@ ./$<
+starpu_tasks_rec_complete.1: starpu_tasks_rec_complete$(EXEEXT)
+	help2man --no-discard-stderr -N --output=$@ ./$<
 starpu_lp2paje.1: starpu_lp2paje$(EXEEXT)
 	help2man --no-discard-stderr -N --output=$@ ./$<
 starpu_workers_activity.1: starpu_workers_activity
@@ -299,6 +302,7 @@ dist_man1_MANS =\
 	starpu_machine_display.1 \
 	starpu_perfmodel_display.1 \
 	starpu_perfmodel_plot.1	\
+	starpu_tasks_rec_complete.1 \
 	starpu_lp2paje.1	\
 	starpu_workers_activity.1 \
 	starpu_codelet_profile.1 \

+ 171 - 0
tools/starpu_tasks_rec_complete.c

@@ -0,0 +1,171 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2011-2014, 2016  Universite de Bordeaux
+ * Copyright (C) 2012-2015  CNRS
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <errno.h>
+#include <string.h>
+#include <common/uthash.h>
+#include <starpu.h>
+
+#define PROGNAME "starpu_tasks_rec_complete"
+
+/*
+ * This program takes a tasks.rec file, and emits a tasks.rec file with
+ * additional information, notably estimated termination times.
+ */
+
+static struct model {
+	UT_hash_handle hh;
+	char *name;
+	struct starpu_perfmodel model;
+} *models;
+
+int main(int argc, char *argv[]) {
+	FILE *input;
+	FILE *output;
+	char s[1024], *c;
+	uint32_t footprint = 0;
+	char *model_name = NULL;
+	struct model *model, *tmp;
+	int ret;
+
+	if (argc >= 2) {
+		if (!strcmp(argv[1], "-h") ||
+		    !strcmp(argv[1], "--help"))
+		{
+			fprintf(stderr, "Complete a tasks.rec file with additional information, notably estimated termination times.\n");
+			fprintf(stderr, "\n");
+			fprintf(stderr, "Usage: %s [input-file [output-file]]\n", PROGNAME);
+			fprintf(stderr, "\n");
+			fprintf(stderr, "If input or output file names are not given, stdin and stdout are used.", PROGNAME);
+			fprintf(stderr, "\n");
+			fprintf(stderr, "Report bugs to <" PACKAGE_BUGREPORT ">.\n");
+			exit(EXIT_SUCCESS);
+		}
+	}
+
+	if (starpu_init(NULL) != 0)
+	{
+		fprintf(stderr, "StarPU initialization failure\n");
+		exit(EXIT_FAILURE);
+	}
+	starpu_pause();
+
+	if (argc >= 2)
+	{
+		input = fopen(argv[1], "r");
+		if (!input)
+		{
+			fprintf(stderr, "couldn't open %s for read: %s\n", argv[1], strerror(errno));
+			exit(EXIT_FAILURE);
+		}
+	}
+	else
+		input = stdin;
+
+	if (argc >= 3)
+	{
+		output = fopen(argv[2], "w+");
+		if (!output)
+		{
+			fprintf(stderr, "couldn't open %s for write: %s\n", argv[1], strerror(errno));
+			exit(EXIT_FAILURE);
+		}
+	}
+	else
+		output = stdout;
+
+	while (fgets(s, sizeof(s), input))
+	{
+		if (strlen(s) == sizeof(s) - 1)
+		{
+			fprintf(stderr, "oops, very long line '%s', it's odd\n", s);
+			exit(EXIT_FAILURE);
+		}
+
+		if (s[0] == '\n')
+		{
+			/* empty line, end of task */
+			if (model_name)
+			{
+				/* Try to get already-loaded model */
+				HASH_FIND_STR(models, model_name, model);
+				if (model == NULL)
+				{
+					model = malloc(sizeof(*model));
+					model->name = model_name;
+					memset(&model->model, 0, sizeof(model->model));
+					model->model.type = STARPU_PERFMODEL_INVALID;
+					ret = starpu_perfmodel_load_symbol(model_name, &model->model);
+					if (ret == 1)
+					{
+						fprintf(stderr, "The performance model for the symbol <%s> could not be loaded\n", model_name);
+						exit(EXIT_FAILURE);
+					}
+					HASH_ADD_STR(models, name, model);
+				}
+				else
+					free(model_name);
+				fprintf(output, "EstimatedTime: ");
+				starpu_perfmodel_print_estimations(&model->model, footprint, output);
+				fprintf(output, "\n");
+				model_name = NULL;
+			}
+			fprintf(output, "\n");
+			continue;
+		}
+
+		/* Get rec field name */
+		c = index(s, ':');
+		if (!c)
+		{
+			fprintf(stderr, "odd line '%s'\n", s);
+			exit(EXIT_FAILURE);
+		}
+
+#define STRHEADCMP(s, head) strncmp(s, head, strlen(head))
+
+		if (!STRHEADCMP(s, "Footprint: "))
+		{
+			footprint = strtoul(s + strlen("Footprint: "), NULL, 16);
+		}
+		else if (!STRHEADCMP(s, "Model: "))
+		{
+			model_name = strdup(s + strlen("Model: "));
+			model_name[strlen(model_name) - 1] = '\0'; /* Drop '\n' */
+		}
+		fprintf(output, s);
+	}
+
+	if (fclose(output))
+	{
+		fprintf(stderr, "couldn't close output: %s\n", strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+	starpu_resume();
+	starpu_shutdown();
+	HASH_ITER(hh, models, model, tmp)
+	{
+		free(model->name);
+		HASH_DEL(models, model);
+	}
+	return 0;
+}
+