occa icon indicating copy to clipboard operation
occa copied to clipboard

[API][Core] Memory Pools

Open noelchalmers opened this issue 4 years ago • 1 comments

Description

Adds new occa::memoryPool object to the OCCA API, which allows users to access a pool of device memory.

The occa::memoryPool object is created from an initialized occa::device as

occa::memoryPool memPool = device.createMemoryPool(props);

After creation, the user can reserve space inside the memory pool, receiving a corresponding occa::memory object which references a reserved memory region:

occa::memory a = memPool.reserve<float>(entries);

The underlying device memory pool region managed by the occa::memoryPool is automatically resized and de-fragmented as new reservations are added. The user can query how large the underlying memory region is, and how much space is currently reserved:

udim_t  s = memPool.size();
udim_t  r = memPool.reserved();

Reservations are automatically released when all occa::memory references to a given region are deleted/freed.

The user can manually resize the underlying pool:

memPool.resize(bytes);

However, the size of the memory pool cannot be reduced below the current reservation total.

ToDo

  • [ ] C bindings
  • [ ] Testing for each backend in small benchmarks

noelchalmers avatar Nov 27 '21 18:11 noelchalmers

Codecov Report

Merging #543 (8b14acb) into development (f5e4972) will increase coverage by 0.11%. The diff coverage is 71.19%.

:exclamation: Current head 8b14acb differs from pull request most recent head c001ae6. Consider uploading reports for the commit c001ae6 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #543      +/-   ##
===============================================
+ Coverage        76.27%   76.38%   +0.11%     
===============================================
  Files              265      271       +6     
  Lines            19554    19833     +279     
===============================================
+ Hits             14915    15150     +235     
- Misses            4639     4683      +44     
Impacted Files Coverage Δ
src/c/device.cpp 89.06% <0.00%> (-5.94%) :arrow_down:
src/occa/internal/core/buffer.cpp 100.00% <ø> (ø)
src/occa/internal/core/buffer.hpp 0.00% <0.00%> (ø)
src/occa/internal/c/types.cpp 77.64% <55.00%> (-0.81%) :arrow_down:
src/occa/internal/core/memoryPool.cpp 67.66% <67.66%> (ø)
src/core/memoryPool.cpp 68.47% <68.47%> (ø)
src/c/experimental/memoryPool.cpp 86.66% <86.66%> (ø)
include/occa/core/memoryPool.tpp 100.00% <100.00%> (ø)
src/c/base.cpp 88.17% <100.00%> (+0.96%) :arrow_up:
src/core/base.cpp 71.57% <100.00%> (+0.61%) :arrow_up:
... and 11 more

codecov[bot] avatar Nov 27 '21 18:11 codecov[bot]