starpu_data_interfaces.h 13 KB

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