Repository navigation
[REVIEW] Memory resource design - #96
Conversation
5b82703 to
aa1cf79
Compare
|
rerun tests |
jirikraus
left a comment
There was a problem hiding this comment.
Looks good to me. I think it would be helpful to add examples how to use this with thrust and stl containers.
| /**---------------------------------------------------------------------------* | ||
| * @brief Allocates memory of size at least \p bytes. | ||
| * | ||
| * The returned pointer will have at minimum 256 byte alignment. |
There was a problem hiding this comment.
Maybe add an assert checking for this alignment on the pointer returned by do_allocate?
|
@jrhemstad Should this move to branch-0.9? |
Sure, unless you want to try and review and merge for 0.8. Doesn't affect me either way. |
|
I'll leave it here until end of burndown in case I get time to review. |
harrism
left a comment
There was a problem hiding this comment.
Overall excellent. Main concern is having to provide a size in order to deallocate -- definitely non-standard, right?
Also one about naming cnmem_memory_resource and the right level of abstraction.
Some questions and documentation requests.
Co-Authored-By: Mark Harris <[email protected]>
This is a precursor to the
cudf::columnredesign: NVIDIA/cudf#1443Based on
std::pmr::memory_resourceandthrust::mr::memory_resource.Key differences:
alignmentargument. It will be assumed that all implementations ofdevice_memory_resourcewill provide at least 256B alignment.streamargument for optional allocation/deallocation within a CUDA stream (e.g., CNMEM supports streams in alloc/free)supports_streamspure virtual function to query if the resource supports streamsIn short, the
device_memory_resourceis a base class that has two public functions:allocateanddeallocate. These functions call corresponding private, pure virtual functionsdo_allocateanddo_deallocate.To define a custom memory resource, all that need be done is define a new class, derive from
device_memory_resource, and implementdo_allocateanddo_deallocateto perform whatever custom behavior is desired. To see an example, look at how I've implementedcuda_memory_resource, which just usescudaMallocandcudaFreefor alloc/free.Example usage:
By using runtime polymorphism via virtual functions in
device_memory_resource, this design allows us to keep APIs template-free while still providing the option to the user to customize memory allocation behavior.This PR adds 3 memory resources based on existing RMM functionality:
cuda_memory_resource- allocates withcudaMalloc/cudaFreemanaged_memory_resource- uses managed memorycnmem_memory_resource- uses CNMEM pool suballocatorTODO: Add a
cnmem_managed_resourcefor a CNMEM pool allocated w/ managed memoryIt also adds a
default_memory_resourcethat can be used when a memory resource is not explicitly specified. Initially, the default memory resource is set to acuda_memory_resource.Tests were added and expanded based on existing RMM tests.
thrust_allocator_adaptorto enable using armm::memory_resourcefor Thrust allocation.Future tasks:
device_memory_resourcebase class (or create alogging_device_memory_resourcebase class)rmm::allocandrmm::freeto simply forward to calling the default memory resourcermm::allocandrmm::freecalls should be deprecated in favor of using the memory resources directly