standard_memory_library.doxy 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2015 CNRS
  5. * Copyright (C) 2011, 2012 INRIA
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Standard_Memory_Library Standard Memory Library
  9. \def starpu_data_malloc_pinned_if_possible
  10. \ingroup API_Standard_Memory_Library
  11. \deprecated
  12. Equivalent to starpu_malloc(). This macro is provided to avoid breaking old codes.
  13. \def starpu_data_free_pinned_if_possible
  14. \ingroup API_Standard_Memory_Library
  15. \deprecated
  16. Equivalent to starpu_free(). This macro is provided to avoid breaking old codes.
  17. \def STARPU_MALLOC_PINNED
  18. \ingroup API_Standard_Memory_Library
  19. Value passed to the function starpu_malloc_flags() to indicate the memory allocation should be pinned.
  20. \def STARPU_MALLOC_COUNT
  21. \ingroup API_Standard_Memory_Library
  22. Value passed to the function starpu_malloc_flags() to indicate
  23. the memory allocation should be in the limit defined by the
  24. environment variables \ref STARPU_LIMIT_CUDA_devid_MEM,
  25. \ref STARPU_LIMIT_CUDA_MEM, \ref STARPU_LIMIT_OPENCL_devid_MEM,
  26. \ref STARPU_LIMIT_OPENCL_MEM and \ref STARPU_LIMIT_CPU_MEM (see
  27. Section \ref HowToLimitMemoryPerNode).
  28. If no memory is available, it tries to reclaim memory from StarPU.
  29. Memory allocated this way needs to be freed by calling the function
  30. starpu_free_flags() with the same flag.
  31. \def STARPU_MALLOC_NORECLAIM
  32. \ingroup API_Standard_Memory_Library
  33. Value passed to the function starpu_malloc_flags() along STARPU_MALLOC_COUNT
  34. to indicate that while the memory allocation should be kept in the limits
  35. defined for STARPU_MALLOC_COUNT, no reclaiming should be performed by
  36. starpu_malloc_flags itself, thus potentially overflowing the
  37. memory node a bit. StarPU will reclaim memory after next task termination,
  38. according to the STARPU_MINIMUM_AVAILABLE_MEM and STARPU_TARGET_AVAILABLE_MEM
  39. environment variables. If STARPU_MEMORY_WAIT is set, no overflowing will happen,
  40. starpu_malloc_flags() will wait for other eviction mechanisms to release enough memory.
  41. \fn int starpu_malloc_flags(void **A, size_t dim, int flags)
  42. \ingroup API_Standard_Memory_Library
  43. Performs a memory allocation based on the constraints defined
  44. by the given flag.
  45. \fn void starpu_malloc_set_align(size_t align)
  46. \ingroup API_Standard_Memory_Library
  47. This function sets an alignment constraints for starpu_malloc()
  48. allocations. align must be a power of two. This is for instance called
  49. automatically by the OpenCL driver to specify its own alignment
  50. constraints.
  51. \fn int starpu_malloc(void **A, size_t dim)
  52. \ingroup API_Standard_Memory_Library
  53. This function allocates data of the given size in main memory.
  54. It will also try to pin it in CUDA or OpenCL, so that data transfers
  55. from this buffer can be asynchronous, and thus permit data transfer
  56. and computation overlapping. The allocated buffer must be freed thanks
  57. to the starpu_free() function.
  58. \fn int starpu_free(void *A)
  59. \ingroup API_Standard_Memory_Library
  60. This function frees memory which has previously been allocated
  61. with starpu_malloc().
  62. \fn int starpu_free_flags(void *A, size_t dim, int flags)
  63. \ingroup API_Standard_Memory_Library
  64. This function frees memory by specifying its size. The given
  65. flags should be consistent with the ones given to starpu_malloc_flags()
  66. when allocating the memory.
  67. \fn int starpu_memory_pin(void *addr, size_t size)
  68. \ingroup API_Standard_Memory_Library
  69. This function pins the given memory area, so that CPU-GPU transfers can be done
  70. asynchronously with DMAs. The memory must be unpinned with
  71. starpu_memory_unpin() before being freed. Returns 0 on success, -1 on error.
  72. \fn int starpu_memory_unpin(void *addr, size_t size)
  73. \ingroup API_Standard_Memory_Library
  74. This function unpins the given memory area previously pinned with
  75. starpu_memory_pin(). Returns 0 on success, -1 on error.
  76. \fn ssize_t starpu_memory_get_total(unsigned node)
  77. \ingroup API_Standard_Memory_Library
  78. If a memory limit is defined on the given node (see Section \ref
  79. HowToLimitMemoryPerNode), return the amount of total memory
  80. on the node. Otherwise return -1.
  81. \fn ssize_t starpu_memory_get_available(unsigned node)
  82. \ingroup API_Standard_Memory_Library
  83. If a memory limit is defined on the given node (see Section \ref
  84. HowToLimitMemoryPerNode), return the amount of available memory
  85. on the node. Otherwise return -1.
  86. \fn int starpu_memory_allocate(unsigned node, size_t size, int flags)
  87. \ingroup API_Standard_Memory_Library
  88. If a memory limit is defined on the given node (see Section \ref
  89. HowToLimitMemoryPerNode), try to allocate some of it. This does not actually
  90. allocate memory, but only accounts for it. This can be useful when the
  91. application allocates data another way, but want StarPU to be aware of the
  92. allocation size e.g. for memory reclaiming.
  93. By default, the function returns -ENOMEM if there is not enough room on
  94. the given node. \p flags can be either STARPU_MEMORY_WAIT or
  95. STARPU_MEMORY_OVERFLOW to change this.
  96. \fn void starpu_memory_deallocate(unsigned node, size_t size)
  97. \ingroup API_Standard_Memory_Library
  98. If a memory limit is defined on the given node (see Section \ref
  99. HowToLimitMemoryPerNode), free some of it. This does not actually free memory,
  100. but only accounts for it, like starpu_memory_allocate(). The amount does not
  101. have to be exactly the same as what was passed to starpu_memory_allocate(),
  102. only the eventual amount needs to be the same, i.e. one call to
  103. starpu_memory_allocate() can be followed by several calls to
  104. starpu_memory_deallocate() to declare the deallocation piece by piece.
  105. \fn void starpu_memory_wait_available(unsigned node, size_t size)
  106. \ingroup API_Standard_Memory_Library
  107. If a memory limit is defined on the given
  108. node (see Section \ref HowToLimitMemoryPerNode), this will wait for \p size
  109. bytes to become available on \p node. Of course, since another thread may be
  110. allocating memory concurrently, this does not necessarily mean that this amount
  111. will be actually available, just that it was reached. To atomically wait for
  112. some amount of memory and reserve it, starpu_memory_allocate() should be used
  113. with the STARPU_MEMORY_WAIT flag.
  114. \def STARPU_MEMORY_WAIT
  115. \ingroup API_Standard_Memory_Library
  116. Value passed to starpu_memory_allocate() to specify that the function should
  117. wait for the requested amount of memory to become available, and atomically
  118. allocate it.
  119. \def STARPU_MEMORY_OVERFLOW
  120. \ingroup API_Standard_Memory_Library
  121. Value passed to starpu_memory_allocate() to specify that the function should
  122. allocate the amount of memory, even if that means overflowing the total size of
  123. the memory node.
  124. */