Bladeren bron

Add dependency backward information in debugging mode for gdb's starpu-print-task

Samuel Thibault 7 jaren geleden
bovenliggende
commit
7cf5765b75
7 gewijzigde bestanden met toevoegingen van 121 en 24 verwijderingen
  1. 2 0
      ChangeLog
  2. 8 0
      src/core/debug.c
  3. 31 3
      src/core/dependencies/cg.c
  4. 15 3
      src/core/dependencies/cg.h
  5. 3 3
      src/core/dependencies/tags.c
  6. 24 3
      src/core/dependencies/task_deps.c
  7. 38 12
      tools/gdbinit

+ 2 - 0
ChangeLog

@@ -66,6 +66,8 @@ Small features:
   * New starpu_task_insert parameter STARPU_TASK_DEPS_ARRAY which
     allows to declare task dependencies similarly to
     starpu_task_declare_deps_array()
+  * Add dependency backward information in debugging mode for gdb's
+    starpu-print-task
 
 Changes:
   * Vastly improve simgrid simulation time.

+ 8 - 0
src/core/debug.c

@@ -26,6 +26,14 @@ static starpu_pthread_mutex_t logfile_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
 static FILE *logfile = NULL;
 #endif
 
+int _starpu_debug
+#ifdef STARPU_DEBUG
+	= 1
+#else
+	= 0
+#endif
+	;
+
 /* Tell gdb whether FXT is compiled in or not */
 int _starpu_use_fxt
 #ifdef STARPU_USE_FXT

+ 31 - 3
src/core/dependencies/cg.c

@@ -29,6 +29,10 @@ void _starpu_cg_list_init(struct _starpu_cg_list *list)
 	_starpu_spin_init(&list->lock);
 	list->ndeps = 0;
 	list->ndeps_completed = 0;
+#ifdef STARPU_DEBUG
+	list->deps = NULL;
+	list->done = NULL;
+#endif
 
 	list->terminated = 0;
 
@@ -57,6 +61,10 @@ void _starpu_cg_list_deinit(struct _starpu_cg_list *list)
 #ifdef STARPU_DYNAMIC_DEPS_SIZE
 	free(list->succ);
 #endif
+#ifdef STARPU_DEBUG
+	free(list->deps);
+	free(list->done);
+#endif
 	_starpu_spin_destroy(&list->lock);
 }
 
@@ -158,7 +166,7 @@ int _starpu_list_tag_successors_in_cg_list(struct _starpu_cg_list *successors, u
 }
 
 /* Note: in case of a tag, it must be already locked */
-void _starpu_notify_cg(struct _starpu_cg *cg)
+void _starpu_notify_cg(void *pred, struct _starpu_cg *cg)
 {
 	STARPU_ASSERT(cg);
 	unsigned remaining = STARPU_ATOMIC_ADD(&cg->remaining, -1);
@@ -222,6 +230,26 @@ void _starpu_notify_cg(struct _starpu_cg *cg)
 				STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 
 				job_successors = &j->job_successors;
+#ifdef STARPU_DEBUG
+				if (!j->task->regenerate) {
+					unsigned i;
+					/* Remove backward cg pointers for easier debugging */
+					if (job_successors->deps) {
+						for (i = 0; i < job_successors->ndeps; i++)
+							if (job_successors->deps[i] == cg)
+								break;
+						STARPU_ASSERT(i < job_successors->ndeps);
+						job_successors->done[i] = 1;
+					}
+					if (cg->deps) {
+						for (i = 0; i < cg->ndeps; i++)
+							if (cg->deps[i] == pred)
+								break;
+						STARPU_ASSERT(i < cg->ndeps);
+						cg->done[i] = 1;
+					}
+				}
+#endif
 
 				unsigned ndeps_completed =
 					STARPU_ATOMIC_ADD(&job_successors->ndeps_completed, 1);
@@ -255,7 +283,7 @@ void _starpu_notify_cg(struct _starpu_cg *cg)
  * _starpu_notify_cg_list protects the list itself.
  * No job lock should be held, since we might want to immediately call the callback of an empty task.
  */
-void _starpu_notify_cg_list(struct _starpu_cg_list *successors)
+void _starpu_notify_cg_list(void *pred, struct _starpu_cg_list *successors)
 {
 	unsigned succ;
 
@@ -285,7 +313,7 @@ void _starpu_notify_cg_list(struct _starpu_cg_list *successors)
 			_starpu_spin_lock(&cgtag->lock);
 		}
 
-		_starpu_notify_cg(cg);
+		_starpu_notify_cg(pred, cg);
 
 		if (cg_type == STARPU_CG_TAG)
 			_starpu_spin_unlock(&cgtag->lock);

+ 15 - 3
src/core/dependencies/cg.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2012-2013, 2015-2016  Université de Bordeaux
+ * Copyright (C) 2010, 2012-2013, 2015-2017  Université de Bordeaux
  * Copyright (C) 2010, 2011, 2013  CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -44,6 +44,12 @@ struct _starpu_cg_list
 	/* Number of notifications to be waited for */
 	unsigned ndeps; /* how many deps ? */
 	unsigned ndeps_completed; /* how many deps are done ? */
+#ifdef STARPU_DEBUG
+	/* Array of the notifications, size ndeps */
+	struct _starpu_cg **deps;
+	/* Which ones have notified, size ndeps */
+	char *done;
+#endif
 
 	/* Whether the completion is finished.
 	 * For restartable/restarted tasks, only the first iteration is taken into account here.
@@ -73,6 +79,12 @@ struct _starpu_cg
 	unsigned ntags; /* number of tags depended on */
 	unsigned remaining; /* number of remaining tags */
 
+#ifdef STARPU_DEBUG
+	unsigned ndeps;
+	void **deps; /* array of predecessors, size ndeps */
+	char *done;  /* which ones have notified, size ndeps */
+#endif
+
 	enum _starpu_cg_type cg_type;
 
 	union
@@ -102,8 +114,8 @@ int _starpu_add_successor_to_cg_list(struct _starpu_cg_list *successors, struct
 int _starpu_list_task_successors_in_cg_list(struct _starpu_cg_list *successors, unsigned ndeps, struct starpu_task *task_array[]);
 int _starpu_list_task_scheduled_successors_in_cg_list(struct _starpu_cg_list *successors, unsigned ndeps, struct starpu_task *task_array[]);
 int _starpu_list_tag_successors_in_cg_list(struct _starpu_cg_list *successors, unsigned ndeps, starpu_tag_t tag_array[]);
-void _starpu_notify_cg(struct _starpu_cg *cg);
-void _starpu_notify_cg_list(struct _starpu_cg_list *successors);
+void _starpu_notify_cg(void *pred, struct _starpu_cg *cg);
+void _starpu_notify_cg_list(void *pred, struct _starpu_cg_list *successors);
 void _starpu_notify_task_dependencies(struct _starpu_job *j);
 
 #endif // __CG_H__

+ 3 - 3
src/core/dependencies/tags.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2013, 2016  Université de Bordeaux
+ * Copyright (C) 2009-2013, 2016-2017  Université de Bordeaux
  * Copyright (C) 2010, 2011, 2012, 2013, 2016, 2017  CNRS
  * Copyright (C) 2016  Inria
  *
@@ -246,7 +246,7 @@ static void _starpu_tag_add_succ(struct _starpu_tag *tag, struct _starpu_cg *cg)
 	if (tag->state == STARPU_DONE)
 	{
 		/* the tag was already completed sooner */
-		_starpu_notify_cg(cg);
+		_starpu_notify_cg(tag, cg);
 	}
 }
 
@@ -263,7 +263,7 @@ void _starpu_notify_tag_dependencies(struct _starpu_tag *tag)
 	tag->state = STARPU_DONE;
 	_STARPU_TRACE_TAG_DONE(tag);
 
-	_starpu_notify_cg_list(&tag->tag_successors);
+	_starpu_notify_cg_list(tag, &tag->tag_successors);
 
 	_starpu_spin_unlock(&tag->lock);
 }

+ 24 - 3
src/core/dependencies/task_deps.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2016  Université de Bordeaux
+ * Copyright (C) 2010-2017  Université de Bordeaux
  * Copyright (C) 2010, 2011, 2012, 2013, 2015, 2016  CNRS
  * Copyright (C) 2014, 2016  INRIA
  *
@@ -35,10 +35,21 @@ static struct _starpu_cg *create_cg_task(unsigned ntags, struct _starpu_job *j)
 
 	cg->ntags = ntags;
 	cg->remaining = ntags;
+#ifdef STARPU_DEBUG
+	cg->ndeps = ntags;
+	cg->deps = NULL;
+	cg->done = NULL;
+#endif
 	cg->cg_type = STARPU_CG_TASK;
 
 	cg->succ.job = j;
 	j->job_successors.ndeps++;
+#ifdef STARPU_DEBUG
+	_STARPU_REALLOC(j->job_successors.deps, j->job_successors.ndeps * sizeof(j->job_successors.deps[0]));
+	_STARPU_REALLOC(j->job_successors.done, j->job_successors.ndeps * sizeof(j->job_successors.done[0]));
+	j->job_successors.deps[j->job_successors.ndeps-1] = cg;
+	j->job_successors.done[j->job_successors.ndeps-1] = 0;
+#endif
 
 	return cg;
 }
@@ -49,12 +60,12 @@ static void _starpu_task_add_succ(struct _starpu_job *j, struct _starpu_cg *cg)
 
 	if (_starpu_add_successor_to_cg_list(&j->job_successors, cg))
 		/* the task was already completed sooner */
-		_starpu_notify_cg(cg);
+		_starpu_notify_cg(j, cg);
 }
 
 void _starpu_notify_task_dependencies(struct _starpu_job *j)
 {
-	_starpu_notify_cg_list(&j->job_successors);
+	_starpu_notify_cg_list(j, &j->job_successors);
 }
 
 /* task depends on the tasks in task array */
@@ -81,6 +92,11 @@ void _starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, s
 	struct _starpu_cg *cg = create_cg_task(ndeps, job);
 	STARPU_PTHREAD_MUTEX_UNLOCK(&job->sync_mutex);
 
+#ifdef STARPU_DEBUG
+	_STARPU_MALLOC(cg->deps, ndeps * sizeof(cg->deps[0]));
+	_STARPU_MALLOC(cg->done, ndeps * sizeof(cg->done[0]));
+#endif
+
 	unsigned i;
 	for (i = 0; i < ndeps; i++)
 	{
@@ -91,6 +107,11 @@ void _starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, s
 
 		dep_job = _starpu_get_job_associated_to_task(dep_task);
 
+#ifdef STARPU_DEBUG
+		cg->deps[i] = dep_job;
+		cg->done[i] = 0;
+#endif
+
 		STARPU_ASSERT_MSG(dep_job != job, "A task must not depend on itself.");
 		STARPU_PTHREAD_MUTEX_LOCK(&dep_job->sync_mutex);
 		if (check)

+ 38 - 12
tools/gdbinit

@@ -85,6 +85,24 @@ define starpu-print-task
   printf "\tjob:\t\t\t\t<%p>\n", $job
   printf "\ttag_id:\t\t\t\t<%d>\n", $task->tag_id
   printf "\tndeps:\t\t\t\t<%u>\n", $job->job_successors->ndeps
+  printf "\tndeps_remaining:\t\t<%u>\n", $job->job_successors->ndeps - $job->job_successors->ndeps_completed
+  if _starpu_debug
+    set $n = 0
+    while $n < $job->job_successors->ndeps
+      if ! $job->job_successors->done[$n]
+        set $cg = $job->job_successors->deps[$n]
+        set $m = 0
+	while $m < $cg->ndeps
+	  if ! $cg->done[$m]
+	    set $depj = (struct _starpu_job *) $cg->deps[$m]
+            printf "\t\ttask %p\n", $depj->task
+	  end
+	  set $m = $m + 1
+	end
+      end
+      set $n = $n + 1
+    end
+  end
   printf "\tndeps_completed:\t\t<%u>\n", $job->job_successors->ndeps_completed
   printf "\tnsuccs:\t\t\t\t<%u>\n", $job->job_successors->nsuccs
   if $job
@@ -243,23 +261,31 @@ end
 
 define starpu-print-all-tasks
   set language c
-  set $l = all_jobs_list->next
-  while $l != &all_jobs_list
-    set $j = (struct _starpu_job*) (((unsigned long) $l) - ((unsigned long) &((struct _starpu_job *)0)->all_submitted))
-    printf "task %p\n", $j->task
-    starpu-print-task $j->task
-    set $l = $l->next
+  if ! _starpu_debug
+    printf "you need to configure with --enable-debug to get starpu-print-all-tasks working"
+  else
+    set $l = all_jobs_list->next
+    while $l != &all_jobs_list
+      set $j = (struct _starpu_job*) (((unsigned long) $l) - ((unsigned long) &((struct _starpu_job *)0)->all_submitted))
+      printf "task %p\n", $j->task
+      starpu-print-task $j->task
+      set $l = $l->next
+    end
   end
 end
 
 define starpu-all-tasks
   set language c
-  set $l = all_jobs_list->next
-  while $l != &all_jobs_list
-    set $j = (struct _starpu_job*) (((unsigned long) $l) - ((unsigned long) &((struct _starpu_job *)0)->all_submitted))
-    set $task = $j->task
-    printf "task %p %s\n", $task, $task->name ? $task->name : ""
-    set $l = $l->next
+  if ! _starpu_debug
+    printf "you need to configure with --enable-debug to get starpu-all-tasks working"
+  else
+    set $l = all_jobs_list->next
+    while $l != &all_jobs_list
+      set $j = (struct _starpu_job*) (((unsigned long) $l) - ((unsigned long) &((struct _starpu_job *)0)->all_submitted))
+      set $task = $j->task
+      printf "task %p %s\n", $task, $task->name ? $task->name : ""
+      set $l = $l->next
+    end
   end
 end