starpu-task.h 6.1 KB

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