starpu_data_interfaces.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __STARPU_DATA_INTERFACES_H__
  18. #define __STARPU_DATA_INTERFACES_H__
  19. #include <starpu.h>
  20. #include <starpu_data.h>
  21. #ifdef STARPU_USE_GORDON
  22. /* to get the gordon_strideSize_t data structure from gordon */
  23. #include <gordon.h>
  24. #endif
  25. #ifdef STARPU_USE_CUDA
  26. /* to use CUDA streams */
  27. #include <cuda_runtime.h>
  28. #endif
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* The following structures are used to describe data interfaces */
  33. /* This structure contains the different methods to transfer data between the
  34. * different types of memory nodes */
  35. struct starpu_data_copy_methods {
  36. /* src type is ram */
  37. int (*ram_to_ram)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  38. int (*ram_to_cuda)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  39. int (*ram_to_opencl)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  40. int (*ram_to_spu)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  41. /* src type is cuda */
  42. int (*cuda_to_ram)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  43. int (*cuda_to_cuda)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  44. int (*cuda_to_opencl)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  45. int (*cuda_to_spu)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  46. /* src type is spu */
  47. int (*spu_to_ram)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  48. int (*spu_to_cuda)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  49. int (*spu_to_opencl)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  50. int (*spu_to_spu)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  51. /* src type is opencl */
  52. int (*opencl_to_ram)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  53. int (*opencl_to_cuda)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  54. int (*opencl_to_opencl)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  55. int (*opencl_to_spu)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  56. #ifdef STARPU_USE_CUDA
  57. /* for asynchronous CUDA transfers */
  58. int (*ram_to_cuda_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  59. int (*cuda_to_ram_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  60. int (*cuda_to_cuda_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  61. #endif
  62. #ifdef STARPU_USE_OPENCL
  63. /* for asynchronous OpenCL transfers */
  64. /* XXX we do not use a cl_event *event type for the last argument
  65. * because nvcc does not like when we have to include OpenCL headers */
  66. int (*ram_to_opencl_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, /* cl_event * */ void *event);
  67. int (*opencl_to_ram_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, /* cl_event * */ void *event);
  68. int (*opencl_to_opencl_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, /* cl_event * */ void *event);
  69. #endif
  70. };
  71. struct starpu_data_interface_ops_t {
  72. void (*register_data_handle)(starpu_data_handle handle,
  73. uint32_t home_node, void *interface);
  74. ssize_t (*allocate_data_on_node)(void *interface, uint32_t node);
  75. void (*free_data_on_node)(void *interface, uint32_t node);
  76. const struct starpu_data_copy_methods *copy_methods;
  77. size_t (*get_size)(starpu_data_handle handle);
  78. uint32_t (*footprint)(starpu_data_handle handle);
  79. int (*compare)(void *interface_a, void *interface_b);
  80. void (*display)(starpu_data_handle handle, FILE *f);
  81. #ifdef STARPU_USE_GORDON
  82. int (*convert_to_gordon)(void *interface, uint64_t *ptr, gordon_strideSize_t *ss);
  83. #endif
  84. /* an identifier that is unique to each interface */
  85. unsigned interfaceid;
  86. size_t interface_size;
  87. };
  88. void starpu_data_register(starpu_data_handle *handleptr, uint32_t home_node,
  89. void *interface,
  90. struct starpu_data_interface_ops_t *ops);
  91. extern struct starpu_data_interface_ops_t _starpu_interface_matrix_ops;
  92. /* "node" means memory node: 0 for main RAM, then 1, 2, etc. for various GPUs,
  93. * etc.
  94. *
  95. * On registration, the source of data is usually a pointer in RAM, in which
  96. * case 0 should be passed.
  97. */
  98. void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memory_node);
  99. /* Matrix interface for dense matrices */
  100. typedef struct starpu_matrix_interface_s {
  101. uintptr_t ptr;
  102. uintptr_t dev_handle;
  103. size_t offset;
  104. uint32_t nx;
  105. uint32_t ny;
  106. uint32_t ld;
  107. size_t elemsize;
  108. } starpu_matrix_interface_t;
  109. void starpu_matrix_data_register(starpu_data_handle *handle, uint32_t home_node,
  110. uintptr_t ptr, uint32_t ld, uint32_t nx,
  111. uint32_t ny, size_t elemsize);
  112. uint32_t starpu_matrix_get_nx(starpu_data_handle handle);
  113. uint32_t starpu_matrix_get_ny(starpu_data_handle handle);
  114. uint32_t starpu_matrix_get_local_ld(starpu_data_handle handle);
  115. uintptr_t starpu_matrix_get_local_ptr(starpu_data_handle handle);
  116. size_t starpu_matrix_get_elemsize(starpu_data_handle handle);
  117. /* helper methods */
  118. #define STARPU_MATRIX_GET_PTR(interface) (((starpu_matrix_interface_t *)(interface))->ptr)
  119. #define STARPU_MATRIX_GET_NX(interface) (((starpu_matrix_interface_t *)(interface))->nx)
  120. #define STARPU_MATRIX_GET_NY(interface) (((starpu_matrix_interface_t *)(interface))->ny)
  121. #define STARPU_MATRIX_GET_LD(interface) (((starpu_matrix_interface_t *)(interface))->ld)
  122. #define STARPU_MATRIX_GET_ELEMSIZE(interface) (((starpu_matrix_interface_t *)(interface))->elemsize)
  123. /* BLOCK interface for 3D dense blocks */
  124. /* TODO: rename to 3dmatrix? */
  125. typedef struct starpu_block_interface_s {
  126. uintptr_t ptr;
  127. uintptr_t dev_handle;
  128. size_t offset;
  129. uint32_t nx;
  130. uint32_t ny;
  131. uint32_t nz;
  132. uint32_t ldy; /* number of elements between two lines */
  133. uint32_t ldz; /* number of elements between two planes */
  134. size_t elemsize;
  135. } starpu_block_interface_t;
  136. void starpu_block_data_register(starpu_data_handle *handle, uint32_t home_node,
  137. uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
  138. uint32_t ny, uint32_t nz, size_t elemsize);
  139. uint32_t starpu_block_get_nx(starpu_data_handle handle);
  140. uint32_t starpu_block_get_ny(starpu_data_handle handle);
  141. uint32_t starpu_block_get_nz(starpu_data_handle handle);
  142. uint32_t starpu_block_get_local_ldy(starpu_data_handle handle);
  143. uint32_t starpu_block_get_local_ldz(starpu_data_handle handle);
  144. uintptr_t starpu_block_get_local_ptr(starpu_data_handle handle);
  145. size_t starpu_block_get_elemsize(starpu_data_handle handle);
  146. /* helper methods */
  147. #define STARPU_BLOCK_GET_PTR(interface) (((starpu_block_interface_t *)(interface))->ptr)
  148. #define STARPU_BLOCK_GET_NX(interface) (((starpu_block_interface_t *)(interface))->nx)
  149. #define STARPU_BLOCK_GET_NY(interface) (((starpu_block_interface_t *)(interface))->ny)
  150. #define STARPU_BLOCK_GET_NZ(interface) (((starpu_block_interface_t *)(interface))->nz)
  151. #define STARPU_BLOCK_GET_LDY(interface) (((starpu_block_interface_t *)(interface))->ldy)
  152. #define STARPU_BLOCK_GET_LDZ(interface) (((starpu_block_interface_t *)(interface))->ldz)
  153. #define STARPU_BLOCK_GET_ELEMSIZE(interface) (((starpu_block_interface_t *)(interface))->elemsize)
  154. /* vector interface for contiguous (non-strided) buffers */
  155. typedef struct starpu_vector_interface_s {
  156. uintptr_t ptr;
  157. uintptr_t dev_handle;
  158. size_t offset;
  159. uint32_t nx;
  160. size_t elemsize;
  161. } starpu_vector_interface_t;
  162. void starpu_vector_data_register(starpu_data_handle *handle, uint32_t home_node,
  163. uintptr_t ptr, uint32_t nx, size_t elemsize);
  164. uint32_t starpu_vector_get_nx(starpu_data_handle handle);
  165. size_t starpu_vector_get_elemsize(starpu_data_handle handle);
  166. uintptr_t starpu_vector_get_local_ptr(starpu_data_handle handle);
  167. /* helper methods */
  168. #define STARPU_VECTOR_GET_PTR(interface) (((starpu_vector_interface_t *)(interface))->ptr)
  169. #define STARPU_VECTOR_GET_NX(interface) (((starpu_vector_interface_t *)(interface))->nx)
  170. #define STARPU_VECTOR_GET_ELEMSIZE(interface) (((starpu_vector_interface_t *)(interface))->elemsize)
  171. /* variable interface for a single data (not a vector, a matrix, a list, ...) */
  172. typedef struct starpu_variable_interface_s {
  173. uintptr_t ptr;
  174. size_t elemsize;
  175. } starpu_variable_interface_t;
  176. void starpu_variable_data_register(starpu_data_handle *handle, uint32_t home_node,
  177. uintptr_t ptr, size_t elemsize);
  178. size_t starpu_variable_get_elemsize(starpu_data_handle handle);
  179. uintptr_t starpu_variable_get_local_ptr(starpu_data_handle handle);
  180. /* helper methods */
  181. #define STARPU_VARIABLE_GET_PTR(interface) (((starpu_variable_interface_t *)(interface))->ptr)
  182. #define STARPU_VARIABLE_GET_ELEMSIZE(interface) (((starpu_variable_interface_t *)(interface))->elemsize)
  183. /* void interface. There is no data really associated to that interface, but it
  184. * may be used as a synchronization mechanism. It also permits to express an
  185. * abstract piece of data that is managed by the application internally: this
  186. * makes it possible to forbid the concurrent execution of different tasks
  187. * accessing the same "void" data in read-write concurrently. */
  188. void starpu_void_data_register(starpu_data_handle *handleptr);
  189. /* CSR interface for sparse matrices (compressed sparse row representation) */
  190. typedef struct starpu_csr_interface_s {
  191. uint32_t nnz; /* number of non-zero entries */
  192. uint32_t nrow; /* number of rows */
  193. uintptr_t nzval; /* non-zero values */
  194. uint32_t *colind; /* position of non-zero entried on the row */
  195. uint32_t *rowptr; /* index (in nzval) of the first entry of the row */
  196. /* k for k-based indexing (0 or 1 usually) */
  197. /* also useful when partitionning the matrix ... */
  198. uint32_t firstentry;
  199. size_t elemsize;
  200. } starpu_csr_interface_t;
  201. void starpu_csr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  202. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);
  203. uint32_t starpu_csr_get_nnz(starpu_data_handle handle);
  204. uint32_t starpu_csr_get_nrow(starpu_data_handle handle);
  205. uint32_t starpu_csr_get_firstentry(starpu_data_handle handle);
  206. uintptr_t starpu_csr_get_local_nzval(starpu_data_handle handle);
  207. uint32_t *starpu_csr_get_local_colind(starpu_data_handle handle);
  208. uint32_t *starpu_csr_get_local_rowptr(starpu_data_handle handle);
  209. size_t starpu_csr_get_elemsize(starpu_data_handle handle);
  210. #define STARPU_CSR_GET_NNZ(interface) (((starpu_csr_interface_t *)(interface))->nnz)
  211. #define STARPU_CSR_GET_NROW(interface) (((starpu_csr_interface_t *)(interface))->nrow)
  212. #define STARPU_CSR_GET_NZVAL(interface) (((starpu_csr_interface_t *)(interface))->nzval)
  213. #define STARPU_CSR_GET_COLIND(interface) (((starpu_csr_interface_t *)(interface))->colind)
  214. #define STARPU_CSR_GET_ROWPTR(interface) (((starpu_csr_interface_t *)(interface))->rowptr)
  215. #define STARPU_CSR_GET_FIRSTENTRY(interface) (((starpu_csr_interface_t *)(interface))->firstentry)
  216. #define STARPU_CSR_GET_ELEMSIZE(interface) (((starpu_csr_interface_t *)(interface))->elemsize)
  217. /* BCSR interface for sparse matrices (blocked compressed sparse row
  218. * representation) */
  219. typedef struct starpu_bcsr_interface_s {
  220. uint32_t nnz; /* number of non-zero BLOCKS */
  221. uint32_t nrow; /* number of rows (in terms of BLOCKS) */
  222. uintptr_t nzval; /* non-zero values */
  223. uint32_t *colind; /* position of non-zero entried on the row */
  224. // uint32_t *rowind; /* position of non-zero entried on the col */
  225. uint32_t *rowptr; /* index (in nzval) of the first entry of the row */
  226. /* k for k-based indexing (0 or 1 usually) */
  227. /* also useful when partitionning the matrix ... */
  228. uint32_t firstentry;
  229. /* size of the blocks */
  230. uint32_t r;
  231. uint32_t c;
  232. size_t elemsize;
  233. } starpu_bcsr_interface_t;
  234. void starpu_bcsr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  235. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);
  236. uint32_t starpu_bcsr_get_nnz(starpu_data_handle);
  237. uint32_t starpu_bcsr_get_nrow(starpu_data_handle);
  238. uint32_t starpu_bcsr_get_firstentry(starpu_data_handle);
  239. uintptr_t starpu_bcsr_get_local_nzval(starpu_data_handle);
  240. uint32_t *starpu_bcsr_get_local_colind(starpu_data_handle);
  241. uint32_t *starpu_bcsr_get_local_rowptr(starpu_data_handle);
  242. uint32_t starpu_bcsr_get_r(starpu_data_handle);
  243. uint32_t starpu_bcsr_get_c(starpu_data_handle);
  244. size_t starpu_bcsr_get_elemsize(starpu_data_handle);
  245. #define STARPU_MATRIX_INTERFACE_ID 0
  246. #define STARPU_BLOCK_INTERFACE_ID 1
  247. #define STARPU_VECTOR_INTERFACE_ID 2
  248. #define STARPU_CSR_INTERFACE_ID 3
  249. #define STARPU_BCSR_INTERFACE_ID 4
  250. #define STARPU_VARIABLE_INTERFACE_ID 5
  251. #define STARPU_VOID_INTERFACE_ID 6
  252. #define STARPU_NINTERFACES_ID 7 /* number of data interfaces */
  253. unsigned starpu_get_handle_interface_id(starpu_data_handle);
  254. #ifdef __cplusplus
  255. }
  256. #endif
  257. #endif // __STARPU_DATA_INTERFACES_H__