When sharing a pool between different parts of your application, or even between co-ordinating libraries in the same application, you might want to grow and shrink a pool on demand. By limiting the size of a pool using device memory, you leave more space on the GPU for "unified memory" to move data there.
The basic idea is to create a pool that allocates a block of your minimum size, and then allocate a single word from this pool to ensure the initial block is never freed:
../../../examples/cookbook/recipe_shrink.cpp
To increase the pool size you can preallocate a large chunk and then immediately free it. The pool will retain this memory for use by later allocations:
../../../examples/cookbook/recipe_shrink.cpp
Assuming that there are no allocations left in the larger "chunk" of the pool, you can shrink the pool back down to the initial size by calling umpire::Allocator::release
:
../../../examples/cookbook/recipe_shrink.cpp
The complete example is included below:
../../../examples/cookbook/recipe_shrink.cpp