starpu_data_interfaces.h 14 KB

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