data_management.doxy 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 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 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. Data_Interfaces, but developers can design their own data interfaces
  12. if required.
  13. \typedef starpu_data_handle_t
  14. \ingroup 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 Data_Management
  22. This datatype describes a data access mode.
  23. \var starpu_data_access_mode::STARPU_NONE
  24. \ingroup Data_Management
  25. TODO!
  26. \var starpu_data_access_mode::STARPU_R
  27. \ingroup Data_Management
  28. read-only mode.
  29. \var starpu_data_access_mode::STARPU_W
  30. \ingroup Data_Management
  31. write-only mode.
  32. \var starpu_data_access_mode::STARPU_RW
  33. \ingroup Data_Management
  34. read-write mode. This is equivalent to ::STARPU_R|::STARPU_W
  35. \var starpu_data_access_mode::STARPU_SCRATCH
  36. \ingroup 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 Data_Management
  51. todo
  52. \var starpu_data_access_mode::STARPU_COMMUTE
  53. \ingroup Data_Management
  54. todo
  55. @name Basic Data Management API
  56. \ingroup Data_Management
  57. Data management is done at a high-level in StarPU: rather than
  58. accessing a mere list of contiguous buffers, the tasks may manipulate
  59. data that are described by a high-level construct which we call data
  60. interface.
  61. An example of data interface is the "vector" interface which describes
  62. a contiguous data array on a spefic memory node. This interface is a
  63. simple structure containing the number of elements in the array, the
  64. size of the elements, and the address of the array in the appropriate
  65. address space (this address may be invalid if there is no valid copy
  66. of the array in the memory node). More informations on the data
  67. interfaces provided by StarPU are given in \ref Data_Interfaces.
  68. When a piece of data managed by StarPU is used by a task, the task
  69. implementation is given a pointer to an interface describing a valid
  70. copy of the data that is accessible from the current processing unit.
  71. Every worker is associated to a memory node which is a logical
  72. abstraction of the address space from which the processing unit gets
  73. its data. For instance, the memory node associated to the different
  74. CPU workers represents main memory (RAM), the memory node associated
  75. to a GPU is DRAM embedded on the device. Every memory node is
  76. identified by a logical index which is accessible from the
  77. starpu_worker_get_memory_node function. When registering a piece of
  78. data to StarPU, the specified memory node indicates where the piece of
  79. data initially resides (we also call this memory node the home node of
  80. a piece of data).
  81. \fn void starpu_data_register(starpu_data_handle_t *handleptr, unsigned home_node, void *data_interface, struct starpu_data_interface_ops *ops)
  82. \ingroup Data_Management
  83. Register a piece of data into the handle located at the
  84. \p handleptr address. The \p data_interface buffer contains the initial
  85. description of the data in the \p home_node. The \p ops argument is a
  86. pointer to a structure describing the different methods used to
  87. manipulate this type of interface. See starpu_data_interface_ops for
  88. more details on this structure.
  89. If \p home_node is -1, StarPU will automatically allocate the memory when
  90. it is used for the first time in write-only mode. Once such data
  91. handle has been automatically allocated, it is possible to access it
  92. using any access mode.
  93. Note that StarPU supplies a set of predefined types of interface (e.g.
  94. vector or matrix) which can be registered by the means of helper
  95. functions (e.g. starpu_vector_data_register() or
  96. starpu_matrix_data_register()).
  97. \fn void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc)
  98. \ingroup Data_Management
  99. Register a new piece of data into the handle \p handledst with the
  100. same interface as the handle \p handlesrc.
  101. \fn void starpu_data_unregister(starpu_data_handle_t handle)
  102. \ingroup Data_Management
  103. This function unregisters a data handle from StarPU. If the
  104. data was automatically allocated by StarPU because the home node was
  105. -1, all automatically allocated buffers are freed. Otherwise, a valid
  106. copy of the data is put back into the home node in the buffer that was
  107. initially registered. Using a data handle that has been unregistered
  108. from StarPU results in an undefined behaviour. In case we do not need
  109. to update the value of the data in the home node, we can use
  110. the function starpu_data_unregister_no_coherency() instead.
  111. \fn void starpu_data_unregister_no_coherency(starpu_data_handle_t handle)
  112. \ingroup Data_Management
  113. This is the same as starpu_data_unregister(), except that
  114. StarPU does not put back a valid copy into the home node, in the
  115. buffer that was initially registered.
  116. \fn void starpu_data_unregister_submit(starpu_data_handle_t handle)
  117. \ingroup Data_Management
  118. Destroy the data handle once it is not needed anymore by any
  119. submitted task. No coherency is assumed.
  120. \fn void starpu_data_invalidate(starpu_data_handle_t handle)
  121. \ingroup Data_Management
  122. Destroy all replicates of the data handle immediately. After
  123. data invalidation, the first access to the handle must be performed in
  124. write-only mode. Accessing an invalidated data in read-mode results in
  125. undefined behaviour.
  126. \fn void starpu_data_invalidate_submit(starpu_data_handle_t handle)
  127. \ingroup Data_Management
  128. Submits invalidation of the data handle after completion of
  129. previously submitted tasks.
  130. \fn void starpu_data_set_wt_mask(starpu_data_handle_t handle, uint32_t wt_mask)
  131. \ingroup Data_Management
  132. This function sets the write-through mask of a given data (and
  133. its children), i.e. a bitmask of nodes where the data should be always
  134. replicated after modification. It also prevents the data from being
  135. evicted from these nodes when memory gets scarse. When the data is
  136. modified, it is automatically transfered into those memory node. For
  137. instance a <c>1<<0</c> write-through mask means that the CUDA workers
  138. will commit their changes in main memory (node 0).
  139. \fn int starpu_data_prefetch_on_node(starpu_data_handle_t handle, unsigned node, unsigned async)
  140. \ingroup Data_Management
  141. Issue a prefetch request for a given data to a given node, i.e.
  142. requests that the data be replicated to the given node, so that it is
  143. available there for tasks. If the \p async parameter is 0, the call will
  144. block until the transfer is achieved, else the call will return as
  145. soon as the request is scheduled (which may however have to wait for a
  146. task completion).
  147. \fn starpu_data_handle_t starpu_data_lookup(const void *ptr)
  148. \ingroup Data_Management
  149. Return the handle corresponding to the data pointed to by the \p ptr host pointer.
  150. \fn int starpu_data_request_allocation(starpu_data_handle_t handle, unsigned node)
  151. \ingroup Data_Management
  152. Explicitly ask StarPU to allocate room for a piece of data on
  153. the specified memory node.
  154. \fn void starpu_data_query_status(starpu_data_handle_t handle, int memory_node, int *is_allocated, int *is_valid, int *is_requested)
  155. \ingroup Data_Management
  156. Query the status of \p handle on the specified \p memory_node.
  157. \fn void starpu_data_advise_as_important(starpu_data_handle_t handle, unsigned is_important)
  158. \ingroup Data_Management
  159. This function allows to specify that a piece of data can be
  160. discarded without impacting the application.
  161. \fn void starpu_data_set_reduction_methods(starpu_data_handle_t handle, struct starpu_codelet *redux_cl, struct starpu_codelet *init_cl)
  162. \ingroup Data_Management
  163. This sets the codelets to be used for \p handle when it is
  164. accessed in STARPU_REDUX mode. Per-worker buffers will be initialized with
  165. the \p init_cl codelet, and reduction between per-worker buffers will be
  166. done with the \p redux_cl codelet.
  167. @name Access registered data from the application
  168. \ingroup Data_Management
  169. \fn int starpu_data_acquire(starpu_data_handle_t handle, enum starpu_data_access_mode mode)
  170. \ingroup Data_Management
  171. The application must call this function prior to accessing
  172. registered data from main memory outside tasks. StarPU ensures that
  173. the application will get an up-to-date copy of the data in main memory
  174. located where the data was originally registered, and that all
  175. concurrent accesses (e.g. from tasks) will be consistent with the
  176. access mode specified in the mode argument. starpu_data_release() must
  177. be called once the application does not need to access the piece of
  178. data anymore. Note that implicit data dependencies are also enforced
  179. by starpu_data_acquire(), i.e. starpu_data_acquire() will wait for all
  180. tasks scheduled to work on the data, unless they have been disabled
  181. explictly by calling starpu_data_set_default_sequential_consistency_flag() or
  182. starpu_data_set_sequential_consistency_flag(). starpu_data_acquire() is a
  183. blocking call, so that it cannot be called from tasks or from their
  184. callbacks (in that case, starpu_data_acquire() returns <c>-EDEADLK</c>). Upon
  185. successful completion, this function returns 0.
  186. \fn int starpu_data_acquire_cb(starpu_data_handle_t handle, enum starpu_data_access_mode mode, void (*callback)(void *), void *arg)
  187. \ingroup Data_Management
  188. Asynchronous equivalent of starpu_data_acquire(). When the data
  189. specified in \p handle is available in the appropriate access
  190. mode, the \p callback function is executed. The application may access
  191. the requested data during the execution of this \p callback. The \p callback
  192. function must call starpu_data_release() once the application does not
  193. need to access the piece of data anymore. Note that implicit data
  194. dependencies are also enforced by starpu_data_acquire_cb() in case they
  195. are not disabled. Contrary to starpu_data_acquire(), this function is
  196. non-blocking and may be called from task callbacks. Upon successful
  197. completion, this function returns 0.
  198. \fn int starpu_data_acquire_on_node(starpu_data_handle_t handle, unsigned node, enum starpu_data_access_mode mode)
  199. \ingroup Data_Management
  200. This is the same as starpu_data_acquire(), except that the data
  201. will be available on the given memory node instead of main memory.
  202. \fn int starpu_data_acquire_on_node_cb(starpu_data_handle_t handle, unsigned node, enum starpu_data_access_mode mode, void (*callback)(void *), void *arg)
  203. \ingroup Data_Management
  204. This is the same as starpu_data_acquire_cb(), except that the
  205. data will be available on the given memory node instead of main
  206. memory.
  207. \def STARPU_DATA_ACQUIRE_CB(starpu_data_handle_t handle, enum starpu_data_access_mode mode, code)
  208. \ingroup Data_Management
  209. STARPU_DATA_ACQUIRE_CB() is the same as starpu_data_acquire_cb(),
  210. except that the code to be executed in a callback is directly provided
  211. as a macro parameter, and the data \p handle is automatically released
  212. after it. This permits to easily execute code which depends on the
  213. value of some registered data. This is non-blocking too and may be
  214. called from task callbacks.
  215. \fn void starpu_data_release(starpu_data_handle_t handle)
  216. \ingroup Data_Management
  217. This function releases the piece of data acquired by the
  218. application either by starpu_data_acquire() or by
  219. starpu_data_acquire_cb().
  220. \fn void starpu_data_release_on_node(starpu_data_handle_t handle, unsigned node)
  221. \ingroup Data_Management
  222. This is the same as starpu_data_release(), except that the data
  223. will be available on the given memory \p node instead of main memory.
  224. */