data_partition.doxy 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2017 CNRS
  5. * Copyright (C) 2011, 2012 INRIA
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Data_Partition Data Partition
  9. \struct starpu_data_filter
  10. The filter structure describes a data partitioning operation, to be
  11. given to the starpu_data_partition() function.
  12. \ingroup API_Data_Partition
  13. \var void (*starpu_data_filter::filter_func)(void *father_interface, void *child_interface, struct starpu_data_filter *, unsigned id, unsigned nparts)
  14. Fill the \p child_interface structure with interface information
  15. for the \p id -th child of the parent \p father_interface (among
  16. \p nparts).
  17. \var unsigned starpu_data_filter::nchildren
  18. Number of parts to partition the data into.
  19. \var unsigned (*starpu_data_filter::get_nchildren)(struct starpu_data_filter *, starpu_data_handle_t initial_handle)
  20. Return the number of children. This can be used instead of
  21. starpu_data_filter::nchildren when the number of children depends
  22. on the actual data (e.g. the number of blocks in a sparse matrix).
  23. \var struct starpu_data_interface_ops *(*starpu_data_filter::get_child_ops)(struct starpu_data_filter *, unsigned id)
  24. In case the resulting children use a different data interface,
  25. this function returns which interface is used by child number \p
  26. id.
  27. \var unsigned starpu_data_filter::filter_arg
  28. Allow to define an additional parameter for the filter function.
  29. \var void *starpu_data_filter::filter_arg_ptr
  30. Allow to define an additional pointer parameter for the filter
  31. function, such as the sizes of the different parts.
  32. @name Basic API
  33. \ingroup API_Data_Partition
  34. \fn void starpu_data_partition(starpu_data_handle_t initial_handle, struct starpu_data_filter *f)
  35. \ingroup API_Data_Partition
  36. Request the partitioning of \p initial_handle into several subdata
  37. according to the filter \p f.
  38. Here an example of how to use the function.
  39. \code{.c}
  40. struct starpu_data_filter f = {
  41. .filter_func = starpu_matrix_filter_block,
  42. .nchildren = nslicesx
  43. };
  44. starpu_data_partition(A_handle, &f);
  45. \endcode
  46. \fn void starpu_data_unpartition(starpu_data_handle_t root_data, unsigned gathering_node)
  47. \ingroup API_Data_Partition
  48. Unapply the filter which has been applied to \p root_data, thus
  49. unpartitioning the data. The pieces of data are collected back into
  50. one big piece in the \p gathering_node (usually ::STARPU_MAIN_RAM).
  51. Tasks working on the partitioned data must be already finished when
  52. calling starpu_data_unpartition().
  53. Here an example of how to use the function.
  54. \code{.c}
  55. starpu_data_unpartition(A_handle, STARPU_MAIN_RAM);
  56. \endcode
  57. \fn int starpu_data_get_nb_children(starpu_data_handle_t handle)
  58. \ingroup API_Data_Partition
  59. Return the number of children \p handle has been partitioned into.
  60. \fn starpu_data_handle_t starpu_data_get_child(starpu_data_handle_t handle, unsigned i)
  61. \ingroup API_Data_Partition
  62. Return the \p i -th child of the given \p handle, which must have been
  63. partitionned beforehand.
  64. \fn starpu_data_handle_t starpu_data_get_sub_data(starpu_data_handle_t root_data, unsigned depth, ... )
  65. \ingroup API_Data_Partition
  66. After partitioning a StarPU data by applying a filter,
  67. starpu_data_get_sub_data() can be used to get handles for each of the
  68. data portions. \p root_data is the parent data that was partitioned.
  69. \p depth is the number of filters to traverse (in case several filters
  70. have been applied, to e.g. partition in row blocks, and then in column
  71. blocks), and the subsequent parameters are the indexes. The function
  72. returns a handle to the subdata.
  73. Here an example of how to use the function.
  74. \code{.c}
  75. h = starpu_data_get_sub_data(A_handle, 1, taskx);
  76. \endcode
  77. \fn starpu_data_handle_t starpu_data_vget_sub_data(starpu_data_handle_t root_data, unsigned depth, va_list pa)
  78. \ingroup API_Data_Partition
  79. This function is similar to starpu_data_get_sub_data() but uses a
  80. va_list for the parameter list.
  81. \fn void starpu_data_map_filters(starpu_data_handle_t root_data, unsigned nfilters, ...)
  82. \ingroup API_Data_Partition
  83. Apply \p nfilters filters to the handle designated by
  84. \p root_handle recursively. \p nfilters pointers to variables of the type
  85. starpu_data_filter should be given.
  86. \fn void starpu_data_vmap_filters(starpu_data_handle_t root_data, unsigned nfilters, va_list pa)
  87. \ingroup API_Data_Partition
  88. Apply \p nfilters filters to the handle designated by
  89. \p root_handle recursively. It uses a va_list of pointers to variables of
  90. the type starpu_data_filter.
  91. @name Asynchronous API
  92. \ingroup API_Data_Partition
  93. \fn void starpu_data_partition_plan(starpu_data_handle_t initial_handle, struct starpu_data_filter *f, starpu_data_handle_t *children)
  94. \ingroup API_Data_Partition
  95. Plan to partition \p initial_handle into several subdata according to
  96. the filter \p f.
  97. The handles are returned into the \p children array, which has to be
  98. the same size as the number of parts described in \p f. These handles
  99. are not immediately usable, starpu_data_partition_submit() has to be
  100. called to submit the actual partitioning.
  101. Here is an example of how to use the function:
  102. \code{.c}
  103. starpu_data_handle_t children[nslicesx];
  104. struct starpu_data_filter f = {
  105. .filter_func = starpu_matrix_filter_block,
  106. .nchildren = nslicesx
  107. };
  108. starpu_data_partition_plan(A_handle, &f, children);
  109. \endcode
  110. \fn void starpu_data_partition_submit(starpu_data_handle_t initial_handle, unsigned nparts, starpu_data_handle_t *children)
  111. \ingroup API_Data_Partition
  112. Submit the actual partitioning of \p initial_handle into the \p nparts
  113. \p children handles. This call is asynchronous, it only submits that the
  114. partitioning should be done, so that the \p children handles can now be used to
  115. submit tasks, and \p initial_handle can not be used to submit tasks any more (to
  116. guarantee coherency).
  117. For instance,
  118. \code{.c}
  119. starpu_data_partition_submit(A_handle, nslicesx, children);
  120. \endcode
  121. \fn void starpu_data_partition_readonly_submit(starpu_data_handle_t initial_handle, unsigned nparts, starpu_data_handle_t *children)
  122. \ingroup API_Data_Partition
  123. This is the same as starpu_data_partition_submit(), but it does not invalidate \p
  124. initial_handle. This allows to continue using it, but the application has to be
  125. careful not to write to \p initial_handle or \p children handles, only read from
  126. them, since the coherency is otherwise not guaranteed. This thus allows to
  127. submit various tasks which concurrently read from various partitions of the data.
  128. When the application wants to write to \p initial_handle again, it should call
  129. starpu_data_unpartition_submit(), which will properly add dependencies between the
  130. reads on the \p children and the writes to be submitted.
  131. If instead the application wants to write to \p children handles, it should
  132. call starpu_data_partition_readwrite_upgrade_submit(), which will correctly add
  133. dependencies between the reads on the \p initial_handle and the writes to be
  134. submitted.
  135. \fn void starpu_data_partition_readwrite_upgrade_submit(starpu_data_handle_t initial_handle, unsigned nparts, starpu_data_handle_t *children)
  136. \ingroup API_Data_Partition
  137. This assumes that a partitioning of \p initial_handle has already been submited
  138. in readonly mode through starpu_data_partition_readonly_submit(), and will upgrade
  139. that partitioning into read-write mode for the \p children, by invalidating \p
  140. initial_handle, and adding the necessary dependencies.
  141. \fn void starpu_data_unpartition_submit(starpu_data_handle_t initial_handle, unsigned nparts, starpu_data_handle_t *children, int gathering_node)
  142. \ingroup API_Data_Partition
  143. This assumes that \p initial_handle is partitioned into \p children, and submits
  144. an unpartitionning of it, i.e. submitting a gathering of the pieces on the
  145. requested \p gathering_node memory node, and submitting an invalidation of the
  146. children.
  147. \p gathering_node can be set to -1 to let the runtime decide which memory node
  148. should be used to gather the pieces.
  149. \fn void starpu_data_unpartition_readonly_submit(starpu_data_handle_t initial_handle, unsigned nparts, starpu_data_handle_t *children, int gathering_node)
  150. \ingroup API_Data_Partition
  151. This assumes that \p initial_handle is partitioned into \p children, and submits
  152. just a readonly unpartitionning of it, i.e. submitting a gathering of the pieces
  153. on the requested \p gathering_node memory node. It does not invalidate the
  154. children. This brings \p initial_handle and \p children handles to the same
  155. state as obtained with starpu_data_partition_readonly_submit().
  156. \p gathering_node can be set to -1 to let the runtime decide which memory node
  157. should be used to gather the pieces.
  158. \fn void starpu_data_partition_clean(starpu_data_handle_t root_data, unsigned nparts, starpu_data_handle_t *children)
  159. \ingroup API_Data_Partition
  160. This should be used to clear the partition planning established between \p
  161. root_data and \p children with starpu_data_partition_plan(). This will notably
  162. submit an unregister all the \p children, which can thus not be used any more
  163. afterwards.
  164. @name Predefined Vector Filter Functions
  165. \ingroup API_Data_Partition
  166. This section gives a partial list of the predefined partitioning
  167. functions for vector data. Examples on how to use them are shown in
  168. \ref PartitioningData. The complete list can be found in the file
  169. <c>starpu_data_filters.h</c>.
  170. \fn void starpu_vector_filter_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  171. \ingroup API_Data_Partition
  172. Return in \p child_interface the \p id th element of the vector
  173. represented by \p father_interface once partitioned in \p nparts chunks of
  174. equal size.
  175. \fn void starpu_vector_filter_block_shadow(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  176. \ingroup API_Data_Partition
  177. Return in \p child_interface the \p id th element of the vector
  178. represented by \p father_interface once partitioned in \p nparts chunks of
  179. equal size with a shadow border <c>filter_arg_ptr</c>, thus getting a vector
  180. of size <c>(n-2*shadow)/nparts+2*shadow</c>. The <c>filter_arg_ptr</c> field
  181. of \p f must be the shadow size casted into \c void*.
  182. <b>IMPORTANT</b>: This can only be used for read-only access, as no coherency is
  183. enforced for the shadowed parts. An usage example is available in
  184. examples/filters/shadow.c
  185. \fn void starpu_vector_filter_list(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  186. \ingroup API_Data_Partition
  187. Return in \p child_interface the \p id th element of the vector
  188. represented by \p father_interface once partitioned into \p nparts chunks
  189. according to the <c>filter_arg_ptr</c> field of \p f. The
  190. <c>filter_arg_ptr</c> field must point to an array of \p nparts uint32_t
  191. elements, each of which specifies the number of elements in each chunk
  192. of the partition.
  193. \fn void starpu_vector_filter_divide_in_2(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  194. \ingroup API_Data_Partition
  195. Return in \p child_interface the \p id th element of the vector
  196. represented by \p father_interface once partitioned in <c>2</c> chunks of
  197. equal size, ignoring nparts. Thus, \p id must be <c>0</c> or <c>1</c>.
  198. @name Predefined Matrix Filter Functions
  199. \ingroup API_Data_Partition
  200. This section gives a partial list of the predefined partitioning
  201. functions for matrix data. Examples on how to use them are shown in
  202. \ref PartitioningData. The complete list can be found in the file
  203. <c>starpu_data_filters.h</c>.
  204. \fn void starpu_matrix_filter_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  205. \ingroup API_Data_Partition
  206. Partition a dense Matrix along the x dimension, thus
  207. getting (x/\p nparts ,y) matrices. If \p nparts does not divide x, the
  208. last submatrix contains the remainder.
  209. \fn void starpu_matrix_filter_block_shadow(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  210. \ingroup API_Data_Partition
  211. Partition a dense Matrix along the x dimension, with a
  212. shadow border <c>filter_arg_ptr</c>, thus getting ((x-2*shadow)/\p
  213. nparts +2*shadow,y) matrices. If \p nparts does not divide x-2*shadow,
  214. the last submatrix contains the remainder.
  215. <b>IMPORTANT</b>: This can
  216. only be used for read-only access, as no coherency is enforced for the
  217. shadowed parts. A usage example is available in
  218. examples/filters/shadow2d.c
  219. \fn void starpu_matrix_filter_vertical_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  220. \ingroup API_Data_Partition
  221. Partition a dense Matrix along the y dimension, thus
  222. getting (x,y/\p nparts) matrices. If \p nparts does not divide y, the
  223. last submatrix contains the remainder.
  224. \fn void starpu_matrix_filter_vertical_block_shadow(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  225. \ingroup API_Data_Partition
  226. Partition a dense Matrix along the y dimension, with a
  227. shadow border <c>filter_arg_ptr</c>, thus getting
  228. (x,(y-2*shadow)/\p nparts +2*shadow) matrices. If \p nparts does not
  229. divide y-2*shadow, the last submatrix contains the remainder.
  230. <b>IMPORTANT</b>: This can only be used for read-only access, as no
  231. coherency is enforced for the shadowed parts. A usage example is
  232. available in examples/filters/shadow2d.c
  233. @name Predefined Block Filter Functions
  234. \ingroup API_Data_Partition
  235. This section gives a partial list of the predefined partitioning
  236. functions for block data. Examples on how to use them are shown in
  237. \ref PartitioningData. The complete list can be found in the file
  238. <c>starpu_data_filters.h</c>. A usage example is available in
  239. examples/filters/shadow3d.c
  240. \fn void starpu_block_filter_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  241. \ingroup API_Data_Partition
  242. Partition a block along the X dimension, thus getting
  243. (x/\p nparts ,y,z) 3D matrices. If \p nparts does not divide x, the last
  244. submatrix contains the remainder.
  245. \fn void starpu_block_filter_block_shadow(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  246. \ingroup API_Data_Partition
  247. Partition a block along the X dimension, with a
  248. shadow border <c>filter_arg_ptr</c>, thus getting
  249. ((x-2*shadow)/\p nparts +2*shadow,y,z) blocks. If \p nparts does not
  250. divide x, the last submatrix contains the remainder.
  251. <b>IMPORTANT</b>:
  252. This can only be used for read-only access, as no coherency is
  253. enforced for the shadowed parts.
  254. \fn void starpu_block_filter_vertical_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  255. \ingroup API_Data_Partition
  256. Partition a block along the Y dimension, thus getting
  257. (x,y/\p nparts ,z) blocks. If \p nparts does not divide y, the last
  258. submatrix contains the remainder.
  259. \fn void starpu_block_filter_vertical_block_shadow(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  260. \ingroup API_Data_Partition
  261. Partition a block along the Y dimension, with a
  262. shadow border <c>filter_arg_ptr</c>, thus getting
  263. (x,(y-2*shadow)/\p nparts +2*shadow,z) 3D matrices. If \p nparts does not
  264. divide y, the last submatrix contains the remainder.
  265. <b>IMPORTANT</b>:
  266. This can only be used for read-only access, as no coherency is
  267. enforced for the shadowed parts.
  268. \fn void starpu_block_filter_depth_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  269. \ingroup API_Data_Partition
  270. Partition a block along the Z dimension, thus getting
  271. (x,y,z/\p nparts) blocks. If \p nparts does not divide z, the last
  272. submatrix contains the remainder.
  273. \fn void starpu_block_filter_depth_block_shadow(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  274. \ingroup API_Data_Partition
  275. Partition a block along the Z dimension, with a
  276. shadow border <c>filter_arg_ptr</c>, thus getting
  277. (x,y,(z-2*shadow)/\p nparts +2*shadow) blocks. If \p nparts does not
  278. divide z, the last submatrix contains the remainder.
  279. <b>IMPORTANT</b>:
  280. This can only be used for read-only access, as no coherency is
  281. enforced for the shadowed parts.
  282. @name Predefined BCSR Filter Functions
  283. \ingroup API_Data_Partition
  284. This section gives a partial list of the predefined partitioning
  285. functions for BCSR data. Examples on how to use them are shown in
  286. \ref PartitioningData. The complete list can be found in the file
  287. <c>starpu_data_filters.h</c>.
  288. \fn void starpu_bcsr_filter_canonical_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  289. \ingroup API_Data_Partition
  290. Partition a block-sparse matrix into dense matrices.
  291. \fn void starpu_csr_filter_vertical_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts)
  292. \ingroup API_Data_Partition
  293. Partition a block-sparse matrix into vertical block-sparse matrices.
  294. */