starpu_task.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013 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_task_bundle.h>
  24. #include <errno.h>
  25. #if defined STARPU_USE_CUDA && !defined STARPU_DONT_INCLUDE_CUDA_HEADERS
  26. # include <cuda.h>
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #endif
  32. #define STARPU_CPU ((1ULL)<<1)
  33. #define STARPU_CUDA ((1ULL)<<3)
  34. #define STARPU_OPENCL ((1ULL)<<6)
  35. #define STARPU_MIC ((1ULL)<<7)
  36. #define STARPU_SCC ((1ULL)<<8)
  37. enum starpu_codelet_type
  38. {
  39. STARPU_SEQ,
  40. STARPU_SPMD,
  41. STARPU_FORKJOIN
  42. };
  43. enum starpu_task_status
  44. {
  45. STARPU_TASK_INVALID,
  46. #define STARPU_TASK_INVALID 0
  47. STARPU_TASK_BLOCKED,
  48. STARPU_TASK_READY,
  49. STARPU_TASK_RUNNING,
  50. STARPU_TASK_FINISHED,
  51. STARPU_TASK_BLOCKED_ON_TAG,
  52. STARPU_TASK_BLOCKED_ON_TASK,
  53. STARPU_TASK_BLOCKED_ON_DATA
  54. };
  55. typedef uint64_t starpu_tag_t;
  56. typedef void (*starpu_cpu_func_t)(void **, void*);
  57. typedef void (*starpu_cuda_func_t)(void **, void*);
  58. typedef void (*starpu_opencl_func_t)(void **, void*);
  59. typedef void (*starpu_mic_kernel_t)(void **, void*);
  60. typedef void (*starpu_scc_kernel_t)(void **, void*);
  61. typedef starpu_mic_kernel_t (*starpu_mic_func_t)(void);
  62. typedef starpu_scc_kernel_t (*starpu_scc_func_t)(void);
  63. #define STARPU_MULTIPLE_CPU_IMPLEMENTATIONS ((starpu_cpu_func_t) -1)
  64. #define STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS ((starpu_cuda_func_t) -1)
  65. #define STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS ((starpu_opencl_func_t) -1)
  66. struct starpu_task;
  67. struct starpu_codelet
  68. {
  69. uint32_t where;
  70. int (*can_execute)(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  71. enum starpu_codelet_type type;
  72. int max_parallelism;
  73. starpu_cpu_func_t cpu_func STARPU_DEPRECATED;
  74. starpu_cuda_func_t cuda_func STARPU_DEPRECATED;
  75. starpu_opencl_func_t opencl_func STARPU_DEPRECATED;
  76. starpu_cpu_func_t cpu_funcs[STARPU_MAXIMPLEMENTATIONS];
  77. starpu_cuda_func_t cuda_funcs[STARPU_MAXIMPLEMENTATIONS];
  78. starpu_opencl_func_t opencl_funcs[STARPU_MAXIMPLEMENTATIONS];
  79. starpu_mic_func_t mic_funcs[STARPU_MAXIMPLEMENTATIONS];
  80. starpu_scc_func_t scc_funcs[STARPU_MAXIMPLEMENTATIONS];
  81. char *cpu_funcs_name[STARPU_MAXIMPLEMENTATIONS];
  82. unsigned nbuffers;
  83. enum starpu_data_access_mode modes[STARPU_NMAXBUFS];
  84. enum starpu_data_access_mode *dyn_modes;
  85. struct starpu_perfmodel *model;
  86. struct starpu_perfmodel *power_model;
  87. unsigned long per_worker_stats[STARPU_NMAXWORKERS];
  88. const char *name;
  89. };
  90. struct starpu_task
  91. {
  92. struct starpu_codelet *cl;
  93. struct starpu_data_descr buffers[STARPU_NMAXBUFS] STARPU_DEPRECATED;
  94. starpu_data_handle_t handles[STARPU_NMAXBUFS];
  95. void *interfaces[STARPU_NMAXBUFS];
  96. starpu_data_handle_t *dyn_handles;
  97. void **dyn_interfaces;
  98. void *cl_arg;
  99. size_t cl_arg_size;
  100. unsigned cl_arg_free;
  101. void (*callback_func)(void *);
  102. void *callback_arg;
  103. unsigned use_tag;
  104. starpu_tag_t tag_id;
  105. unsigned sequential_consistency;
  106. unsigned synchronous;
  107. int priority;
  108. unsigned execute_on_a_specific_worker;
  109. unsigned workerid;
  110. starpu_task_bundle_t bundle;
  111. int detach;
  112. int destroy;
  113. int regenerate;
  114. enum starpu_task_status status;
  115. struct starpu_profiling_task_info *profiling_info;
  116. double predicted;
  117. double predicted_transfer;
  118. unsigned int mf_skip;
  119. struct starpu_task *prev;
  120. struct starpu_task *next;
  121. void *starpu_private;
  122. int magic;
  123. unsigned sched_ctx;
  124. int hypervisor_tag;
  125. double flops;
  126. unsigned scheduled;
  127. };
  128. #define STARPU_TASK_INITIALIZER \
  129. { \
  130. .cl = NULL, \
  131. .cl_arg = NULL, \
  132. .cl_arg_size = 0, \
  133. .callback_func = NULL, \
  134. .callback_arg = NULL, \
  135. .priority = STARPU_DEFAULT_PRIO, \
  136. .use_tag = 0, \
  137. .synchronous = 0, \
  138. .execute_on_a_specific_worker = 0, \
  139. .bundle = NULL, \
  140. .detach = 1, \
  141. .destroy = 0, \
  142. .regenerate = 0, \
  143. .status = STARPU_TASK_INVALID, \
  144. .profiling_info = NULL, \
  145. .predicted = -1.0, \
  146. .predicted_transfer = -1.0, \
  147. .starpu_private = NULL, \
  148. .magic = 42, \
  149. .sched_ctx = 0, \
  150. .hypervisor_tag = 0, \
  151. .flops = 0.0, \
  152. .scheduled = 0, \
  153. .dyn_handles = NULL, \
  154. .dyn_interfaces = NULL \
  155. }
  156. #define STARPU_TASK_GET_HANDLE(task, i) ((task->dyn_handles) ? task->dyn_handles[i] : task->handles[i])
  157. #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)
  158. #define STARPU_CODELET_GET_MODE(codelet, i) ((codelet->dyn_modes) ? codelet->dyn_modes[i] : codelet->modes[i])
  159. #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)
  160. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  161. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  162. void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  163. int starpu_tag_wait(starpu_tag_t id);
  164. int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  165. void starpu_tag_notify_from_apps(starpu_tag_t id);
  166. void starpu_tag_restart(starpu_tag_t id);
  167. void starpu_tag_remove(starpu_tag_t id);
  168. void starpu_task_init(struct starpu_task *task);
  169. void starpu_task_clean(struct starpu_task *task);
  170. struct starpu_task *starpu_task_create(void);
  171. void starpu_task_destroy(struct starpu_task *task);
  172. int starpu_task_submit(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  173. int starpu_task_submit_to_ctx(struct starpu_task *task, unsigned sched_ctx_id);
  174. int starpu_task_wait(struct starpu_task *task) STARPU_WARN_UNUSED_RESULT;
  175. int starpu_task_wait_for_all(void);
  176. int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx_id);
  177. int starpu_task_wait_for_no_ready(void);
  178. int starpu_task_nready(void);
  179. int starpu_task_nsubmitted(void);
  180. void starpu_codelet_init(struct starpu_codelet *cl);
  181. void starpu_codelet_display_stats(struct starpu_codelet *cl);
  182. struct starpu_task *starpu_task_get_current(void);
  183. void starpu_parallel_task_barrier_init(struct starpu_task* task, int workerid);
  184. struct starpu_task *starpu_task_dup(struct starpu_task *task);
  185. void starpu_task_set_implementation(struct starpu_task *task, unsigned impl);
  186. unsigned starpu_task_get_implementation(struct starpu_task *task);
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif /* __STARPU_TASK_H__ */