Skip to content

Commit 05347a2

Browse files
committed
Merge branch 'develop' into task/rhornung67/docs-improve
2 parents 7d1e81b + ede1f08 commit 05347a2

16 files changed

Lines changed: 303 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ set (raja_sources
136136
src/AlignedRangeIndexSetBuilders.cpp
137137
src/DepGraphNode.cpp
138138
src/LockFreeIndexSetBuilders.cpp
139+
src/Memory.cpp
139140
src/MemUtils_CUDA.cpp
140141
src/MemUtils_HIP.cpp
141142
src/PluginStrategy.cpp)

docs/sphinx/user_guide/feature/multi-reduction.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Please see the following cook book sections for guidance on policy usage:
4747

4848
* :ref:`cook-book-multi-reductions-label`.
4949

50+
Some backend multi-reduction implementations may use RAJA internal temporary
51+
storage. Please see the following section for guidance on releasing unused
52+
internal memory:
53+
54+
* :ref:`memory-release-internal-pool-label`.
5055

5156
--------------------
5257
MultiReduction Types

docs/sphinx/user_guide/feature/reduction.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ Please see the following cook book sections for guidance on policy usage:
5353

5454
* :ref:`cook-book-reductions-label`.
5555

56+
Some backend reduction implementations may use RAJA internal temporary storage.
57+
Please see the following section for guidance on releasing unused internal
58+
memory:
59+
60+
* :ref:`memory-release-internal-pool-label`.
5661

5762
----------------
5863
Reduction Types

docs/sphinx/user_guide/feature/scan.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ RAJA scan operations:
4343

4444
* :ref:`tut-scan-label`.
4545

46+
Some backend scan implementations may use RAJA internal temporary storage.
47+
Please see the following section for guidance on releasing unused internal
48+
memory:
49+
50+
* :ref:`memory-release-internal-pool-label`.
51+
4652
-----------------
4753
Scan Operations
4854
-----------------

docs/sphinx/user_guide/feature/sort.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ RAJA scan operations:
4747

4848
* :ref:`tut-sort-label`
4949

50+
Some backend sort implementations may use RAJA internal temporary storage.
51+
Please see the following section for guidance on releasing unused internal
52+
memory:
53+
54+
* :ref:`memory-release-internal-pool-label`.
55+
5056
-----------------
5157
Sort Operations
5258
-----------------

docs/sphinx/user_guide/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ to use RAJA in an application can be found in :ref:`app-considerations-label`.
3535
features
3636
cook_book
3737
profiling_with_caliper
38+
memory
3839
app_considerations
3940
tutorial

docs/sphinx/user_guide/memory.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. ##
2+
.. ## Copyright (c) Lawrence Livermore National Security, LLC and other
3+
.. ## RAJA Project Developers. See top-level LICENSE and COPYRIGHT
4+
.. ## files for dates and other details. No copyright assignment is required
5+
.. ## to contribute to RAJA.
6+
.. ##
7+
.. ## SPDX-License-Identifier: (BSD-3-Clause)
8+
.. ##
9+
10+
.. _memory-label:
11+
12+
******
13+
Memory
14+
******
15+
16+
.. _memory-release-internal-pool-label:
17+
18+
Releasing RAJA Internal Pool Memory
19+
===================================
20+
21+
Some RAJA backend operations, including reductions, scans, and sorts, may use
22+
temporary storage. RAJA keeps some of this storage for reuse in internal memory
23+
pools. Applications can call ``RAJA::release_unused_internal_memory()`` after
24+
outstanding RAJA and device work has completed to return unused internal memory
25+
to the backend allocator. Typical use is to call the function at application shutdown
26+
to prevent the internal memory pools from appearing in memory-leak reports. Frequent
27+
runtime calls are generally unnecessary because the pools retained for reuse are
28+
typically not large.
29+
30+
The function returns the number of bytes released and does not synchronize
31+
CUDA, HIP, or SYCL work. RAJA does not do this automatically during static
32+
destruction because CUDA and HIP runtime teardown can make late ``cudaFree`` or
33+
``hipFree`` calls fail. As such, this function must only be called before the
34+
end of main to avoid racing with backend runtime cleanup.

include/RAJA/RAJA.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@
157157
//
158158
#include "RAJA/util/BitMask.hpp"
159159

160+
//
161+
// Memory utility routines
162+
//
163+
#include "RAJA/util/memory.hpp"
164+
160165
//
161166
// sort algorithms
162167
//

include/RAJA/policy/cuda/MemUtils_CUDA.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ using device_pinned_mempool_type =
185185
basic_mempool::MemPool<DevicePinnedAllocator>;
186186
using pinned_mempool_type = basic_mempool::MemPool<PinnedAllocator>;
187187

188+
RAJA_INLINE
189+
size_t release_unused_internal_memory()
190+
{
191+
size_t released = 0;
192+
released += device_mempool_type::getInstance().release_unused();
193+
released += device_zeroed_mempool_type::getInstance().release_unused();
194+
released += device_pinned_mempool_type::getInstance().release_unused();
195+
released += pinned_mempool_type::getInstance().release_unused();
196+
return released;
197+
}
198+
188199
namespace detail
189200
{
190201

include/RAJA/policy/hip/MemUtils_HIP.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ using device_pinned_mempool_type =
162162
basic_mempool::MemPool<DevicePinnedAllocator>;
163163
using pinned_mempool_type = basic_mempool::MemPool<PinnedAllocator>;
164164

165+
RAJA_INLINE
166+
size_t release_unused_internal_memory()
167+
{
168+
size_t released = 0;
169+
released += device_mempool_type::getInstance().release_unused();
170+
released += device_zeroed_mempool_type::getInstance().release_unused();
171+
released += device_pinned_mempool_type::getInstance().release_unused();
172+
released += pinned_mempool_type::getInstance().release_unused();
173+
return released;
174+
}
175+
165176
namespace detail
166177
{
167178

0 commit comments

Comments
 (0)