starpu_data_interfaces.h 13 KB

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