starpu_data_interfaces.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2010 (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_DATA_INTERFACES_H__
  17. #define __STARPU_DATA_INTERFACES_H__
  18. #include <starpu.h>
  19. #include <starpu_data.h>
  20. #include <starpu_opencl.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)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  38. int (*ram_to_cuda)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  39. int (*ram_to_opencl)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  40. int (*ram_to_spu)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  41. /* src type is cuda */
  42. int (*cuda_to_ram)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  43. int (*cuda_to_cuda)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  44. int (*cuda_to_opencl)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  45. int (*cuda_to_spu)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  46. /* src type is spu */
  47. int (*spu_to_ram)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  48. int (*spu_to_cuda)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  49. int (*spu_to_opencl)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  50. int (*spu_to_spu)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  51. /* src type is opencl */
  52. int (*opencl_to_ram)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  53. int (*opencl_to_cuda)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  54. int (*opencl_to_opencl)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  55. int (*opencl_to_spu)(starpu_data_handle handle, uint32_t src, uint32_t dst);
  56. #ifdef STARPU_USE_CUDA
  57. /* for asynchronous CUDA transfers */
  58. int (*ram_to_cuda_async)(starpu_data_handle handle, uint32_t src,
  59. uint32_t dst, cudaStream_t *stream);
  60. int (*cuda_to_ram_async)(starpu_data_handle handle, uint32_t src,
  61. uint32_t dst, cudaStream_t *stream);
  62. int (*cuda_to_cuda_async)(starpu_data_handle handle, uint32_t src,
  63. uint32_t dst, cudaStream_t *stream);
  64. #endif
  65. #ifdef STARPU_USE_OPENCL
  66. /* for asynchronous OpenCL transfers */
  67. int (*ram_to_opencl_async)(starpu_data_handle handle, uint32_t src, uint32_t dst, cl_event *event);
  68. int (*opencl_to_ram_async)(starpu_data_handle handle, uint32_t src, uint32_t dst, cl_event *event);
  69. int (*opencl_to_opencl_async)(starpu_data_handle handle, uint32_t src, uint32_t dst, cl_event *event);
  70. #endif
  71. };
  72. struct starpu_data_interface_ops_t {
  73. void (*register_data_handle)(starpu_data_handle handle,
  74. uint32_t home_node, void *interface);
  75. size_t (*allocate_data_on_node)(void *interface, uint32_t node);
  76. void (*free_data_on_node)(void *interface, uint32_t node);
  77. const struct starpu_data_copy_methods *copy_methods;
  78. size_t (*get_size)(starpu_data_handle handle);
  79. uint32_t (*footprint)(starpu_data_handle handle);
  80. int (*compare)(void *interface_a, void *interface_b);
  81. void (*display)(starpu_data_handle handle, FILE *f);
  82. #ifdef STARPU_USE_GORDON
  83. int (*convert_to_gordon)(void *interface, uint64_t *ptr, gordon_strideSize_t *ss);
  84. #endif
  85. /* an identifier that is unique to each interface */
  86. unsigned interfaceid;
  87. size_t interface_size;
  88. };
  89. void starpu_data_register(starpu_data_handle *handleptr, uint32_t home_node,
  90. void *interface,
  91. struct starpu_data_interface_ops_t *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_GET_MATRIX_PTR(interface) (((starpu_matrix_interface_t *)(interface))->ptr)
  119. #define STARPU_GET_MATRIX_NX(interface) (((starpu_matrix_interface_t *)(interface))->nx)
  120. #define STARPU_GET_MATRIX_NY(interface) (((starpu_matrix_interface_t *)(interface))->ny)
  121. #define STARPU_GET_MATRIX_LD(interface) (((starpu_matrix_interface_t *)(interface))->ld)
  122. #define STARPU_GET_MATRIX_ELEMSIZE(interface) (((starpu_matrix_interface_t *)(interface))->elemsize)
  123. /* BLOCK interface for 3D dense blocks */
  124. typedef struct starpu_block_interface_s {
  125. uintptr_t ptr;
  126. uintptr_t dev_handle;
  127. size_t offset;
  128. uint32_t nx;
  129. uint32_t ny;
  130. uint32_t nz;
  131. uint32_t ldy; /* number of elements between two lines */
  132. uint32_t ldz; /* number of elements between two planes */
  133. size_t elemsize;
  134. } starpu_block_interface_t;
  135. void starpu_block_data_register(starpu_data_handle *handle, uint32_t home_node,
  136. uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
  137. uint32_t ny, uint32_t nz, size_t elemsize);
  138. uint32_t starpu_block_get_nx(starpu_data_handle handle);
  139. uint32_t starpu_block_get_ny(starpu_data_handle handle);
  140. uint32_t starpu_block_get_nz(starpu_data_handle handle);
  141. uint32_t starpu_block_get_local_ldy(starpu_data_handle handle);
  142. uint32_t starpu_block_get_local_ldz(starpu_data_handle handle);
  143. uintptr_t starpu_block_get_local_ptr(starpu_data_handle handle);
  144. size_t starpu_block_get_elemsize(starpu_data_handle handle);
  145. /* helper methods */
  146. #define STARPU_GET_BLOCK_PTR(interface) (((starpu_block_interface_t *)(interface))->ptr)
  147. #define STARPU_GET_BLOCK_NX(interface) (((starpu_block_interface_t *)(interface))->nx)
  148. #define STARPU_GET_BLOCK_NY(interface) (((starpu_block_interface_t *)(interface))->ny)
  149. #define STARPU_GET_BLOCK_NZ(interface) (((starpu_block_interface_t *)(interface))->nz)
  150. #define STARPU_GET_BLOCK_LDY(interface) (((starpu_block_interface_t *)(interface))->ldy)
  151. #define STARPU_GET_BLOCK_LDZ(interface) (((starpu_block_interface_t *)(interface))->ldz)
  152. #define STARPU_GET_BLOCK_ELEMSIZE(interface) (((starpu_block_interface_t *)(interface))->elemsize)
  153. /* vector interface for contiguous (non-strided) buffers */
  154. typedef struct starpu_vector_interface_s {
  155. uintptr_t ptr;
  156. uintptr_t dev_handle;
  157. size_t offset;
  158. uint32_t nx;
  159. size_t elemsize;
  160. } starpu_vector_interface_t;
  161. void starpu_vector_data_register(starpu_data_handle *handle, uint32_t home_node,
  162. uintptr_t ptr, uint32_t nx, size_t elemsize);
  163. uint32_t starpu_vector_get_nx(starpu_data_handle handle);
  164. size_t starpu_vector_get_elemsize(starpu_data_handle handle);
  165. uintptr_t starpu_vector_get_local_ptr(starpu_data_handle handle);
  166. /* helper methods */
  167. #define STARPU_GET_VECTOR_PTR(interface) (((starpu_vector_interface_t *)(interface))->ptr)
  168. #define STARPU_GET_VECTOR_NX(interface) (((starpu_vector_interface_t *)(interface))->nx)
  169. #define STARPU_GET_VECTOR_ELEMSIZE(interface) (((starpu_vector_interface_t *)(interface))->elemsize)
  170. /* variable interface for a single data (not a vector, a matrix, a list, ...) */
  171. typedef struct starpu_variable_interface_s {
  172. uintptr_t ptr;
  173. size_t elemsize;
  174. } starpu_variable_interface_t;
  175. void starpu_variable_data_register(starpu_data_handle *handle, uint32_t home_node,
  176. uintptr_t ptr, size_t elemsize);
  177. size_t starpu_variable_get_elemsize(starpu_data_handle handle);
  178. uintptr_t starpu_variable_get_local_ptr(starpu_data_handle handle);
  179. /* helper methods */
  180. #define STARPU_GET_VARIABLE_PTR(interface) (((starpu_variable_interface_t *)(interface))->ptr)
  181. #define STARPU_GET_VARIABLE_ELEMSIZE(interface) (((starpu_variable_interface_t *)(interface))->elemsize)
  182. /* CSR interface for sparse matrices (compressed sparse row representation) */
  183. typedef struct starpu_csr_interface_s {
  184. uint32_t nnz; /* number of non-zero entries */
  185. uint32_t nrow; /* number of rows */
  186. uintptr_t nzval; /* non-zero values */
  187. uint32_t *colind; /* position of non-zero entried on the row */
  188. uint32_t *rowptr; /* index (in nzval) of the first entry of the row */
  189. /* k for k-based indexing (0 or 1 usually) */
  190. /* also useful when partitionning the matrix ... */
  191. uint32_t firstentry;
  192. size_t elemsize;
  193. } starpu_csr_interface_t;
  194. void starpu_csr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  195. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);
  196. uint32_t starpu_csr_get_nnz(starpu_data_handle handle);
  197. uint32_t starpu_csr_get_nrow(starpu_data_handle handle);
  198. uint32_t starpu_csr_get_firstentry(starpu_data_handle handle);
  199. uintptr_t starpu_csr_get_local_nzval(starpu_data_handle handle);
  200. uint32_t *starpu_csr_get_local_colind(starpu_data_handle handle);
  201. uint32_t *starpu_csr_get_local_rowptr(starpu_data_handle handle);
  202. size_t starpu_csr_get_elemsize(starpu_data_handle handle);
  203. #define STARPU_GET_CSR_NNZ(interface) (((starpu_csr_interface_t *)(interface))->nnz)
  204. #define STARPU_GET_CSR_NROW(interface) (((starpu_csr_interface_t *)(interface))->nrow)
  205. #define STARPU_GET_CSR_NZVAL(interface) (((starpu_csr_interface_t *)(interface))->nzval)
  206. #define STARPU_GET_CSR_COLIND(interface) (((starpu_csr_interface_t *)(interface))->colind)
  207. #define STARPU_GET_CSR_ROWPTR(interface) (((starpu_csr_interface_t *)(interface))->rowptr)
  208. #define STARPU_GET_CSR_FIRSTENTRY(interface) (((starpu_csr_interface_t *)(interface))->firstentry)
  209. #define STARPU_GET_CSR_ELEMSIZE(interface) (((starpu_csr_interface_t *)(interface))->elemsize)
  210. /* CSC interface for sparse matrices (compressed sparse column representation) */
  211. typedef struct starpu_csc_interface_s {
  212. int nnz; /* number of non-zero entries */
  213. int nrow; /* number of rows */
  214. float *nzval; /* non-zero values */
  215. int *colind; /* position of non-zero entried on the row */
  216. int *rowptr; /* index (in nzval) of the first entry of the row */
  217. /* k for k-based indexing (0 or 1 usually) */
  218. /* also useful when partitionning the matrix ... */
  219. int firstentry;
  220. } starpu_csc_interface_t;
  221. /* BCSR interface for sparse matrices (blocked compressed sparse row
  222. * representation) */
  223. typedef struct starpu_bcsr_interface_s {
  224. uint32_t nnz; /* number of non-zero BLOCKS */
  225. uint32_t nrow; /* number of rows (in terms of BLOCKS) */
  226. uintptr_t nzval; /* non-zero values */
  227. uint32_t *colind; /* position of non-zero entried on the row */
  228. // uint32_t *rowind; /* position of non-zero entried on the col */
  229. uint32_t *rowptr; /* index (in nzval) of the first entry of the row */
  230. /* k for k-based indexing (0 or 1 usually) */
  231. /* also useful when partitionning the matrix ... */
  232. uint32_t firstentry;
  233. /* size of the blocks */
  234. uint32_t r;
  235. uint32_t c;
  236. size_t elemsize;
  237. } starpu_bcsr_interface_t;
  238. void starpu_bcsr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  239. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);
  240. uint32_t starpu_bcsr_get_nnz(starpu_data_handle);
  241. uint32_t starpu_bcsr_get_nrow(starpu_data_handle);
  242. uint32_t starpu_bcsr_get_firstentry(starpu_data_handle);
  243. uintptr_t starpu_bcsr_get_local_nzval(starpu_data_handle);
  244. uint32_t *starpu_bcsr_get_local_colind(starpu_data_handle);
  245. uint32_t *starpu_bcsr_get_local_rowptr(starpu_data_handle);
  246. uint32_t starpu_bcsr_get_r(starpu_data_handle);
  247. uint32_t starpu_bcsr_get_c(starpu_data_handle);
  248. size_t starpu_bcsr_get_elemsize(starpu_data_handle);
  249. #define STARPU_MATRIX_INTERFACE_ID 0
  250. #define STARPU_BLOCK_INTERFACE_ID 1
  251. #define STARPU_VECTOR_INTERFACE_ID 2
  252. #define STARPU_CSR_INTERFACE_ID 3
  253. #define STARPU_CSC_INTERFACE_ID 4
  254. #define STARPU_BCSCR_INTERFACE_ID 5
  255. #define STARPU_VARIABLE_INTERFACE_ID 6
  256. #define STARPU_NINTERFACES_ID 7 /* number of data interfaces */
  257. unsigned starpu_get_handle_interface_id(starpu_data_handle);
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif // __STARPU_DATA_INTERFACES_H__