401_out_of_core.doxy 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013,2014,2016-2019 CNRS
  4. * Copyright (C) 2013,2014,2017,2018 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. \section UseANewDiskMemory Use a new disk memory
  41. To use a disk memory node, you have to register it with this function:
  42. \code{.c}
  43. int new_dd = starpu_disk_register(&starpu_disk_unistd_ops, (void *) "/tmp/", 1024*1024*200);
  44. \endcode
  45. Here, we use the \c unistd library to realize the read/write operations, i.e.
  46. \c fread/\c fwrite. This structure must have a path where to store files, as well as
  47. the maximum size the software can afford storing on the disk.
  48. Don't forget to check if the result is correct!
  49. 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 :
  50. \verbatim
  51. export STARPU_DISK_SWAP=/tmp
  52. export STARPU_DISK_SWAP_BACKEND=unistd
  53. export STARPU_DISK_SWAP_SIZE=200
  54. \endverbatim
  55. The backend can be set to \c stdio (some caching is done by \c libc), \c unistd (only
  56. caching in the kernel), \c unistd_o_direct (no caching), \c leveldb, or \c hdf5.
  57. When that register call is made, StarPU will benchmark the disk. This can
  58. take some time.
  59. <strong>Warning: the size thus has to be at least \ref STARPU_DISK_SIZE_MIN bytes ! </strong>
  60. StarPU will then automatically try to evict unused data to this new disk. One
  61. can also use the standard StarPU memory node API to prefetch data etc., see the
  62. \ref API_Standard_Memory_Library and the \ref API_Data_Interfaces.
  63. The disk is unregistered during the starpu_shutdown().
  64. \section OOCDataRegistration Data Registration
  65. StarPU will only be able to achieve Out-Of-Core eviction if it controls memory
  66. allocation. For instance, if the application does the following:
  67. \code{.c}
  68. p = malloc(1024*1024*sizeof(float));
  69. fill_with_data(p);
  70. starpu_matrix_data_register(&h, STARPU_MAIN_RAM, (uintptr_t) p, 1024, 1024, 1024, sizeof(float));
  71. \endcode
  72. StarPU will not be able to release the corresponding memory since it's the
  73. application which allocated it, and StarPU can not know how, and thus how to
  74. release it. One thus have to use the following instead:
  75. \code{.c}
  76. starpu_matrix_data_register(&h, -1, NULL, 1024, 1024, 1024, sizeof(float));
  77. starpu_task_insert(cl_fill_with_data, STARPU_W, h, 0);
  78. \endcode
  79. Which makes StarPU automatically do the allocation when the task running
  80. cl_fill_with_data gets executed. And then if its needs to, it will be able to
  81. release it after having pushed the data to the disk.
  82. \section OOCWontUse Using Wont Use
  83. By default, StarPU uses a Least-Recently-Used (LRU) algorithm to determine
  84. which data should be evicted to the disk. This algorithm can be hinted
  85. by telling which data will no be used in the coming future thanks to
  86. starpu_data_wont_use(), for instance:
  87. \code{.c}
  88. starpu_task_insert(&cl_work, STARPU_RW, h, 0);
  89. starpu_data_wont_use(h);
  90. \endcode
  91. StarPU will mark the data as "inactive" and tend to evict to the disk that data
  92. rather than others.
  93. \section ExampleDiskCopy Examples: disk_copy
  94. \snippet disk_copy.c To be included. You should update doxygen if you see this text.
  95. \section ExampleDiskCompute Examples: disk_compute
  96. \snippet disk_compute.c To be included. You should update doxygen if you see this text.
  97. \section Performances
  98. Scheduling heuristics for Out-of-core are still relatively experimental. The
  99. tricky part is that you usually have to find a compromise between privileging
  100. locality (which avoids back and forth with the disk) and privileging the
  101. critical path, i.e. taking into account priorities to avoid lack of parallelism
  102. at the end of the task graph.
  103. It is notably better to avoid defining different priorities to tasks with low
  104. priority, since that will make the scheduler want to schedule them by levels of
  105. priority, at the depense of locality.
  106. The scheduling algorithms worth trying are thus <code>dmdar</code> and
  107. <code>lws</code>, which privilege data locality over priorities. There will be
  108. work on this area in the coming future.
  109. \section DiskFunctions Disk functions
  110. There are various ways to operate a disk memory node, described by the structure
  111. starpu_disk_ops. For instance, the variable #starpu_disk_unistd_ops
  112. uses read/write functions.
  113. All structures are in \ref API_Out_Of_Core.
  114. */