starpu-task.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 USE_CUDA
  22. #include <cuda.h>
  23. #endif
  24. #include <starpu-data.h>
  25. #define CORE ((1ULL)<<1)
  26. #define CUDA ((1ULL)<<3)
  27. #define SPU ((1ULL)<<4)
  28. #define GORDON ((1ULL)<<5)
  29. #define MIN_PRIO (-4)
  30. #define MAX_PRIO 5
  31. #define DEFAULT_PRIO 0
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. typedef uint64_t starpu_tag_t;
  36. /*
  37. * A codelet describes the various function
  38. * that may be called from a worker
  39. */
  40. typedef struct starpu_codelet_t {
  41. /* where can it be performed ? */
  42. uint32_t where;
  43. /* the different implementations of the codelet */
  44. //void (*cuda_func)(starpu_data_interface_t *, void *);
  45. //void (*core_func)(starpu_data_interface_t *, void *);
  46. void (*cuda_func)(void **, void *);
  47. void (*core_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. //starpu_data_interface_t interface[STARPU_NMAXBUFS];
  62. void *interface[STARPU_NMAXBUFS];
  63. /* arguments not managed by the DSM are given as a buffer */
  64. void *cl_arg;
  65. /* in case the argument buffer has to be uploaded explicitely */
  66. size_t cl_arg_size;
  67. /* when the task is done, callback_func(callback_arg) is called */
  68. void (*callback_func)(void *);
  69. void *callback_arg;
  70. unsigned use_tag;
  71. starpu_tag_t tag_id;
  72. /* options for the task execution */
  73. unsigned synchronous; /* if set, a call to push is blocking */
  74. int priority; /* MAX_PRIO = most important
  75. : MIN_PRIO = least important */
  76. /* in case the task has to be executed on a specific worker */
  77. unsigned execute_on_a_specific_worker;
  78. unsigned workerid;
  79. /* If this flag is set, it is not possible to synchronize with the task
  80. * by the means of starpu_wait_task later on. Internal data structures
  81. * are only garanteed to be liberated once starpu_wait_task is called
  82. * if that flag is not set. */
  83. int detach;
  84. /* If that flag is set, the task structure will automatically be
  85. * liberated, either after the execution of the callback if the task is
  86. * detached, or during starpu_task_wait otherwise. If this flag is not
  87. * set, dynamically allocated data structures will not be liberated
  88. * until starpu_task_destroy is called explicitely. Setting this flag
  89. * for a statically allocated task structure will result in undefined
  90. * behaviour. */
  91. int destroy;
  92. /* this is private to StarPU, do not modify. If the task is allocated
  93. * by hand (without starpu_task_create), this field should be set to
  94. * NULL. */
  95. void *starpu_private;
  96. };
  97. /* It is possible to initialize statically allocated tasks with this value.
  98. * This is equivalent to initializing a starpu_task structure with the
  99. * starpu_task_init function. */
  100. #define STARPU_TASK_INITIALIZER \
  101. { \
  102. .cl = NULL, \
  103. .cl_arg = NULL, \
  104. .cl_arg_size = 0, \
  105. .callback_func = NULL, \
  106. .callback_arg = NULL, \
  107. .priority = DEFAULT_PRIO, \
  108. .use_tag = 0, \
  109. .synchronous = 0, \
  110. .execute_on_a_specific_worker = 0, \
  111. .detach = 1, \
  112. .destroy = 0, \
  113. .starpu_private = NULL \
  114. };
  115. /*
  116. * handle task dependencies: it is possible to associate a task with a unique
  117. * "tag" and to express dependencies between tasks by the means of those tags
  118. *
  119. * To do so, fill the tag_id field with a tag number (can be arbitrary) and set
  120. * use_tag to 1.
  121. *
  122. * If starpu_tag_declare_deps is called with that tag number, the task will not
  123. * be started until the task which wears the declared dependency tags are
  124. * complete.
  125. */
  126. /*
  127. * WARNING ! use with caution ...
  128. * In case starpu_tag_declare_deps is passed constant arguments, the caller
  129. * must make sure that the constants are casted to starpu_tag_t. Otherwise,
  130. * due to integer sizes and argument passing on the stack, the C compiler
  131. * might consider the tag * 0x200000003 instead of 0x2 and 0x3 when calling:
  132. * "starpu_tag_declare_deps(0x1, 2, 0x2, 0x3)"
  133. * Using starpu_tag_declare_deps_array is a way to avoid this problem.
  134. */
  135. /* make id depend on the list of ids */
  136. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  137. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  138. int starpu_tag_wait(starpu_tag_t id);
  139. int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  140. /* The application can feed a tag explicitely */
  141. void starpu_tag_notify_from_apps(starpu_tag_t id);
  142. /* To release resources, tags should be freed after use */
  143. void starpu_tag_remove(starpu_tag_t id);
  144. /* Initialize a task structure with default values. */
  145. void starpu_task_init(struct starpu_task *task);
  146. /* Allocate a task structure and initialize it with default values. Tasks
  147. * allocated dynamically with starpu_task_create are automatically liberated
  148. * when the task is terminated. If the destroy flag is explicitely unset, the
  149. * ressources used by the task are liberated by calling starpu_task_destroy.
  150. * */
  151. struct starpu_task *starpu_task_create(void);
  152. /* Liberate the ressource allocated during starpu_task_create. This function
  153. * can be called automatically after the execution of a task by setting the
  154. * "destroy" flag of the starpu_task structure (default behaviour). Calling
  155. * this function on a statically allocated task results in an undefined
  156. * behaviour. */
  157. void starpu_task_destroy(struct starpu_task *task);
  158. int starpu_submit_task(struct starpu_task *task);
  159. /* This function blocks until the task was executed. It is not possible to
  160. * synchronize with a task more than once. It is not possible to wait
  161. * synchronous or detached tasks.
  162. * Upon successful completion, this function returns 0. Otherwise, -EINVAL
  163. * indicates that the waited task was either synchronous or detached. */
  164. int starpu_wait_task(struct starpu_task *task);
  165. /* This function waits until all the tasks that were already submitted have
  166. * been executed. */
  167. int starpu_wait_all_tasks(void);
  168. void starpu_display_codelet_stats(struct starpu_codelet_t *cl);
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif // __STARPU_TASK_H__