data_management.doxy 11 KB

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