standard_memory_library.doxy 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013,2015-2017 CNRS
  4. * Copyright (C) 2009-2011,2014-2017 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 int starpu_memory_pin(void *addr, size_t size)
  90. \ingroup API_Standard_Memory_Library
  91. Pin the given memory area, so that CPU-GPU transfers can be done
  92. asynchronously with DMAs. The memory must be unpinned with
  93. starpu_memory_unpin() before being freed. Returns 0 on success, -1 on error.
  94. \fn int starpu_memory_unpin(void *addr, size_t size)
  95. \ingroup API_Standard_Memory_Library
  96. Unpin the given memory area previously pinned with
  97. starpu_memory_pin(). Returns 0 on success, -1 on error.
  98. \fn ssize_t starpu_memory_get_total(unsigned node)
  99. \ingroup API_Standard_Memory_Library
  100. If a memory limit is defined on the given node (see Section
  101. \ref HowToLimitMemoryPerNode), return the amount of total memory
  102. on the node. Otherwise return -1.
  103. \fn ssize_t starpu_memory_get_total_all_nodes()
  104. \ingroup API_Standard_Memory_Library
  105. Return the amount of total memory on all memory nodes for whose a memory limit
  106. is defined (see Section \ref HowToLimitMemoryPerNode).
  107. \fn ssize_t starpu_memory_get_available(unsigned node)
  108. \ingroup API_Standard_Memory_Library
  109. If a memory limit is defined on the given node (see Section
  110. \ref HowToLimitMemoryPerNode), return the amount of available memory
  111. on the node. Otherwise return -1.
  112. \fn ssize_t starpu_memory_get_available_all_nodes()
  113. \ingroup API_Standard_Memory_Library
  114. Return the amount of available memory on all memory nodes for whose a memory limit
  115. is defined (see Section \ref HowToLimitMemoryPerNode).
  116. \fn int starpu_memory_allocate(unsigned node, size_t size, int flags)
  117. \ingroup API_Standard_Memory_Library
  118. If a memory limit is defined on the given node (see Section
  119. \ref HowToLimitMemoryPerNode), try to allocate some of it. This does not actually
  120. allocate memory, but only accounts for it. This can be useful when the
  121. application allocates data another way, but want StarPU to be aware of the
  122. allocation size e.g. for memory reclaiming.
  123. By default, the function returns <c>-ENOMEM</c> if there is not enough room on
  124. the given node. \p flags can be either ::STARPU_MEMORY_WAIT or
  125. ::STARPU_MEMORY_OVERFLOW to change this.
  126. \fn void starpu_memory_deallocate(unsigned node, size_t size)
  127. \ingroup API_Standard_Memory_Library
  128. If a memory limit is defined on the given node (see Section
  129. \ref HowToLimitMemoryPerNode), free some of it. This does not actually free memory,
  130. but only accounts for it, like starpu_memory_allocate(). The amount does not
  131. have to be exactly the same as what was passed to starpu_memory_allocate(),
  132. only the eventual amount needs to be the same, i.e. one call to
  133. starpu_memory_allocate() can be followed by several calls to
  134. starpu_memory_deallocate() to declare the deallocation piece by piece.
  135. \fn void starpu_memory_wait_available(unsigned node, size_t size)
  136. \ingroup API_Standard_Memory_Library
  137. If a memory limit is defined on the given
  138. node (see Section \ref HowToLimitMemoryPerNode), this will wait for \p size
  139. bytes to become available on \p node. Of course, since another thread may be
  140. allocating memory concurrently, this does not necessarily mean that this amount
  141. will be actually available, just that it was reached. To atomically wait for
  142. some amount of memory and reserve it, starpu_memory_allocate() should be used
  143. with the ::STARPU_MEMORY_WAIT flag.
  144. \def STARPU_MEMORY_WAIT
  145. \ingroup API_Standard_Memory_Library
  146. Value passed to starpu_memory_allocate() to specify that the function should
  147. wait for the requested amount of memory to become available, and atomically
  148. allocate it.
  149. \def STARPU_MEMORY_OVERFLOW
  150. \ingroup API_Standard_Memory_Library
  151. Value passed to starpu_memory_allocate() to specify that the function should
  152. allocate the amount of memory, even if that means overflowing the total size of
  153. the memory node.
  154. */