implicit_data_deps.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <common/config.h>
  19. #include <core/task.h>
  20. #include <datawizard/datawizard.h>
  21. #include <profiling/bound.h>
  22. #include <core/debug.h>
  23. #if 0
  24. # define _STARPU_DEP_DEBUG(fmt, args ...) fprintf(stderr, fmt, ##args);
  25. #else
  26. # define _STARPU_DEP_DEBUG(fmt, args ...)
  27. #endif
  28. static void _starpu_add_ghost_dependency(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED, unsigned long previous STARPU_ATTRIBUTE_UNUSED, struct starpu_task *next STARPU_ATTRIBUTE_UNUSED)
  29. {
  30. struct _starpu_job *next_job = _starpu_get_job_associated_to_task(next);
  31. _starpu_bound_job_id_dep(handle, next_job, previous);
  32. #ifdef HAVE_AYUDAME_H
  33. if (AYU_event) {
  34. uintptr_t AYU_data[3] = { previous, (uintptr_t) handle, (uintptr_t) handle };
  35. AYU_event(AYU_ADDDEPENDENCY, next_job->job_id, AYU_data);
  36. }
  37. #endif
  38. }
  39. static void _starpu_add_dependency(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED, struct starpu_task *previous STARPU_ATTRIBUTE_UNUSED, struct starpu_task *next STARPU_ATTRIBUTE_UNUSED)
  40. {
  41. _starpu_add_ghost_dependency(handle, _starpu_get_job_associated_to_task(previous)->job_id, next);
  42. }
  43. /* Read after Write (RAW) or Read after Read (RAR) */
  44. static void _starpu_add_reader_after_writer(starpu_data_handle_t handle, struct starpu_task *pre_sync_task, struct starpu_task *post_sync_task)
  45. {
  46. /* Add this task to the list of readers */
  47. struct _starpu_task_wrapper_list *link = (struct _starpu_task_wrapper_list *) malloc(sizeof(struct _starpu_task_wrapper_list));
  48. link->task = post_sync_task;
  49. link->next = handle->last_submitted_readers;
  50. handle->last_submitted_readers = link;
  51. /* This task depends on the previous writer if any */
  52. if (handle->last_submitted_writer && handle->last_submitted_writer != post_sync_task)
  53. {
  54. _STARPU_DEP_DEBUG("RAW %p\n", handle);
  55. struct starpu_task *task_array[1] = {handle->last_submitted_writer};
  56. _starpu_task_declare_deps_array(pre_sync_task, 1, task_array, 0);
  57. _starpu_add_dependency(handle, handle->last_submitted_writer, pre_sync_task);
  58. _STARPU_DEP_DEBUG("dep %p -> %p\n", handle->last_submitted_writer, pre_sync_task);
  59. }
  60. else
  61. {
  62. _STARPU_DEP_DEBUG("No dep\n");
  63. }
  64. /* There was perhaps no last submitted writer but a
  65. * ghost one, we should report that here, and keep the
  66. * ghost writer valid */
  67. if (
  68. (
  69. #ifdef STARPU_USE_FXT
  70. 1
  71. #else
  72. _starpu_bound_recording
  73. #endif
  74. #ifdef HAVE_AYUDAME_H
  75. || AYU_event
  76. #endif
  77. ) && handle->last_submitted_ghost_writer_id_is_valid)
  78. {
  79. _STARPU_TRACE_GHOST_TASK_DEPS(handle->last_submitted_ghost_writer_id,
  80. _starpu_get_job_associated_to_task(pre_sync_task)->job_id);
  81. _starpu_add_ghost_dependency(handle, handle->last_submitted_ghost_writer_id, pre_sync_task);
  82. _STARPU_DEP_DEBUG("dep ID%lu -> %p\n", handle->last_submitted_ghost_writer_id, pre_sync_task);
  83. }
  84. if (!pre_sync_task->cl)
  85. _starpu_get_job_associated_to_task(pre_sync_task)->implicit_dep_handle = handle;
  86. }
  87. /* Write after Read (WAR) */
  88. static void _starpu_add_writer_after_readers(starpu_data_handle_t handle, struct starpu_task *pre_sync_task, struct starpu_task *post_sync_task)
  89. {
  90. /* Count the readers */
  91. unsigned nreaders = 0;
  92. struct _starpu_task_wrapper_list *l;
  93. l = handle->last_submitted_readers;
  94. while (l)
  95. {
  96. if (l->task != post_sync_task)
  97. nreaders++;
  98. l = l->next;
  99. }
  100. _STARPU_DEP_DEBUG("%d readers\n", nreaders);
  101. if (nreaders > 0)
  102. {
  103. /* Put all tasks in the list into task_array */
  104. struct starpu_task *task_array[nreaders];
  105. unsigned i = 0;
  106. l = handle->last_submitted_readers;
  107. while (l)
  108. {
  109. STARPU_ASSERT(l->task);
  110. if (l->task != post_sync_task) {
  111. task_array[i++] = l->task;
  112. _starpu_add_dependency(handle, l->task, pre_sync_task);
  113. _STARPU_DEP_DEBUG("dep %p -> %p\n", l->task, pre_sync_task);
  114. }
  115. struct _starpu_task_wrapper_list *prev = l;
  116. l = l->next;
  117. free(prev);
  118. }
  119. _starpu_task_declare_deps_array(pre_sync_task, nreaders, task_array, 0);
  120. }
  121. #ifndef STARPU_USE_FXT
  122. if (_starpu_bound_recording)
  123. #endif
  124. {
  125. /* Declare all dependencies with ghost readers */
  126. struct _starpu_jobid_list *ghost_readers_id = handle->last_submitted_ghost_readers_id;
  127. while (ghost_readers_id)
  128. {
  129. unsigned long id = ghost_readers_id->id;
  130. _STARPU_TRACE_GHOST_TASK_DEPS(id,
  131. _starpu_get_job_associated_to_task(pre_sync_task)->job_id);
  132. _starpu_add_ghost_dependency(handle, id, pre_sync_task);
  133. _STARPU_DEP_DEBUG("dep ID%lu -> %p\n", id, pre_sync_task);
  134. struct _starpu_jobid_list *prev = ghost_readers_id;
  135. ghost_readers_id = ghost_readers_id->next;
  136. free(prev);
  137. }
  138. handle->last_submitted_ghost_readers_id = NULL;
  139. }
  140. handle->last_submitted_readers = NULL;
  141. handle->last_submitted_writer = post_sync_task;
  142. if (!post_sync_task->cl)
  143. _starpu_get_job_associated_to_task(post_sync_task)->implicit_dep_handle = handle;
  144. }
  145. /* Write after Write (WAW) */
  146. static void _starpu_add_writer_after_writer(starpu_data_handle_t handle, struct starpu_task *pre_sync_task, struct starpu_task *post_sync_task)
  147. {
  148. /* (Read) Write */
  149. /* This task depends on the previous writer */
  150. if (handle->last_submitted_writer && handle->last_submitted_writer != post_sync_task)
  151. {
  152. struct starpu_task *task_array[1] = {handle->last_submitted_writer};
  153. _starpu_task_declare_deps_array(pre_sync_task, 1, task_array, 0);
  154. _starpu_add_dependency(handle, handle->last_submitted_writer, pre_sync_task);
  155. _STARPU_DEP_DEBUG("dep %p -> %p\n", handle->last_submitted_writer, pre_sync_task);
  156. }
  157. else
  158. {
  159. _STARPU_DEP_DEBUG("No dep\n");
  160. }
  161. /* If there is a ghost writer instead, we
  162. * should declare a ghost dependency here, and
  163. * invalidate the ghost value. */
  164. #ifndef STARPU_USE_FXT
  165. if (_starpu_bound_recording)
  166. #endif
  167. {
  168. if (handle->last_submitted_ghost_writer_id_is_valid)
  169. {
  170. _STARPU_TRACE_GHOST_TASK_DEPS(handle->last_submitted_ghost_writer_id,
  171. _starpu_get_job_associated_to_task(pre_sync_task)->job_id);
  172. _starpu_add_ghost_dependency(handle, handle->last_submitted_ghost_writer_id, pre_sync_task);
  173. _STARPU_DEP_DEBUG("dep ID%lu -> %p\n", handle->last_submitted_ghost_writer_id, pre_sync_task);
  174. handle->last_submitted_ghost_writer_id_is_valid = 0;
  175. }
  176. else
  177. {
  178. _STARPU_DEP_DEBUG("No dep ID\n");
  179. }
  180. }
  181. handle->last_submitted_writer = post_sync_task;
  182. if (!post_sync_task->cl)
  183. _starpu_get_job_associated_to_task(post_sync_task)->implicit_dep_handle = handle;
  184. }
  185. /* This function adds the implicit task dependencies introduced by data
  186. * sequential consistency. Two tasks are provided: pre_sync and post_sync which
  187. * respectively indicates which task is going to depend on the previous deps
  188. * and on which task future deps should wait. In the case of a dependency
  189. * introduced by a task submission, both tasks are just the submitted task, but
  190. * in the case of user interactions with the DSM, these may be different tasks.
  191. * */
  192. /* NB : handle->sequential_consistency_mutex must be hold by the caller;
  193. * returns a task, to be submitted after releasing that mutex. */
  194. struct starpu_task *_starpu_detect_implicit_data_deps_with_handle(struct starpu_task *pre_sync_task, struct starpu_task *post_sync_task,
  195. starpu_data_handle_t handle, enum starpu_access_mode mode)
  196. {
  197. struct starpu_task *task = NULL;
  198. STARPU_ASSERT(!(mode & STARPU_SCRATCH));
  199. _STARPU_LOG_IN();
  200. if (handle->sequential_consistency)
  201. {
  202. struct _starpu_job *pre_sync_job = _starpu_get_job_associated_to_task(pre_sync_task);
  203. struct _starpu_job *post_sync_job = _starpu_get_job_associated_to_task(post_sync_task);
  204. /* Skip tasks that are associated to a reduction phase so that
  205. * they do not interfere with the application. */
  206. if (pre_sync_job->reduction_task || post_sync_job->reduction_task)
  207. return NULL;
  208. _STARPU_DEP_DEBUG("Tasks %p %p\n", pre_sync_task, post_sync_task);
  209. /* In case we are generating the DAG, we add an implicit
  210. * dependency between the pre and the post sync tasks in case
  211. * they are not the same. */
  212. if (pre_sync_task != post_sync_task
  213. #ifndef STARPU_USE_FXT
  214. && _starpu_bound_recording
  215. #endif
  216. )
  217. {
  218. _STARPU_TRACE_GHOST_TASK_DEPS(pre_sync_job->job_id, post_sync_job->job_id);
  219. _starpu_bound_task_dep(post_sync_job, pre_sync_job);
  220. }
  221. enum starpu_access_mode previous_mode = handle->last_submitted_mode;
  222. if (mode & STARPU_W)
  223. {
  224. _STARPU_DEP_DEBUG("W %p\n", handle);
  225. if (previous_mode & STARPU_W)
  226. {
  227. _STARPU_DEP_DEBUG("WAW %p\n", handle);
  228. _starpu_add_writer_after_writer(handle, pre_sync_task, post_sync_task);
  229. }
  230. else
  231. {
  232. /* The task submitted previously were in read-only
  233. * mode: this task must depend on all those read-only
  234. * tasks and we get rid of the list of readers */
  235. _STARPU_DEP_DEBUG("WAR %p\n", handle);
  236. _starpu_add_writer_after_readers(handle, pre_sync_task, post_sync_task);
  237. }
  238. }
  239. else
  240. {
  241. _STARPU_DEP_DEBUG("R %p %d -> %d\n", handle, previous_mode, mode);
  242. /* Add a reader, after a writer or a reader. */
  243. STARPU_ASSERT(pre_sync_task);
  244. STARPU_ASSERT(post_sync_task);
  245. STARPU_ASSERT(mode & (STARPU_R|STARPU_REDUX));
  246. if (!(previous_mode & STARPU_W) && (mode != previous_mode))
  247. {
  248. /* Read after Redux or Redux after Read: we
  249. * insert a dummy synchronization task so that
  250. * we don't need to have a gigantic number of
  251. * dependencies between all readers and all
  252. * redux tasks. */
  253. /* Create an empty task */
  254. struct starpu_task *new_sync_task;
  255. new_sync_task = starpu_task_create();
  256. STARPU_ASSERT(new_sync_task);
  257. new_sync_task->cl = NULL;
  258. #ifdef STARPU_USE_FXT
  259. _starpu_get_job_associated_to_task(new_sync_task)->model_name = "sync_task_redux";
  260. #endif
  261. _starpu_add_writer_after_readers(handle, new_sync_task, new_sync_task);
  262. task = new_sync_task;
  263. }
  264. _starpu_add_reader_after_writer(handle, pre_sync_task, post_sync_task);
  265. }
  266. handle->last_submitted_mode = mode;
  267. }
  268. _STARPU_LOG_OUT();
  269. return task;
  270. }
  271. /* Create the implicit dependencies for a newly submitted task */
  272. void _starpu_detect_implicit_data_deps(struct starpu_task *task)
  273. {
  274. STARPU_ASSERT(task->cl);
  275. _STARPU_LOG_IN();
  276. /* We don't want to enforce a sequential consistency for tasks that are
  277. * not visible to the application. */
  278. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  279. if (j->reduction_task)
  280. return;
  281. unsigned nbuffers = task->cl->nbuffers;
  282. unsigned buffer;
  283. for (buffer = 0; buffer < nbuffers; buffer++)
  284. {
  285. starpu_data_handle_t handle = task->handles[buffer];
  286. enum starpu_access_mode mode = task->cl->modes[buffer];
  287. struct starpu_task *new_task;
  288. /* Scratch memory does not introduce any deps */
  289. if (mode & STARPU_SCRATCH)
  290. continue;
  291. _STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  292. new_task = _starpu_detect_implicit_data_deps_with_handle(task, task, handle, mode);
  293. _STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  294. if (new_task) {
  295. int ret = starpu_task_submit(new_task);
  296. STARPU_ASSERT(!ret);
  297. }
  298. }
  299. _STARPU_LOG_OUT();
  300. }
  301. /* This function is called when a task has been executed so that we don't
  302. * create dependencies to task that do not exist anymore. */
  303. /* NB: We maintain a list of "ghost deps" in case FXT is enabled. Ghost
  304. * dependencies are the dependencies that are implicitely enforced by StarPU
  305. * even if they do not imply a real dependency. For instance in the following
  306. * sequence, f(Ar) g(Ar) h(Aw), we expect to have h depend on both f and g, but
  307. * if h is submitted after the termination of f or g, StarPU will not create a
  308. * dependency as this is not needed anymore. */
  309. /* the sequential_consistency_mutex of the handle has to be already held */
  310. void _starpu_release_data_enforce_sequential_consistency(struct starpu_task *task, starpu_data_handle_t handle)
  311. {
  312. _STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  313. if (handle->sequential_consistency)
  314. {
  315. /* If this is the last writer, there is no point in adding
  316. * extra deps to that tasks that does not exists anymore */
  317. if (task == handle->last_submitted_writer)
  318. {
  319. handle->last_submitted_writer = NULL;
  320. #ifndef STARPU_USE_FXT
  321. if (_starpu_bound_recording)
  322. #endif
  323. {
  324. /* Save the previous writer as the ghost last writer */
  325. handle->last_submitted_ghost_writer_id_is_valid = 1;
  326. struct _starpu_job *ghost_job = _starpu_get_job_associated_to_task(task);
  327. handle->last_submitted_ghost_writer_id = ghost_job->job_id;
  328. }
  329. }
  330. /* XXX can a task be both the last writer associated to a data
  331. * and be in its list of readers ? If not, we should not go
  332. * through the entire list once we have detected it was the
  333. * last writer. */
  334. /* Same if this is one of the readers: we go through the list
  335. * of readers and remove the task if it is found. */
  336. struct _starpu_task_wrapper_list *l;
  337. l = handle->last_submitted_readers;
  338. struct _starpu_task_wrapper_list *prev = NULL;
  339. #ifdef STARPU_DEVEL
  340. #warning TODO: use double-linked list to make finding ourself fast
  341. #endif
  342. while (l)
  343. {
  344. struct _starpu_task_wrapper_list *next = l->next;
  345. if (l->task == task)
  346. {
  347. /* If we found the task in the reader list */
  348. free(l);
  349. #ifndef STARPU_USE_FXT
  350. if (_starpu_bound_recording)
  351. #endif
  352. {
  353. /* Save the job id of the reader task in the ghost reader linked list list */
  354. struct _starpu_job *ghost_reader_job = _starpu_get_job_associated_to_task(task);
  355. struct _starpu_jobid_list *link = (struct _starpu_jobid_list *) malloc(sizeof(struct _starpu_jobid_list));
  356. STARPU_ASSERT(link);
  357. link->next = handle->last_submitted_ghost_readers_id;
  358. link->id = ghost_reader_job->job_id;
  359. handle->last_submitted_ghost_readers_id = link;
  360. }
  361. if (prev)
  362. {
  363. prev->next = next;
  364. }
  365. else
  366. {
  367. /* This is the first element of the list */
  368. handle->last_submitted_readers = next;
  369. }
  370. /* XXX can we really find the same task again
  371. * once we have found it ? Otherwise, we should
  372. * avoid going through the entire list and stop
  373. * as soon as we find the task. TODO: check how
  374. * duplicate dependencies are treated. */
  375. }
  376. else
  377. {
  378. prev = l;
  379. }
  380. l = next;
  381. }
  382. }
  383. _STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  384. }
  385. /* This is the same as _starpu_release_data_enforce_sequential_consistency, but
  386. * for all data of a task */
  387. void _starpu_release_task_enforce_sequential_consistency(struct _starpu_job *j)
  388. {
  389. struct starpu_task *task = j->task;
  390. struct starpu_buffer_descr *descrs = j->ordered_buffers;
  391. if (!task->cl)
  392. return;
  393. unsigned nbuffers = task->cl->nbuffers;
  394. unsigned index;
  395. for (index = 0; index < nbuffers; index++)
  396. {
  397. starpu_data_handle_t handle = descrs[index].handle;
  398. if (index && descrs[index-1].handle == descrs[index].handle)
  399. /* We have already released this data, skip it. This
  400. * depends on ordering putting writes before reads, see
  401. * _starpu_compar_handles */
  402. continue;
  403. _starpu_release_data_enforce_sequential_consistency(task, handle);
  404. /* Release the reference acquired in _starpu_push_task_output */
  405. _starpu_spin_lock(&handle->header_lock);
  406. STARPU_ASSERT(handle->busy_count > 0);
  407. handle->busy_count--;
  408. if (!_starpu_data_check_not_busy(handle))
  409. _starpu_spin_unlock(&handle->header_lock);
  410. }
  411. }
  412. void _starpu_add_post_sync_tasks(struct starpu_task *post_sync_task, starpu_data_handle_t handle)
  413. {
  414. _STARPU_LOG_IN();
  415. _STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  416. if (handle->sequential_consistency)
  417. {
  418. handle->post_sync_tasks_cnt++;
  419. struct _starpu_task_wrapper_list *link = (struct _starpu_task_wrapper_list *) malloc(sizeof(struct _starpu_task_wrapper_list));
  420. link->task = post_sync_task;
  421. link->next = handle->post_sync_tasks;
  422. handle->post_sync_tasks = link;
  423. }
  424. _STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  425. _STARPU_LOG_OUT();
  426. }
  427. void _starpu_unlock_post_sync_tasks(starpu_data_handle_t handle)
  428. {
  429. struct _starpu_task_wrapper_list *post_sync_tasks = NULL;
  430. unsigned do_submit_tasks = 0;
  431. _STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  432. if (handle->sequential_consistency)
  433. {
  434. STARPU_ASSERT(handle->post_sync_tasks_cnt > 0);
  435. if (--handle->post_sync_tasks_cnt == 0)
  436. {
  437. /* unlock all tasks : we need not hold the lock while unlocking all these tasks */
  438. do_submit_tasks = 1;
  439. post_sync_tasks = handle->post_sync_tasks;
  440. handle->post_sync_tasks = NULL;
  441. }
  442. }
  443. _STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  444. if (do_submit_tasks)
  445. {
  446. struct _starpu_task_wrapper_list *link = post_sync_tasks;
  447. while (link)
  448. {
  449. /* There is no need to depend on that task now, since it was already unlocked */
  450. _starpu_release_data_enforce_sequential_consistency(link->task, handle);
  451. int ret = starpu_task_submit(link->task);
  452. STARPU_ASSERT(!ret);
  453. struct _starpu_task_wrapper_list *tmp = link;
  454. link = link->next;
  455. free(tmp);
  456. }
  457. }
  458. }
  459. /* If sequential consistency mode is enabled, this function blocks until the
  460. * handle is available in the requested access mode. */
  461. int _starpu_data_wait_until_available(starpu_data_handle_t handle, enum starpu_access_mode mode)
  462. {
  463. /* If sequential consistency is enabled, wait until data is available */
  464. _STARPU_PTHREAD_MUTEX_LOCK(&handle->sequential_consistency_mutex);
  465. int sequential_consistency = handle->sequential_consistency;
  466. if (sequential_consistency)
  467. {
  468. struct starpu_task *sync_task, *new_task;
  469. sync_task = starpu_task_create();
  470. sync_task->detach = 0;
  471. sync_task->destroy = 1;
  472. #ifdef STARPU_USE_FXT
  473. _starpu_get_job_associated_to_task(sync_task)->model_name = "sync_task";
  474. #endif
  475. /* It is not really a RW access, but we want to make sure that
  476. * all previous accesses are done */
  477. new_task = _starpu_detect_implicit_data_deps_with_handle(sync_task, sync_task, handle, mode);
  478. _STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  479. if (new_task) {
  480. int ret = starpu_task_submit(new_task);
  481. STARPU_ASSERT(!ret);
  482. }
  483. /* TODO detect if this is superflous */
  484. int ret = starpu_task_submit(sync_task);
  485. STARPU_ASSERT(!ret);
  486. ret = starpu_task_wait(sync_task);
  487. STARPU_ASSERT(ret == 0);
  488. }
  489. else
  490. {
  491. _STARPU_PTHREAD_MUTEX_UNLOCK(&handle->sequential_consistency_mutex);
  492. }
  493. return 0;
  494. }