Bitmap#

2025-10-17

4 min read time

Applies to Linux

#include <raft/core/bitmap.cuh>

namespace raft::core

template<typename bitmap_t = uint32_t, typename index_t = uint32_t>
struct bitmap_view : public raft::core::bitset_view<uint32_t, uint32_t>#
#include <bitmap.hpp>

View of a RAFT Bitmap.

This lightweight structure which represents and manipulates a two-dimensional bitmap matrix view with row major order. This class provides functionality for handling a matrix where each element is represented as a bit in a bitmap.

Template Parameters:
  • bitmap_t – Underlying type of the bitmap array. Default is uint32_t.

  • index_t – Indexing type used. Default is uint32_t.

Public Functions

inline _RAFT_HOST_DEVICE bitmap_view(
bitmap_t *bitmap_ptr,
index_t rows,
index_t cols,
index_t original_nbits = 0
)#

Create a bitmap view from a device raw pointer.

Parameters:
  • bitmap_ptr – Device raw pointer

  • rows – Number of row in the matrix.

  • cols – Number of col in the matrix.

  • original_nbits – Original number of bits used when the bitmap was created, to handle potential mismatches of data types. This is useful for using ANN indexes when a bitmap was originally created with a different data type than the ones currently supported in cuVS ANN indexes.

inline _RAFT_HOST_DEVICE bitmap_view(
raft::device_vector_view<bitmap_t, index_t> bitmap_span,
index_t rows,
index_t cols,
index_t original_nbits = 0
)#

Create a bitmap view from a device vector view of the bitset.

Parameters:
  • bitmap_span – Device vector view of the bitmap

  • rows – Number of row in the matrix.

  • cols – Number of col in the matrix.

  • original_nbits – Original number of bits used when the bitmap was created, to handle potential mismatches of data types. This is useful for using ANN indexes when a bitmap was originally created with a different data type than the ones currently supported in cuVS ANN indexes.

inline _RAFT_HOST_DEVICE bool test (const index_t row, const index_t col) const

Device function to test if a given row and col are set in the bitmap.

Parameters:
  • row – Row index of the bit to test

  • col – Col index of the bit to test

Returns:

bool True if index has not been unset in the bitset

inline _RAFT_DEVICE void set (const index_t row, const index_t col, bool new_value) const

Device function to set a given row and col to set_value in the bitset.

Parameters:
  • row – Row index of the bit to set

  • col – Col index of the bit to set

  • new_value – Value to set the bit to (true or false)

inline _RAFT_HOST_DEVICE index_t get_n_rows () const

Get the total number of rows.

Returns:

index_t The total number of rows

inline _RAFT_HOST_DEVICE index_t get_n_cols () const

Get the total number of columns.

Returns:

index_t The total number of columns

template<typename csr_matrix_t>
void to_csr(
const raft::resources &res,
csr_matrix_t &csr
) const#

Converts to a Compressed Sparse Row (CSR) format matrix.

This method transforms a two-dimensional bitmap matrix into a CSR representation, where each ‘1’ bit in the bitmap corresponds to a non-zero entry in the CSR matrix. The bitmap is interpreted as a row-major matrix, with rows and columns defined by the dimensions of the bitmap.

The caller must ensure that: The csr matrix is pre-allocated with dimensions and non-zero count matching the expected output.

Template Parameters:

csr_matrix_t – Specifies the CSR matrix type, constrained to raft::device_csr_matrix.

Parameters:
  • res[in] RAFT resources for managing CUDA streams and execution policies.

  • csr[out] Output parameter where the resulting CSR matrix is stored. Each ‘1’ bit in the bitmap corresponds to a non-zero element in the CSR matrix.