RAPIDS Memory Manager
NOTE: For the latest stable README.md ensure you are on the main branch.
Achieving optimal performance in GPU-centric workflows frequently requires customizing how host and device memory are allocated. For example, using "pinned" host memory for asynchronous host device memory transfers, or using a device memory pool sub-allocator to reduce the cost of dynamic device memory allocation.
The goal of RMM is to provide:
For information on the interface RMM provides and how to use RMM in your C++ code, see below.
For a walkthrough of the design of RMM, read Fast, Flexible Allocation for NVIDIA CUDA with RMM on the NVIDIA Developer Blog.
Please see the Installation Guide for NVIDIA CUDA-X libraries for data science for information about supported operating systems, GPU drivers, and CUDA versions.
Stable releases of librmm and rmm are available on PyPI. Match the package suffix to the
major CUDA version supported by your installed driver.
# CUDA 13
pip install librmm-cu13
pip install rmm-cu13
# CUDA 12
pip install librmm-cu12
pip install rmm-cu12Development versions are available as nightly releases:
# CUDA 13
pip install --pre \
--extra-index-url=https://pypi.anaconda.org/rapidsai-wheels-nightly/simple \
librmm-cu13
pip install --pre \
--extra-index-url=https://pypi.anaconda.org/rapidsai-wheels-nightly/simple \
rmm-cu13
# CUDA 12
pip install --pre \
--extra-index-url=https://pypi.anaconda.org/rapidsai-wheels-nightly/simple \
librmm-cu12
pip install --pre \
--extra-index-url=https://pypi.anaconda.org/rapidsai-wheels-nightly/simple \
rmm-cu12Stable releases of librmm and rmm are available from the rapidsai channel. Development
versions are available from the rapidsai-nightly channel.
# Stable
conda install -c rapidsai -c conda-forge librmm
conda install -c rapidsai -c conda-forge rmm
# Nightly
conda install -c rapidsai-nightly -c conda-forge librmm
conda install -c rapidsai-nightly -c conda-forge rmmCompiler requirements:
gcc version 13.3+nvcc version 12.9+cmake version 4.0+CUDA/GPU runtime requirements:
GPU Support:
Python requirements:
rapids-build-backend (available from PyPI or the rapidsai conda channel)scikit-build-corecuda-pythoncythonFor more details, see pyproject.toml
To install RMM from source, ensure the dependencies are met and follow the steps below:
$ git clone https://github.com/rapidsai/rmm.git
$ cd rmmrmm_dev:# create the conda environment (assuming in base `rmm` directory)
$ conda env create --name rmm_dev --file conda/environments/all_cuda-133_arch-$(uname -m).yaml
# activate the environment
$ conda activate rmm_devlibrmm using cmake & make. CMake depends on the nvcc executable being on
your path or defined in CUDACXX environment variable.$ mkdir build # make a build directory
$ cd build # enter the build directory
$ cmake .. -DCMAKE_INSTALL_PREFIX=/install/path # configure cmake ... use $CONDA_PREFIX if you're using a conda environment
$ make -j # compile the library librmm.so ... '-j' will start a parallel job using the number of physical cores available on your system
$ make install # install the library librmm.so to '/install/path'librmm and rmm using build.sh. build.sh creates a build directory
at the root of the git repository. build.sh depends on the nvcc executable being on your path or
defined in the CUDACXX environment variable.$ ./build.sh -h # Display help and exit
$ ./build.sh -n librmm # Build librmm without installing
$ ./build.sh -n rmm # Build rmm without installing
$ ./build.sh -n librmm rmm # Build librmm and rmm without installing
$ ./build.sh librmm rmm # Build and install librmm and rmm$ cd build (if you are not already in the build directory)
$ make testrmm python package, in the python folder:# In the root rmm directory
$ python -m pip wheel ./python/librmm
$ python -m pip install --find-links=. -e ./python/rmm
$ pytest -vDone! You are ready to develop for the RMM project.
RMM uses CPM.cmake to handle third-party dependencies like
CCCL, GoogleTest, GoogleBenchmark. In general you won't have to worry about it. If CMake finds an
appropriate version on your system, it uses it (you can help it along by setting CMAKE_PREFIX_PATH
to point to the installed location). Otherwise those dependencies will be downloaded as part of the
build.
If you frequently start new builds from scratch, consider setting the environment variable
CPM_SOURCE_CACHE to an external download directory to avoid repeated downloads of the third-party
dependencies.
RMM symbols are placed in an inline namespace derived from the RMM major and minor version. The
public API remains available through the rmm:: namespace, while static RMM libraries built for
different ABI versions can coexist in one process. Process-global state is shared by RMM copies
with the same ABI version and kept separate across different ABI versions.
The installed RMM library provides a set of config files that makes it easy to
integrate RMM into your own CMake project. Add the following to CMakeLists.txt:
find_package(rmm [VERSION])
# ...
target_link_libraries( (PRIVATE|PUBLIC|INTERFACE) rmm::rmm)This links librmm, makes RMM headers available, and pulls in transitive dependencies.
If RMM is not installed in a default location, use
CMAKE_PREFIX_PATH or rmm_ROOT to point to its location.
RMM uses CPM.cmake to manage its dependencies, including CCCL, and you can use CPM for your project's dependency on RMM.
There is an issue with using CPM's single-argument compact syntax for
RMM/CCCL as it transitively marks targets as SYSTEM dependencies.
This causes the CCCL headers pulled in through CPM to be of lower priority
to the preprocessor than the (potentially outdated) CCCL headers provided
by the CUDA SDK. To avoid this issue, use CPM's multi-argument syntax
instead:
CPMAddPackage(NAME rmm [VERSION]
GITHUB_REPOSITORY rapidsai/rmm
SYSTEM OFF
SOURCE_SUBDIR cpp)
# ...
target_link_libraries( (PRIVATE|PUBLIC|INTERFACE) rmm::rmm)The first goal of RMM is to provide a common interface for device memory allocation. This allows both users and implementers of custom allocation logic to program to a single interface.
RMM's memory resources use CCCL's memory resource
concepts.
Resource APIs accept either concrete resource objects, non-owning resource refs such as
rmm::device_async_resource_ref, or owning type-erased resources such as
cuda::mr::any_resource.
A device memory resource satisfies the CCCL resource concept and provides stream-ordered allocation and deallocation:
void* allocate(cuda::stream_ref stream,
std::size_t bytes,
std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT);
void deallocate(cuda::stream_ref stream,
void* ptr,
std::size_t bytes,
std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept;RMM also uses rmm::device_async_resource_ref, an alias for
cuda::mr::resource_ref, as a lightweight non-owning reference to a
device resource. RMM uses cuda::mr::any_resource as an owning
type-erased resource. RMM resources with non-trivial state are value types with shared ownership of
their internal state, so copying a resource object is inexpensive and keeps the underlying state
alive.
RMM memory resources provide stream-ordered memory allocation. This allows optimizations such as re-using memory deallocated on the same stream without the overhead of synchronization.
A call to resource.allocate(stream_a, bytes) returns a pointer that is valid to use on stream_a.
Using the memory on a different stream (say stream_b) is Undefined Behavior unless the two streams
are first synchronized, for example by using cudaStreamSynchronize(stream_a) or by recording a CUDA
event on stream_a and then calling cudaStreamWaitEvent(stream_b, event).
The stream specified to deallocate should be a stream on which it is valid to use the deallocated
memory immediately for another allocation. Typically this is the stream on which the allocation was
last used before the call to deallocate. The passed stream may be used internally by a memory
resource for managing available memory with minimal synchronization, and it may also be synchronized
at a later time, for example using a call to cudaStreamSynchronize().
For this reason, it is Undefined Behavior to destroy a CUDA stream that is passed to
deallocate. If the stream on which the allocation was last used has been destroyed before calling
deallocate or it is known that it will be destroyed, it is likely better to synchronize the stream
(before destroying it) and then pass a different stream to deallocate (e.g. the default stream).
Note that device memory data structures such as rmm::device_buffer and rmm::device_uvector
follow these stream-ordered memory allocation semantics and rules.
For further information about stream-ordered memory allocation semantics, read Using the NVIDIA CUDA Stream-Ordered Memory Allocator on the NVIDIA Developer Blog.
RMM provides several device memory resources to satisfy various user requirements. For more detailed information about these resources, see their respective documentation.
cuda_memory_resourceAllocates and frees device memory using cudaMalloc
No open issues yet, or sync has not completed.