Преглед на файлове

Add task submission file+line in traces

Samuel Thibault преди 4 години
родител
ревизия
18b4a1e02a

+ 1 - 0
ChangeLog

@@ -45,6 +45,7 @@ New features:
   * Add starpu_data_release_to() and starpu_data_release_to_on_node().
   * Add profiling based on papi performance counters.
   * Add an experimental python interface (not actually parallel yet)
+  * Add task submission file+line in traces.
 
 Small changes:
   * Add a synthetic energy efficiency testcase.

+ 1 - 0
examples/stencil/implicit-stencil-tasks.c

@@ -36,6 +36,7 @@
 
 #if defined(STARPU_USE_MPI) && !defined(STARPU_USE_MPI_MASTER_SLAVE)
 #include <starpu_mpi.h>
+#undef starpu_insert_task
 #define starpu_insert_task(...) starpu_mpi_insert_task(MPI_COMM_WORLD, __VA_ARGS__)
 #endif
 

+ 22 - 0
include/starpu_task.h

@@ -603,6 +603,18 @@ struct starpu_task
 	const char *name;
 
 	/**
+	   Optional file name where the task was submitted. This can be useful
+	   for debugging purposes.
+	*/
+	const char *file;
+
+	/**
+	  Optional line number where the task was submitted. This can be useful
+	   for debugging purposes.
+	*/
+	int line;
+
+	/**
 	   Pointer to the corresponding structure starpu_codelet. This
 	   describes where the kernel should be executed, and supplies
 	   the appropriate implementations. When set to <c>NULL</c>,
@@ -1437,6 +1449,16 @@ void starpu_task_destroy(struct starpu_task *task);
 */
 int starpu_task_submit(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
 
+#ifdef STARPU_USE_FXT
+static inline int starpu_task_submit_line(struct starpu_task *task, const char *file, int line)
+{
+	task->file = file;
+	task->line = line;
+	return starpu_task_submit(task);
+}
+#define starpu_task_submit(task) starpu_task_submit_line((task), __FILE__, __LINE__)
+#endif
+
 /**
    Submit \p task to StarPU with dependency bypass.
 

+ 34 - 1
include/starpu_task_util.h

@@ -327,7 +327,23 @@ extern "C"
  */
 #define STARPU_TASK_SCHED_DATA (41<<STARPU_MODE_SHIFT)
 
-#define STARPU_SHIFTED_MODE_MAX (42<<STARPU_MODE_SHIFT)
+/**
+   Used when calling starpu_task_insert(), must be followed by a
+   char * stored in starpu_task::file.
+
+   This is automatically set when FXT is enabled.
+*/
+#define STARPU_TASK_FILE	 (42<<STARPU_MODE_SHIFT)
+
+/**
+   Used when calling starpu_task_insert(), must be followed by an
+   int stored in starpu_task::line.
+
+   This is automatically set when FXT is enabled.
+*/
+#define STARPU_TASK_LINE	 (43<<STARPU_MODE_SHIFT)
+
+#define STARPU_SHIFTED_MODE_MAX (44<<STARPU_MODE_SHIFT)
 
 /**
    Set the given \p task corresponding to \p cl with the following arguments.
@@ -338,6 +354,11 @@ extern "C"
    starpu_task::cl_arg_free will be set to 1.
 */
 int starpu_task_set(struct starpu_task *task, struct starpu_codelet *cl, ...);
+#ifdef STARPU_USE_FXT
+#define starpu_task_set(task, cl, ...) \
+	starpu_task_set((task), (cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__)
+#endif
+
 
 /**
    Create a task corresponding to \p cl with the following arguments.
@@ -348,6 +369,10 @@ int starpu_task_set(struct starpu_task *task, struct starpu_codelet *cl, ...);
    starpu_task::cl_arg_free will be set to 1.
 */
 struct starpu_task *starpu_task_build(struct starpu_codelet *cl, ...);
+#ifdef STARPU_USE_FXT
+#define starpu_task_build(cl, ...) \
+	starpu_task_build((cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__)
+#endif
 
 /**
    Create and submit a task corresponding to \p cl with the following
@@ -386,11 +411,19 @@ struct starpu_task *starpu_task_build(struct starpu_codelet *cl, ...);
    starpu_codelet_unpack_args() must be called within the codelet implementation to retrieve them.
 */
 int starpu_task_insert(struct starpu_codelet *cl, ...);
+#ifdef STARPU_USE_FXT
+#define starpu_task_insert(cl, ...) \
+	starpu_task_insert((cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__)
+#endif
 
 /**
    Similar to starpu_task_insert(). Kept to avoid breaking old codes.
 */
 int starpu_insert_task(struct starpu_codelet *cl, ...);
+#ifdef STARPU_USE_FXT
+#define starpu_insert_task(cl, ...) \
+	starpu_insert_task((cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__)
+#endif
 
 /**
    Assuming that there are already \p current_buffer data handles

+ 12 - 0
mpi/include/starpu_mpi.h

@@ -597,11 +597,19 @@ starpu_mpi_tag_t starpu_mpi_data_get_tag(starpu_data_handle_t handle);
    STARPU_MPI_CACHE).
 */
 int starpu_mpi_task_insert(MPI_Comm comm, struct starpu_codelet *codelet, ...);
+#ifdef STARPU_USE_FXT
+#define starpu_mpi_task_insert(comm, cl, ...) \
+	starpu_mpi_task_insert((comm), (cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__)
+#endif
 
 /**
    Call starpu_mpi_task_insert(). Symbol kept for backward compatibility.
 */
 int starpu_mpi_insert_task(MPI_Comm comm, struct starpu_codelet *codelet, ...);
+#ifdef STARPU_USE_FXT
+#define starpu_mpi_insert_task(comm, cl, ...) \
+	starpu_mpi_insert_task((comm), (cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__)
+#endif
 
 /**
    Create a task corresponding to \p codelet with the following given
@@ -617,6 +625,10 @@ int starpu_mpi_insert_task(MPI_Comm comm, struct starpu_codelet *codelet, ...);
    creates it, with the SAME list of arguments.
 */
 struct starpu_task *starpu_mpi_task_build(MPI_Comm comm, struct starpu_codelet *codelet, ...);
+#ifdef STARPU_USE_FXT
+#define starpu_mpi_task_build(comm, cl, ...) \
+	starpu_mpi_task_build((comm), (cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__)
+#endif
 
 /**
    MUST be called after a call to starpu_mpi_task_build(),

+ 11 - 0
mpi/src/starpu_mpi_task_insert.c

@@ -505,6 +505,14 @@ int _starpu_mpi_task_decode_v(struct starpu_codelet *codelet, int me, int nb_nod
 		{
 			(void)va_arg(varg_list_copy, void *);
 		}
+		else if (arg_type==STARPU_TASK_FILE)
+		{
+			(void)va_arg(varg_list_copy, const char *);
+		}
+		else if (arg_type==STARPU_TASK_LINE)
+		{
+			(void)va_arg(varg_list_copy, int);
+		}
 		else
 		{
 			STARPU_ABORT_MSG("Unrecognized argument %d, did you perhaps forget to end arguments with 0?\n", arg_type);
@@ -661,6 +669,7 @@ int _starpu_mpi_task_insert_v(MPI_Comm comm, struct starpu_codelet *codelet, va_
 	return val;
 }
 
+#undef starpu_mpi_task_insert
 int starpu_mpi_task_insert(MPI_Comm comm, struct starpu_codelet *codelet, ...)
 {
 	va_list varg_list;
@@ -672,6 +681,7 @@ int starpu_mpi_task_insert(MPI_Comm comm, struct starpu_codelet *codelet, ...)
 	return ret;
 }
 
+#undef starpu_mpi_insert_task
 int starpu_mpi_insert_task(MPI_Comm comm, struct starpu_codelet *codelet, ...)
 {
 	va_list varg_list;
@@ -683,6 +693,7 @@ int starpu_mpi_insert_task(MPI_Comm comm, struct starpu_codelet *codelet, ...)
 	return ret;
 }
 
+#undef starpu_mpi_task_build
 struct starpu_task *starpu_mpi_task_build(MPI_Comm comm, struct starpu_codelet *codelet, ...)
 {
 	va_list varg_list;

+ 10 - 0
mpi/src/starpu_mpi_task_insert_fortran.c

@@ -367,6 +367,16 @@ int _fstarpu_mpi_task_decode_v(struct starpu_codelet *codelet, int me, int nb_no
 			arg_i++;
 			/* void * */
 		}
+		else if (arg_type==STARPU_TASK_FILE)
+		{
+			arg_i++;
+			/* char* */
+		}
+		else if (arg_type==STARPU_TASK_LINE)
+		{
+			arg_i++;
+			/* int */
+		}
 		else
 		{
 			STARPU_ABORT_MSG("Unrecognized argument %d, did you perhaps forget to end arguments with 0?\n", arg_type);

+ 9 - 0
src/common/fxt.h

@@ -110,6 +110,8 @@
 
 #define _STARPU_FUT_DATA_DOING_WONT_USE	0x512e
 
+#define _STARPU_FUT_TASK_LINE	0x512f
+
 #define	_STARPU_FUT_START_MEMRECLAIM	0x5131
 #define	_STARPU_FUT_END_MEMRECLAIM	0x5132
 
@@ -839,6 +841,12 @@ do {									\
 	FUT_FULL_PROBE2(_STARPU_FUT_KEYMASK_TASK, _STARPU_FUT_TASK_EXCLUDE_FROM_DAG, (job)->job_id, (long unsigned)exclude_from_dag); \
 } while(0)
 
+#define _STARPU_TRACE_TASK_LINE(job)					\
+	do {								\
+		if ((job)->task->file)					\
+			_STARPU_FUT_FULL_PROBE2STR(_STARPU_FUT_KEYMASK_TASK, _STARPU_FUT_TASK_LINE, (job)->job_id, (job)->task->line, (job)->task->file); \
+} while(0)
+
 #define _STARPU_TRACE_TASK_NAME(job)					\
 	do {								\
         const char *model_name = _starpu_job_get_model_name((job));		\
@@ -1327,6 +1335,7 @@ do {										\
 #define _STARPU_TRACE_GHOST_TASK_DEPS(a, b)	do {(void)(a); (void)(b);} while(0)
 #define _STARPU_TRACE_TASK_EXCLUDE_FROM_DAG(a)	do {(void)(a);} while(0)
 #define _STARPU_TRACE_TASK_NAME(a)		do {(void)(a);} while(0)
+#define _STARPU_TRACE_TASK_LINE(a)		do {(void)(a);} while(0)
 #define _STARPU_TRACE_TASK_COLOR(a)		do {(void)(a);} while(0)
 #define _STARPU_TRACE_TASK_DONE(a)		do {(void)(a);} while(0)
 #define _STARPU_TRACE_TAG_DONE(a)		do {(void)(a);} while(0)

+ 2 - 0
src/core/task.c

@@ -913,6 +913,7 @@ int _starpu_task_submit(struct starpu_task *task, int nodeps)
 			_starpu_get_sched_ctx_struct(task->sched_ctx)->iterations[0],
 			_starpu_get_sched_ctx_struct(task->sched_ctx)->iterations[1]);
 		_STARPU_TRACE_TASK_NAME(j);
+		_STARPU_TRACE_TASK_LINE(j);
 	}
 
 	/* If this is a continuation, we don't modify the implicit data dependencies detected earlier. */
@@ -983,6 +984,7 @@ int _starpu_task_submit(struct starpu_task *task, int nodeps)
 	return ret;
 }
 
+#undef starpu_task_submit
 int starpu_task_submit(struct starpu_task *task)
 {
 	return _starpu_task_submit(task, 0);

+ 28 - 0
src/debug/traces/starpu_fxt.c

@@ -105,6 +105,8 @@ struct task_info
 	UT_hash_handle hh;
 	char *model_name;
 	char *name;
+	char *file;
+	int line;
 	int exclude_from_dag;
 	int show;
 	unsigned type;
@@ -143,6 +145,8 @@ static struct task_info *get_task(unsigned long job_id, int mpi_rank)
 		_STARPU_MALLOC(task, sizeof(*task));
 		task->model_name = NULL;
 		task->name = NULL;
+		task->file = NULL;
+		task->line = -1;
 		task->exclude_from_dag = 0;
 		task->show = 0;
 		task->type = 0;
@@ -201,6 +205,10 @@ static void task_dump(struct task_info *task, struct starpu_fxt_options *options
 		fprintf(tasks_file, "Name: %s\n", task->name);
 	if (task->model_name)
 		fprintf(tasks_file, "Model: %s\n", task->model_name);
+	if (task->file) {
+		fprintf(tasks_file, "File: %s\n", task->file);
+		fprintf(tasks_file, "Line: %d\n", task->line);
+	}
 	fprintf(tasks_file, "JobId: %s%lu\n", prefix, task->job_id);
 	if (task->submit_order)
 		fprintf(tasks_file, "SubmitOrder: %lu\n", task->submit_order);
@@ -272,6 +280,7 @@ static void task_dump(struct task_info *task, struct starpu_fxt_options *options
 out:
 	free(task->name);
 	free(task->model_name);
+	free(task->file);
 	free(task->dependencies);
 	if (task->dep_labels)
 	{
@@ -2906,6 +2915,21 @@ static void handle_task_name(struct fxt_ev_64 *ev, struct starpu_fxt_options *op
 		_starpu_fxt_dag_set_task_name(options->file_prefix, job_id, task->name, color);
 }
 
+static void handle_task_line(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
+{
+	unsigned long job_id = ev->param[0];
+	int line = ev->param[1];
+	char *file = get_fxt_string(ev,2);
+
+	struct task_info *task = get_task(job_id, options->file_rank);
+	task->file = strdup(file);
+	task->line = line;
+
+	if (!task->exclude_from_dag && show_task(task, options))
+		_starpu_fxt_dag_set_task_line(options->file_prefix, job_id, task->file, line);
+}
+
+
 static void handle_task_done(struct fxt_ev_64 *ev, struct starpu_fxt_options *options)
 {
         /* Ideally, we would be able to dump tasks as they terminate, to save
@@ -3715,6 +3739,10 @@ void _starpu_fxt_parse_new_file(char *filename_in, struct starpu_fxt_options *op
 				handle_task_name(&ev, options);
 				break;
 
+			case _STARPU_FUT_TASK_LINE:
+				handle_task_line(&ev, options);
+				break;
+
 			case _STARPU_FUT_TASK_COLOR:
 				handle_task_color(&ev, options);
 				break;

+ 1 - 0
src/debug/traces/starpu_fxt.h

@@ -50,6 +50,7 @@ void _starpu_fxt_dag_add_tag_deps(const char *prefix, uint64_t child, uint64_t f
 void _starpu_fxt_dag_set_tag_done(const char *prefix, uint64_t tag, const char *color);
 void _starpu_fxt_dag_add_task_deps(const char *prefix, unsigned long dep_prev, unsigned long dep_succ, const char *label);
 void _starpu_fxt_dag_set_task_name(const char *prefix, unsigned long job_id, const char *label, const char *color);
+void _starpu_fxt_dag_set_task_line(const char *prefix, unsigned long job_id, const char *file, int line);
 void _starpu_fxt_dag_add_send(int src, unsigned long dep_prev, unsigned long tag, unsigned long id);
 void _starpu_fxt_dag_add_receive(int dst, unsigned long dep_prev, unsigned long tag, unsigned long id);
 void _starpu_fxt_dag_add_sync_point(void);

+ 6 - 0
src/debug/traces/starpu_fxt_dag.c

@@ -110,6 +110,12 @@ void _starpu_fxt_dag_set_task_name(const char *prefix, unsigned long job_id, con
 		fprintf(out_file, "\t \"task_%s%lu\" [ style=filled, label=\"%s\", fillcolor=\"%s\"]\n", prefix, job_id, label, color);
 }
 
+void _starpu_fxt_dag_set_task_line(const char *prefix, unsigned long job_id, const char *file, int line)
+{
+	if (out_file)
+		fprintf(out_file, "\t \"task_%s%lu\" [ href=\"%s#%d\" ]\n", prefix, job_id, file, line);
+}
+
 void _starpu_fxt_dag_add_send(int src, unsigned long dep_prev, unsigned long tag, unsigned long id)
 {
 	if (out_file)

+ 2 - 0
src/util/fstarpu.c

@@ -70,6 +70,8 @@ static const intptr_t fstarpu_sequential_consistency = STARPU_SEQUENTIAL_CONSIST
 static const intptr_t fstarpu_task_profiling_info = STARPU_TASK_PROFILING_INFO;
 static const intptr_t fstarpu_task_no_submitorder = STARPU_TASK_NO_SUBMITORDER;
 static const intptr_t fstarpu_task_sched_data = STARPU_TASK_SCHED_DATA;
+static const intptr_t fstarpu_task_file = STARPU_TASK_FILE;
+static const intptr_t fstarpu_task_line = STARPU_TASK_LINE;
 
 static const intptr_t fstarpu_value = STARPU_VALUE;
 static const intptr_t fstarpu_sched_ctx = STARPU_SCHED_CTX;

+ 4 - 0
src/util/starpu_task_insert.c

@@ -152,6 +152,7 @@ int _starpu_task_insert_v(struct starpu_codelet *cl, va_list varg_list)
 	return ret;
 }
 
+#undef starpu_task_set
 int starpu_task_set(struct starpu_task *task, struct starpu_codelet *cl, ...)
 {
 	va_list varg_list;
@@ -162,6 +163,7 @@ int starpu_task_set(struct starpu_task *task, struct starpu_codelet *cl, ...)
 	return 0;
 }
 
+#undef starpu_task_insert
 int starpu_task_insert(struct starpu_codelet *cl, ...)
 {
 	va_list varg_list;
@@ -173,6 +175,7 @@ int starpu_task_insert(struct starpu_codelet *cl, ...)
 	return ret;
 }
 
+#undef starpu_insert_task
 int starpu_insert_task(struct starpu_codelet *cl, ...)
 {
 	va_list varg_list;
@@ -184,6 +187,7 @@ int starpu_insert_task(struct starpu_codelet *cl, ...)
 	return ret;
 }
 
+#undef starpu_task_build
 struct starpu_task *starpu_task_build(struct starpu_codelet *cl, ...)
 {
 	struct starpu_task *task;

+ 26 - 0
src/util/starpu_task_insert_utils.c

@@ -249,6 +249,14 @@ int _starpu_codelet_pack_args(void **arg_buffer, size_t *arg_buffer_size, va_lis
 		{
 			(void)va_arg(varg_list, void *);
 		}
+		else if (arg_type==STARPU_TASK_FILE)
+		{
+			(void)va_arg(varg_list, const char *);
+		}
+		else if (arg_type==STARPU_TASK_LINE)
+		{
+			(void)va_arg(varg_list, int);
+		}
 		else
 		{
 			STARPU_ABORT_MSG("Unrecognized argument %d, did you perhaps forget to end arguments with 0?\n", arg_type);
@@ -610,6 +618,14 @@ int _starpu_task_insert_create(struct starpu_codelet *cl, struct starpu_task *ta
 		{
 			task->sched_data = va_arg(varg_list, void *);
 		}
+		else if (arg_type==STARPU_TASK_FILE)
+		{
+			task->file = va_arg(varg_list, const char *);
+		}
+		else if (arg_type==STARPU_TASK_LINE)
+		{
+			task->line = va_arg(varg_list, int);
+		}
 		else
 		{
 			STARPU_ABORT_MSG("Unrecognized argument %d, did you perhaps forget to end arguments with 0?\n", arg_type);
@@ -935,6 +951,16 @@ int _fstarpu_task_insert_create(struct starpu_codelet *cl, struct starpu_task *t
 			arg_i++;
 			task->sched_data = (void*)arglist[arg_i];
 		}
+		else if (arg_type == STARPU_TASK_FILE)
+		{
+			arg_i++;
+			task->file = arglist[arg_i];
+		}
+		else if (arg_type == STARPU_TASK_LINE)
+		{
+			arg_i++;
+			task->line = *(int *)arglist[arg_i];
+		}
 		else
 		{
 			STARPU_ABORT_MSG("unknown/unsupported argument %d, did you perhaps forget to end arguments with 0?", arg_type);