starpu_task.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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_H__
  21. #define __STARPU_TASK_H__
  22. /** @defgroup
  23. *
  24. * @{
  25. */
  26. #include <starpu.h>
  27. #include <errno.h>
  28. #include <assert.h>
  29. #if defined STARPU_USE_CUDA && !defined STARPU_DONT_INCLUDE_CUDA_HEADERS
  30. # include <cuda.h>
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. #define STARPU_NOWHERE ((1ULL)<<0)
  37. #define STARPU_CPU ((1ULL)<<1)
  38. #define STARPU_CUDA ((1ULL)<<3)
  39. #define STARPU_OPENCL ((1ULL)<<6)
  40. #define STARPU_MIC ((1ULL)<<7)
  41. #define STARPU_SCC ((1ULL)<<8)
  42. #define STARPU_MPI_MS ((1ULL)<<9)
  43. #define STARPU_CODELET_SIMGRID_EXECUTE (1<<0)
  44. #define STARPU_CODELET_SIMGRID_EXECUTE_AND_INJECT (1<<1)
  45. #define STARPU_CODELET_NOPLANS (1<<2)
  46. #define STARPU_CUDA_ASYNC (1<<0)
  47. #define STARPU_OPENCL_ASYNC (1<<0)
  48. enum starpu_codelet_type
  49. {
  50. STARPU_SEQ = 0,
  51. STARPU_SPMD,
  52. STARPU_FORKJOIN
  53. };
  54. enum starpu_task_status
  55. {
  56. STARPU_TASK_INVALID,
  57. #define STARPU_TASK_INVALID 0
  58. STARPU_TASK_BLOCKED,
  59. STARPU_TASK_READY,
  60. STARPU_TASK_RUNNING,
  61. STARPU_TASK_FINISHED,
  62. STARPU_TASK_BLOCKED_ON_TAG,
  63. STARPU_TASK_BLOCKED_ON_TASK,
  64. STARPU_TASK_BLOCKED_ON_DATA,
  65. STARPU_TASK_STOPPED
  66. };
  67. typedef uint64_t starpu_tag_t;
  68. typedef void (*starpu_cpu_func_t)(void **, void*);
  69. typedef void (*starpu_cuda_func_t)(void **, void*);
  70. typedef void (*starpu_opencl_func_t)(void **, void*);
  71. typedef void (*starpu_mic_kernel_t)(void **, void*);
  72. typedef void (*starpu_mpi_ms_kernel_t)(void **, void*);
  73. typedef void (*starpu_scc_kernel_t)(void **, void*);
  74. typedef starpu_mic_kernel_t (*starpu_mic_func_t)(void);
  75. typedef starpu_mpi_ms_kernel_t (*starpu_mpi_ms_func_t)(void);
  76. typedef starpu_scc_kernel_t (*starpu_scc_func_t)(void);
  77. #define STARPU_MULTIPLE_CPU_IMPLEMENTATIONS ((starpu_cpu_func_t) -1)
  78. #define STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS ((starpu_cuda_func_t) -1)
  79. #define STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS ((starpu_opencl_func_t) -1)
  80. #define STARPU_VARIABLE_NBUFFERS (-1)
  81. #define STARPU_SPECIFIC_NODE_LOCAL (-1)
  82. #define STARPU_SPECIFIC_NODE_CPU (-2)
  83. #define STARPU_SPECIFIC_NODE_SLOW (-3)
  84. #define STARPU_SPECIFIC_NODE_FAST (-4)
  85. struct starpu_task;
  86. struct starpu_codelet
  87. {
  88. uint32_t where;
  89. int (*can_execute)(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  90. enum starpu_codelet_type type;
  91. int max_parallelism;
  92. starpu_cpu_func_t cpu_func STARPU_DEPRECATED;
  93. starpu_cuda_func_t cuda_func STARPU_DEPRECATED;
  94. starpu_opencl_func_t opencl_func STARPU_DEPRECATED;
  95. starpu_cpu_func_t cpu_funcs[STARPU_MAXIMPLEMENTATIONS];
  96. starpu_cuda_func_t cuda_funcs[STARPU_MAXIMPLEMENTATIONS];
  97. char cuda_flags[STARPU_MAXIMPLEMENTATIONS];
  98. starpu_opencl_func_t opencl_funcs[STARPU_MAXIMPLEMENTATIONS];
  99. char opencl_flags[STARPU_MAXIMPLEMENTATIONS];
  100. starpu_mic_func_t mic_funcs[STARPU_MAXIMPLEMENTATIONS];
  101. starpu_mpi_ms_func_t mpi_ms_funcs[STARPU_MAXIMPLEMENTATIONS];
  102. starpu_scc_func_t scc_funcs[STARPU_MAXIMPLEMENTATIONS];
  103. const char *cpu_funcs_name[STARPU_MAXIMPLEMENTATIONS];
  104. int nbuffers;
  105. enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  106. enum starpu_data_access_mode *dyn_modes;
  107. unsigned specific_nodes;
  108. int nodes[STARPU_NMAXBUFS];
  109. int *dyn_nodes;
  110. struct starpu_perfmodel *model;
  111. struct starpu_perfmodel *energy_model;
  112. unsigned long per_worker_stats[STARPU_NMAXWORKERS];
  113. const char *name;
  114. unsigned color;
  115. int flags;
  116. };
  117. struct starpu_task
  118. {
  119. const char *name;
  120. struct starpu_codelet *cl;
  121. int32_t where;
  122. int nbuffers;
  123. /* We keep these before the static arrays, so we can detect dyn_handles
  124. * being NULL while nbuffers being bigger that STARPU_NMAXBUFS
  125. * (otherwise the overflow would put a non-NULL) */
  126. starpu_data_handle_t *dyn_handles;
  127. void **dyn_interfaces;
  128. enum starpu_data_access_mode *dyn_modes;
  129. starpu_data_handle_t handles[STARPU_NMAXBUFS];
  130. void *interfaces[STARPU_NMAXBUFS];
  131. enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  132. unsigned char *handles_sequential_consistency;
  133. void *cl_arg;
  134. size_t cl_arg_size;
  135. void (*callback_func)(void *);
  136. void *callback_arg;
  137. /* must StarPU release callback_arg ? - 0 by default */
  138. void (*prologue_callback_func)(void *);
  139. void *prologue_callback_arg;
  140. void (*prologue_callback_pop_func)(void *);
  141. void *prologue_callback_pop_arg;
  142. starpu_tag_t tag_id;
  143. unsigned cl_arg_free:1;
  144. unsigned callback_arg_free:1;
  145. /* must StarPU release prologue_callback_arg ? - 0 by default */
  146. unsigned prologue_callback_arg_free:1;
  147. /* must StarPU release prologue_callback_pop_arg ? - 0 by default */
  148. unsigned prologue_callback_pop_arg_free:1;
  149. unsigned use_tag:1;
  150. unsigned sequential_consistency:1;
  151. unsigned synchronous:1;
  152. unsigned execute_on_a_specific_worker:1;
  153. unsigned detach:1;
  154. unsigned destroy:1;
  155. unsigned regenerate:1;
  156. unsigned mf_skip:1;
  157. unsigned no_submitorder:1; /* do not allocate a submitorder id for this task */
  158. unsigned scheduled:1;
  159. unsigned prefetched:1;
  160. unsigned workerid;
  161. unsigned workerorder;
  162. uint32_t *workerids;
  163. unsigned workerids_len;
  164. int priority;
  165. enum starpu_task_status status;
  166. int magic;
  167. unsigned type;
  168. unsigned color;
  169. unsigned sched_ctx;
  170. int hypervisor_tag;
  171. unsigned possibly_parallel;
  172. starpu_task_bundle_t bundle;
  173. struct starpu_profiling_task_info *profiling_info;
  174. double flops;
  175. double predicted;
  176. double predicted_transfer;
  177. double predicted_start;
  178. struct starpu_task *prev;
  179. struct starpu_task *next;
  180. void *starpu_private;
  181. #ifdef STARPU_OPENMP
  182. struct starpu_omp_task *omp_task;
  183. #else
  184. void *omp_task;
  185. #endif
  186. unsigned nb_termination_call_required;
  187. void *sched_data;
  188. };
  189. #define STARPU_TASK_TYPE_NORMAL 0
  190. #define STARPU_TASK_TYPE_INTERNAL (1<<0)
  191. #define STARPU_TASK_TYPE_DATA_ACQUIRE (1<<1)
  192. /* Note: remember to update starpu_task_init as well */
  193. #define STARPU_TASK_INITIALIZER \
  194. { \
  195. .cl = NULL, \
  196. .where = -1, \
  197. .cl_arg = NULL, \
  198. .cl_arg_size = 0, \
  199. .callback_func = NULL, \
  200. .callback_arg = NULL, \
  201. .priority = STARPU_DEFAULT_PRIO, \
  202. .use_tag = 0, \
  203. .sequential_consistency = 1, \
  204. .synchronous = 0, \
  205. .execute_on_a_specific_worker = 0, \
  206. .workerorder = 0, \
  207. .bundle = NULL, \
  208. .detach = 1, \
  209. .destroy = 0, \
  210. .regenerate = 0, \
  211. .status = STARPU_TASK_INVALID, \
  212. .profiling_info = NULL, \
  213. .predicted = NAN, \
  214. .predicted_transfer = NAN, \
  215. .predicted_start = NAN, \
  216. .starpu_private = NULL, \
  217. .magic = 42, \
  218. .type = 0, \
  219. .color = 0, \
  220. .sched_ctx = STARPU_NMAX_SCHED_CTXS, \
  221. .hypervisor_tag = 0, \
  222. .flops = 0.0, \
  223. .scheduled = 0, \
  224. .prefetched = 0, \
  225. .dyn_handles = NULL, \
  226. .dyn_interfaces = NULL, \
  227. .dyn_modes = NULL, \
  228. .name = NULL, \
  229. .possibly_parallel = 0 \
  230. }
  231. #define STARPU_TASK_GET_NBUFFERS(task) ((unsigned)((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS ? ((task)->nbuffers) : ((task)->cl->nbuffers)))
  232. #define STARPU_TASK_GET_HANDLE(task, i) (((task)->dyn_handles) ? (task)->dyn_handles[i] : (task)->handles[i])
  233. #define STARPU_TASK_GET_HANDLES(task) (((task)->dyn_handles) ? (task)->dyn_handles : (task)->handles)
  234. #define STARPU_TASK_SET_HANDLE(task, handle, i) do { if ((task)->dyn_handles) (task)->dyn_handles[i] = handle; else (task)->handles[i] = handle; } while(0)
  235. #define STARPU_CODELET_GET_MODE(codelet, i) (((codelet)->dyn_modes) ? (codelet)->dyn_modes[i] : (assert(i < STARPU_NMAXBUFS), (codelet)->modes[i]))
  236. #define STARPU_CODELET_SET_MODE(codelet, mode, i) do { if ((codelet)->dyn_modes) (codelet)->dyn_modes[i] = mode; else (codelet)->modes[i] = mode; } while(0)
  237. #define STARPU_TASK_GET_MODE(task, i) ((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS || (task)->dyn_modes ? \
  238. (((task)->dyn_modes) ? (task)->dyn_modes[i] : (task)->modes[i]) : \
  239. STARPU_CODELET_GET_MODE((task)->cl, i) )
  240. #define STARPU_TASK_SET_MODE(task, mode, i) do { \
  241. if ((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS || (task)->cl->nbuffers > STARPU_NMAXBUFS) \
  242. if ((task)->dyn_modes) (task)->dyn_modes[i] = mode; else (task)->modes[i] = mode; \
  243. else \
  244. STARPU_CODELET_SET_MODE((task)->cl, mode, i); \
  245. } while(0)
  246. #define STARPU_CODELET_GET_NODE(codelet, i) (((codelet)->dyn_nodes) ? (codelet)->dyn_nodes[i] : (codelet)->nodes[i])
  247. #define STARPU_CODELET_SET_NODE(codelet, __node, i) do { if ((codelet)->dyn_nodes) (codelet)->dyn_nodes[i] = __node; else (codelet)->nodes[i] = __node; } while(0)
  248. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  249. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  250. void starpu_task_declare_deps(struct starpu_task *task, unsigned ndeps, ...);
  251. void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  252. void starpu_task_declare_end_deps(struct starpu_task *task, unsigned ndeps, ...);
  253. void starpu_task_declare_end_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  254. void starpu_task_end_dep_add(struct starpu_task *t, int nb_deps);
  255. void starpu_task_end_dep_release(struct starpu_task *t);
  256. int starpu_task_get_task_succs(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  257. int starpu_task_get_task_scheduled_succs(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  258. int starpu_tag_wait(starpu_tag_t id);
  259. int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  260. void starpu_tag_notify_from_apps(starpu_tag_t id);
  261. void starpu_tag_restart(starpu_tag_t id);
  262. void starpu_tag_remove(starpu_tag_t id);
  263. struct starpu_task *starpu_tag_get_task(starpu_tag_t id);
  264. void starpu_task_init(struct starpu_task *task);
  265. void starpu_task_clean(struct starpu_task *task);
  266. struct starpu_task *starpu_task_create(void) STARPU_ATTRIBUTE_MALLOC;
  267. void starpu_task_destroy(struct starpu_task *task);
  268. int starpu_task_submit(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  269. int starpu_task_submit_to_ctx(struct starpu_task *task, unsigned sched_ctx_id);
  270. int starpu_task_finished(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  271. int starpu_task_wait(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  272. int starpu_task_wait_array(struct starpu_task **tasks, unsigned nb_tasks) STARPU_WARN_UNUSED_RESULT;
  273. int starpu_task_wait_for_all(void);
  274. int starpu_task_wait_for_n_submitted(unsigned n);
  275. int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx_id);
  276. int starpu_task_wait_for_n_submitted_in_ctx(unsigned sched_ctx_id, unsigned n);
  277. int starpu_task_wait_for_no_ready(void);
  278. int starpu_task_nready(void);
  279. int starpu_task_nsubmitted(void);
  280. void starpu_iteration_push(unsigned long iteration);
  281. void starpu_iteration_pop(void);
  282. void starpu_do_schedule(void);
  283. void starpu_codelet_init(struct starpu_codelet *cl);
  284. void starpu_codelet_display_stats(struct starpu_codelet *cl);
  285. struct starpu_task *starpu_task_get_current(void);
  286. int starpu_task_get_current_data_node(unsigned i);
  287. const char *starpu_task_get_model_name(struct starpu_task *task);
  288. const char *starpu_task_get_name(struct starpu_task *task);
  289. void starpu_parallel_task_barrier_init(struct starpu_task *task, int workerid);
  290. void starpu_parallel_task_barrier_init_n(struct starpu_task *task, int worker_size);
  291. struct starpu_task *starpu_task_dup(struct starpu_task *task);
  292. void starpu_task_set_implementation(struct starpu_task *task, unsigned impl);
  293. unsigned starpu_task_get_implementation(struct starpu_task *task);
  294. #ifdef __cplusplus
  295. }
  296. #endif
  297. /** @} */
  298. #endif /* __STARPU_TASK_H__ */