starpu_task.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2014 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011 Télécom-SudParis
  6. * Copyright (C) 2011 INRIA
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #ifndef __STARPU_TASK_H__
  20. #define __STARPU_TASK_H__
  21. #include <starpu.h>
  22. #include <starpu_data.h>
  23. #include <starpu_util.h>
  24. #include <starpu_task_bundle.h>
  25. #include <errno.h>
  26. #if defined STARPU_USE_CUDA && !defined STARPU_DONT_INCLUDE_CUDA_HEADERS
  27. # include <cuda.h>
  28. #endif
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #endif
  33. #define STARPU_CPU ((1ULL)<<1)
  34. #define STARPU_CUDA ((1ULL)<<3)
  35. #define STARPU_OPENCL ((1ULL)<<6)
  36. #define STARPU_MIC ((1ULL)<<7)
  37. #define STARPU_SCC ((1ULL)<<8)
  38. #define STARPU_CUDA_ASYNC (1<<0)
  39. #define STARPU_OPENCL_ASYNC (1<<0)
  40. enum starpu_codelet_type
  41. {
  42. STARPU_SEQ = 0,
  43. STARPU_SPMD,
  44. STARPU_FORKJOIN
  45. };
  46. enum starpu_task_status
  47. {
  48. STARPU_TASK_INVALID,
  49. #define STARPU_TASK_INVALID 0
  50. STARPU_TASK_BLOCKED,
  51. STARPU_TASK_READY,
  52. STARPU_TASK_RUNNING,
  53. STARPU_TASK_FINISHED,
  54. STARPU_TASK_BLOCKED_ON_TAG,
  55. STARPU_TASK_BLOCKED_ON_TASK,
  56. STARPU_TASK_BLOCKED_ON_DATA
  57. };
  58. typedef uint64_t starpu_tag_t;
  59. typedef void (*starpu_cpu_func_t)(void **, void*);
  60. typedef void (*starpu_cuda_func_t)(void **, void*);
  61. typedef void (*starpu_opencl_func_t)(void **, void*);
  62. typedef void (*starpu_mic_kernel_t)(void **, void*);
  63. typedef void (*starpu_scc_kernel_t)(void **, void*);
  64. typedef starpu_mic_kernel_t (*starpu_mic_func_t)(void);
  65. typedef starpu_scc_kernel_t (*starpu_scc_func_t)(void);
  66. #define STARPU_MULTIPLE_CPU_IMPLEMENTATIONS ((starpu_cpu_func_t) -1)
  67. #define STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS ((starpu_cuda_func_t) -1)
  68. #define STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS ((starpu_opencl_func_t) -1)
  69. #define STARPU_VARIABLE_NBUFFERS (-1)
  70. struct starpu_task;
  71. struct starpu_codelet
  72. {
  73. uint32_t where;
  74. int (*can_execute)(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  75. enum starpu_codelet_type type;
  76. int max_parallelism;
  77. starpu_cpu_func_t cpu_func STARPU_DEPRECATED;
  78. starpu_cuda_func_t cuda_func STARPU_DEPRECATED;
  79. starpu_opencl_func_t opencl_func STARPU_DEPRECATED;
  80. starpu_cpu_func_t cpu_funcs[STARPU_MAXIMPLEMENTATIONS];
  81. starpu_cuda_func_t cuda_funcs[STARPU_MAXIMPLEMENTATIONS];
  82. char cuda_flags[STARPU_MAXIMPLEMENTATIONS];
  83. starpu_opencl_func_t opencl_funcs[STARPU_MAXIMPLEMENTATIONS];
  84. char opencl_flags[STARPU_MAXIMPLEMENTATIONS];
  85. starpu_mic_func_t mic_funcs[STARPU_MAXIMPLEMENTATIONS];
  86. starpu_scc_func_t scc_funcs[STARPU_MAXIMPLEMENTATIONS];
  87. char *cpu_funcs_name[STARPU_MAXIMPLEMENTATIONS];
  88. int nbuffers;
  89. enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  90. enum starpu_data_access_mode *dyn_modes;
  91. unsigned specific_nodes;
  92. int nodes[STARPU_NMAXBUFS];
  93. int *dyn_nodes;
  94. struct starpu_perfmodel *model;
  95. struct starpu_perfmodel *power_model;
  96. unsigned long per_worker_stats[STARPU_NMAXWORKERS];
  97. const char *name;
  98. };
  99. struct starpu_task
  100. {
  101. const char *name;
  102. struct starpu_codelet *cl;
  103. int nbuffers;
  104. starpu_data_handle_t handles[STARPU_NMAXBUFS];
  105. void *interfaces[STARPU_NMAXBUFS];
  106. enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  107. starpu_data_handle_t *dyn_handles;
  108. void **dyn_interfaces;
  109. enum starpu_data_access_mode *dyn_modes;
  110. void *cl_arg;
  111. size_t cl_arg_size;
  112. void (*callback_func)(void *);
  113. void *callback_arg;
  114. /* must StarPU release callback_arg ? - 0 by default */
  115. void (*prologue_callback_func)(void *);
  116. void *prologue_callback_arg;
  117. void (*prologue_callback_pop_func)(void *);
  118. void *prologue_callback_pop_arg;
  119. starpu_tag_t tag_id;
  120. unsigned cl_arg_free:1;
  121. unsigned callback_arg_free:1;
  122. /* must StarPU release prologue_callback_arg ? - 0 by default */
  123. unsigned prologue_callback_arg_free:1;
  124. /* must StarPU release prologue_callback_pop_arg ? - 0 by default */
  125. unsigned prologue_callback_pop_arg_free:1;
  126. unsigned use_tag:1;
  127. unsigned sequential_consistency:1;
  128. unsigned synchronous:1;
  129. unsigned execute_on_a_specific_worker:1;
  130. unsigned detach:1;
  131. unsigned destroy:1;
  132. unsigned regenerate:1;
  133. unsigned workerid;
  134. unsigned scheduled:1;
  135. unsigned int mf_skip:1;
  136. int priority;
  137. enum starpu_task_status status;
  138. int magic;
  139. unsigned sched_ctx;
  140. int hypervisor_tag;
  141. unsigned possibly_parallel;
  142. starpu_task_bundle_t bundle;
  143. struct starpu_profiling_task_info *profiling_info;
  144. double flops;
  145. double predicted;
  146. double predicted_transfer;
  147. struct starpu_task *prev;
  148. struct starpu_task *next;
  149. void *starpu_private;
  150. };
  151. #define STARPU_TASK_INITIALIZER \
  152. { \
  153. .cl = NULL, \
  154. .cl_arg = NULL, \
  155. .cl_arg_size = 0, \
  156. .callback_func = NULL, \
  157. .callback_arg = NULL, \
  158. .priority = STARPU_DEFAULT_PRIO, \
  159. .use_tag = 0, \
  160. .synchronous = 0, \
  161. .execute_on_a_specific_worker = 0, \
  162. .bundle = NULL, \
  163. .detach = 1, \
  164. .destroy = 0, \
  165. .regenerate = 0, \
  166. .status = STARPU_TASK_INVALID, \
  167. .profiling_info = NULL, \
  168. .predicted = -1.0, \
  169. .predicted_transfer = -1.0, \
  170. .starpu_private = NULL, \
  171. .magic = 42, \
  172. .sched_ctx = 0, \
  173. .hypervisor_tag = 0, \
  174. .flops = 0.0, \
  175. .scheduled = 0, \
  176. .dyn_handles = NULL, \
  177. .dyn_interfaces = NULL, \
  178. .dyn_modes = NULL, \
  179. .name = NULL, \
  180. .possibly_parallel = 0 \
  181. }
  182. #define STARPU_TASK_GET_NBUFFERS(task) ((unsigned)((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS ? ((task)->nbuffers) : ((task)->cl->nbuffers)))
  183. #define STARPU_TASK_GET_HANDLE(task, i) (((task)->dyn_handles) ? (task)->dyn_handles[i] : (task)->handles[i])
  184. #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)
  185. #define STARPU_CODELET_GET_MODE(codelet, i) (((codelet)->dyn_modes) ? (codelet)->dyn_modes[i] : (codelet)->modes[i])
  186. #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)
  187. #define STARPU_TASK_GET_MODE(task, i) ((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS ? \
  188. (((task)->dyn_modes) ? (task)->dyn_modes[i] : (task)->modes[i]) : \
  189. STARPU_CODELET_GET_MODE((task)->cl, i) )
  190. #define STARPU_TASK_SET_MODE(task, mode, i) do { \
  191. if ((task)->cl->nbuffers == STARPU_VARIABLE_NBUFFERS) \
  192. if ((task)->dyn_modes) (task)->dyn_modes[i] = mode; else (task)->modes[i] = mode; \
  193. else \
  194. STARPU_CODELET_SET_MODE((task)->cl, mode, i); \
  195. } while(0)
  196. #define STARPU_CODELET_GET_NODE(codelet, i) (((codelet)->dyn_nodes) ? (codelet)->dyn_nodes[i] : (codelet)->nodes[i])
  197. #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)
  198. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  199. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  200. void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  201. int starpu_tag_wait(starpu_tag_t id);
  202. int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  203. void starpu_tag_notify_from_apps(starpu_tag_t id);
  204. void starpu_tag_restart(starpu_tag_t id);
  205. void starpu_tag_remove(starpu_tag_t id);
  206. void starpu_task_init(struct starpu_task *task);
  207. void starpu_task_clean(struct starpu_task *task);
  208. struct starpu_task *starpu_task_create(void);
  209. void starpu_task_destroy(struct starpu_task *task);
  210. int starpu_task_submit(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  211. int starpu_task_submit_to_ctx(struct starpu_task *task, unsigned sched_ctx_id);
  212. int starpu_task_finished(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  213. int starpu_task_wait(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  214. int starpu_task_wait_for_all(void);
  215. int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx_id);
  216. int starpu_task_wait_for_no_ready(void);
  217. int starpu_task_nready(void);
  218. int starpu_task_nsubmitted(void);
  219. void starpu_codelet_init(struct starpu_codelet *cl);
  220. void starpu_codelet_display_stats(struct starpu_codelet *cl);
  221. struct starpu_task *starpu_task_get_current(void);
  222. void starpu_parallel_task_barrier_init(struct starpu_task *task, int workerid);
  223. void starpu_parallel_task_barrier_init_n(struct starpu_task *task, int worker_size);
  224. struct starpu_task *starpu_task_dup(struct starpu_task *task);
  225. void starpu_task_set_implementation(struct starpu_task *task, unsigned impl);
  226. unsigned starpu_task_get_implementation(struct starpu_task *task);
  227. #ifdef __cplusplus
  228. }
  229. #endif
  230. #endif /* __STARPU_TASK_H__ */