Prechádzať zdrojové kódy

Safely notify+restart a tag

otherwise we could step over the task notifying it back in a loop
Samuel Thibault 4 rokov pred
rodič
commit
c27d4e101c

+ 7 - 0
include/starpu_task_dep.h

@@ -210,6 +210,13 @@ void starpu_tag_remove(starpu_tag_t id);
 */
 void starpu_tag_notify_from_apps(starpu_tag_t id);
 
+/**
+   Atomically call starpu_tag_notify_from_apps() and starpu_tag_restart() on tag
+   \p id.
+   This is useful with cyclic graphs, when we want to safely trigger its startup.
+*/
+void starpu_tag_notify_restart_from_apps(starpu_tag_t id);
+
 struct starpu_task *starpu_tag_get_task(starpu_tag_t id);
 
 /** @} */

+ 27 - 0
src/core/dependencies/tags.c

@@ -290,6 +290,33 @@ void starpu_tag_notify_from_apps(starpu_tag_t id)
 	_starpu_notify_tag_dependencies(tag);
 }
 
+void _starpu_notify_restart_tag_dependencies(struct _starpu_tag *tag)
+{
+	_starpu_spin_lock(&tag->lock);
+
+	if (tag->state == STARPU_DONE)
+	{
+		tag->state = STARPU_BLOCKED;
+		_starpu_spin_unlock(&tag->lock);
+		return;
+	}
+
+	_STARPU_TRACE_TAG_DONE(tag);
+
+	tag->state = STARPU_BLOCKED;
+
+	_starpu_notify_cg_list(tag, &tag->tag_successors);
+
+	_starpu_spin_unlock(&tag->lock);
+}
+
+void starpu_tag_notify_restart_from_apps(starpu_tag_t id)
+{
+	struct _starpu_tag *tag = gettag_struct(id);
+
+	_starpu_notify_restart_tag_dependencies(tag);
+}
+
 void _starpu_tag_declare(starpu_tag_t id, struct _starpu_job *job)
 {
 	_STARPU_TRACE_TAG(id, job);

+ 1 - 2
tests/main/subgraph_repeat_regenerate_tag_cycle.c

@@ -187,8 +187,7 @@ int main(int argc, char **argv)
 	ret = starpu_task_submit(&taskD); if (ret == -ENODEV) goto enodev; STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
 
 	/* Break the loop */
-	starpu_tag_notify_from_apps((starpu_tag_t) TAG_D);
-	starpu_tag_restart((starpu_tag_t) TAG_D);
+	starpu_tag_notify_restart_from_apps((starpu_tag_t) TAG_D);
 
 	starpu_do_schedule();
 	/* Wait for the termination of all loops */