standard_memory_library.doxy 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013,2015-2017 CNRS
  4. * Copyright (C) 2009-2011,2014-2017,2019 Université de Bordeaux
  5. * Copyright (C) 2011,2012 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. /*! \defgroup API_Standard_Memory_Library Standard Memory Library
  19. \def starpu_ssize_t
  20. \ingroup API_Standard_Memory_Library
  21. todo
  22. \def starpu_data_malloc_pinned_if_possible
  23. \ingroup API_Standard_Memory_Library
  24. \deprecated
  25. Equivalent to starpu_malloc(). This macro is provided to avoid breaking old codes.
  26. \def starpu_data_free_pinned_if_possible
  27. \ingroup API_Standard_Memory_Library
  28. \deprecated
  29. Equivalent to starpu_free(). This macro is provided to avoid breaking old codes.
  30. \def STARPU_MALLOC_PINNED
  31. \ingroup API_Standard_Memory_Library
  32. Value passed to the function starpu_malloc_flags() to indicate the memory allocation should be pinned.
  33. \def STARPU_MALLOC_COUNT
  34. \ingroup API_Standard_Memory_Library
  35. Value passed to the function starpu_malloc_flags() to indicate
  36. the memory allocation should be in the limit defined by the
  37. environment variables \ref STARPU_LIMIT_CUDA_devid_MEM,
  38. \ref STARPU_LIMIT_CUDA_MEM, \ref STARPU_LIMIT_OPENCL_devid_MEM,
  39. \ref STARPU_LIMIT_OPENCL_MEM and \ref STARPU_LIMIT_CPU_MEM (see
  40. Section \ref HowToLimitMemoryPerNode).
  41. If no memory is available, it tries to reclaim memory from StarPU.
  42. Memory allocated this way needs to be freed by calling the function
  43. starpu_free_flags() with the same flag.
  44. \def STARPU_MALLOC_NORECLAIM
  45. \ingroup API_Standard_Memory_Library
  46. Value passed to the function starpu_malloc_flags() along ::STARPU_MALLOC_COUNT
  47. to indicate that while the memory allocation should be kept in the limits
  48. defined for ::STARPU_MALLOC_COUNT, no reclaiming should be performed by
  49. starpu_malloc_flags() itself, thus potentially overflowing the
  50. memory node a bit. StarPU will reclaim memory after next task termination,
  51. according to the \ref STARPU_MINIMUM_AVAILABLE_MEM, \ref STARPU_TARGET_AVAILABLE_MEM,
  52. \ref STARPU_MINIMUM_CLEAN_BUFFERS, and \ref STARPU_TARGET_CLEAN_BUFFERS
  53. environment variables. If ::STARPU_MEMORY_WAIT is set, no overflowing will happen,
  54. starpu_malloc_flags() will wait for other eviction mechanisms to release enough memory.
  55. \def STARPU_MALLOC_SIMULATION_FOLDED
  56. \ingroup API_Standard_Memory_Library
  57. Value passed to the function starpu_malloc_flags() to indicate that when
  58. StarPU is using simgrid, the allocation can be "folded", i.e. a memory area is
  59. allocated, but its content is actually a replicate of the same memory area, to
  60. avoid having to actually allocate that much memory . This thus allows to have a
  61. memory area that does not actually consumes memory, to which one can read from
  62. and write to normally, but get bogus values.
  63. \fn int starpu_malloc_flags(void **A, size_t dim, int flags)
  64. \ingroup API_Standard_Memory_Library
  65. Perform a memory allocation based on the constraints defined
  66. by the given flag.
  67. \fn void starpu_malloc_set_align(size_t align)
  68. \ingroup API_Standard_Memory_Library
  69. Set an alignment constraints for starpu_malloc()
  70. allocations. \p align must be a power of two. This is for instance called
  71. automatically by the OpenCL driver to specify its own alignment
  72. constraints.
  73. \fn int starpu_malloc(void **A, size_t dim)
  74. \ingroup API_Standard_Memory_Library
  75. Allocate data of the given size \p dim in main memory, and
  76. return the pointer to the allocated data through \p A.
  77. It will also try to pin it in CUDA or OpenCL, so that data transfers
  78. from this buffer can be asynchronous, and thus permit data transfer
  79. and computation overlapping. The allocated buffer must be freed thanks
  80. to the starpu_free() function.
  81. \fn int starpu_free(void *A)
  82. \ingroup API_Standard_Memory_Library
  83. Free memory which has previously been allocated with starpu_malloc().
  84. \fn int starpu_free_flags(void *A, size_t dim, int flags)
  85. \ingroup API_Standard_Memory_Library
  86. Free memory by specifying its size. The given
  87. flags should be consistent with the ones given to starpu_malloc_flags()
  88. when allocating the memory.
  89. \fn void starpu_malloc_set_hooks(starpu_malloc_hook malloc_hook, starpu_free_hook free_hook)
  90. \ingroup API_Standard_Memory_Library
  91. Sets allocation functions to be used by StarPU. By default, StarPU will use
  92. \c malloc() (or \c cudaHostAlloc() if CUDA GPUs are used) for all its data
  93. handle allocations. The application can specify another allocation primitive
  94. by calling this. The malloc_hook should pass the allocated pointer through
  95. the \c A parameter, and return 0 on success. On allocation failure, it should
  96. return -ENOMEM. The \c flags parameter contains STARPU_MALLOC_PINNED if the
  97. memory should be pinned by the hook for GPU transfer efficiency. The hook
  98. can use starpu_memory_pin() to achieve this. The \c dst_node parameter
  99. is the starpu memory node, one can convert it to an hwloc logical id with
  100. starpu_memory_nodes_numa_id_to_hwloclogid() or to an OS NUMA number with
  101. starpu_memory_nodes_numa_devid_to_id().
  102. \fn int starpu_memory_pin(void *addr, size_t size)
  103. \ingroup API_Standard_Memory_Library
  104. Pin the given memory area, so that CPU-GPU transfers can be done
  105. asynchronously with DMAs. The memory must be unpinned with
  106. starpu_memory_unpin() before being freed. Returns 0 on success, -1 on error.
  107. \fn int starpu_memory_unpin(void *addr, size_t size)
  108. \ingroup API_Standard_Memory_Library
  109. Unpin the given memory area previously pinned with
  110. starpu_memory_pin(). Returns 0 on success, -1 on error.
  111. \fn ssize_t starpu_memory_get_total(unsigned node)
  112. \ingroup API_Standard_Memory_Library
  113. If a memory limit is defined on the given node (see Section
  114. \ref HowToLimitMemoryPerNode), return the amount of total memory
  115. on the node. Otherwise return -1.
  116. \fn ssize_t starpu_memory_get_total_all_nodes()
  117. \ingroup API_Standard_Memory_Library
  118. Return the amount of total memory on all memory nodes for whose a memory limit
  119. is defined (see Section \ref HowToLimitMemoryPerNode).
  120. \fn ssize_t starpu_memory_get_available(unsigned node)
  121. \ingroup API_Standard_Memory_Library
  122. If a memory limit is defined on the given node (see Section
  123. \ref HowToLimitMemoryPerNode), return the amount of available memory
  124. on the node. Otherwise return -1.
  125. \fn ssize_t starpu_memory_get_available_all_nodes()
  126. \ingroup API_Standard_Memory_Library
  127. Return the amount of available memory on all memory nodes for whose a memory limit
  128. is defined (see Section \ref HowToLimitMemoryPerNode).
  129. \fn int starpu_memory_allocate(unsigned node, size_t size, int flags)
  130. \ingroup API_Standard_Memory_Library
  131. If a memory limit is defined on the given node (see Section
  132. \ref HowToLimitMemoryPerNode), try to allocate some of it. This does not actually
  133. allocate memory, but only accounts for it. This can be useful when the
  134. application allocates data another way, but want StarPU to be aware of the
  135. allocation size e.g. for memory reclaiming.
  136. By default, the function returns <c>-ENOMEM</c> if there is not enough room on
  137. the given node. \p flags can be either ::STARPU_MEMORY_WAIT or
  138. ::STARPU_MEMORY_OVERFLOW to change this.
  139. \fn void starpu_memory_deallocate(unsigned node, size_t size)
  140. \ingroup API_Standard_Memory_Library
  141. If a memory limit is defined on the given node (see Section
  142. \ref HowToLimitMemoryPerNode), free some of it. This does not actually free memory,
  143. but only accounts for it, like starpu_memory_allocate(). The amount does not
  144. have to be exactly the same as what was passed to starpu_memory_allocate(),
  145. only the eventual amount needs to be the same, i.e. one call to
  146. starpu_memory_allocate() can be followed by several calls to
  147. starpu_memory_deallocate() to declare the deallocation piece by piece.
  148. \fn void starpu_memory_wait_available(unsigned node, size_t size)
  149. \ingroup API_Standard_Memory_Library
  150. If a memory limit is defined on the given
  151. node (see Section \ref HowToLimitMemoryPerNode), this will wait for \p size
  152. bytes to become available on \p node. Of course, since another thread may be
  153. allocating memory concurrently, this does not necessarily mean that this amount
  154. will be actually available, just that it was reached. To atomically wait for
  155. some amount of memory and reserve it, starpu_memory_allocate() should be used
  156. with the ::STARPU_MEMORY_WAIT flag.
  157. \def STARPU_MEMORY_WAIT
  158. \ingroup API_Standard_Memory_Library
  159. Value passed to starpu_memory_allocate() to specify that the function should
  160. wait for the requested amount of memory to become available, and atomically
  161. allocate it.
  162. \def STARPU_MEMORY_OVERFLOW
  163. \ingroup API_Standard_Memory_Library
  164. Value passed to starpu_memory_allocate() to specify that the function should
  165. allocate the amount of memory, even if that means overflowing the total size of
  166. the memory node.
  167. */