starpu_task_dep.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2011 Télécom-SudParis
  5. * Copyright (C) 2016 Uppsala University
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_TASK_DEP_H__
  19. #define __STARPU_TASK_DEP_H__
  20. #include <starpu.h>
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. /**
  26. @defgroup API_Explicit_Dependencies Explicit Dependencies
  27. @{
  28. */
  29. /**
  30. Declare task dependencies between a \p task and an array of tasks
  31. of length \p ndeps. This function must be called prior to the
  32. submission of the task, but it may called after the submission or
  33. the execution of the tasks in the array, provided the tasks are
  34. still valid (i.e. they were not automatically destroyed). Calling
  35. this function on a task that was already submitted or with an entry
  36. of \p task_array that is no longer a valid task results in an
  37. undefined behaviour. If \p ndeps is 0, no dependency is added. It
  38. is possible to call starpu_task_declare_deps_array() several times
  39. on the same task, in this case, the dependencies are added. It is
  40. possible to have redundancy in the task dependencies.
  41. */
  42. void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  43. /**
  44. Declare task dependencies between a \p task and an series of \p
  45. ndeps tasks, similarly to starpu_task_declare_deps_array(), but the
  46. tasks are passed after \p ndeps, which indicates how many tasks \p
  47. task shall be made to depend on. If \p ndeps is 0, no dependency is
  48. added.
  49. */
  50. void starpu_task_declare_deps(struct starpu_task *task, unsigned ndeps, ...);
  51. /**
  52. Declare task end dependencies between a \p task and an array of
  53. tasks of length \p ndeps. \p task will appear as terminated not
  54. only when \p task is termination, but also when the tasks of \p
  55. task_array have terminated. This function must be called prior to
  56. the termination of the task, but it may called after the submission
  57. or the execution of the tasks in the array, provided the tasks are
  58. still valid (i.e. they were not automatically destroyed). Calling
  59. this function on a task that was already terminated or with an
  60. entry of \p task_array that is no longer a valid task results in an
  61. undefined behaviour. If \p ndeps is 0, no dependency is added. It
  62. is possible to call starpu_task_declare_end_deps_array() several
  63. times on the same task, in this case, the dependencies are added.
  64. It is currently not implemented to have redundancy in the task
  65. dependencies.
  66. */
  67. void starpu_task_declare_end_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  68. /**
  69. Declare task end dependencies between a \p task and an series of \p
  70. ndeps tasks, similarly to starpu_task_declare_end_deps_array(), but
  71. the tasks are passed after \p ndeps, which indicates how many tasks
  72. \p task 's termination shall be made to depend on. If \p ndeps is
  73. 0, no dependency is added.
  74. */
  75. void starpu_task_declare_end_deps(struct starpu_task *task, unsigned ndeps, ...);
  76. /**
  77. Fill \p task_array with the list of tasks which are direct children
  78. of \p task. \p ndeps is the size of \p task_array. This function
  79. returns the number of direct children. \p task_array can be set to
  80. <c>NULL</c> if \p ndeps is 0, which allows to compute the number of
  81. children before allocating an array to store them. This function
  82. can only be called if \p task has not completed yet, otherwise the
  83. results are undefined. The result may also be outdated if some
  84. additional dependency has been added in the meanwhile.
  85. */
  86. int starpu_task_get_task_succs(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  87. /**
  88. Behave like starpu_task_get_task_succs(), except that it only
  89. reports tasks which will go through the scheduler, thus avoiding
  90. tasks with not codelet, or with explicit placement.
  91. */
  92. int starpu_task_get_task_scheduled_succs(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  93. /**
  94. Add \p nb_deps end dependencies to the task \p t. This means the
  95. task will not terminate until the required number of calls to the
  96. function starpu_task_end_dep_release() has been made.
  97. */
  98. void starpu_task_end_dep_add(struct starpu_task *t, int nb_deps);
  99. /**
  100. Unlock 1 end dependency to the task \p t. This function must be
  101. called after starpu_task_end_dep_add().
  102. */
  103. void starpu_task_end_dep_release(struct starpu_task *t);
  104. /**
  105. Define a task logical identifer. It is possible to associate a task
  106. with a unique <em>tag</em> chosen by the application, and to
  107. express dependencies between tasks by the means of those tags. To
  108. do so, fill the field starpu_task::tag_id with a tag number (can be
  109. arbitrary) and set the field starpu_task::use_tag to 1. If
  110. starpu_tag_declare_deps() is called with this tag number, the task
  111. will not be started until the tasks which holds the declared
  112. dependency tags are completed.
  113. */
  114. typedef uint64_t starpu_tag_t;
  115. /**
  116. Specify the dependencies of the task identified by tag \p id. The
  117. first argument specifies the tag which is configured, the second
  118. argument gives the number of tag(s) on which \p id depends. The
  119. following arguments are the tags which have to be terminated to
  120. unlock the task. This function must be called before the associated
  121. task is submitted to StarPU with starpu_task_submit().
  122. <b>WARNING! Use with caution</b>. Because of the variable arity of
  123. starpu_tag_declare_deps(), note that the last arguments must be of
  124. type ::starpu_tag_t : constant values typically need to be
  125. explicitly casted. Otherwise, due to integer sizes and argument
  126. passing on the stack, the C compiler might consider the tag
  127. <c>0x200000003</c> instead of <c>0x2</c> and <c>0x3</c> when
  128. calling <c>starpu_tag_declare_deps(0x1, 2, 0x2, 0x3)</c>. Using the
  129. starpu_tag_declare_deps_array() function avoids this hazard.
  130. \code{.c}
  131. // Tag 0x1 depends on tags 0x32 and 0x52
  132. starpu_tag_declare_deps((starpu_tag_t)0x1, 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
  133. \endcode
  134. */
  135. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  136. /**
  137. Similar to starpu_tag_declare_deps(), except that its does not take
  138. a variable number of arguments but an \p array of tags of size \p
  139. ndeps.
  140. \code{.c}
  141. // Tag 0x1 depends on tags 0x32 and 0x52
  142. starpu_tag_t tag_array[2] = {0x32, 0x52};
  143. starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
  144. \endcode
  145. */
  146. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  147. /**
  148. Block until the task associated to tag \p id has been executed.
  149. This is a blocking call which must therefore not be called within
  150. tasks or callbacks, but only from the application directly. It is
  151. possible to synchronize with the same tag multiple times, as long
  152. as the starpu_tag_remove() function is not called. Note that it is
  153. still possible to synchronize with a tag associated to a task for
  154. which the strucuture starpu_task was freed (e.g. if the field
  155. starpu_task::destroy was enabled).
  156. */
  157. int starpu_tag_wait(starpu_tag_t id);
  158. /**
  159. Similar to starpu_tag_wait() except that it blocks until all the \p
  160. ntags tags contained in the array \p id are terminated.
  161. */
  162. int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  163. /**
  164. Clear the <em>already notified</em> status of a tag which is not
  165. associated with a task. Before that, calling
  166. starpu_tag_notify_from_apps() again will not notify the successors.
  167. After that, the next call to starpu_tag_notify_from_apps() will
  168. notify the successors.
  169. */
  170. void starpu_tag_restart(starpu_tag_t id);
  171. /**
  172. Release the resources associated to tag \p id. It can be called
  173. once the corresponding task has been executed and when there is no
  174. other tag that depend on this tag anymore.
  175. */
  176. void starpu_tag_remove(starpu_tag_t id);
  177. /**
  178. Explicitly unlock tag \p id. It may be useful in the case of
  179. applications which execute part of their computation outside StarPU
  180. tasks (e.g. third-party libraries). It is also provided as a
  181. convenient tool for the programmer, for instance to entirely
  182. construct the task DAG before actually giving StarPU the
  183. opportunity to execute the tasks. When called several times on the
  184. same tag, notification will be done only on first call, thus
  185. implementing "OR" dependencies, until the tag is restarted using
  186. starpu_tag_restart().
  187. */
  188. void starpu_tag_notify_from_apps(starpu_tag_t id);
  189. /**
  190. Atomically call starpu_tag_notify_from_apps() and starpu_tag_restart() on tag
  191. \p id.
  192. This is useful with cyclic graphs, when we want to safely trigger its startup.
  193. */
  194. void starpu_tag_notify_restart_from_apps(starpu_tag_t id);
  195. /**
  196. Return the task associated to the tag \p id
  197. */
  198. struct starpu_task *starpu_tag_get_task(starpu_tag_t id);
  199. /** @} */
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif /* __STARPU_TASK_DEP_H__ */