starpu_task.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __STARPU_TASK_H__
  17. #define __STARPU_TASK_H__
  18. #include <errno.h>
  19. #include <starpu_config.h>
  20. #include <starpu.h>
  21. #ifdef STARPU_USE_CUDA
  22. #include <cuda.h>
  23. #endif
  24. #include <starpu_data.h>
  25. #define STARPU_CPU ((1ULL)<<1)
  26. #define STARPU_CUDA ((1ULL)<<3)
  27. #define STARPU_SPU ((1ULL)<<4)
  28. #define STARPU_GORDON ((1ULL)<<5)
  29. #define STARPU_OPENCL ((1ULL)<<6)
  30. #define STARPU_MIN_PRIO (-4)
  31. #define STARPU_MAX_PRIO 5
  32. #define STARPU_DEFAULT_PRIO 0
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. typedef uint64_t starpu_tag_t;
  37. /*
  38. * A codelet describes the various function
  39. * that may be called from a worker
  40. */
  41. typedef struct starpu_codelet_t {
  42. /* where can it be performed ? */
  43. uint32_t where;
  44. /* the different implementations of the codelet */
  45. void (*cuda_func)(void **, void *);
  46. void (*cpu_func)(void **, void *);
  47. void (*opencl_func)(void **, void *);
  48. uint8_t gordon_func;
  49. /* how many buffers do the codelet takes as argument ? */
  50. unsigned nbuffers;
  51. struct starpu_perfmodel_t *model;
  52. /* statistics collected at runtime: this is filled by StarPU and should
  53. * not be accessed directly (use the starpu_display_codelet_stats
  54. * function instead for instance). */
  55. unsigned long per_worker_stats[STARPU_NMAXWORKERS];
  56. } starpu_codelet;
  57. struct starpu_task {
  58. struct starpu_codelet_t *cl;
  59. /* arguments managed by the DSM */
  60. struct starpu_buffer_descr_t buffers[STARPU_NMAXBUFS];
  61. void *interface[STARPU_NMAXBUFS];
  62. /* arguments not managed by the DSM are given as a buffer */
  63. void *cl_arg;
  64. /* in case the argument buffer has to be uploaded explicitely */
  65. size_t cl_arg_size;
  66. /* when the task is done, callback_func(callback_arg) is called */
  67. void (*callback_func)(void *);
  68. void *callback_arg;
  69. unsigned use_tag;
  70. starpu_tag_t tag_id;
  71. /* options for the task execution */
  72. unsigned synchronous; /* if set, a call to push is blocking */
  73. int priority; /* STARPU_MAX_PRIO = most important
  74. : STARPU_MIN_PRIO = least important */
  75. /* in case the task has to be executed on a specific worker */
  76. unsigned execute_on_a_specific_worker;
  77. unsigned workerid;
  78. /* If this flag is set, it is not possible to synchronize with the task
  79. * by the means of starpu_task_wait later on. Internal data structures
  80. * are only garanteed to be freed once starpu_task_wait is called if
  81. * that flag is not set. */
  82. int detach;
  83. /* If that flag is set, the task structure will automatically be freed,
  84. * either after the execution of the callback if the task is detached,
  85. * or during starpu_task_wait otherwise. If this flag is not set,
  86. * dynamically allocated data structures will not be freed until
  87. * starpu_task_destroy is called explicitely. Setting this flag for a
  88. * statically allocated task structure will result in undefined
  89. * behaviour. */
  90. int destroy;
  91. /* If this flag is set, the task will be re-submitted to StarPU once it
  92. * has been executed. This flag must not be set if the destroy flag is
  93. * set too. */
  94. int regenerate;
  95. struct starpu_task_profiling_info *profiling_info;
  96. /* this is private to StarPU, do not modify. If the task is allocated
  97. * by hand (without starpu_task_create), this field should be set to
  98. * NULL. */
  99. void *starpu_private;
  100. };
  101. /* It is possible to initialize statically allocated tasks with this value.
  102. * This is equivalent to initializing a starpu_task structure with the
  103. * starpu_task_init function. */
  104. #define STARPU_TASK_INITIALIZER \
  105. { \
  106. .cl = NULL, \
  107. .cl_arg = NULL, \
  108. .cl_arg_size = 0, \
  109. .callback_func = NULL, \
  110. .callback_arg = NULL, \
  111. .priority = STARPU_DEFAULT_PRIO, \
  112. .use_tag = 0, \
  113. .synchronous = 0, \
  114. .execute_on_a_specific_worker = 0, \
  115. .detach = 1, \
  116. .destroy = 0, \
  117. .regenerate = 0, \
  118. .profiling_info = NULL, \
  119. .starpu_private = NULL \
  120. };
  121. /*
  122. * handle task dependencies: it is possible to associate a task with a unique
  123. * "tag" and to express dependencies between tasks by the means of those tags
  124. *
  125. * To do so, fill the tag_id field with a tag number (can be arbitrary) and set
  126. * use_tag to 1.
  127. *
  128. * If starpu_tag_declare_deps is called with that tag number, the task will not
  129. * be started until the task which wears the declared dependency tags are
  130. * complete.
  131. */
  132. /*
  133. * WARNING ! use with caution ...
  134. * In case starpu_tag_declare_deps is passed constant arguments, the caller
  135. * must make sure that the constants are casted to starpu_tag_t. Otherwise,
  136. * due to integer sizes and argument passing on the stack, the C compiler
  137. * might consider the tag * 0x200000003 instead of 0x2 and 0x3 when calling:
  138. * "starpu_tag_declare_deps(0x1, 2, 0x2, 0x3)"
  139. * Using starpu_tag_declare_deps_array is a way to avoid this problem.
  140. */
  141. /* make id depend on the list of ids */
  142. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  143. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  144. /* task depends on the tasks in task array */
  145. void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
  146. int starpu_tag_wait(starpu_tag_t id);
  147. int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  148. /* The application can feed a tag explicitely */
  149. void starpu_tag_notify_from_apps(starpu_tag_t id);
  150. /* To release resources, tags should be freed after use */
  151. void starpu_tag_remove(starpu_tag_t id);
  152. /* Initialize a task structure with default values. */
  153. void starpu_task_init(struct starpu_task *task);
  154. /* Release all the structures automatically allocated to execute the task. This
  155. * is called implicitely by starpu_task_destroy, but the task structure itself
  156. * is not freed. This should be used for statically allocated tasks for
  157. * instance. */
  158. void starpu_task_deinit(struct starpu_task *task);
  159. /* Allocate a task structure and initialize it with default values. Tasks
  160. * allocated dynamically with starpu_task_create are automatically freed when
  161. * the task is terminated. If the destroy flag is explicitely unset, the
  162. * ressources used by the task are freed by calling starpu_task_destroy.
  163. * */
  164. struct starpu_task *starpu_task_create(void);
  165. /* Free the ressource allocated during the execution of the task and deallocate
  166. * the task structure itself. This function can be called automatically after
  167. * the execution of a task by setting the "destroy" flag of the starpu_task
  168. * structure (default behaviour). Calling this function on a statically
  169. * allocated task results in an undefined behaviour. */
  170. void starpu_task_destroy(struct starpu_task *task);
  171. int starpu_task_submit(struct starpu_task *task);
  172. /* This function blocks until the task was executed. It is not possible to
  173. * synchronize with a task more than once. It is not possible to wait
  174. * synchronous or detached tasks.
  175. * Upon successful completion, this function returns 0. Otherwise, -EINVAL
  176. * indicates that the waited task was either synchronous or detached. */
  177. int starpu_task_wait(struct starpu_task *task);
  178. /* This function waits until all the tasks that were already submitted have
  179. * been executed. */
  180. int starpu_task_wait_for_all(void);
  181. void starpu_display_codelet_stats(struct starpu_codelet_t *cl);
  182. /* Return the task currently executed by the worker, or NULL if this is called
  183. * either from a thread that is not a task or simply because there is no task
  184. * being executed at the moment. */
  185. struct starpu_task *starpu_get_current_task(void);
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif // __STARPU_TASK_H__