Bläddra i källkod

Fix a commute bug, thanks Stojce for the report!

Samuel Thibault 10 år sedan
förälder
incheckning
f95cd146b8
2 ändrade filer med 27 tillägg och 9 borttagningar
  1. 14 2
      src/core/dependencies/implicit_data_deps.c
  2. 13 7
      tests/datawizard/commute2.c

+ 14 - 2
src/core/dependencies/implicit_data_deps.c

@@ -225,7 +225,7 @@ struct starpu_task *_starpu_detect_implicit_data_deps_with_handle(struct starpu_
 		 * In other cases, the tasks have to depend on each other.
 		 */
 
-		if ((mode & STARPU_W && mode & STARPU_COMMUTE && previous_mode & STARPU_W && previous_mode && STARPU_COMMUTE)
+		if ((mode & STARPU_W && mode & STARPU_COMMUTE && previous_mode & STARPU_W && previous_mode & STARPU_COMMUTE)
 		  || (mode == STARPU_R && previous_mode == STARPU_R)
 		  || (mode == STARPU_REDUX && previous_mode == STARPU_REDUX))
 		{
@@ -246,6 +246,7 @@ struct starpu_task *_starpu_detect_implicit_data_deps_with_handle(struct starpu_
 
 				if (mode == STARPU_W)
 				{
+					_STARPU_DEP_DEBUG("several predecessors, and this is a W-only task, thus can serve directly as a synchronization task.\n");
 					/* Optimization: this task can not
 					 * combine with others anyway, use it
 					 * as synchronization task by making it
@@ -259,7 +260,12 @@ struct starpu_task *_starpu_detect_implicit_data_deps_with_handle(struct starpu_
 					 * number of dependencies. */
 					struct starpu_task *sync_task = starpu_task_create();
 					STARPU_ASSERT(sync_task);
-					sync_task->name = "sync_task_redux";
+					if (previous_mode == STARPU_REDUX)
+						sync_task->name = "sync_task_redux";
+					else if (mode ==  STARPU_COMMUTE || previous_mode == STARPU_COMMUTE)
+						sync_task->name = "sync_task_commute";
+					else
+						sync_task->name = "sync_task";
 					sync_task->cl = NULL;
 
 					/* Make this task wait for the previous ones */
@@ -276,6 +282,7 @@ struct starpu_task *_starpu_detect_implicit_data_deps_with_handle(struct starpu_
 				 * task, and start depending on it. */
 				if (l != &handle->last_submitted_accessors)
 				{
+					_STARPU_DEP_DEBUG("One previous accessor, depending on it\n");
 					handle->last_sync_task = l->task;
 					l->next = NULL;
 					l->prev = NULL;
@@ -284,11 +291,16 @@ struct starpu_task *_starpu_detect_implicit_data_deps_with_handle(struct starpu_
 				}
 				else if (handle->last_submitted_ghost_accessors_id)
 				{
+					_STARPU_DEP_DEBUG("No more currently running accessor, but a ghost id, taking it.\n");
 					handle->last_submitted_ghost_sync_id = handle->last_submitted_ghost_accessors_id->id;
 					handle->last_submitted_ghost_sync_id_is_valid = 1;
 					free(handle->last_submitted_ghost_accessors_id);
 					handle->last_submitted_ghost_accessors_id = NULL;
 				}
+				else
+				{
+					_STARPU_DEP_DEBUG("No previous accessor, no dependency\n");
+				}
 				_starpu_add_accessor(handle, pre_sync_task, post_sync_task, post_sync_task_dependency_slot);
 			}
 		}

+ 13 - 7
tests/datawizard/commute2.c

@@ -1,5 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
+ * Copyright (C) 2014 Université Bordeaux
  * Copyright (C) 2014 Inria
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -21,25 +22,24 @@
 #ifdef STARPU_USE_CUDA
 #include <starpu_cuda.h>
 #endif
+#include "../helper.h"
 
 static unsigned cnt;
 
 static void cpu_memcpy(void *descr[], void *cl_arg)
 {
-	double *res = (double *)STARPU_VECTOR_GET_PTR(descr[0]);
-	double *dst = (double *)STARPU_VECTOR_GET_PTR(descr[1]);
-	int n = (int) STARPU_VECTOR_GET_NX(descr[0]);
 	int me = (uintptr_t)cl_arg;
 
+	FPRINTF(stderr,"%d\n", me);
+
 	if (me == 0)
 	{
+		/* let commute tasks potentially happen */
 		sleep(1);
 		STARPU_ASSERT(STARPU_ATOMIC_ADD(&cnt,1) == 1);
 	}
 	else
 		STARPU_ASSERT(STARPU_ATOMIC_ADD(&cnt,1) != 1);
-
-	memcpy(dst, res, n*sizeof(double));
 }
 
 
@@ -58,7 +58,7 @@ main()
 	unsigned nb_tasks = 10, worker;
 
 	if (starpu_init(NULL)) 
-		exit(-1);
+		exit(EXIT_FAILURE);
 
 	starpu_malloc((void**)&res, n*sizeof(double));
 	starpu_malloc((void**)&a,   n*sizeof(double));
@@ -69,10 +69,12 @@ main()
 	starpu_vector_data_register(&res_handle, 0, (uintptr_t)res, (uint32_t)n, sizeof(double));
 	starpu_vector_data_register(&a_handle,   0, (uintptr_t)a,   (uint32_t)n, sizeof(double));
 
+	starpu_data_acquire(a_handle, STARPU_RW);
+
 	for (i = 0; i < nb_tasks; i++) {
 		struct starpu_task *task = starpu_task_create();
 		task->cl=&my_cl;
-		task->nbuffers = 2;
+		task->nbuffers = i == 0 ? 2 : 1;
 		task->handles[0] = res_handle;
 
 		if (i == 0)
@@ -90,6 +92,10 @@ main()
 		}
 	}
 
+	/* let commute tasks potentially happen */
+	sleep(1);
+	starpu_data_release(a_handle);
+
 	starpu_task_wait_for_all ();
 
 	starpu_data_unregister(res_handle);