310_data_management.doxy 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2019 CNRS
  4. * Copyright (C) 2009-2011,2014-2019 Université de Bordeaux
  5. * Copyright (C) 2011,2012 Inria
  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. /*! \page DataManagement Data Management
  19. TODO: intro which mentions consistency among other things
  20. \section DataInterface Data Interface
  21. StarPU provides several data interfaces for programmers to describe
  22. the data layout of their application. There are predefined interfaces
  23. already available in StarPU. Users can define new data interfaces as
  24. explained in \ref DefiningANewDataInterface. All functions provided by
  25. StarPU are documented in \ref API_Data_Interfaces. You will find a
  26. short list below.
  27. \subsection VariableDataInterface Variable Data Interface
  28. A variable is a given-size byte element, typically a scalar. Here an
  29. example of how to register a variable data to StarPU by using
  30. starpu_variable_data_register().
  31. \code{.c}
  32. float var = 42.0;
  33. starpu_data_handle_t var_handle;
  34. starpu_variable_data_register(&var_handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  35. \endcode
  36. \subsection VectorDataInterface Vector Data Interface
  37. A vector is a fixed number of elements of a given size. Here an
  38. example of how to register a vector data to StarPU by using
  39. starpu_vector_data_register().
  40. \code{.c}
  41. float vector[NX];
  42. starpu_data_handle_t vector_handle;
  43. starpu_vector_data_register(&vector_handle, STARPU_MAIN_RAM, (uintptr_t)vector, NX, sizeof(vector[0]));
  44. \endcode
  45. Vectors can be partitioned into pieces by using
  46. starpu_vector_filter_block(). They can also be partitioned with some overlapping
  47. by using starpu_vector_filter_block_shadow(). By default StarPU
  48. uses the same size for each piece. If different sizes are desired,
  49. starpu_vector_filter_list() or starpu_vector_filter_list_long() can be used
  50. instead. To just divide in two pieces, starpu_vector_filter_divide_in_2() can be used.
  51. \subsection MatrixDataInterface Matrix Data Interface
  52. To register 2-D matrices with a potential padding, one can use the
  53. matrix data interface. Here an example of how to register a matrix
  54. data to StarPU by using starpu_matrix_data_register().
  55. \code{.c}
  56. float *matrix;
  57. starpu_data_handle_t matrix_handle;
  58. matrix = (float*)malloc(width * height * sizeof(float));
  59. starpu_matrix_data_register(&matrix_handle, STARPU_MAIN_RAM, (uintptr_t)matrix, width, width, height, sizeof(float));
  60. \endcode
  61. 2D matrices can be partitioned into 2D matrices along the x dimension by
  62. using starpu_matrix_filter_block(), and along the y dimension by using
  63. starpu_matrix_filter_vertical_block(). They can also be partitioned
  64. with some overlapping by using starpu_matrix_filter_block_shadow() and
  65. starpu_matrix_filter_vertical_block_shadow().
  66. \subsection BlockDataInterface Block Data Interface
  67. To register 3-D matrices with potential paddings on Y and Z dimensions,
  68. one can use the block data interface. Here an example of how to
  69. register a block data to StarPU by using starpu_block_data_register().
  70. \code{.c}
  71. float *block;
  72. starpu_data_handle_t block_handle;
  73. block = (float*)malloc(nx*ny*nz*sizeof(float));
  74. starpu_block_data_register(&block_handle, STARPU_MAIN_RAM, (uintptr_t)block, nx, nx*ny, nx, ny, nz, sizeof(float));
  75. \endcode
  76. 3D matrices can be partitioned along the x dimension by
  77. using starpu_block_filter_block(), or along the y dimension
  78. by using starpu_block_filter_vertical_block, or along the
  79. z dimension by using starpu_block_filter_depth_block. They
  80. can also be partitioned with some overlapping by using
  81. starpu_block_filter_block_shadow(), starpu_block_filter_vertical_block_shadow(),
  82. or starpu_block_filter_depth_block_shadow().
  83. \subsection TensorDataInterface Tensor Data Interface
  84. To register 4-D matrices with potential paddings on Y, Z, and T dimensions,
  85. one can use the tensor data interface. Here an example of how to
  86. register a tensor data to StarPU by using starpu_tensor_data_register().
  87. \code{.c}
  88. float *block;
  89. starpu_data_handle_t block_handle;
  90. block = (float*)malloc(nx*ny*nz*nt*sizeof(float));
  91. starpu_tensor_data_register(&block_handle, STARPU_MAIN_RAM, (uintptr_t)block, nx, nx*ny, nx*ny*nz, nx, ny, nz, nt, sizeof(float));
  92. \endcode
  93. Partitioning filters are not implemented yet.
  94. \subsection BCSRDataInterface BCSR Data Interface
  95. BCSR (Blocked Compressed Sparse Row Representation) sparse matrix data
  96. can be registered to StarPU using the bcsr data interface. Here an
  97. example on how to do so by using starpu_bcsr_data_register().
  98. \code{.c}
  99. /*
  100. * We use the following matrix:
  101. *
  102. * +----------------+
  103. * | 0 1 0 0 |
  104. * | 2 3 0 0 |
  105. * | 4 5 8 9 |
  106. * | 6 7 10 11 |
  107. * +----------------+
  108. *
  109. * nzval = [0, 1, 2, 3] ++ [4, 5, 6, 7] ++ [8, 9, 10, 11]
  110. * colind = [0, 0, 1]
  111. * rowptr = [0, 1, 3]
  112. * r = c = 2
  113. */
  114. /* Size of the blocks */
  115. int R = 2;
  116. int C = 2;
  117. int NROWS = 2;
  118. int NNZ_BLOCKS = 3; /* out of 4 */
  119. int NZVAL_SIZE = (R*C*NNZ_BLOCKS);
  120. int nzval[NZVAL_SIZE] =
  121. {
  122. 0, 1, 2, 3, /* First block */
  123. 4, 5, 6, 7, /* Second block */
  124. 8, 9, 10, 11 /* Third block */
  125. };
  126. uint32_t colind[NNZ_BLOCKS] =
  127. {
  128. 0, /* block-column index for first block in nzval */
  129. 0, /* block-column index for second block in nzval */
  130. 1 /* block-column index for third block in nzval */
  131. };
  132. uint32_t rowptr[NROWS+1] =
  133. {
  134. 0, / * block-index in nzval of the first block of the first row. */
  135. 1, / * block-index in nzval of the first block of the second row. */
  136. NNZ_BLOCKS /* number of blocks, to allow an easier element's access for the kernels */
  137. };
  138. starpu_data_handle_t bcsr_handle;
  139. starpu_bcsr_data_register(&bcsr_handle,
  140. STARPU_MAIN_RAM,
  141. NNZ_BLOCKS,
  142. NROWS,
  143. (uintptr_t) nzval,
  144. colind,
  145. rowptr,
  146. 0, /* firstentry */
  147. R,
  148. C,
  149. sizeof(nzval[0]));
  150. \endcode
  151. StarPU provides an example on how to deal with such matrices in
  152. <c>examples/spmv</c>.
  153. BCSR data handles can be partitioned into its dense matrix blocks by using
  154. starpu_bcsr_filter_canonical_block().
  155. \subsection CSRDataInterface CSR Data Interface
  156. TODO
  157. CSR data handles can be partitioned into vertical CSR matrices by using
  158. starpu_csr_filter_vertical_block().
  159. \subsection VariableSizeDataInterface Data Interface with Variable Size
  160. Tasks are actually allowed to change the size of data interfaces.
  161. The simplest case is just changing the amount of data actually used within the
  162. allocated buffer. This is for instance implemented for the matrix interface: one
  163. can set the new NX/NY values with STARPU_MATRIX_SET_NX(), STARPU_MATRIX_SET_NY(), and STARPU_MATRIX_SET_LD()
  164. at the end of the task implementation. Data transfers achieved by StarPU will
  165. then use these values instead of the whole allocated size. The values of course
  166. need to be set within the original allocation. To reserve room for increasing
  167. the NX/NY values, one can use starpu_matrix_data_register_allocsize() instead of
  168. starpu_matrix_data_register(), to specify the allocation size to be used instead
  169. of the default NX*NY*ELEMSIZE. To support this, the data interface
  170. has to implement the starpu_data_interface_ops::alloc_footprint and
  171. starpu_data_interface_ops::alloc_compare methods, for proper StarPU allocation
  172. management.
  173. A more involved case is changing the amount of allocated data.
  174. The task implementation can just reallocate the buffer during its execution, and
  175. set the proper new values in the interface structure, e.g. nx, ny, ld, etc. so
  176. that the StarPU core knows the new data layout. The starpu_data_interface_ops
  177. structure however then needs to have the starpu_data_interface_ops::dontcache
  178. field set to 1, to prevent StarPU from trying to perform any cached allocation,
  179. since the allocated size will vary. An example is available in
  180. <c>tests/datawizard/variable_size.c</c>
  181. \section DataManagement Data Management
  182. When the application allocates data, whenever possible it should use
  183. the starpu_malloc() function, which will ask CUDA or OpenCL to make
  184. the allocation itself and pin the corresponding allocated memory, or to use the
  185. starpu_memory_pin() function to pin memory allocated by other ways, such as local arrays. This
  186. is needed to permit asynchronous data transfer, i.e. permit data
  187. transfer to overlap with computations. Otherwise, the trace will show
  188. that the <c>DriverCopyAsync</c> state takes a lot of time, this is
  189. because CUDA or OpenCL then reverts to synchronous transfers.
  190. The application can provide its own allocation function by calling
  191. starpu_malloc_set_hooks(). StarPU will then use them for all data handle
  192. allocations in the main memory.
  193. By default, StarPU leaves replicates of data wherever they were used, in case they
  194. will be re-used by other tasks, thus saving the data transfer time. When some
  195. task modifies some data, all the other replicates are invalidated, and only the
  196. processing unit which ran this task will have a valid replicate of the data. If the application knows
  197. that this data will not be re-used by further tasks, it should advise StarPU to
  198. immediately replicate it to a desired list of memory nodes (given through a
  199. bitmask). This can be understood like the write-through mode of CPU caches.
  200. \code{.c}
  201. starpu_data_set_wt_mask(img_handle, 1<<0);
  202. \endcode
  203. will for instance request to always automatically transfer a replicate into the
  204. main memory (node <c>0</c>), as bit <c>0</c> of the write-through bitmask is being set.
  205. \code{.c}
  206. starpu_data_set_wt_mask(img_handle, ~0U);
  207. \endcode
  208. will request to always automatically broadcast the updated data to all memory
  209. nodes.
  210. Setting the write-through mask to <c>~0U</c> can also be useful to make sure all
  211. memory nodes always have a copy of the data, so that it is never evicted when
  212. memory gets scarse.
  213. Implicit data dependency computation can become expensive if a lot
  214. of tasks access the same piece of data. If no dependency is required
  215. on some piece of data (e.g. because it is only accessed in read-only
  216. mode, or because write accesses are actually commutative), use the
  217. function starpu_data_set_sequential_consistency_flag() to disable
  218. implicit dependencies on this data.
  219. In the same vein, accumulation of results in the same data can become a
  220. bottleneck. The use of the mode ::STARPU_REDUX permits to optimize such
  221. accumulation (see \ref DataReduction). To a lesser extent, the use of
  222. the flag ::STARPU_COMMUTE keeps the bottleneck (see \ref DataCommute), but at least permits
  223. the accumulation to happen in any order.
  224. Applications often need a data just for temporary results. In such a case,
  225. registration can be made without an initial value, for instance this produces a vector data:
  226. \code{.c}
  227. starpu_vector_data_register(&handle, -1, 0, n, sizeof(float));
  228. \endcode
  229. StarPU will then allocate the actual buffer only when it is actually needed,
  230. e.g. directly on the GPU without allocating in main memory.
  231. In the same vein, once the temporary results are not useful any more, the
  232. data should be thrown away. If the handle is not to be reused, it can be
  233. unregistered:
  234. \code{.c}
  235. starpu_data_unregister_submit(handle);
  236. \endcode
  237. actual unregistration will be done after all tasks working on the handle
  238. terminate.
  239. If the handle is to be reused, instead of unregistering it, it can simply be invalidated:
  240. \code{.c}
  241. starpu_data_invalidate_submit(handle);
  242. \endcode
  243. the buffers containing the current value will then be freed, and reallocated
  244. only when another task writes some value to the handle.
  245. \section DataPrefetch Data Prefetch
  246. The scheduling policies <c>heft</c>, <c>dmda</c> and <c>pheft</c>
  247. perform data prefetch (see \ref STARPU_PREFETCH):
  248. as soon as a scheduling decision is taken for a task, requests are issued to
  249. transfer its required data to the target processing unit, if needed, so that
  250. when the processing unit actually starts the task, its data will hopefully be
  251. already available and it will not have to wait for the transfer to finish.
  252. The application may want to perform some manual prefetching, for several reasons
  253. such as excluding initial data transfers from performance measurements, or
  254. setting up an initial statically-computed data distribution on the machine
  255. before submitting tasks, which will thus guide StarPU toward an initial task
  256. distribution (since StarPU will try to avoid further transfers).
  257. This can be achieved by giving the function starpu_data_prefetch_on_node() the
  258. handle and the desired target memory node. The
  259. starpu_data_idle_prefetch_on_node() variant can be used to issue the transfer
  260. only when the bus is idle.
  261. Conversely, one can advise StarPU that some data will not be useful in the
  262. close future by calling starpu_data_wont_use(). StarPU will then write its value
  263. back to its home node, and evict it from GPUs when room is needed.
  264. \section PartitioningData Partitioning Data
  265. An existing piece of data can be partitioned in sub parts to be used by different tasks, for instance:
  266. \code{.c}
  267. #define NX 1048576
  268. #define PARTS 16
  269. int vector[NX];
  270. starpu_data_handle_t handle;
  271. /* Declare data to StarPU */
  272. starpu_vector_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)vector, NX, sizeof(vector[0]));
  273. /* Partition the vector in PARTS sub-vectors */
  274. struct starpu_data_filter f =
  275. {
  276. .filter_func = starpu_vector_filter_block,
  277. .nchildren = PARTS
  278. };
  279. starpu_data_partition(handle, &f);
  280. \endcode
  281. The task submission then uses the function starpu_data_get_sub_data()
  282. to retrieve the sub-handles to be passed as tasks parameters.
  283. \code{.c}
  284. /* Submit a task on each sub-vector */
  285. for (i=0; i<starpu_data_get_nb_children(handle); i++)
  286. {
  287. /* Get subdata number i (there is only 1 dimension) */
  288. starpu_data_handle_t sub_handle = starpu_data_get_sub_data(handle, 1, i);
  289. struct starpu_task *task = starpu_task_create();
  290. task->handles[0] = sub_handle;
  291. task->cl = &cl;
  292. task->synchronous = 1;
  293. task->cl_arg = &factor;
  294. task->cl_arg_size = sizeof(factor);
  295. starpu_task_submit(task);
  296. }
  297. \endcode
  298. Partitioning can be applied several times, see
  299. <c>examples/basic_examples/mult.c</c> and <c>examples/filters/</c>.
  300. Wherever the whole piece of data is already available, the partitioning will
  301. be done in-place, i.e. without allocating new buffers but just using pointers
  302. inside the existing copy. This is particularly important to be aware of when
  303. using OpenCL, where the kernel parameters are not pointers, but \c cl_mem handles. The
  304. kernel thus needs to be also passed the offset within the OpenCL buffer:
  305. \code{.c}
  306. void opencl_func(void *buffers[], void *cl_arg)
  307. {
  308. cl_mem vector = (cl_mem) STARPU_VECTOR_GET_DEV_HANDLE(buffers[0]);
  309. unsigned offset = STARPU_BLOCK_GET_OFFSET(buffers[0]);
  310. ...
  311. clSetKernelArg(kernel, 0, sizeof(vector), &vector);
  312. clSetKernelArg(kernel, 1, sizeof(offset), &offset);
  313. ...
  314. }
  315. \endcode
  316. And the kernel has to shift from the pointer passed by the OpenCL driver:
  317. \code{.c}
  318. __kernel void opencl_kernel(__global int *vector, unsigned offset)
  319. {
  320. block = (__global void *)block + offset;
  321. ...
  322. }
  323. \endcode
  324. When the sub-data is not of the same type as the original data, the
  325. starpu_data_filter::get_child_ops field needs to be set appropriately for StarPU
  326. to know which type should be used.
  327. StarPU provides various interfaces and filters for matrices, vectors, etc.,
  328. but applications can also write their own data interfaces and filters, see
  329. <c>examples/interface</c> and <c>examples/filters/custom_mf</c> for an example,
  330. and see \ref DefiningANewDataInterface and \ref DefiningANewDataFilter
  331. for documentation.
  332. \section AsynchronousPartitioning Asynchronous Partitioning
  333. The partitioning functions described in the previous section are synchronous:
  334. starpu_data_partition() and starpu_data_unpartition() both wait for all the tasks
  335. currently working on the data. This can be a bottleneck for the application.
  336. An asynchronous API also exists, it works only on handles with sequential
  337. consistency. The principle is to first plan the partitioning, which returns
  338. data handles of the partition, which are not functional yet. When submitting
  339. tasks, one can mix using the handles of the partition, of the whole data. One
  340. can even partition recursively and mix using handles at different levels of the
  341. recursion. Of course, StarPU will have to introduce coherency synchronization.
  342. <c>fmultiple_submit_implicit</c> is a complete example using this technique.
  343. One can also look at <c>fmultiple_submit_readonly</c> which contains the
  344. explicit coherency synchronization which are automatically introduced by StarPU
  345. for <c>fmultiple_submit_implicit</c>.
  346. In short, we first register a matrix and plan the partitioning:
  347. \code{.c}
  348. starpu_matrix_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)matrix, NX, NX, NY, sizeof(matrix[0]));
  349. struct starpu_data_filter f_vert =
  350. {
  351. .filter_func = starpu_matrix_filter_block,
  352. .nchildren = PARTS
  353. };
  354. starpu_data_partition_plan(handle, &f_vert, vert_handle);
  355. \endcode
  356. starpu_data_partition_plan() returns the handles for the partition in <c>vert_handle</c>.
  357. One can then submit tasks working on the main handle, and tasks working on
  358. <c>vert_handle</c> handles. Between using the main handle and <c>vert_handle</c>
  359. handles, StarPU will automatically call starpu_data_partition_submit() and
  360. starpu_data_unpartition_submit().
  361. All this code is asynchronous, just submitting which tasks, partitioning and
  362. unpartitioning will be done at runtime.
  363. Planning several partitioning of the same data is also possible, StarPU will
  364. unpartition and repartition as needed when mixing accesses of different
  365. partitions. If data access is done in read-only mode, StarPU will allow the
  366. different partitioning to coexist. As soon as a data is accessed in read-write
  367. mode, StarPU will automatically unpartition everything and activate only the
  368. partitioning leading to the data being written to.
  369. For instance, for a stencil application, one can split a subdomain into
  370. its interior and halos, and then just submit a task updating the whole
  371. subdomain, then submit MPI sends/receives to update the halos, then submit
  372. again a task updating the whole subdomain, etc. and StarPU will automatically
  373. partition/unpartition each time.
  374. \section ManualPartitioning Manual Partitioning
  375. One can also handle partitioning by hand, by registering several views on the
  376. same piece of data. The idea is then to manage the coherency of the various
  377. views through the common buffer in the main memory.
  378. <c>fmultiple_manual</c> is a complete example using this technique.
  379. In short, we first register the same matrix several times:
  380. \code{.c}
  381. starpu_matrix_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)matrix, NX, NX, NY, sizeof(matrix[0]));
  382. for (i = 0; i < PARTS; i++)
  383. starpu_matrix_data_register(&vert_handle[i], STARPU_MAIN_RAM, (uintptr_t)&matrix[0][i*(NX/PARTS)], NX, NX/PARTS, NY, sizeof(matrix[0][0]));
  384. \endcode
  385. Since StarPU is not aware that the two handles are actually pointing to the same
  386. data, we have a danger of inadvertently submitting tasks to both views, which
  387. will bring a mess since StarPU will not guarantee any coherency between the two
  388. views. To make sure we don't do this, we invalidate the view that we will not
  389. use:
  390. \code{.c}
  391. for (i = 0; i < PARTS; i++)
  392. starpu_data_invalidate(vert_handle[i]);
  393. \endcode
  394. Then we can safely work on <c>handle</c>.
  395. When we want to switch to the vertical slice view, all we need to do is bring
  396. coherency between them by running an empty task on the home node of the data:
  397. \code{.c}
  398. void empty(void *buffers[], void *cl_arg)
  399. { }
  400. struct starpu_codelet cl_switch =
  401. {
  402. .cpu_funcs = {empty},
  403. .nbuffers = STARPU_VARIABLE_NBUFFERS,
  404. };
  405. ret = starpu_task_insert(&cl_switch, STARPU_RW, handle,
  406. STARPU_W, vert_handle[0],
  407. STARPU_W, vert_handle[1],
  408. 0);
  409. \endcode
  410. The execution of the <c>switch</c> task will get back the matrix data into the
  411. main memory, and thus the vertical slices will get the updated value there.
  412. Again, we prefer to make sure that we don't accidentally access the matrix through the whole-matrix handle:
  413. \code{.c}
  414. starpu_data_invalidate_submit(handle);
  415. \endcode
  416. And now we can start using vertical slices, etc.
  417. \section DataPointers Handles data buffer pointers
  418. A simple understanding of starpu handles is that it's a collection of buffers on
  419. each memory node of the machine, which contain the same data. The picture is
  420. however made more complex with the OpenCL support and with partitioning.
  421. When partitioning a handle, the data buffers of the subhandles will indeed
  422. be inside the data buffers of the main handle (to save transferring data
  423. back and forth between the main handle and the subhandles). But in OpenCL,
  424. a <c>cl_mem</c> is not a pointer, but an opaque value on which pointer
  425. arithmetic can not be used. That is why data interfaces contain three members:
  426. <c>dev_handle</c>, <c>offset</c>, and <c>ptr</c>. The <c>dev_handle</c> member
  427. is what the allocation function returned, and one can not do arithmetic on
  428. it. The <c>offset</c> member is the offset inside the allocated area, most often
  429. it will be 0 because data start at the beginning of the allocated area, but
  430. when the handle is partitioned, the subhandles will have varying <c>offset</c>
  431. values, for each subpiece. The <c>ptr</c> member, in the non-OpenCL case, i.e.
  432. when pointer arithmetic can be used on <c>dev_handle</c>, is just the sum of
  433. <c>dev_handle</c> and <c>offset</c>, provided for convenience.
  434. This means that:
  435. <ul>
  436. <li>computation kernels can use <c>ptr</c> in non-OpenCL implementations.</li>
  437. <li>computation kernels have to use <c>dev_handle</c> and <c>offset</c> in the OpenCL implementation.</li>
  438. <li>allocation methods of data interfaces have to store the value returned by starpu_malloc_on_node in <c>dev_handle</c> and <c>ptr</c>, and set <c>offset</c> to 0.</li>
  439. <li>partitioning filters have to copy over <c>dev_handle</c> without modifying it, set in the child different values of <c>offset</c>, and set <c>ptr</c> accordingly as the sum of <c>dev_handle</c> and <c>offset</c>.</li>
  440. </ul>
  441. \section DefiningANewDataFilter Defining A New Data Filter
  442. StarPU provides a series of predefined filters in \ref API_Data_Partition, but
  443. additional filters can be defined by the application. The principle is that the
  444. filter function just fills the memory location of the <c>i-th</c> subpart of a data.
  445. Examples are provided in <c>src/datawizard/interfaces/*_filters.c</c>,
  446. and see \ref starpu_data_filter::filter_func for the details.
  447. The starpu_filter_nparts_compute_chunk_size_and_offset() helper can be used to
  448. compute the division of pieces of data.
  449. \section DataReduction Data Reduction
  450. In various cases, some piece of data is used to accumulate intermediate
  451. results. For instances, the dot product of a vector, maximum/minimum finding,
  452. the histogram of a photograph, etc. When these results are produced along the
  453. whole machine, it would not be efficient to accumulate them in only one place,
  454. incurring data transmission each and access concurrency.
  455. StarPU provides a mode ::STARPU_REDUX, which permits to optimize
  456. this case: it will allocate a buffer on each memory node, and accumulate
  457. intermediate results there. When the data is eventually accessed in the normal
  458. mode ::STARPU_R, StarPU will collect the intermediate results in just one
  459. buffer.
  460. For this to work, the user has to use the function
  461. starpu_data_set_reduction_methods() to declare how to initialize these
  462. buffers, and how to assemble partial results.
  463. For instance, <c>cg</c> uses that to optimize its dot product: it first defines
  464. the codelets for initialization and reduction:
  465. \code{.c}
  466. struct starpu_codelet bzero_variable_cl =
  467. {
  468. .cpu_funcs = { bzero_variable_cpu },
  469. .cpu_funcs_name = { "bzero_variable_cpu" },
  470. .cuda_funcs = { bzero_variable_cuda },
  471. .nbuffers = 1,
  472. }
  473. static void accumulate_variable_cpu(void *descr[], void *cl_arg)
  474. {
  475. double *v_dst = (double *)STARPU_VARIABLE_GET_PTR(descr[0]);
  476. double *v_src = (double *)STARPU_VARIABLE_GET_PTR(descr[1]);
  477. *v_dst = *v_dst + *v_src;
  478. }
  479. static void accumulate_variable_cuda(void *descr[], void *cl_arg)
  480. {
  481. double *v_dst = (double *)STARPU_VARIABLE_GET_PTR(descr[0]);
  482. double *v_src = (double *)STARPU_VARIABLE_GET_PTR(descr[1]);
  483. cublasaxpy(1, (double)1.0, v_src, 1, v_dst, 1);
  484. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  485. }
  486. struct starpu_codelet accumulate_variable_cl =
  487. {
  488. .cpu_funcs = { accumulate_variable_cpu },
  489. .cpu_funcs_name = { "accumulate_variable_cpu" },
  490. .cuda_funcs = { accumulate_variable_cuda },
  491. .nbuffers = 1,
  492. }
  493. \endcode
  494. and attaches them as reduction methods for its handle <c>dtq</c>:
  495. \code{.c}
  496. starpu_variable_data_register(&dtq_handle, -1, NULL, sizeof(type));
  497. starpu_data_set_reduction_methods(dtq_handle, &accumulate_variable_cl, &bzero_variable_cl);
  498. \endcode
  499. and <c>dtq_handle</c> can now be used in mode ::STARPU_REDUX for the
  500. dot products with partitioned vectors:
  501. \code{.c}
  502. for (b = 0; b < nblocks; b++)
  503. starpu_task_insert(&dot_kernel_cl,
  504. STARPU_REDUX, dtq_handle,
  505. STARPU_R, starpu_data_get_sub_data(v1, 1, b),
  506. STARPU_R, starpu_data_get_sub_data(v2, 1, b),
  507. 0);
  508. \endcode
  509. During registration, we have here provided <c>NULL</c>, i.e. there is
  510. no initial value to be taken into account during reduction. StarPU
  511. will thus only take into account the contributions from the tasks
  512. <c>dot_kernel_cl</c>. Also, it will not allocate any memory for
  513. <c>dtq_handle</c> before tasks <c>dot_kernel_cl</c> are ready to run.
  514. If another dot product has to be performed, one could unregister
  515. <c>dtq_handle</c>, and re-register it. But one can also call
  516. starpu_data_invalidate_submit() with the parameter <c>dtq_handle</c>,
  517. which will clear all data from the handle, thus resetting it back to
  518. the initial status <c>register(NULL)</c>.
  519. The example <c>cg</c> also uses reduction for the blocked gemv kernel,
  520. leading to yet more relaxed dependencies and more parallelism.
  521. ::STARPU_REDUX can also be passed to starpu_mpi_task_insert() in the MPI
  522. case. This will however not produce any MPI communication, but just pass
  523. ::STARPU_REDUX to the underlying starpu_task_insert(). It is up to the
  524. application to call starpu_mpi_redux_data(), which posts tasks which will
  525. reduce the partial results among MPI nodes into the MPI node which owns the
  526. data. For instance, some hypothetical application which collects partial results
  527. into data <c>res</c>, then uses it for other computation, before looping again
  528. with a new reduction:
  529. \code{.c}
  530. for (i = 0; i < 100; i++)
  531. {
  532. starpu_mpi_task_insert(MPI_COMM_WORLD, &init_res, STARPU_W, res, 0);
  533. starpu_mpi_task_insert(MPI_COMM_WORLD, &work, STARPU_RW, A, STARPU_R, B, STARPU_REDUX, res, 0);
  534. starpu_mpi_redux_data(MPI_COMM_WORLD, res);
  535. starpu_mpi_task_insert(MPI_COMM_WORLD, &work2, STARPU_RW, B, STARPU_R, res, 0);
  536. }
  537. \endcode
  538. \section DataCommute Commute Data Access
  539. By default, the implicit dependencies computed from data access use the
  540. sequential semantic. Notably, write accesses are always serialized in the order
  541. of submission. In some applicative cases, the write contributions can actually
  542. be performed in any order without affecting the eventual result. In this case
  543. it is useful to drop the strictly sequential semantic, to improve parallelism
  544. by allowing StarPU to reorder the write accesses. This can be done by using
  545. the ::STARPU_COMMUTE data access flag. Accesses without this flag will however
  546. properly be serialized against accesses with this flag. For instance:
  547. \code{.c}
  548. starpu_task_insert(&cl1, STARPU_R, h, STARPU_RW, handle, 0);
  549. starpu_task_insert(&cl2, STARPU_R, handle1, STARPU_RW|STARPU_COMMUTE, handle, 0);
  550. starpu_task_insert(&cl2, STARPU_R, handle2, STARPU_RW|STARPU_COMMUTE, handle, 0);
  551. starpu_task_insert(&cl3, STARPU_R, g, STARPU_RW, handle, 0);
  552. \endcode
  553. The two tasks running <c>cl2</c> will be able to commute: depending on whether the
  554. value of <c>handle1</c> or <c>handle2</c> becomes available first, the corresponding task
  555. running <c>cl2</c> will start first. The task running <c>cl1</c> will however always be run
  556. before them, and the task running <c>cl3</c> will always be run after them.
  557. If a lot of tasks use the commute access on the same set of data and a lot of
  558. them are ready at the same time, it may become interesting to use an arbiter,
  559. see \ref ConcurrentDataAccess.
  560. \section ConcurrentDataAccess Concurrent Data Accesses
  561. When several tasks are ready and will work on several data, StarPU is faced with
  562. the classical Dining Philosophers problem, and has to determine the order in
  563. which it will run the tasks.
  564. Data accesses usually use sequential ordering, so data accesses are usually
  565. already serialized, and thus by default StarPU uses the Dijkstra solution which
  566. scales very well in terms of overhead: tasks will just acquire data one by one
  567. by data handle pointer value order.
  568. When sequential ordering is disabled or the ::STARPU_COMMUTE flag is used, there
  569. may be a lot of concurrent accesses to the same data, and the Dijkstra solution
  570. gets only poor parallelism, typically in some pathological cases which do happen
  571. in various applications. In this case, one can use a data access arbiter, which
  572. implements the classical centralized solution for the Dining Philosophers
  573. problem. This is more expensive in terms of overhead since it is centralized,
  574. but it opportunistically gets a lot of parallelism. The centralization can also
  575. be avoided by using several arbiters, thus separating sets of data for which
  576. arbitration will be done. If a task accesses data from different arbiters, it
  577. will acquire them arbiter by arbiter, in arbiter pointer value order.
  578. See the <c>tests/datawizard/test_arbiter.cpp</c> example.
  579. Arbiters however do not support the ::STARPU_REDUX flag yet.
  580. \section TemporaryBuffers Temporary Buffers
  581. There are two kinds of temporary buffers: temporary data which just pass results
  582. from a task to another, and scratch data which are needed only internally by
  583. tasks.
  584. \subsection TemporaryData Temporary Data
  585. Data can sometimes be entirely produced by a task, and entirely consumed by
  586. another task, without the need for other parts of the application to access
  587. it. In such case, registration can be done without prior allocation, by using
  588. the special memory node number <c>-1</c>, and passing a zero pointer. StarPU will
  589. actually allocate memory only when the task creating the content gets scheduled,
  590. and destroy it on unregistration.
  591. In addition to this, it can be tedious for the application to have to unregister
  592. the data, since it will not use its content anyway. The unregistration can be
  593. done lazily by using the function starpu_data_unregister_submit(),
  594. which will record that no more tasks accessing the handle will be submitted, so
  595. that it can be freed as soon as the last task accessing it is over.
  596. The following code examplifies both points: it registers the temporary
  597. data, submits three tasks accessing it, and records the data for automatic
  598. unregistration.
  599. \code{.c}
  600. starpu_vector_data_register(&handle, -1, 0, n, sizeof(float));
  601. starpu_task_insert(&produce_data, STARPU_W, handle, 0);
  602. starpu_task_insert(&compute_data, STARPU_RW, handle, 0);
  603. starpu_task_insert(&summarize_data, STARPU_R, handle, STARPU_W, result_handle, 0);
  604. starpu_data_unregister_submit(handle);
  605. \endcode
  606. The application may also want to see the temporary data initialized
  607. on the fly before being used by the task. This can be done by using
  608. starpu_data_set_reduction_methods() to set an initialization codelet (no redux
  609. codelet is needed).
  610. \subsection ScratchData Scratch Data
  611. Some kernels sometimes need temporary data to achieve the computations, i.e. a
  612. workspace. The application could allocate it at the start of the codelet
  613. function, and free it at the end, but this would be costly. It could also
  614. allocate one buffer per worker (similarly to \ref HowToInitializeAComputationLibraryOnceForEachWorker),
  615. but this would
  616. make them systematic and permanent. A more optimized way is to use
  617. the data access mode ::STARPU_SCRATCH, as examplified below, which
  618. provides per-worker buffers without content consistency. The buffer is
  619. registered only once, using memory node <c>-1</c>, i.e. the application didn't allocate
  620. memory for it, and StarPU will allocate it on demand at task execution.
  621. \code{.c}
  622. starpu_vector_data_register(&workspace, -1, 0, sizeof(float));
  623. for (i = 0; i < N; i++)
  624. starpu_task_insert(&compute, STARPU_R, input[i], STARPU_SCRATCH, workspace, STARPU_W, output[i], 0);
  625. \endcode
  626. StarPU will make sure that the buffer is allocated before executing the task,
  627. and make this allocation per-worker: for CPU workers, notably, each worker has
  628. its own buffer. This means that each task submitted above will actually have its
  629. own workspace, which will actually be the same for all tasks running one after
  630. the other on the same worker. Also, if for instance memory becomes scarce,
  631. StarPU will notice that it can free such buffers easily, since the content does
  632. not matter.
  633. The example <c>examples/pi</c> uses scratches for some temporary buffer.
  634. \section ChangingDataSize Changing the size of a data
  635. The size of the output of a task may not be known in advance. In such a case,
  636. a task can dynamically allocate or even reallocate the data. An example can
  637. be found in <c>tests/datawizard/variable_size.c</c>. The example uses its own data
  638. interface so as to contain some simulation information for data growth, but the
  639. principle can be applied for any data interface.
  640. The principle is to use <c>starpu_malloc_on_node_flags</c> to make the new
  641. allocation, and use <c>starpu_free_on_node_flags</c> to release any previous
  642. allocation. The flags have to be precisely like in the example:
  643. \code{.c}
  644. unsigned workerid = starpu_worker_get_id_check();
  645. unsigned dst_node = starpu_worker_get_memory_node(workerid);
  646. interface->ptr = starpu_malloc_on_node_flags(dst_node, size + increase, STARPU_MALLOC_PINNED | STARPU_MALLOC_COUNT | STARPU_MEMORY_OVERFLOW);
  647. starpu_free_on_node_flags(dst_node, old, size, STARPU_MALLOC_PINNED | STARPU_MALLOC_COUNT | STARPU_MEMORY_OVERFLOW);
  648. interface->size += increase;
  649. \endcode
  650. so that the allocated area has the expected properties and the allocation is accounted for properly.
  651. Depending on the interface (vector, CSR, etc.) you may have to fix several
  652. members of the data interface: e.g. both <c>nx</c> and <c>allocsize</c> for
  653. vectors, and store the pointer both in <c>ptr</c> and <c>dev_handle</c>.
  654. Some interfaces make a distinction between the actual number of elements
  655. stored in the data and the actually allocated buffer. For instance, the vector
  656. interface uses the <c>nx</c> field for the former, and the <c>allocsize</c> for
  657. the latter. This allows for lazy reallocation to avoid reallocating the buffer
  658. everytime to exactly match the actual number of elements. Computations and data
  659. transfers will use <c>nx</c> field, while allocation functions will use the
  660. <c>allocsize</c>. One just has to make sure that <c>allocsize</c> is always
  661. bigger or equal to <c>nx</c>.
  662. Important note: one can not change the size of a partitioned data.
  663. \section TheMultiformatInterface The Multiformat Interface
  664. It may be interesting to represent the same piece of data using two different
  665. data structures: one only used on CPUs, and one only used on GPUs.
  666. This can be done by using the multiformat interface. StarPU
  667. will be able to convert data from one data structure to the other when needed.
  668. Note that the scheduler <c>dmda</c> is the only one optimized for this
  669. interface. The user must provide StarPU with conversion codelets:
  670. \snippet multiformat.c To be included. You should update doxygen if you see this text.
  671. Kernels can be written almost as for any other interface. Note that
  672. ::STARPU_MULTIFORMAT_GET_CPU_PTR shall only be used for CPU kernels. CUDA kernels
  673. must use ::STARPU_MULTIFORMAT_GET_CUDA_PTR, and OpenCL kernels must use
  674. ::STARPU_MULTIFORMAT_GET_OPENCL_PTR. ::STARPU_MULTIFORMAT_GET_NX may
  675. be used in any kind of kernel.
  676. \code{.c}
  677. static void
  678. multiformat_scal_cpu_func(void *buffers[], void *args)
  679. {
  680. struct point *aos;
  681. unsigned int n;
  682. aos = STARPU_MULTIFORMAT_GET_CPU_PTR(buffers[0]);
  683. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  684. ...
  685. }
  686. extern "C" void multiformat_scal_cuda_func(void *buffers[], void *_args)
  687. {
  688. unsigned int n;
  689. struct struct_of_arrays *soa;
  690. soa = (struct struct_of_arrays *) STARPU_MULTIFORMAT_GET_CUDA_PTR(buffers[0]);
  691. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  692. ...
  693. }
  694. \endcode
  695. A full example may be found in <c>examples/basic_examples/multiformat.c</c>.
  696. \section DefiningANewDataInterface Defining A New Data Interface
  697. This section proposes an example how to define your own interface, when the
  698. StarPU-provided interface do not fit your needs. Here we take a dumb example of
  699. an array of complex numbers represented by two arrays of double values.
  700. Let's thus define a new data interface to manage arrays of complex numbers:
  701. \code{.c}
  702. /* interface for complex numbers */
  703. struct starpu_complex_interface
  704. {
  705. double *real;
  706. double *imaginary;
  707. int nx;
  708. };
  709. \endcode
  710. That structure stores enough to describe <b>one</b> buffer of such kind of
  711. data. It is used for the buffer stored in the main memory, another instance
  712. is used for the buffer stored in a GPU, etc. A <i>data handle</i> is thus a
  713. collection of such structures, to remember each buffer on each memory node.
  714. Note: one should not take pointers into such structures, because StarPU needs
  715. to be able to copy over the content of it to various places, for instance to
  716. efficiently migrate a data buffer from one data handle to another data handle.
  717. Registering such a data to StarPU is easily done using the function
  718. starpu_data_register(). The last
  719. parameter of the function, <c>interface_complex_ops</c>, will be
  720. described below.
  721. \code{.c}
  722. void starpu_complex_data_register(starpu_data_handle_t *handle,
  723. unsigned home_node, double *real, double *imaginary, int nx)
  724. {
  725. struct starpu_complex_interface complex =
  726. {
  727. .real = real,
  728. .imaginary = imaginary,
  729. .nx = nx
  730. };
  731. if (interface_complex_ops.interfaceid == STARPU_UNKNOWN_INTERFACE_ID)
  732. {
  733. interface_complex_ops.interfaceid = starpu_data_interface_get_next_id();
  734. }
  735. starpu_data_register(handleptr, home_node, &complex, &interface_complex_ops);
  736. }
  737. \endcode
  738. The <c>struct starpu_complex_interface complex</c> is here used just to store the
  739. parameters that the user provided to <c>starpu_complex_data_register</c>.
  740. starpu_data_register() will first allocate the handle, and
  741. then pass the <c>starpu_complex_interface</c> structure to the
  742. starpu_data_interface_ops::register_data_handle method, which records them
  743. within the data handle (it is called once per node by starpu_data_register()):
  744. \code{.c}
  745. static void complex_register_data_handle(starpu_data_handle_t handle, unsigned home_node, void *data_interface)
  746. {
  747. struct starpu_complex_interface *complex_interface = (struct starpu_complex_interface *) data_interface;
  748. unsigned node;
  749. for (node = 0; node < STARPU_MAXNODES; node++)
  750. {
  751. struct starpu_complex_interface *local_interface = (struct starpu_complex_interface *)
  752. starpu_data_get_interface_on_node(handle, node);
  753. local_interface->nx = complex_interface->nx;
  754. if (node == home_node)
  755. {
  756. local_interface->real = complex_interface->real;
  757. local_interface->imaginary = complex_interface->imaginary;
  758. }
  759. else
  760. {
  761. local_interface->real = NULL;
  762. local_interface->imaginary = NULL;
  763. }
  764. }
  765. }
  766. \endcode
  767. If the application provided a home node, the corresponding pointers will be
  768. recorded for that node. Others have no buffer allocated yet.
  769. Different operations need to be defined for a data interface through
  770. the type starpu_data_interface_ops. We only define here the basic
  771. operations needed to run simple applications. The source code for the
  772. different functions can be found in the file
  773. <c>examples/interface/complex_interface.c</c>, the details of the hooks to be
  774. provided are documented in \ref starpu_data_interface_ops .
  775. \code{.c}
  776. static struct starpu_data_interface_ops interface_complex_ops =
  777. {
  778. .register_data_handle = complex_register_data_handle,
  779. .allocate_data_on_node = complex_allocate_data_on_node,
  780. .copy_methods = &complex_copy_methods,
  781. .get_size = complex_get_size,
  782. .footprint = complex_footprint,
  783. .interfaceid = STARPU_UNKNOWN_INTERFACE_ID,
  784. .interface_size = sizeof(struct starpu_complex_interface),
  785. };
  786. \endcode
  787. Functions need to be defined to access the different fields of the
  788. complex interface from a StarPU data handle.
  789. \code{.c}
  790. double *starpu_complex_get_real(starpu_data_handle_t handle)
  791. {
  792. struct starpu_complex_interface *complex_interface =
  793. (struct starpu_complex_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  794. return complex_interface->real;
  795. }
  796. double *starpu_complex_get_imaginary(starpu_data_handle_t handle);
  797. int starpu_complex_get_nx(starpu_data_handle_t handle);
  798. \endcode
  799. Similar functions need to be defined to access the different fields of the
  800. complex interface from a <c>void *</c> pointer to be used within codelet
  801. implemetations.
  802. \snippet complex.c To be included. You should update doxygen if you see this text.
  803. Complex data interfaces can then be registered to StarPU.
  804. \code{.c}
  805. double real = 45.0;
  806. double imaginary = 12.0;
  807. starpu_complex_data_register(&handle1, STARPU_MAIN_RAM, &real, &imaginary, 1);
  808. starpu_task_insert(&cl_display, STARPU_R, handle1, 0);
  809. \endcode
  810. and used by codelets.
  811. \code{.c}
  812. void display_complex_codelet(void *descr[], void *_args)
  813. {
  814. int nx = STARPU_COMPLEX_GET_NX(descr[0]);
  815. double *real = STARPU_COMPLEX_GET_REAL(descr[0]);
  816. double *imaginary = STARPU_COMPLEX_GET_IMAGINARY(descr[0]);
  817. int i;
  818. for(i=0 ; i<nx ; i++)
  819. {
  820. fprintf(stderr, "Complex[%d] = %3.2f + %3.2f i\n", i, real[i], imaginary[i]);
  821. }
  822. }
  823. \endcode
  824. The whole code for this complex data interface is available in the
  825. directory <c>examples/interface/</c>.
  826. \section SpecifyingATargetNode Specifying A Target Node For Task Data
  827. When executing a task on a GPU for instance, StarPU would normally copy all the
  828. needed data for the tasks on the embedded memory of the GPU. It may however
  829. happen that the task kernel would rather have some of the datas kept in the
  830. main memory instead of copied in the GPU, a pivoting vector for instance.
  831. This can be achieved by setting the starpu_codelet::specific_nodes flag to
  832. <c>1</c>, and then fill the starpu_codelet::nodes array (or starpu_codelet::dyn_nodes when
  833. starpu_codelet::nbuffers is greater than \ref STARPU_NMAXBUFS) with the node numbers
  834. where data should be copied to, or ::STARPU_SPECIFIC_NODE_LOCAL to let
  835. StarPU copy it to the memory node where the task will be executed.
  836. ::STARPU_SPECIFIC_NODE_CPU can also be used to request data to be
  837. put in CPU-accessible memory (and let StarPU choose the NUMA node).
  838. ::STARPU_SPECIFIC_NODE_FAST and ::STARPU_SPECIFIC_NODE_SLOW can also be
  839. used
  840. For instance,
  841. with the following codelet:
  842. \code{.c}
  843. struct starpu_codelet cl =
  844. {
  845. .cuda_funcs = { kernel },
  846. .nbuffers = 2,
  847. .modes = {STARPU_RW, STARPU_RW},
  848. .specific_nodes = 1,
  849. .nodes = {STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_LOCAL},
  850. };
  851. \endcode
  852. the first data of the task will be kept in the CPU memory, while the second
  853. data will be copied to the CUDA GPU as usual. A working example is available in
  854. <c>tests/datawizard/specific_node.c</c>
  855. With the following codelet:
  856. \code{.c}
  857. struct starpu_codelet cl =
  858. {
  859. .cuda_funcs = { kernel },
  860. .nbuffers = 2,
  861. .modes = {STARPU_RW, STARPU_RW},
  862. .specific_nodes = 1,
  863. .nodes = {STARPU_SPECIFIC_NODE_LOCAL, STARPU_SPECIFIC_NODE_SLOW},
  864. };
  865. \endcode
  866. The first data will be copied into fast (but probably size-limited) local memory
  867. while the second data will be left in slow (but large) memory. This makes sense
  868. when the kernel does not make so many accesses to the second data, and thus data
  869. being remote e.g. over a PCI bus is not a performance problem, and avoids
  870. filling the fast local memory with data which does not need the performance.
  871. In cases where the kernel is fine with some data being either local or in the
  872. main memory, ::STARPU_SPECIFIC_NODE_LOCAL_OR_CPU can be used. StarPU will then
  873. be free to leave the data in the main memory and let the kernel access it from
  874. accelerators, or to move it to the accelerator before starting the kernel, for
  875. instance:
  876. \code{.c}
  877. struct starpu_codelet cl =
  878. {
  879. .cuda_funcs = { kernel },
  880. .nbuffers = 2,
  881. .modes = {STARPU_RW, STARPU_R},
  882. .specific_nodes = 1,
  883. .nodes = {STARPU_SPECIFIC_NODE_LOCAL, STARPU_SPECIFIC_NODE_LOCAL_OR_CPU},
  884. };
  885. \endcode
  886. */