starpu-task.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. /* this is a randomly choosen value ... */
  21. #ifndef MAXCUDADEVS
  22. #define MAXCUDADEVS 4
  23. #endif
  24. #ifdef USE_CUDA
  25. #include <cuda.h>
  26. #endif
  27. #include <starpu-data.h>
  28. #define ANY (~0)
  29. #define CORE ((1ULL)<<1)
  30. #define CUBLAS ((1ULL)<<2)
  31. #define CUDA ((1ULL)<<3)
  32. #define SPU ((1ULL)<<4)
  33. #define GORDON ((1ULL)<<5)
  34. #define MIN_PRIO (-4)
  35. #define MAX_PRIO 5
  36. #define DEFAULT_PRIO 0
  37. typedef uint64_t starpu_tag_t;
  38. /*
  39. * A codelet describes the various function
  40. * that may be called from a worker
  41. */
  42. typedef struct starpu_codelet_t {
  43. /* where can it be performed ? */
  44. uint32_t where;
  45. /* the different implementations of the codelet */
  46. void *cuda_func;
  47. void *cublas_func;
  48. void *core_func;
  49. void *spu_func;
  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. } starpu_codelet;
  55. struct starpu_task {
  56. struct starpu_codelet_t *cl;
  57. /* arguments managed by the DSM */
  58. struct starpu_buffer_descr_t buffers[NMAXBUFS];
  59. starpu_data_interface_t interface[NMAXBUFS];
  60. /* arguments not managed by the DSM are given as a buffer */
  61. void *cl_arg;
  62. /* in case the argument buffer has to be uploaded explicitely */
  63. size_t cl_arg_size;
  64. /* when the task is done, callback_func(callback_arg) is called */
  65. void (*callback_func)(void *);
  66. void *callback_arg;
  67. unsigned use_tag;
  68. starpu_tag_t tag_id;
  69. /* options for the task execution */
  70. unsigned synchronous; /* if set, a call to push is blocking */
  71. int priority; /* MAX_PRIO = most important
  72. : MIN_PRIO = least important */
  73. /* should the task be automatically liberated once executed ? */
  74. int cleanup;
  75. /* this is private to StarPU, do not modify */
  76. void *starpu_private;
  77. };
  78. #ifdef USE_CUDA
  79. /* CUDA specific codelets */
  80. typedef struct starpu_cuda_module_s {
  81. CUmodule module;
  82. char *module_path;
  83. unsigned is_loaded[MAXCUDADEVS];
  84. } starpu_cuda_module_t;
  85. typedef struct starpu_cuda_function_s {
  86. struct starpu_cuda_module_s *module;
  87. CUfunction function;
  88. char *symbol;
  89. unsigned is_loaded[MAXCUDADEVS];
  90. } starpu_cuda_function_t;
  91. typedef struct starpu_cuda_codelet_s {
  92. /* which function to execute on the card ? */
  93. struct starpu_cuda_function_s *func;
  94. /* grid and block shapes */
  95. unsigned gridx;
  96. unsigned gridy;
  97. unsigned blockx;
  98. unsigned blocky;
  99. unsigned shmemsize;
  100. void *stack; /* arguments */
  101. size_t stack_size;
  102. } starpu_cuda_codelet_t;
  103. void starpu_init_cuda_module(struct starpu_cuda_module_s *module, char *path);
  104. void starpu_load_cuda_module(int devid, struct starpu_cuda_module_s *module);
  105. void starpu_init_cuda_function(struct starpu_cuda_function_s *func,
  106. struct starpu_cuda_module_s *module,
  107. char *symbol);
  108. void starpu_load_cuda_function(int devid, struct starpu_cuda_function_s *function);
  109. #endif // USE_CUDA
  110. /* handle task dependencies: it is possible to associate a task with a unique
  111. * "tag" and to express dependencies among tasks by the means of those tags */
  112. void starpu_tag_remove(starpu_tag_t id);
  113. /*
  114. * WARNING ! use with caution ...
  115. * In case starpu_tag_declare_deps is passed constant arguments, the caller
  116. * must make sure that the constants have the same size as starpu_tag_t.
  117. * Otherwise, nothing prevents the C compiler to consider the tag 0x20000003
  118. * instead of 0x2 and 0x3 when calling:
  119. * "starpu_tag_declare_deps(0x1, 2, 0x2, 0x3)"
  120. * Using starpu_tag_declare_deps_array is a way to avoid this problem.
  121. */
  122. void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
  123. void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
  124. void starpu_tag_wait(starpu_tag_t id);
  125. void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
  126. struct starpu_task *starpu_task_create(void);
  127. int starpu_submit_task(struct starpu_task *task);
  128. #endif // __STARPU_TASK_H__