starpu_task.h 11 KB

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