starpu_data_interfaces.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (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 __cplusplus
  21. extern "C" {
  22. #endif
  23. /* "node" means memory node: 0 for main RAM, then 1, 2, etc. for various GPUs,
  24. * etc.
  25. *
  26. * On registration, the source of data is usually a pointer in RAM, in which
  27. * case 0 should be passed.
  28. */
  29. void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memory_node);
  30. /* Matrix interface for dense matrices */
  31. typedef struct starpu_matrix_interface_s {
  32. uintptr_t ptr;
  33. uintptr_t dev_handle;
  34. size_t offset;
  35. uint32_t nx;
  36. uint32_t ny;
  37. uint32_t ld;
  38. size_t elemsize;
  39. } starpu_matrix_interface_t;
  40. void starpu_matrix_data_register(starpu_data_handle *handle, uint32_t home_node,
  41. uintptr_t ptr, uint32_t ld, uint32_t nx,
  42. uint32_t ny, size_t elemsize);
  43. uint32_t starpu_matrix_get_nx(starpu_data_handle handle);
  44. uint32_t starpu_matrix_get_ny(starpu_data_handle handle);
  45. uint32_t starpu_matrix_get_local_ld(starpu_data_handle handle);
  46. uintptr_t starpu_matrix_get_local_ptr(starpu_data_handle handle);
  47. size_t starpu_matrix_get_elemsize(starpu_data_handle handle);
  48. /* helper methods */
  49. #define STARPU_GET_MATRIX_PTR(interface) (((starpu_matrix_interface_t *)(interface))->ptr)
  50. #define STARPU_GET_MATRIX_NX(interface) (((starpu_matrix_interface_t *)(interface))->nx)
  51. #define STARPU_GET_MATRIX_NY(interface) (((starpu_matrix_interface_t *)(interface))->ny)
  52. #define STARPU_GET_MATRIX_LD(interface) (((starpu_matrix_interface_t *)(interface))->ld)
  53. #define STARPU_GET_MATRIX_ELEMSIZE(interface) (((starpu_matrix_interface_t *)(interface))->elemsize)
  54. /* BLOCK interface for 3D dense blocks */
  55. typedef struct starpu_block_interface_s {
  56. uintptr_t ptr;
  57. uintptr_t dev_handle;
  58. size_t offset;
  59. uint32_t nx;
  60. uint32_t ny;
  61. uint32_t nz;
  62. uint32_t ldy; /* number of elements between two lines */
  63. uint32_t ldz; /* number of elements between two planes */
  64. size_t elemsize;
  65. } starpu_block_interface_t;
  66. void starpu_block_data_register(starpu_data_handle *handle, uint32_t home_node,
  67. uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
  68. uint32_t ny, uint32_t nz, size_t elemsize);
  69. uint32_t starpu_block_get_nx(starpu_data_handle handle);
  70. uint32_t starpu_block_get_ny(starpu_data_handle handle);
  71. uint32_t starpu_block_get_nz(starpu_data_handle handle);
  72. uint32_t starpu_block_get_local_ldy(starpu_data_handle handle);
  73. uint32_t starpu_block_get_local_ldz(starpu_data_handle handle);
  74. uintptr_t starpu_block_get_local_ptr(starpu_data_handle handle);
  75. size_t starpu_block_get_elemsize(starpu_data_handle handle);
  76. /* helper methods */
  77. #define STARPU_GET_BLOCK_PTR(interface) (((starpu_block_interface_t *)(interface))->ptr)
  78. #define STARPU_GET_BLOCK_NX(interface) (((starpu_block_interface_t *)(interface))->nx)
  79. #define STARPU_GET_BLOCK_NY(interface) (((starpu_block_interface_t *)(interface))->ny)
  80. #define STARPU_GET_BLOCK_NZ(interface) (((starpu_block_interface_t *)(interface))->nz)
  81. #define STARPU_GET_BLOCK_LDY(interface) (((starpu_block_interface_t *)(interface))->ldy)
  82. #define STARPU_GET_BLOCK_LDZ(interface) (((starpu_block_interface_t *)(interface))->ldz)
  83. #define STARPU_GET_BLOCK_ELEMSIZE(interface) (((starpu_block_interface_t *)(interface))->elemsize)
  84. /* vector interface for contiguous (non-strided) buffers */
  85. typedef struct starpu_vector_interface_s {
  86. uintptr_t ptr;
  87. uintptr_t dev_handle;
  88. size_t offset;
  89. uint32_t nx;
  90. size_t elemsize;
  91. } starpu_vector_interface_t;
  92. void starpu_vector_data_register(starpu_data_handle *handle, uint32_t home_node,
  93. uintptr_t ptr, uint32_t nx, size_t elemsize);
  94. uint32_t starpu_vector_get_nx(starpu_data_handle handle);
  95. size_t starpu_vector_get_elemsize(starpu_data_handle handle);
  96. uintptr_t starpu_vector_get_local_ptr(starpu_data_handle handle);
  97. /* helper methods */
  98. #define STARPU_GET_VECTOR_PTR(interface) (((starpu_vector_interface_t *)(interface))->ptr)
  99. #define STARPU_GET_VECTOR_NX(interface) (((starpu_vector_interface_t *)(interface))->nx)
  100. #define STARPU_GET_VECTOR_ELEMSIZE(interface) (((starpu_vector_interface_t *)(interface))->elemsize)
  101. /* variable interface for a single data (not a vector, a matrix, a list, ...) */
  102. typedef struct starpu_variable_interface_s {
  103. uintptr_t ptr;
  104. size_t elemsize;
  105. } starpu_variable_interface_t;
  106. void starpu_variable_data_register(starpu_data_handle *handle, uint32_t home_node,
  107. uintptr_t ptr, size_t elemsize);
  108. size_t starpu_variable_get_elemsize(starpu_data_handle handle);
  109. uintptr_t starpu_variable_get_local_ptr(starpu_data_handle handle);
  110. /* helper methods */
  111. #define STARPU_GET_VARIABLE_PTR(interface) (((starpu_variable_interface_t *)(interface))->ptr)
  112. #define STARPU_GET_VARIABLE_ELEMSIZE(interface) (((starpu_variable_interface_t *)(interface))->elemsize)
  113. /* CSR interface for sparse matrices (compressed sparse row representation) */
  114. typedef struct starpu_csr_interface_s {
  115. uint32_t nnz; /* number of non-zero entries */
  116. uint32_t nrow; /* number of rows */
  117. uintptr_t nzval; /* non-zero values */
  118. uint32_t *colind; /* position of non-zero entried on the row */
  119. uint32_t *rowptr; /* index (in nzval) of the first entry of the row */
  120. /* k for k-based indexing (0 or 1 usually) */
  121. /* also useful when partitionning the matrix ... */
  122. uint32_t firstentry;
  123. size_t elemsize;
  124. } starpu_csr_interface_t;
  125. void starpu_csr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  126. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize);
  127. uint32_t starpu_csr_get_nnz(starpu_data_handle handle);
  128. uint32_t starpu_csr_get_nrow(starpu_data_handle handle);
  129. uint32_t starpu_csr_get_firstentry(starpu_data_handle handle);
  130. uintptr_t starpu_csr_get_local_nzval(starpu_data_handle handle);
  131. uint32_t *starpu_csr_get_local_colind(starpu_data_handle handle);
  132. uint32_t *starpu_csr_get_local_rowptr(starpu_data_handle handle);
  133. size_t starpu_csr_get_elemsize(starpu_data_handle handle);
  134. #define STARPU_GET_CSR_NNZ(interface) (((starpu_csr_interface_t *)(interface))->nnz)
  135. #define STARPU_GET_CSR_NROW(interface) (((starpu_csr_interface_t *)(interface))->nrow)
  136. #define STARPU_GET_CSR_NZVAL(interface) (((starpu_csr_interface_t *)(interface))->nzval)
  137. #define STARPU_GET_CSR_COLIND(interface) (((starpu_csr_interface_t *)(interface))->colind)
  138. #define STARPU_GET_CSR_ROWPTR(interface) (((starpu_csr_interface_t *)(interface))->rowptr)
  139. #define STARPU_GET_CSR_FIRSTENTRY(interface) (((starpu_csr_interface_t *)(interface))->firstentry)
  140. #define STARPU_GET_CSR_ELEMSIZE(interface) (((starpu_csr_interface_t *)(interface))->elemsize)
  141. /* CSC interface for sparse matrices (compressed sparse column representation) */
  142. typedef struct starpu_csc_interface_s {
  143. int nnz; /* number of non-zero entries */
  144. int nrow; /* number of rows */
  145. float *nzval; /* non-zero values */
  146. int *colind; /* position of non-zero entried on the row */
  147. int *rowptr; /* index (in nzval) of the first entry of the row */
  148. /* k for k-based indexing (0 or 1 usually) */
  149. /* also useful when partitionning the matrix ... */
  150. int firstentry;
  151. } starpu_csc_interface_t;
  152. /* BCSR interface for sparse matrices (blocked compressed sparse row
  153. * representation) */
  154. typedef struct starpu_bcsr_interface_s {
  155. uint32_t nnz; /* number of non-zero BLOCKS */
  156. uint32_t nrow; /* number of rows (in terms of BLOCKS) */
  157. uintptr_t nzval; /* non-zero values */
  158. uint32_t *colind; /* position of non-zero entried on the row */
  159. // uint32_t *rowind; /* position of non-zero entried on the col */
  160. uint32_t *rowptr; /* index (in nzval) of the first entry of the row */
  161. /* k for k-based indexing (0 or 1 usually) */
  162. /* also useful when partitionning the matrix ... */
  163. uint32_t firstentry;
  164. /* size of the blocks */
  165. uint32_t r;
  166. uint32_t c;
  167. size_t elemsize;
  168. } starpu_bcsr_interface_t;
  169. void starpu_bcsr_data_register(starpu_data_handle *handle, uint32_t home_node, uint32_t nnz, uint32_t nrow,
  170. uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, uint32_t r, uint32_t c, size_t elemsize);
  171. uint32_t starpu_bcsr_get_nnz(starpu_data_handle);
  172. uint32_t starpu_bcsr_get_nrow(starpu_data_handle);
  173. uint32_t starpu_bcsr_get_firstentry(starpu_data_handle);
  174. uintptr_t starpu_bcsr_get_local_nzval(starpu_data_handle);
  175. uint32_t *starpu_bcsr_get_local_colind(starpu_data_handle);
  176. uint32_t *starpu_bcsr_get_local_rowptr(starpu_data_handle);
  177. uint32_t starpu_bcsr_get_r(starpu_data_handle);
  178. uint32_t starpu_bcsr_get_c(starpu_data_handle);
  179. size_t starpu_bcsr_get_elemsize(starpu_data_handle);
  180. #define STARPU_MATRIX_INTERFACE_ID 0
  181. #define STARPU_BLOCK_INTERFACE_ID 1
  182. #define STARPU_VECTOR_INTERFACE_ID 2
  183. #define STARPU_CSR_INTERFACE_ID 3
  184. #define STARPU_CSC_INTERFACE_ID 4
  185. #define STARPU_BCSCR_INTERFACE_ID 5
  186. #define STARPU_VARIABLE_INTERFACE_ID 6
  187. #define STARPU_NINTERFACES_ID 7 /* number of data interfaces */
  188. unsigned starpu_get_handle_interface_id(starpu_data_handle);
  189. #ifdef __cplusplus
  190. }
  191. #endif
  192. #endif // __STARPU_DATA_INTERFACES_H__