401_out_of_core.doxy 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013,2014,2016-2019 CNRS
  4. * Copyright (C) 2013,2014,2017,2018-2019 Université de Bordeaux
  5. * Copyright (C) 2013 Inria
  6. * Copyright (C) 2013 Corentin Salingue
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. /*! \page OutOfCore Out Of Core
  20. \section Introduction Introduction
  21. When using StarPU, one may need to store more data than what the main memory
  22. (RAM) can store. This part describes the method to add a new memory node on a
  23. disk and to use it.
  24. Similarly to what happens with GPUs (it's actually exactly the same code), when
  25. available main memory becomes scarse, StarPU will evict unused data to the disk,
  26. thus leaving room for new allocations. Whenever some evicted data is needed
  27. again for a task, StarPU will automatically fetch it back from the disk.
  28. The principle is that one first registers a disk location, seen by StarPU as a
  29. <c>void*</c>, which can be for instance a Unix path for the \c stdio, \c unistd or
  30. \c unistd_o_direct backends, or a leveldb database for the \c leveldb backend, an HDF5
  31. file path for the \c HDF5 backend, etc. The \c disk backend opens this place with the
  32. plug() method.
  33. StarPU can then start using it to allocate room and store data there with the
  34. disk write method, without user intervention.
  35. The user can also use starpu_disk_open() to explicitly open an object within the
  36. disk, e.g. a file name in the \c stdio or \c unistd cases, or a database key in the
  37. \c leveldb case, and then use <c>starpu_*_register</c> functions to turn it into a StarPU
  38. data handle. StarPU will then use this file as external source of data, and
  39. automatically read and write data as appropriate.
  40. In any case, the user also needs to set \ref STARPU_LIMIT_CPU_MEM to the amount of
  41. data that StarPU will be allowed to afford. By default StarPU will use the
  42. machine memory size, but part of it is taken by the kernel, the system,
  43. daemons, and the application's own allocated data, whose size can not be
  44. predicted. That is why the user needs to specify what StarPU can afford.
  45. Some Out-of-core tests are worth giving a read, see <c>tests/disk/*.c</c>
  46. \section UseANewDiskMemory Use a new disk memory
  47. To use a disk memory node, you have to register it with this function:
  48. \code{.c}
  49. int new_dd = starpu_disk_register(&starpu_disk_unistd_ops, (void *) "/tmp/", 1024*1024*200);
  50. \endcode
  51. Here, we use the \c unistd library to realize the read/write operations, i.e.
  52. \c fread/\c fwrite. This structure must have a path where to store files, as well as
  53. the maximum size the software can afford storing on the disk.
  54. Don't forget to check if the result is correct!
  55. This can also be achieved by just setting environment variables \ref STARPU_DISK_SWAP, \ref STARPU_DISK_SWAP_BACKEND and \ref STARPU_DISK_SWAP_SIZE :
  56. \verbatim
  57. export STARPU_DISK_SWAP=/tmp
  58. export STARPU_DISK_SWAP_BACKEND=unistd
  59. export STARPU_DISK_SWAP_SIZE=200
  60. \endverbatim
  61. The backend can be set to \c stdio (some caching is done by \c libc and the kernel), \c unistd (only
  62. caching in the kernel), \c unistd_o_direct (no caching), \c leveldb, or \c hdf5.
  63. It is important to understand that when the backend is not set to \c
  64. unistd_o_direct, some caching will occur at the kernel level (the page cache),
  65. which will also consume memory... \ref STARPU_LIMIT_CPU_MEM might need to be set
  66. to less that half of the machine memory just to leave room for the kernel's
  67. page cache, otherwise the kernel will struggle to get memory. Using \c
  68. unistd_o_direct avoids this caching, thus allowing to set \ref STARPU_LIMIT_CPU_MEM
  69. to the machine memory size (minus some memory for normal kernel operations,
  70. system daemons, and application data).
  71. When the register call is made, StarPU will benchmark the disk. This can
  72. take some time.
  73. <strong>Warning: the size thus has to be at least \ref STARPU_DISK_SIZE_MIN bytes ! </strong>
  74. StarPU will then automatically try to evict unused data to this new disk. One
  75. can also use the standard StarPU memory node API to prefetch data etc., see the
  76. \ref API_Standard_Memory_Library and the \ref API_Data_Interfaces.
  77. The disk is unregistered during the starpu_shutdown().
  78. \section OOCDataRegistration Data Registration
  79. StarPU will only be able to achieve Out-Of-Core eviction if it controls memory
  80. allocation. For instance, if the application does the following:
  81. \code{.c}
  82. p = malloc(1024*1024*sizeof(float));
  83. fill_with_data(p);
  84. starpu_matrix_data_register(&h, STARPU_MAIN_RAM, (uintptr_t) p, 1024, 1024, 1024, sizeof(float));
  85. \endcode
  86. StarPU will not be able to release the corresponding memory since it's the
  87. application which allocated it, and StarPU can not know how, and thus how to
  88. release it. One thus have to use the following instead:
  89. \code{.c}
  90. starpu_matrix_data_register(&h, -1, NULL, 1024, 1024, 1024, sizeof(float));
  91. starpu_task_insert(cl_fill_with_data, STARPU_W, h, 0);
  92. \endcode
  93. Which makes StarPU automatically do the allocation when the task running
  94. cl_fill_with_data gets executed. And then if its needs to, it will be able to
  95. release it after having pushed the data to the disk. Since no initial buffer is
  96. provided to starpu_matrix_data_register(), the handle does not have any initial
  97. value right after this call, and thus the very first task using the handle needs
  98. to use the ::STARPU_W mode like above, ::STARPU_R or ::STARPU_RW would not make
  99. sense.
  100. By default, StarPU will try to push any data handle to the disk.
  101. To specify whether a given handle should be pushed to the disk,
  102. starpu_data_set_ooc_flag() should be used.
  103. \section OOCWontUse Using Wont Use
  104. By default, StarPU uses a Least-Recently-Used (LRU) algorithm to determine
  105. which data should be evicted to the disk. This algorithm can be hinted
  106. by telling which data will no be used in the coming future thanks to
  107. starpu_data_wont_use(), for instance:
  108. \code{.c}
  109. starpu_task_insert(&cl_work, STARPU_RW, h, 0);
  110. starpu_data_wont_use(h);
  111. \endcode
  112. StarPU will mark the data as "inactive" and tend to evict to the disk that data
  113. rather than others.
  114. \section ExampleDiskCopy Examples: disk_copy
  115. \snippet disk_copy.c To be included. You should update doxygen if you see this text.
  116. \section ExampleDiskCompute Examples: disk_compute
  117. \snippet disk_compute.c To be included. You should update doxygen if you see this text.
  118. \section Performances
  119. Scheduling heuristics for Out-of-core are still relatively experimental. The
  120. tricky part is that you usually have to find a compromise between privileging
  121. locality (which avoids back and forth with the disk) and privileging the
  122. critical path, i.e. taking into account priorities to avoid lack of parallelism
  123. at the end of the task graph.
  124. It is notably better to avoid defining different priorities to tasks with low
  125. priority, since that will make the scheduler want to schedule them by levels of
  126. priority, at the depense of locality.
  127. The scheduling algorithms worth trying are thus <code>dmdar</code> and
  128. <code>lws</code>, which privilege data locality over priorities. There will be
  129. work on this area in the coming future.
  130. \section FeedBackFigures Feedback Figures
  131. Beyond pure performance feedback, some figures are interesting to have a look at.
  132. Using <c>export STARPU_BUS_STATS=1</c> gives an overview of the data
  133. transfers which were needed. The values can also be obtained at runtime
  134. by using starpu_bus_get_profiling_info(). An example can be read in
  135. <c>src/profiling/profiling_helpers.c</c>.
  136. \verbatim
  137. #---------------------
  138. Data transfer speed for /tmp/sthibault-disk-DJzhAj (node 1):
  139. 0 -> 1: 99 MB/s
  140. 1 -> 0: 99 MB/s
  141. 0 -> 1: 23858 µs
  142. 1 -> 0: 23858 µs
  143. #---------------------
  144. TEST DISK MEMORY
  145. #---------------------
  146. Data transfer stats:
  147. Disk 0 -> NUMA 0 0.0000 GB 0.0000 MB/s (transfers : 0 - avg -nan MB)
  148. NUMA 0 -> Disk 0 0.0625 GB 63.6816 MB/s (transfers : 2 - avg 32.0000 MB)
  149. Total transfers: 0.0625 GB
  150. #---------------------
  151. \endverbatim
  152. Using <c>export STARPU_ENABLE_STATS=1</c> gives information for each memory node
  153. on data miss/hit and allocation miss/hit.
  154. \verbatim
  155. #---------------------
  156. MSI cache stats :
  157. memory node NUMA 0
  158. hit : 32 (66.67 %)
  159. miss : 16 (33.33 %)
  160. memory node Disk 0
  161. hit : 0 (0.00 %)
  162. miss : 0 (0.00 %)
  163. #---------------------
  164. #---------------------
  165. Allocation cache stats:
  166. memory node NUMA 0
  167. total alloc : 16
  168. cached alloc: 0 (0.00 %)
  169. memory node Disk 0
  170. total alloc : 8
  171. cached alloc: 0 (0.00 %)
  172. #---------------------
  173. \endverbatim
  174. \section DiskFunctions Disk functions
  175. There are various ways to operate a disk memory node, described by the structure
  176. starpu_disk_ops. For instance, the variable #starpu_disk_unistd_ops
  177. uses read/write functions.
  178. All structures are in \ref API_Out_Of_Core.
  179. */