starpu_task_dep.h 9.2 KB

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