data_partition.doxy 19 KB

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