starpu_task.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 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. #ifndef __STARPU_TASK_H__
  18. #define __STARPU_TASK_H__
  19. #include <errno.h>
  20. #include <starpu.h>
  21. #include <starpu_config.h>
  22. #ifdef STARPU_USE_CUDA
  23. #include <cuda.h>
  24. #endif
  25. #include <starpu_data.h>
  26. #define STARPU_CPU ((1ULL)<<1)
  27. #define STARPU_CUDA ((1ULL)<<3)
  28. #define STARPU_SPU ((1ULL)<<4)
  29. #define STARPU_GORDON ((1ULL)<<5)
  30. #define STARPU_OPENCL ((1ULL)<<6)
  31. /* Codelet types */
  32. #define STARPU_SEQ 0
  33. #define STARPU_SPMD 1
  34. #define STARPU_FORKJOIN 2
  35. /* task status */
  36. #define STARPU_TASK_INVALID 0
  37. #define STARPU_TASK_BLOCKED 1
  38. #define STARPU_TASK_READY 2
  39. #define STARPU_TASK_RUNNING 3
  40. #define STARPU_TASK_FINISHED 4
  41. #define STARPU_TASK_BLOCKED_ON_TAG 5
  42. #define STARPU_TASK_BLOCKED_ON_TASK 6
  43. #define STARPU_TASK_BLOCKED_ON_DATA 7
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. typedef uint64_t starpu_tag_t;
  48. /*
  49. * A codelet describes the various function
  50. * that may be called from a worker
  51. */
  52. typedef struct starpu_codelet_t {
  53. /* where can it be performed ? */
  54. uint32_t where;
  55. unsigned type;
  56. int max_parallelism;
  57. /* the different implementations of the codelet */
  58. void (*cuda_func)(void **, void *);
  59. void (*cpu_func)(void **, void *);
  60. void (*opencl_func)(void **, void *);
  61. uint8_t gordon_func;
  62. /* how many buffers do the codelet takes as argument ? */
  63. unsigned nbuffers;
  64. /* performance model of the codelet */
  65. struct starpu_perfmodel_t *model;
  66. /* consumption model of the codelet.
  67. * In the case of parallel codelets, accounts for all units. */
  68. struct starpu_perfmodel_t *power_model;
  69. /* statistics collected at runtime: this is filled by StarPU and should
  70. * not be accessed directly (use the starpu_display_codelet_stats
  71. * function instead for instance). */
  72. unsigned long per_worker_stats[STARPU_NMAXWORKERS];
  73. } starpu_codelet;
  74. struct starpu_task {
  75. struct starpu_codelet_t *cl;
  76. /* arguments managed by the DSM */
  77. struct starpu_buffer_descr_t buffers[STARPU_NMAXBUFS];
  78. void *interfaces[STARPU_NMAXBUFS];
  79. /* arguments not managed by the DSM are given as a buffer */
  80. void *cl_arg;
  81. /* in case the argument buffer has to be uploaded explicitely */
  82. size_t cl_arg_size;
  83. /* when the task is done, callback_func(callback_arg) is called */
  84. void (*callback_func)(void *);
  85. void *callback_arg;
  86. unsigned use_tag;
  87. starpu_tag_t tag_id;
  88. /* options for the task execution */
  89. unsigned synchronous; /* if set, a call to push is blocking */
  90. int priority; /* STARPU_MAX_PRIO = most important
  91. : STARPU_MIN_PRIO = least important */
  92. /* in case the task has to be executed on a specific worker */
  93. unsigned execute_on_a_specific_worker;
  94. unsigned workerid;
  95. /* Bundle including the task */
  96. struct starpu_task_bundle *bundle;
  97. /* If this flag is set, it is not possible to synchronize with the task
  98. * by the means of starpu_task_wait later on. Internal data structures
  99. * are only garanteed to be freed once starpu_task_wait is called if
  100. * that flag is not set. */
  101. int detach;
  102. /* If that flag is set, the task structure will automatically be freed,
  103. * either after the execution of the callback if the task is detached,
  104. * or during starpu_task_wait otherwise. If this flag is not set,
  105. * dynamically allocated data structures will not be freed until
  106. * starpu_task_destroy is called explicitely. Setting this flag for a
  107. * statically allocated task structure will result in undefined
  108. * behaviour. */
  109. int destroy;
  110. /* If this flag is set, the task will be re-submitted to StarPU once it
  111. * has been executed. This flag must not be set if the destroy flag is
  112. * set too. */
  113. int regenerate;
  114. unsigned status;
  115. /* This gets filled when profiling is enabled by using
  116. * starpu_profiling_status_set */
  117. struct starpu_task_profiling_info *profiling_info;
  118. /* Predicted duration of the task in µs. This field is only valid if the
  119. * scheduling strategy uses performance models. */
  120. double predicted;
  121. /* This field are provided for the convenience of the scheduler. */
  122. struct starpu_task *prev;
  123. struct starpu_task *next;
  124. /* this is private to StarPU, do not modify. If the task is allocated
  125. * by hand (without starpu_task_create), this field should be set to
  126. * NULL. */
  127. void *starpu_private;
  128. };
  129. /* It is possible to initialize statically allocated tasks with this value.
  130. * This is equivalent to initializing a starpu_task structure with the
  131. * starpu_task_init function. */
  132. #define STARPU_TASK_INITIALIZER \
  133. { \
  134. .cl = NULL, \
  135. .cl_arg = NULL, \
  136. .cl_arg_size = 0, \
  137. .callback_func = NULL, \
  138. .callback_arg = NULL, \
  139. .priority = STARPU_DEFAULT_PRIO, \
  140. .use_tag = 0, \
  141. .synchronous = 0, \
  142. .execute_on_a_specific_worker = 0, \
  143. .bundle = NULL, \
  144. .detach = 1, \
  145. .destroy = 0, \
  146. .regenerate = 0, \
  147. .status = STARPU_TASK_INVALID, \
  148. .profiling_info = NULL, \
  149. .predicted = -1.0, \
  150. .starpu_private = NULL \
  151. };
  152. /*
  153. * handle task dependencies: it is possible to associate a task with a unique
  154. * "tag" and to express dependencies between tasks by the means of those tags
  155. *
  156. * To do so, fill the tag_id field with a tag number (can be arbitrary) and set
  157. * use_tag to 1.
  158. *
  159. * If starpu_tag_declare_deps is called with that tag number, the task will not
  160. * be started until the task which wears the declared dependency tags are
  161. * complete.
  162. */
  163. /*
  164. * WARNING ! use with caution ...
  165. * In case starpu_tag_declare_deps is passed constant arguments, the caller
  166. * must make sure that the constants are casted to starpu_tag_t. Otherwise,
  167. * due to integer sizes and argument passing on the stack, the C compiler
  168. * might consider the tag * 0x200000003 instead of 0x2 and 0x3 when calling:
  169. * "starpu_tag_declare_deps(0x1, 2, 0x2, 0x3)"
  170. * Using starpu_tag_declare_deps_array is a way to avoid this problem.
  171. */
  172. /* make id depend on the list of ids */
  173. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  174. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  175. /* task depends on the tasks in task array */
  176. void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  177. int starpu_tag_wait(starpu_tag_t id);
  178. int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  179. /* The application can feed a tag explicitely */
  180. void starpu_tag_notify_from_apps(starpu_tag_t id);
  181. /* To release resources, tags should be freed after use */
  182. void starpu_tag_remove(starpu_tag_t id);
  183. /* Initialize a task structure with default values. */
  184. void starpu_task_init(struct starpu_task *task);
  185. /* Release all the structures automatically allocated to execute the task. This
  186. * is called implicitely by starpu_task_destroy, but the task structure itself
  187. * is not freed. This should be used for statically allocated tasks for
  188. * instance. */
  189. void starpu_task_deinit(struct starpu_task *task);
  190. /* Allocate a task structure and initialize it with default values. Tasks
  191. * allocated dynamically with starpu_task_create are automatically freed when
  192. * the task is terminated. If the destroy flag is explicitely unset, the
  193. * ressources used by the task are freed by calling starpu_task_destroy.
  194. * */
  195. struct starpu_task *starpu_task_create(void);
  196. /* Free the ressource allocated during the execution of the task and deallocate
  197. * the task structure itself. This function can be called automatically after
  198. * the execution of a task by setting the "destroy" flag of the starpu_task
  199. * structure (default behaviour). Calling this function on a statically
  200. * allocated task results in an undefined behaviour. */
  201. void starpu_task_destroy(struct starpu_task *task);
  202. int starpu_task_submit(struct starpu_task *task);
  203. /* This function blocks until the task was executed. It is not possible to
  204. * synchronize with a task more than once. It is not possible to wait
  205. * synchronous or detached tasks.
  206. * Upon successful completion, this function returns 0. Otherwise, -EINVAL
  207. * indicates that the waited task was either synchronous or detached. */
  208. int starpu_task_wait(struct starpu_task *task);
  209. /* This function waits until all the tasks that were already submitted have
  210. * been executed. */
  211. int starpu_task_wait_for_all(void);
  212. void starpu_display_codelet_stats(struct starpu_codelet_t *cl);
  213. /* Return the task currently executed by the worker, or NULL if this is called
  214. * either from a thread that is not a task or simply because there is no task
  215. * being executed at the moment. */
  216. struct starpu_task *starpu_get_current_task(void);
  217. #ifdef __cplusplus
  218. }
  219. #endif
  220. #endif /* __STARPU_TASK_H__ */