starpu-task.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. void (*cuda_func)(void **, void *);
  51. void (*core_func)(void **, void *);
  52. uint8_t gordon_func;
  53. /* how many buffers do the codelet takes as argument ? */
  54. unsigned nbuffers;
  55. struct starpu_perfmodel_t *model;
  56. /* statistics collected at runtime: this is filled by StarPU and should
  57. * not be accessed directly (use the starpu_display_codelet_stats
  58. * function instead for instance). */
  59. unsigned long per_worker_stats[STARPU_NMAXWORKERS];
  60. } starpu_codelet;
  61. struct starpu_task {
  62. struct starpu_codelet_t *cl;
  63. /* arguments managed by the DSM */
  64. struct starpu_buffer_descr_t buffers[STARPU_NMAXBUFS];
  65. //starpu_data_interface_t interface[STARPU_NMAXBUFS];
  66. void *interface[STARPU_NMAXBUFS];
  67. /* arguments not managed by the DSM are given as a buffer */
  68. void *cl_arg;
  69. /* in case the argument buffer has to be uploaded explicitely */
  70. size_t cl_arg_size;
  71. /* when the task is done, callback_func(callback_arg) is called */
  72. void (*callback_func)(void *);
  73. void *callback_arg;
  74. unsigned use_tag;
  75. starpu_tag_t tag_id;
  76. /* options for the task execution */
  77. unsigned synchronous; /* if set, a call to push is blocking */
  78. int priority; /* MAX_PRIO = most important
  79. : MIN_PRIO = least important */
  80. /* in case the task has to be executed on a specific worker */
  81. unsigned execute_on_a_specific_worker;
  82. unsigned workerid;
  83. /* If this flag is set, it is not possible to synchronize with the task
  84. * by the means of starpu_wait_task later on. Internal data structures
  85. * are only garanteed to be liberated once starpu_wait_task is called
  86. * if that flag is not set. */
  87. int detach;
  88. /* If that flag is set, the task structure will automatically be
  89. * liberated, either after the execution of the callback if the task is
  90. * detached, or during starpu_task_wait otherwise. If this flag is not
  91. * set, dynamically allocated data structures will not be liberated
  92. * until starpu_task_destroy is called explicitely. Setting this flag
  93. * for a statically allocated task structure will result in undefined
  94. * behaviour. */
  95. int destroy;
  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 = DEFAULT_PRIO, \
  112. .use_tag = 0, \
  113. .synchronous = 0, \
  114. .execute_on_a_specific_worker = 0, \
  115. .detach = 1, \
  116. .destroy = 0, \
  117. .starpu_private = NULL \
  118. };
  119. /*
  120. * handle task dependencies: it is possible to associate a task with a unique
  121. * "tag" and to express dependencies between tasks by the means of those tags
  122. *
  123. * To do so, fill the tag_id field with a tag number (can be arbitrary) and set
  124. * use_tag to 1.
  125. *
  126. * If starpu_tag_declare_deps is called with that tag number, the task will not
  127. * be started until the task which wears the declared dependency tags are
  128. * complete.
  129. */
  130. /*
  131. * WARNING ! use with caution ...
  132. * In case starpu_tag_declare_deps is passed constant arguments, the caller
  133. * must make sure that the constants are casted to starpu_tag_t. Otherwise,
  134. * due to integer sizes and argument passing on the stack, the C compiler
  135. * might consider the tag * 0x200000003 instead of 0x2 and 0x3 when calling:
  136. * "starpu_tag_declare_deps(0x1, 2, 0x2, 0x3)"
  137. * Using starpu_tag_declare_deps_array is a way to avoid this problem.
  138. */
  139. /* make id depend on the list of ids */
  140. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  141. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  142. int starpu_tag_wait(starpu_tag_t id);
  143. int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  144. /* The application can feed a tag explicitely */
  145. void starpu_tag_notify_from_apps(starpu_tag_t id);
  146. /* To release resources, tags should be freed after use */
  147. void starpu_tag_remove(starpu_tag_t id);
  148. void starpu_task_init(struct starpu_task *task);
  149. struct starpu_task *starpu_task_create(void);
  150. void starpu_task_destroy(struct starpu_task *task);
  151. int starpu_submit_task(struct starpu_task *task);
  152. /* This function blocks until the task was executed. It is not possible to
  153. * synchronize with a task more than once. It is not possible to wait
  154. * synchronous or detached tasks.
  155. * Upon successful completion, this function returns 0. Otherwise, -EINVAL
  156. * indicates that the waited task was either synchronous or detached. */
  157. int starpu_wait_task(struct starpu_task *task);
  158. int starpu_wait_all_tasks(void);
  159. void starpu_display_codelet_stats(struct starpu_codelet_t *cl);
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif // __STARPU_TASK_H__