rapidsai/rmm

NVIDIA RMM is a library for allocating and managing GPU memory in C++ and Python.

What is RMM?

RMM (RAPIDS Memory Manager) is a library from NVIDIA that helps you control how memory is allocated and freed on a GPU. In GPU computing, how you allocate memory can greatly affect performance. For example, using "pinned" host memory speeds up copying data between the CPU and GPU, and using a memory pool reduces the overhead of repeatedly asking the GPU for small chunks of memory.

RMM gives you a single, common way to plug in different memory-allocation strategies, plus a set of ready-made strategies and data structures that use them.

Core Idea

RMM provides:

  • A common interface – a standard way to ask for and release GPU memory, so you can swap in different allocation strategies without rewriting your code.
  • A collection of implementations – several built-in memory allocators (called memory resources) that you can use directly or combine.
  • A collection of data structures – containers like device_buffer and device_uvector that automatically use whatever memory resource you choose.

Memory Resources

A memory resource is an object that knows how to allocate and free GPU memory. RMM defines a standard interface for these resources, so you can write code that works with any of them. The built-in resources include:

  • cuda_memory_resource – the simplest: uses CUDA's basic cudaMalloc/cudaFree.
  • managed_memory_resource – uses CUDA managed memory (cudaMallocManaged), which allows the CPU and GPU to share the same memory automatically.
  • pool_memory_resource – a memory pool that reuses freed blocks, reducing the cost of frequent allocations.
  • fixed_size_memory_resource – allocates only blocks of one fixed size, which is very fast.
  • binning_memory_resource – a configurable resource that can route allocations of different sizes to different underlying resources (e.g., small allocations to fixed-size pools, large ones to a general pool).

You can also write your own memory resource by implementing the same interface.

Stream-Ordered Allocation

RMM uses stream-ordered allocation. In CUDA, work is organized into streams – sequences of operations that run in order. When you allocate memory, you specify a stream. The memory is valid to use on that stream immediately. If you want to use it on a different stream, you must first synchronize the two streams (e.g., by waiting for an event). This design allows the allocator to reuse memory that was freed on the same stream without forcing a full GPU sync, which is a big performance win.

RMM's data structures (like device_buffer) follow these rules automatically, so you don't have to manage the details.

Default and Per-Device Resources

Often you want to set up one memory resource and use it everywhere unless you explicitly say otherwise. RMM lets you set a default resource for the currently active GPU device. You can also set a separate resource for each GPU in a multi-GPU system. Functions like set_current_device_resource() and get_current_device_resource_ref() let you do this.

The initial default resource is cuda_memory_resource. You can replace it with, for example, a pool_memory_resource to get faster dynamic allocation.

Data Structures

RMM includes several GPU‑aware containers that use your chosen memory resource:

  • device_buffer – a simple resizable buffer of uninitialized GPU memory.
  • device_uvector – a vector (like std::vector) that lives in GPU memory.
  • device_scalar – a single value stored on the GPU.
  • device_vector – a version of thrust::device_vector that uses RMM for allocation (via a thrust_allocator).

These structures automatically handle the stream‑ordered allocation rules and remember which GPU they were created on, so they are safe to destroy even if you switch devices later.

Streams and Stream Pools

RMM also provides:

  • cuda_stream – a simple RAII wrapper around a CUDA stream (it creates the stream on construction and destroys it on destruction). It cannot represent the default stream.
  • cuda_stream_pool – a pool of streams you can reuse, which can be faster than creating and destroying streams repeatedly.

Installation and Building

You can install RMM via pip or conda. Stable and nightly (development) versions are available. The package names include the CUDA version, e.g., rmm-cu12 for CUDA 12.

To build from source, you need:

  • GCC 13.3+, NVCC 12.9+, CMake 4.0+
  • CUDA 12.2+ (and a GPU with Volta architecture or newer)
  • Python packages like scikit-build-core, cython, etc.

The README provides detailed steps for cloning, building with CMake, and installing the Python package.

Using RMM in Your Own CMake Project

If you want to use RMM in your C++ project, you can use find_package(rmm) and link against rmm::rmm. There are also instructions for using CPM to fetch RMM automatically.

Summary

RMM is a flexible memory management library for NVIDIA GPUs. It gives you a standard way to customize memory allocation, provides several ready‑to‑use allocators, and includes GPU‑aware data structures that work with them. It's designed to help you get the best performance out of GPU‑centric applications by letting you choose the right allocation strategy for your workload.

For full details, see the official documentation.

Related

  • Dispatch
  • Project
  • Project
  • Project
  • Project