浏览代码

Add starpu-all-tasks debugging support

Samuel Thibault 9 年之前
父节点
当前提交
50d55248ee
共有 4 个文件被更改,包括 75 次插入11 次删除
  1. 52 0
      src/core/jobs.c
  2. 8 0
      src/core/jobs.h
  3. 4 10
      src/core/task.c
  4. 11 1
      tools/gdbinit

+ 52 - 0
src/core/jobs.c

@@ -33,6 +33,12 @@
 /* we need to identify each task to generate the DAG. */
 /* we need to identify each task to generate the DAG. */
 static unsigned job_cnt = 0;
 static unsigned job_cnt = 0;
 
 
+#ifdef STARPU_DEBUG
+/* List of all jobs, for debugging */
+static struct _starpu_job *all_jobs_list;
+static starpu_pthread_mutex_t all_jobs_list_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
+#endif
+
 void _starpu_exclude_task_from_dag(struct starpu_task *task)
 void _starpu_exclude_task_from_dag(struct starpu_task *task)
 {
 {
 	struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
 	struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
@@ -210,6 +216,30 @@ void _starpu_job_set_omp_cleanup_callback(struct _starpu_job *j,
 }
 }
 #endif
 #endif
 
 
+void _starpu_handle_job_submission(struct _starpu_job *j)
+{
+	/* Need to atomically set submitted to 1 and check dependencies, since
+	 * this is concucrent with _starpu_notify_cg */
+	j->terminated = 0;
+
+	if (!j->submitted)
+		j->submitted = 1;
+	else
+		j->submitted = 2;
+
+#ifdef STARPU_DEBUG
+	STARPU_PTHREAD_MUTEX_LOCK(&all_jobs_list_mutex);
+	STARPU_ASSERT(!j->next_all);
+	STARPU_ASSERT(!j->prev_all && all_jobs_list != j);
+	if (all_jobs_list)
+		all_jobs_list->prev_all = j;
+	j->next_all = all_jobs_list;
+	j->prev_all = NULL;
+	all_jobs_list = j;
+	STARPU_PTHREAD_MUTEX_UNLOCK(&all_jobs_list_mutex);
+#endif
+}
+
 void _starpu_handle_job_termination(struct _starpu_job *j)
 void _starpu_handle_job_termination(struct _starpu_job *j)
 {
 {
 	struct starpu_task *task = j->task;
 	struct starpu_task *task = j->task;
@@ -223,6 +253,28 @@ void _starpu_handle_job_termination(struct _starpu_job *j)
 #endif
 #endif
 		;
 		;
 
 
+#ifdef STARPU_DEBUG
+	STARPU_PTHREAD_MUTEX_LOCK(&all_jobs_list_mutex);
+	if (j->next_all)
+	{
+		STARPU_ASSERT(j->next_all->prev_all == j);
+		j->next_all->prev_all = j->prev_all;
+	}
+	if (j->prev_all)
+	{
+		STARPU_ASSERT(j->prev_all->next_all == j);
+		j->prev_all->next_all = j->next_all;
+	}
+	else
+	{
+		STARPU_ASSERT(all_jobs_list == j);
+		all_jobs_list = j->next_all;
+	}
+	j->next_all = NULL;
+	j->prev_all = NULL;
+	STARPU_PTHREAD_MUTEX_UNLOCK(&all_jobs_list_mutex);
+#endif
+
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 #ifdef STARPU_OPENMP
 #ifdef STARPU_OPENMP
 	if (continuation)
 	if (continuation)

+ 8 - 0
src/core/jobs.h

@@ -186,6 +186,12 @@ LIST_TYPE(_starpu_job,
 	starpu_pthread_barrier_t before_work_barrier;
 	starpu_pthread_barrier_t before_work_barrier;
 	starpu_pthread_barrier_t after_work_barrier;
 	starpu_pthread_barrier_t after_work_barrier;
 	unsigned after_work_busy_barrier;
 	unsigned after_work_busy_barrier;
+
+#ifdef STARPU_DEBUG
+	/* Linked-list of all jobs, for debugging */
+	struct _starpu_job *prev_all;
+	struct _starpu_job *next_all;
+#endif
 )
 )
 
 
 /* Create an internal struct _starpu_job *structure to encapsulate the task. */
 /* Create an internal struct _starpu_job *structure to encapsulate the task. */
@@ -224,6 +230,8 @@ unsigned _starpu_enforce_deps_starting_from_task(struct _starpu_job *j);
 unsigned _starpu_reenforce_task_deps_and_schedule(struct _starpu_job *j);
 unsigned _starpu_reenforce_task_deps_and_schedule(struct _starpu_job *j);
 #endif
 #endif
 
 
+/* Called at the submission of the job */
+void _starpu_handle_job_submission(struct _starpu_job *j);
 /* This function must be called after the execution of a job, this triggers all
 /* This function must be called after the execution of a job, this triggers all
  * job's dependencies and perform the callback function if any. */
  * job's dependencies and perform the callback function if any. */
 void _starpu_handle_job_termination(struct _starpu_job *j);
 void _starpu_handle_job_termination(struct _starpu_job *j);

+ 4 - 10
src/core/task.c

@@ -367,9 +367,8 @@ int _starpu_submit_job(struct _starpu_job *j)
 
 
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 
 
-	/* Need to atomically set submitted to 1 and check dependencies, since
-	 * this is concucrent with _starpu_notify_cg */
-	j->terminated = 0;
+	_starpu_handle_job_submission(j);
+
 #ifdef STARPU_OPENMP
 #ifdef STARPU_OPENMP
 	if (continuation)
 	if (continuation)
 	{
 	{
@@ -378,11 +377,6 @@ int _starpu_submit_job(struct _starpu_job *j)
 	}
 	}
 #endif
 #endif
 
 
-	if (!j->submitted)
-		j->submitted = 1;
-	else
-		j->submitted = 2;
-
 #ifdef STARPU_OPENMP
 #ifdef STARPU_OPENMP
 	if (continuation)
 	if (continuation)
 	{
 	{
@@ -733,7 +727,7 @@ int _starpu_task_submit_nodeps(struct starpu_task *task)
 	_starpu_increment_nsubmitted_tasks_of_sched_ctx(j->task->sched_ctx);
 	_starpu_increment_nsubmitted_tasks_of_sched_ctx(j->task->sched_ctx);
 
 
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
-	j->submitted = 1;
+	_starpu_handle_job_submission(j);
 	_starpu_increment_nready_tasks_of_sched_ctx(j->task->sched_ctx, j->task->flops, j->task);
 	_starpu_increment_nready_tasks_of_sched_ctx(j->task->sched_ctx, j->task->flops, j->task);
 	if (task->cl)
 	if (task->cl)
 		/* This would be done by data dependencies checking */
 		/* This would be done by data dependencies checking */
@@ -773,7 +767,7 @@ int _starpu_task_submit_conversion_task(struct starpu_task *task,
 	_starpu_increment_nsubmitted_tasks_of_sched_ctx(j->task->sched_ctx);
 	_starpu_increment_nsubmitted_tasks_of_sched_ctx(j->task->sched_ctx);
 
 
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 	STARPU_PTHREAD_MUTEX_LOCK(&j->sync_mutex);
-	j->submitted = 1;
+	_starpu_handle_job_submission(j);
 	_starpu_increment_nready_tasks_of_sched_ctx(j->task->sched_ctx, j->task->flops, j->task);
 	_starpu_increment_nready_tasks_of_sched_ctx(j->task->sched_ctx, j->task->flops, j->task);
 	_starpu_job_set_ordered_buffers(j);
 	_starpu_job_set_ordered_buffers(j);
 
 

+ 11 - 1
tools/gdbinit

@@ -226,6 +226,15 @@ define starpu-tasks
   print "TODO: complete\n"
   print "TODO: complete\n"
 end
 end
 
 
+define starpu-all-tasks
+  set language c
+  set $j = all_jobs_list
+  while $j != 0
+    printf "task %p\n", $j->task
+    set $j = $j->next_all
+  end
+end
+
 define starpu
 define starpu
   printf "Here I am...\n"
   printf "Here I am...\n"
 end
 end
@@ -798,7 +807,8 @@ starpu-print-requests              prints all StarPU data requests
 starpu-print-prequests             prints all pending StarPU data requests
 starpu-print-prequests             prints all pending StarPU data requests
 starpu-print-frequests             prints all StarPU prefetch data requests
 starpu-print-frequests             prints all StarPU prefetch data requests
 starpu-print-irequests             prints all StarPU idle data requests
 starpu-print-irequests             prints all StarPU idle data requests
-starpu-tasks                       prints a list of the tasks flowing in StarPU
+starpu-tasks                       prints a summary of the tasks flowing in StarPU
+starpu-all-tasks                   prints a list of all the tasks flowing in StarPU
 starpu-tags                        prints a list of the tags known to StarPU
 starpu-tags                        prints a list of the tags known to StarPU
 starpu-memusage                    prints the memory node usage
 starpu-memusage                    prints the memory node usage
 starpu-print-archs                 prints all known arch combinations
 starpu-print-archs                 prints all known arch combinations