data_management.doxy 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Data_Management Data Management
  9. \brief This section describes the data management facilities provided
  10. by StarPU. We show how to use existing data interfaces in \ref
  11. API_Data_Interfaces, but developers can design their own data interfaces if
  12. required.
  13. \typedef starpu_data_handle_t
  14. \ingroup API_Data_Management
  15. StarPU uses ::starpu_data_handle_t as an opaque handle to
  16. manage a piece of data. Once a piece of data has been registered to
  17. StarPU, it is associated to a ::starpu_data_handle_t which keeps track
  18. of the state of the piece of data over the entire machine, so that we
  19. can maintain data consistency and locate data replicates for instance.
  20. \enum starpu_data_access_mode
  21. \ingroup API_Data_Management
  22. This datatype describes a data access mode.
  23. \var starpu_data_access_mode::STARPU_NONE
  24. \ingroup API_Data_Management
  25. TODO
  26. \var starpu_data_access_mode::STARPU_R
  27. \ingroup API_Data_Management
  28. read-only mode.
  29. \var starpu_data_access_mode::STARPU_W
  30. \ingroup API_Data_Management
  31. write-only mode.
  32. \var starpu_data_access_mode::STARPU_RW
  33. \ingroup API_Data_Management
  34. read-write mode. This is equivalent to ::STARPU_R|::STARPU_W
  35. \var starpu_data_access_mode::STARPU_SCRATCH
  36. \ingroup API_Data_Management
  37. A temporary buffer is allocated for the task, but StarPU does not
  38. enforce data consistency---i.e. each device has its own buffer,
  39. independently from each other (even for CPUs), and no data transfer is
  40. ever performed. This is useful for temporary variables to avoid
  41. allocating/freeing buffers inside each task. Currently, no behavior is
  42. defined concerning the relation with the ::STARPU_R and ::STARPU_W modes
  43. and the value provided at registration --- i.e., the value of the
  44. scratch buffer is undefined at entry of the codelet function. It is
  45. being considered for future extensions at least to define the initial
  46. value. For now, data to be used in ::STARPU_SCRATCH mode should be
  47. registered with node <c>-1</c> and a <c>NULL</c> pointer, since the
  48. value of the provided buffer is simply ignored for now.
  49. \var starpu_data_access_mode::STARPU_REDUX
  50. \ingroup API_Data_Management
  51. todo
  52. \var starpu_data_access_mode::STARPU_COMMUTE
  53. \ingroup API_Data_Management
  54. In addition to that, ::STARPU_COMMUTE can be passed along ::STARPU_W
  55. or ::STARPU_RW to express that StarPU can let tasks commute, which is
  56. useful e.g. when bringing a contribution into some data, which can be
  57. done in any order (but still require sequential consistency against
  58. reads or non-commutative writes).
  59. \var starpu_data_access_mode::STARPU_SSEND
  60. \ingroup API_Data_Management
  61. used in starpu_mpi_insert_task() to specify the data has to be sent
  62. using a synchronous and non-blocking mode (see starpu_mpi_issend())
  63. @name Basic Data Management API
  64. \ingroup API_Data_Management
  65. Data management is done at a high-level in StarPU: rather than
  66. accessing a mere list of contiguous buffers, the tasks may manipulate
  67. data that are described by a high-level construct which we call data
  68. interface.
  69. An example of data interface is the "vector" interface which describes
  70. a contiguous data array on a spefic memory node. This interface is a
  71. simple structure containing the number of elements in the array, the
  72. size of the elements, and the address of the array in the appropriate
  73. address space (this address may be invalid if there is no valid copy
  74. of the array in the memory node). More informations on the data
  75. interfaces provided by StarPU are given in \ref API_Data_Interfaces.
  76. When a piece of data managed by StarPU is used by a task, the task
  77. implementation is given a pointer to an interface describing a valid
  78. copy of the data that is accessible from the current processing unit.
  79. Every worker is associated to a memory node which is a logical
  80. abstraction of the address space from which the processing unit gets
  81. its data. For instance, the memory node associated to the different
  82. CPU workers represents main memory (RAM), the memory node associated
  83. to a GPU is DRAM embedded on the device. Every memory node is
  84. identified by a logical index which is accessible from the
  85. function starpu_worker_get_memory_node(). When registering a piece of
  86. data to StarPU, the specified memory node indicates where the piece of
  87. data initially resides (we also call this memory node the home node of
  88. a piece of data).
  89. \fn void starpu_data_register(starpu_data_handle_t *handleptr, unsigned home_node, void *data_interface, struct starpu_data_interface_ops *ops)
  90. \ingroup API_Data_Management
  91. Register a piece of data into the handle located at the
  92. \p handleptr address. The \p data_interface buffer contains the initial
  93. description of the data in the \p home_node. The \p ops argument is a
  94. pointer to a structure describing the different methods used to
  95. manipulate this type of interface. See starpu_data_interface_ops for
  96. more details on this structure.
  97. If \p home_node is -1, StarPU will automatically allocate the memory when
  98. it is used for the first time in write-only mode. Once such data
  99. handle has been automatically allocated, it is possible to access it
  100. using any access mode.
  101. Note that StarPU supplies a set of predefined types of interface (e.g.
  102. vector or matrix) which can be registered by the means of helper
  103. functions (e.g. starpu_vector_data_register() or
  104. starpu_matrix_data_register()).
  105. \fn void starpu_data_ptr_register(starpu_data_handle_t handle, unsigned node)
  106. \ingroup API_Data_Management
  107. Register that a buffer for \p handle on \p node will be set. This is typically
  108. used by starpu_*_ptr_register helpers before setting the interface pointers for
  109. this node, to tell the core that that is now allocated.
  110. \fn void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc)
  111. \ingroup API_Data_Management
  112. Register a new piece of data into the handle \p handledst with the
  113. same interface as the handle \p handlesrc.
  114. \fn void starpu_data_unregister(starpu_data_handle_t handle)
  115. \ingroup API_Data_Management
  116. This function unregisters a data handle from StarPU. If the
  117. data was automatically allocated by StarPU because the home node was
  118. -1, all automatically allocated buffers are freed. Otherwise, a valid
  119. copy of the data is put back into the home node in the buffer that was
  120. initially registered. Using a data handle that has been unregistered
  121. from StarPU results in an undefined behaviour. In case we do not need
  122. to update the value of the data in the home node, we can use
  123. the function starpu_data_unregister_no_coherency() instead.
  124. \fn void starpu_data_unregister_no_coherency(starpu_data_handle_t handle)
  125. \ingroup API_Data_Management
  126. This is the same as starpu_data_unregister(), except that
  127. StarPU does not put back a valid copy into the home node, in the
  128. buffer that was initially registered.
  129. \fn void starpu_data_unregister_submit(starpu_data_handle_t handle)
  130. \ingroup API_Data_Management
  131. Destroy the data handle once it is not needed anymore by any
  132. submitted task. No coherency is assumed.
  133. \fn void starpu_data_invalidate(starpu_data_handle_t handle)
  134. \ingroup API_Data_Management
  135. Destroy all replicates of the data handle immediately. After
  136. data invalidation, the first access to the handle must be performed in
  137. write-only mode. Accessing an invalidated data in read-mode results in
  138. undefined behaviour.
  139. \fn void starpu_data_invalidate_submit(starpu_data_handle_t handle)
  140. \ingroup API_Data_Management
  141. Submits invalidation of the data handle after completion of
  142. previously submitted tasks.
  143. \fn void starpu_data_set_wt_mask(starpu_data_handle_t handle, uint32_t wt_mask)
  144. \ingroup API_Data_Management
  145. This function sets the write-through mask of a given data (and
  146. its children), i.e. a bitmask of nodes where the data should be always
  147. replicated after modification. It also prevents the data from being
  148. evicted from these nodes when memory gets scarse. When the data is
  149. modified, it is automatically transfered into those memory node. For
  150. instance a <c>1<<0</c> write-through mask means that the CUDA workers
  151. will commit their changes in main memory (node 0).
  152. \fn int starpu_data_fetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  153. \ingroup API_Data_Management
  154. Issue a fetch request for a given data to a given node, i.e.
  155. requests that the data be replicated to the given node as soon as possible, so that it is
  156. available there for tasks. If the \p async parameter is 0, the call will
  157. block until the transfer is achieved, else the call will return immediately,
  158. after having just queued the request. In the latter case, the request will
  159. asynchronously wait for the completion of any task writing on the data.
  160. \fn int starpu_data_prefetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  161. \ingroup API_Data_Management
  162. Issue a prefetch request for a given data to a given node, i.e.
  163. requests that the data be replicated to the given node when there is room for it, so that it is
  164. available there for tasks. If the \p async parameter is 0, the call will
  165. block until the transfer is achieved, else the call will return immediately,
  166. after having just queued the request. In the latter case, the request will
  167. asynchronously wait for the completion of any task writing on the data.
  168. \fn int starpu_data_idle_prefetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  169. \ingroup API_Data_Management
  170. Issue an idle prefetch request for a given data to a given node, i.e.
  171. requests that the data be replicated to the given node, so that it is
  172. available there for tasks, but only when the bus is really idle. If the \p async parameter is 0, the call will
  173. block until the transfer is achieved, else the call will return immediately,
  174. after having just queued the request. In the latter case, the request will
  175. asynchronously wait for the completion of any task writing on the data.
  176. \fn void star_data_wont_use(starpu_data_handle handle)
  177. \ingroup API_Data_Management
  178. Advise StarPU that this handle will not be used in the close future, and is
  179. thus a good candidate for eviction from GPUs. StarPU will thus write its value
  180. back to its home node when the bus is idle, and select this data in priority
  181. for eviction when memory gets low.
  182. \fn starpu_data_handle_t starpu_data_lookup(const void *ptr)
  183. \ingroup API_Data_Management
  184. Return the handle corresponding to the data pointed to by the \p ptr host pointer.
  185. \fn int starpu_data_request_allocation(starpu_data_handle_t handle, unsigned node)
  186. \ingroup API_Data_Management
  187. Explicitly ask StarPU to allocate room for a piece of data on
  188. the specified memory node.
  189. \fn void starpu_data_query_status(starpu_data_handle_t handle, int memory_node, int *is_allocated, int *is_valid, int *is_requested)
  190. \ingroup API_Data_Management
  191. Query the status of \p handle on the specified \p memory_node.
  192. \fn void starpu_data_advise_as_important(starpu_data_handle_t handle, unsigned is_important)
  193. \ingroup API_Data_Management
  194. This function allows to specify that a piece of data can be
  195. discarded without impacting the application.
  196. \fn void starpu_data_set_reduction_methods(starpu_data_handle_t handle, struct starpu_codelet *redux_cl, struct starpu_codelet *init_cl)
  197. \ingroup API_Data_Management
  198. This sets the codelets to be used for \p handle when it is
  199. accessed in the mode ::STARPU_REDUX. Per-worker buffers will be initialized with
  200. the codelet \p init_cl, and reduction between per-worker buffers will be
  201. done with the codelet \p redux_cl.
  202. \fn struct starpu_data_interface_ops* starpu_data_get_interface_ops(starpu_data_handle_t handle)
  203. \ingroup API_Data_Management
  204. todo
  205. @name Access registered data from the application
  206. \ingroup API_Data_Management
  207. \fn int starpu_data_acquire(starpu_data_handle_t handle, enum starpu_data_access_mode mode)
  208. \ingroup API_Data_Management
  209. The application must call this function prior to accessing
  210. registered data from main memory outside tasks. StarPU ensures that
  211. the application will get an up-to-date copy of the data in main memory
  212. located where the data was originally registered, and that all
  213. concurrent accesses (e.g. from tasks) will be consistent with the
  214. access mode specified in the mode argument. starpu_data_release() must
  215. be called once the application does not need to access the piece of
  216. data anymore. Note that implicit data dependencies are also enforced
  217. by starpu_data_acquire(), i.e. starpu_data_acquire() will wait for all
  218. tasks scheduled to work on the data, unless they have been disabled
  219. explictly by calling starpu_data_set_default_sequential_consistency_flag() or
  220. starpu_data_set_sequential_consistency_flag(). starpu_data_acquire() is a
  221. blocking call, so that it cannot be called from tasks or from their
  222. callbacks (in that case, starpu_data_acquire() returns <c>-EDEADLK</c>). Upon
  223. successful completion, this function returns 0.
  224. \fn int starpu_data_acquire_cb(starpu_data_handle_t handle, enum starpu_data_access_mode mode, void (*callback)(void *), void *arg)
  225. \ingroup API_Data_Management
  226. Asynchronous equivalent of starpu_data_acquire(). When the data
  227. specified in \p handle is available in the appropriate access
  228. mode, the \p callback function is executed. The application may access
  229. the requested data during the execution of this \p callback. The \p callback
  230. function must call starpu_data_release() once the application does not
  231. need to access the piece of data anymore. Note that implicit data
  232. dependencies are also enforced by starpu_data_acquire_cb() in case they
  233. are not disabled. Contrary to starpu_data_acquire(), this function is
  234. non-blocking and may be called from task callbacks. Upon successful
  235. completion, this function returns 0.
  236. \fn int starpu_data_acquire_cb_sequential_consistency(starpu_data_handle_t handle, enum starpu_data_access_mode mode, void (*callback)(void *), void *arg, int sequential_consistency)
  237. \ingroup API_Data_Management
  238. Equivalent of starpu_data_acquire_cb() with the possibility of enabling or disabling data dependencies.
  239. When the data specified in \p handle is available in the appropriate access
  240. mode, the \p callback function is executed. The application may access
  241. the requested data during the execution of this \p callback. The \p callback
  242. function must call starpu_data_release() once the application does not
  243. need to access the piece of data anymore. Note that implicit data
  244. dependencies are also enforced by starpu_data_acquire_cb_sequential_consistency() in case they
  245. are not disabled specifically for the given \p handle or by the parameter \p sequential_consistency.
  246. Similarly to starpu_data_acquire_cb(), this function is
  247. non-blocking and may be called from task callbacks. Upon successful
  248. completion, this function returns 0.
  249. \fn int starpu_data_acquire_on_node(starpu_data_handle_t handle, int node, enum starpu_data_access_mode mode)
  250. \ingroup API_Data_Management
  251. This is the same as starpu_data_acquire(), except that the data
  252. will be available on the given memory node instead of main memory.
  253. \fn int starpu_data_acquire_on_node_cb(starpu_data_handle_t handle, int node, enum starpu_data_access_mode mode, void (*callback)(void *), void *arg)
  254. \ingroup API_Data_Management
  255. This is the same as starpu_data_acquire_cb(), except that the
  256. data will be available on the given memory node instead of main
  257. memory.
  258. \fn int starpu_data_acquire_on_node_cb_sequential_consistency(starpu_data_handle_t handle, int node, enum starpu_data_access_mode mode, void (*callback)(void *), void *arg, int sequential_consistency)
  259. \ingroup API_Data_Management
  260. This is the same as starpu_data_acquire_cb_sequential_consistency(), except that the
  261. data will be available on the given memory node instead of main
  262. memory.
  263. \def STARPU_DATA_ACQUIRE_CB(handle, mode, code)
  264. \ingroup API_Data_Management
  265. STARPU_DATA_ACQUIRE_CB() is the same as starpu_data_acquire_cb(),
  266. except that the code to be executed in a callback is directly provided
  267. as a macro parameter, and the data \p handle is automatically released
  268. after it. This permits to easily execute code which depends on the
  269. value of some registered data. This is non-blocking too and may be
  270. called from task callbacks.
  271. \fn void starpu_data_release(starpu_data_handle_t handle)
  272. \ingroup API_Data_Management
  273. This function releases the piece of data acquired by the
  274. application either by starpu_data_acquire() or by
  275. starpu_data_acquire_cb().
  276. \fn void starpu_data_release_on_node(starpu_data_handle_t handle, int node)
  277. \ingroup API_Data_Management
  278. This is the same as starpu_data_release(), except that the data
  279. will be available on the given memory \p node instead of main memory.
  280. */