conda 安装需按 CUDA 版本选择 cuda-version,装错版本会不匹配;pip 包为实验性且静态编译,C++ 头文件不会随包提供;RAFT 面向底层原语开发,不适合数据科学家直接做探索分析。
raft
NVIDIAApache-2.0活跃维护提供 CUDA 加速的机器学习与信息检索基础算法和原语,方便快速搭建高性能应用,涵盖最近邻搜索、聚类、线性代数等常用模块。
RAFT contains fundamental widely-used algorithms and primitives for machine learning and information retrieval. The algorithms are CUDA-accelerated and form building blocks for more easily writing high performance applications.
mamba install -c rapidsai -c conda-forge raft-dask pylibraft cuda-version=12.9
pip install pylibraft-cu12README 未说明具体显存要求;算法为 CUDA 加速,需 NVIDIA GPU 及对应 CUDA 版本(示例覆盖 CUDA 12 与 13)。
NVIDIA 的 CUDA 加速算法原语库,帮你快速搭建高性能机器学习与检索应用
提供 CUDA 加速的机器学习与信息检索基础算法和原语,方便快速搭建高性能应用,涵盖最近邻搜索、聚类、线性代数等常用模块。
核心能力
- 提供稠密与稀疏线性代数、分解、SVD 等 CUDA 加速原语
- 以 header-only C++ 模板库形式复用,可选共享库加快编译
- 提供 pylibraft 轻量 Python 封装,兼容 __cuda_array_interface__
- raft-dask 支持多节点多 GPU 分布式算法部署
- 用 mdspan/mdarray 统一管理主机与设备多维数组
容易踩的坑
- v26.10.00最新正式版2026-10-19 · 2026-10-19 16:36 UTC
What's Changed
🚨 Breaking Changes
- FastIntDiv: fallback to normal division when values exceed 32-bit ran… by @huuanhhuyn in https://github.com/NVIDIA/raft/pull/3093
- Better error reporting with std::source_location by @achirkin in https://github.com/NVIDIA/raft/pull/3121
- Migrate stream APIs from rmm::cuda_stream_view to cuda::stream_ref by @bdice in https://github.com/NVIDIA/raft/pull/3129
🐛 Bug Fixes
- Fix missing nvtx stack and host mem resource by exporting the symbols by @huuanhhuyn in https://github.com/NVIDIA/raft/pull/3083
- Update pre-commit-hooks, fix UCXX version scheme by @KyleFromNVIDIA in https://github.com/NVIDIA/raft/pull/3087
- Remove orphaned raft::runtime::matrix::select_k declaration by @says1117 in https://github.com/NVIDIA/raft/pull/3084
- Make cuBLASLt descriptor wrappers move-safe by @fallintoplace in https://github.com/NVIDIA/raft/pull/3078
- Mitigate cuBLASLt 13.6 GEMM bug for inputs greater than 2^31 by @divyegala in https://github.com/NVIDIA/raft/pull/3098
cublasteam verified workaround for large GEMMalgo68bug by @divyegala in https://github.com/NVIDIA/raft/pull/3100- Restore tracked device resources on their original GPU by @fallintoplace in https://github.com/NVIDIA/raft/pull/3077
- Fix lanczos launch grid by @achirkin in https://github.com/NVIDIA/raft/pull/3109
- Fix launch_kernel handling of restricted and partially specified kernel arguments by @dantegd in https://github.com/NVIDIA/raft/pull/3117
- Fix devcontainer cache version updates by @bdice in https://github.com/NVIDIA/raft/pull/3119
- Use l-values to initialize RMM constructors by @divyegala in https://github.com/NVIDIA/raft/pull/3123
- Fix curand stream ordering in MST alteration by @dantegd in https://github.com/NVIDIA/raft/pull/3125
- Force stream sync in raft::device_reference by @achirkin in https://github.com/NVIDIA/raft/pull/3124
- Synchronize MST edge count update by @bdice in https://github.com/NVIDIA/raft/pull/3130
- Fix strided reduction block count by @achirkin in https://github.com/NVIDIA/raft/pull/3127
- Fix striding in mdspan 1d copies by @divyegala in https://github.com/NVIDIA/raft/pull/3134
- Update UCX calls to use new send/recv functions by @ChuckHastings in https://github.com/NVIDIA/raft/pull/3135
📖 Documentation
- Enable public docs features in CI by @bdice in https://github.com/NVIDIA/raft/pull/3131
🚀 New Features
- Add sparse Lanczos SVD solver by @Intron7 in https://github.com/NVIDIA/raft/pull/3034
- [REVIEW] Addition of
gemm_strided_batchedby @landrumb in https://github.com/NVIDIA/raft/pull/3106 - Implement a kernel dispatcher raft::launch_kernel by @achirkin in https://github.com/NVIDIA/raft/pull/3104
- Dry Run Protocol by @achirkin in https://github.com/NVIDIA/raft/pull/2961
🛠️ Improvements
- Update RAPIDS.cmake to log source of rapids-cmake by @arhag23 in https://github.com/NVIDIA/raft/pull/3074
- Empty commit to trigger a build by @bdice in https://github.com/NVIDIA/raft/pull/3089
- Use cuda::std::bit_cast in stats minmax instead of hand-rolled helper by @says1117 in https://github.com/NVIDIA/raft/pull/3095
- Use cuda::std::numeric_limits in LAP kernels instead of passing infinity by @says1117 in https://github.com/NVIDIA/raft/pull/3094
- enforce 'yamllint' checks by @jameslamb in https://github.com/NVIDIA/raft/pull/3096
- ensure nightly builds always produce new packages, expand 'changed-files' lists by @jameslamb in https://github.com/NVIDIA/raft/pull/3103
- Update to rapids-logger 0.3 by @bdice in https://github.com/NVIDIA/raft/pull/3102
- wheels: enforce 'abi3audit' checks by @jameslamb in https://github.com/NVIDIA/raft/pull/3111
- ci: avoid triggered-by-schedule and triggered-by-merge builds cancelling each other by @jameslamb in https://github.com/NVIDIA/raft/pull/3120
- X-ORG-3107: Publish API docs to docs.nvidia.com by @josephin
- v26.08.002026-08-05 · 2026-08-05 18:53 UTC
查看更新说明
What's Changed
🚨 Breaking Changes
- Enhanced support for memory-tracking raft resources by @achirkin in https://github.com/NVIDIA/raft/pull/3004
- Fix gather/scatter fast division bug by @huuanhhuyn in https://github.com/NVIDIA/raft/pull/3059
- Predictable raft::resources by @achirkin in https://github.com/NVIDIA/raft/pull/3052
- wheels: build CUDA 13 wheels with latest CTK (13.3.0) by @jameslamb in https://github.com/NVIDIA/raft/pull/3076
🐛 Bug Fixes
- Exclude
*.svgfiles fromverify-hardcoded-versionby @KyleFromNVIDIA in https://github.com/NVIDIA/raft/pull/3018 - clang-tidy: remove AnalyzeTemporaryDtors key by @achirkin in https://github.com/NVIDIA/raft/pull/2945
- Accommodate RMM Breaking Changes by @tarang-jain in https://github.com/NVIDIA/raft/pull/3033
- SelectK race condition fix by @aamijar in https://github.com/NVIDIA/raft/pull/3041
- Temporarily increase
max_days_without_successby @aamijar in https://github.com/NVIDIA/raft/pull/3038 - Relax threshold lanczos SM gtests by @aamijar in https://github.com/NVIDIA/raft/pull/3046
- Add missing
<atomic>include ininterruptible.hppby @legrosbuffle in https://github.com/NVIDIA/raft/pull/3060 - Revert "Temporarily increase
max_days_without_success" by @aamijar in https://github.com/NVIDIA/raft/pull/3065 - [CI nightly] Temporarily disable conda-python-tests codecov reporting by @aamijar in https://github.com/NVIDIA/raft/pull/3066
- fix(pre-commit): normalize SPDX handling by @bdice in https://github.com/NVIDIA/raft/pull/3081
- Update pre-commit-hooks, fix UCXX version scheme by @KyleFromNVIDIA in https://github.com/NVIDIA/raft/pull/3087
- Mitigate cuBLASLt 13.6 GEMM bug for inputs greater than 2^31 by @divyegala in https://github.com/NVIDIA/raft/pull/3098
cublasteam verified workaround for large GEMMalgo68bug by @divyegala in https://github.com/NVIDIA/raft/pull/3100
📖 Documentation
- Fix RMAT docs by @divyegala in https://github.com/NVIDIA/raft/pull/3071
- Remove legacy RAPIDS docs theme assets by @bdice in https://github.com/NVIDIA/raft/pull/3069
🚀 New Features
- Coderabbit integration by @achirkin in https://github.com/NVIDIA/raft/pull/3054
🛠️ Improvements
- Require CMake 4.0 by @KyleFromNVIDIA in https://github.com/NVIDIA/raft/pull/3015
- [REVIEW] Add all-to-all, scatter, and scatterv functions to raft::comms_t by @seunghwak in https://github.com/NVIDIA/raft/pull/3002
- fix(visibility): restrict RAFT_EXPORT to core/ and raft_runtime/ only by @vyasr in https://github.com/NVIDIA/raft/pull/3019
- Improve devcontainer startup times by @trxcllnt in https://github.com/NVIDIA/raft/pull/3032
- Revert NCCL comms updates that require NCCL 2.28 or later. by @seunghwak in https://github.com/NVIDIA/raft/pull/3040
- Add SECURITY.md by @jameslamb in https://github.com/NVIDIA/raft/pull/3044
- fix(ci): fix configuration for breaking change notification workflow by @jameslamb in https://github.com/NVIDIA/raft/pull/3048
- refactor: switch to
rapids-artifact-namefor consistent artifact naming by @gforsyth in https://github.com/NVIDIA/raft/pull/3043 - Build and test with CUDA 13.3.0 by @bdice in https://github.com/NVIDIA/raft/pull/3053
- Use main shared-workflows branch by @bdice in https://github.com/NVIDIA/raft/pull/3057
- Update CODEOWNERS team names for rapidsai->NVIDIA migration by @josephine-wolf-oberholtzer in https://github.com/NVIDIA/raft/pull/3062
- Temporarily disable conda-python-tests codecov reporting by @josephine-wolf-oberholtzer in https://github.com/NVIDIA/raft/pull/3064
- Build script option to change raft active/logging level by @huuanhhuyn in https://github.com/NVIDIA/raft/pull/3061
- Bump rapidsai/pre-commit-hooks to v1.6.0, re-enable verify-codeowners by @josephine-wolf-oberholtzer in https://github.com/NVIDIA/raft/pull/3063
- Update CuPy and NumPy dependency specs by @bdice in https://github.com/NVIDIA/raft/pull/3058
- Add supppo
- v26.06.002026-06-03 · 2026-06-03 23:54 UTC
查看更新说明
What's Changed
🚨 Breaking Changes
- Unify memory resources by @achirkin in https://github.com/rapidsai/raft/pull/2968
- Migrate RMM usage to CCCL MR design by @bdice in https://github.com/rapidsai/raft/pull/2996
- Predictable raft::resources by @achirkin in https://github.com/rapidsai/raft/pull/3005
🐛 Bug Fixes
- Fix gbench 1.9.5 by @aamijar in https://github.com/rapidsai/raft/pull/3000
- Fix eigDC version check for syevd by @lowener in https://github.com/rapidsai/raft/pull/3012
- Fix off-by-one
num_segmentsinmatrix::sort_cols_per_rowby @viclafargue in https://github.com/rapidsai/raft/pull/3010 - Revert "Predictable raft::resources (#3005)" by @divyegala in https://github.com/rapidsai/raft/pull/3027
📖 Documentation
- Docs improvements by @aamijar in https://github.com/rapidsai/raft/pull/2993
🚀 New Features
- Tracking memory resources by @achirkin in https://github.com/rapidsai/raft/pull/2973
- Add Randomized SVDs by @Intron7 in https://github.com/rapidsai/raft/pull/2999
🛠️ Improvements
- chore: bump
codespellversion for Python 3.14+ compatibility by @gforsyth in https://github.com/rapidsai/raft/pull/2989 - pre-commit: consolidate duplicate entries, bump some versions by @jameslamb in https://github.com/rapidsai/raft/pull/2991
- update pip devcontainers' base image tags by @trxcllnt in https://github.com/rapidsai/raft/pull/2995
- Update to clang 20.1.8 by @bdice in https://github.com/rapidsai/raft/pull/3001
- fix(ci): resolve all zizmor findings and add zizmor pre-commit checks by @gforsyth in https://github.com/rapidsai/raft/pull/3009
- [REVIEW] Drop extra copy in
CudaRuntimeErrorby @jakirkham in https://github.com/rapidsai/raft/pull/3007 - Use
token.rapids.nvidia.comwhen issuing S3 bucket creds in devcontainers by @trxcllnt in https://github.com/rapidsai/raft/pull/3008 - Use cudaStream_t instead of cuda_stream_view in pylibraft Cython by @vyasr in https://github.com/rapidsai/raft/pull/3011
- Fix symbol export by @vyasr in https://github.com/rapidsai/raft/pull/3006
- Build and test with CUDA 13.2.0 by @bdice in https://github.com/rapidsai/raft/pull/3013
- fix(ci): add explicit
actions: writepermission fortelemetry-summarizeby @gforsyth in https://github.com/rapidsai/raft/pull/3014 - Expose numpy_serializer helpers as public APIs by @julianmi in https://github.com/rapidsai/raft/pull/3003
- Restore resource_cast guard for RAFT memory pool by @bdice in https://github.com/rapidsai/raft/pull/3020
- skip CuPy 14.1.0 by @jameslamb in https://github.com/rapidsai/raft/pull/3045
New Contributors
- @julianmi made their first contribution in https://github.com/rapidsai/raft/pull/3003
- @Intron7 made their first contribution in https://github.com/rapidsai/raft/pull/2999
Full Changelog: https://github.com/rapidsai/raft/compare/v26.06.00a...v26.06.00
- v26.04.002026-04-08 · 2026-04-08 18:53 UTC
查看更新说明
What's Changed
🚨 Breaking Changes
- Rename lanczos by @aamijar in https://github.com/rapidsai/raft/pull/2936
- Remove deprecated headers by @aamijar in https://github.com/rapidsai/raft/pull/2939
🐛 Bug Fixes
- Disable lanczos SM tests by @aamijar in https://github.com/rapidsai/raft/pull/2941
- Add
binary_multandconstfixes forratioandsqrtapis by @aamijar in https://github.com/rapidsai/raft/pull/2940 - Temporarily increase
max_days_without_successby @aamijar in https://github.com/rapidsai/raft/pull/2950 - Remove "requires" keyword from raft::linalg::map by @tarang-jain in https://github.com/rapidsai/raft/pull/2949
- Add nvjitlink to cuda-toolkit pip extras for cusparse compatibility by @bdice in https://github.com/rapidsai/raft/pull/2948
- Fix cub missing header by @aamijar in https://github.com/rapidsai/raft/pull/2957
- Fix cub header by @aamijar in https://github.com/rapidsai/raft/pull/2959
- [REVIEW] Fix l_offset overflow in select_k kernels for 32-bit IdxT by @yan-zaretskiy in https://github.com/rapidsai/raft/pull/2974
- Use the new reference-based RMM API to set RMM pools in
device_resources_snmgby @viclafargue in https://github.com/rapidsai/raft/pull/2972
📖 Documentation
- Raft docs cleanup by @aamijar in https://github.com/rapidsai/raft/pull/2935
🚀 New Features
- [FEA] Support raft::KeyValuePair Inputs in linalg::map by @tarang-jain in https://github.com/rapidsai/raft/pull/2913
- Backport memory resources PRs by @achirkin in https://github.com/rapidsai/raft/pull/2983
- Move PCA and TSVD from cuml to raft by @aamijar in https://github.com/rapidsai/raft/pull/2952
🛠️ Improvements
- Replace
thrust::tuplewithcuda::std::tupleby @miscco in https://github.com/rapidsai/raft/pull/2928 - Use verify-hardcoded-version pre-commit hook by @KyleFromNVIDIA in https://github.com/rapidsai/raft/pull/2931
- expand CI-skipping logic, other small build changes by @jameslamb in https://github.com/rapidsai/raft/pull/2933
- remove pip.conf migration code in CI scripts, update CI-skipping rules by @jameslamb in https://github.com/rapidsai/raft/pull/2938
- Drop Python 3.10 support by @gforsyth in https://github.com/rapidsai/raft/pull/2932
- Don't hard-code branch names and UCXX version by @KyleFromNVIDIA in https://github.com/rapidsai/raft/pull/2934
- refactor: build wheels and conda packages using Python limited API by @gforsyth in https://github.com/rapidsai/raft/pull/2943
- remove gitutils by @jameslamb in https://github.com/rapidsai/raft/pull/2946
- Use GHA id-token for
sccache-distauth token by @trxcllnt in https://github.com/rapidsai/raft/pull/2947 - Use Specific CCCL Includes by @divyegala in https://github.com/rapidsai/raft/pull/2953
- Drop uses of
thrust/functional.hby @miscco in https://github.com/rapidsai/raft/pull/2954 - check-nightly-ci: update to new version by @jameslamb in https://github.com/rapidsai/raft/pull/2956
- Drop
thrust::constant_iteratorin favor ofcuda::constant_iteratorby @miscco in https://github.com/rapidsai/raft/pull/2955 - Drop
thrust::counting_iteratorin favor ofcuda::counting_iteratorby @miscco in https://github.com/rapidsai/raft/pull/2958 - check-nightly-ci: remove testing config by @jameslamb in https://github.com/rapidsai/raft/pull/2960
- Revert
max_days_without_successby @aamijar in https://github.com/rapidsai/raft/pull/2962 - refactor(limited api): add explicit
wheel.py-apitopyproject.tomlby @gforsyth in https://github.com/rapidsai/raft/pull/2967 - Add support for Python 3.14 by @gforsyth in https://github.com/rapidsai/raft/pull/2966
- Drop uses of
thrust::discard_iteratorin favor ofcuda::discard_iteratorby @miscco in https://github.com/rapidsai/raft/pull/2963 - Update Cython lower bound pin to 3.2.2 by @vyasr in https://github.com/rapidsai/raft/pull/2969
- Remove pytest upper bound pin by @vyasr in https://github.com/rapidsai/raft/
- v26.02.002026-02-04 · 2026-02-04 21:15 UTC
查看更新说明
What's Changed
🚨 Breaking Changes
- Use CCCL's mdspan implementation by @bdice in https://github.com/rapidsai/raft/pull/2836
- Default to static linking of libcudart by @bdice in https://github.com/rapidsai/raft/pull/2890
- Remove
neighbors/,cluster/,distance/,spatial/,sparse/neighbors/apis by @aamijar in https://github.com/rapidsai/raft/pull/2885 - Remove cutlass and cuco dependencies by @divyegala in https://github.com/rapidsai/raft/pull/2916
🐛 Bug Fixes
- Include
<thrust/for_each.h>where it is used by @bdice in https://github.com/rapidsai/raft/pull/2883 - Include CTest module in CMakeLists.txt by @bdice in https://github.com/rapidsai/raft/pull/2895
- Fix Lanczos Determinism by @aamijar in https://github.com/rapidsai/raft/pull/2894
- Change compile-time assertion to runtime assertion on is_strided by @bdice in https://github.com/rapidsai/raft/pull/2909
- Set memory pool through RMM by @viclafargue in https://github.com/rapidsai/raft/pull/2866
📖 Documentation
- New readme image by @aamijar in https://github.com/rapidsai/raft/pull/2907
- Readme improvements by @aamijar in https://github.com/rapidsai/raft/pull/2906
🚀 New Features
- Tile Policy for Uint8 Input (Pairwise) by @tarang-jain in https://github.com/rapidsai/raft/pull/2770
- Add copy_vectorized to RAFT by @lowener in https://github.com/rapidsai/raft/pull/2900
🛠️ Improvements
- Use strict priority in CI conda tests by @bdice in https://github.com/rapidsai/raft/pull/2879
- Use strict priority in CI conda tests by @bdice in https://github.com/rapidsai/raft/pull/2884
- Remove alpha specs from non-RAPIDS dependencies by @bdice in https://github.com/rapidsai/raft/pull/2886
- Enable merge barriers by @KyleFromNVIDIA in https://github.com/rapidsai/raft/pull/2889
- Fix is_exhaustive, no longer constexpr by @bdice in https://github.com/rapidsai/raft/pull/2888
- Add devcontainer fallback for C++ test location by @bdice in https://github.com/rapidsai/raft/pull/2893
eigshoptional seed by @aamijar in https://github.com/rapidsai/raft/pull/2899- Empty commit to trigger a build by @bdice in https://github.com/rapidsai/raft/pull/2904
- Update to C++20 by @divyegala in https://github.com/rapidsai/raft/pull/2908
- Use SPDX license identifiers in pyproject.toml, bump build dependency floors by @jameslamb in https://github.com/rapidsai/raft/pull/2910
- Remove
neighbors/detail/faiss_selectby @aamijar in https://github.com/rapidsai/raft/pull/2902 - Remove
sparse/distanceby @aamijar in https://github.com/rapidsai/raft/pull/2905 - Add CUDA 13.1 support by @bdice in https://github.com/rapidsai/raft/pull/2896
- Fix CCCL 3.2 mdspan constexpr issues by @bdice in https://github.com/rapidsai/raft/pull/2911
- build and test against CUDA 13.1.0 by @jameslamb in https://github.com/rapidsai/raft/pull/2912
- Laplacian Kernel for COO inputs by @aamijar in https://github.com/rapidsai/raft/pull/2891
- Empty commit to trigger a build by @jameslamb in https://github.com/rapidsai/raft/pull/2919
- Use main shared-workflows branch by @jameslamb in https://github.com/rapidsai/raft/pull/2921
- Fix update-version.sh incorrectly replacing main() function names by @AyodeAwe in https://github.com/rapidsai/raft/pull/2923
- Lanczos remove dead code by @aamijar in https://github.com/rapidsai/raft/pull/2918
- wheel builds: react to changes in pip's handling of build constraints by @mmccarty in https://github.com/rapidsai/raft/pull/2927
- fix(build): build package on merge to
release/*branch by @gforsyth in https://github.com/rapidsai/raft/pull/2929
New Contributors
- @mmccarty made their first contribution in https://github.com/rapidsai/raft/pull/2927
Full Changelog: https://github.com/rapidsai/raft/compare/v26.02.00a...v26.02.00
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
RAFT: Reusable Accelerated Functions and Tools
Contents
- Useful Resources
- What is RAFT?
- Use cases
- Is RAFT right for me?
- Getting Started
- Installing RAFT
- Codebase structure and contents
- Contributing
- References
Useful Resources
- RAFT Reference Documentation: API Documentation.
- RAFT Getting Started: Getting started with RAFT.
- Build and Install RAFT: Instructions for installing and building RAFT.
- GitHub repository: Download the RAFT source code.
- Issue tracker: Report issues or request features.
What is RAFT?
RAFT contains fundamental widely-used algorithms and primitives for machine learning and data mining. The algorithms are CUDA-accelerated and form building blocks for more easily writing high performance applications.
By taking a primitives-based approach to algorithm development, RAFT
- accelerates algorithm construction time
- reduces the maintenance burden by maximizing reuse across projects, and
- centralizes core reusable computations, allowing future optimizations to benefit all algorithms that use them.
While not exhaustive, the following general categories help summarize the accelerated functions in RAFT:
| Category | Accelerated Functions in RAFT |
|---|---|
| Data Formats | sparse & dense, conversions, data generation |
| Dense Operations | linear algebra, matrix and vector operations, reductions, slicing, norms, factorization, least squares, svd & eigenvalue problems |
| Sparse Operations | linear algebra, eigenvalue problems, slicing, norms, reductions, factorization, symmetrization, components & labeling |
| Solvers | combinatorial optimization, iterative solvers |
| Statistics | sampling, moments and summary statistics, metrics, model evaluation |
| Tools & Utilities | common tools and utilities for developing CUDA applications, multi-node multi-gpu infrastructure |
RAFT is a C++ header-only template library with an optional shared library that
- can speed up compile times for common template types, and
- provides host-accessible "runtime" APIs, which don't require a CUDA compiler to use
In addition being a C++ library, RAFT also provides 2 Python libraries:
pylibraft- lightweight Python wrappers around RAFT's host-accessible "runtime" APIs.raft-dask- multi-node multi-GPU communicator infrastructure for building distributed algorithms on the GPU with Dask.

Is RAFT right for me?
RAFT contains low-level primitives for accelerating applications and workflows. Data source providers and application developers may find specific tools very useful. RAFT is not intended to be used directly by data scientists for discovery and experimentation. For data science tools, please see the NVIDIA CUDA-X libraries for data science.
Getting started
Memory Management
RAFT uses memory resources for managing device memory. RAFT can use memory resources from CCCL or NVIDIA RMM,
defined as either cuda::mr::resource_ref<cuda::mr::device_accessible> or rmm::device_async_resource_ref.
Multi-dimensional Arrays
The APIs in RAFT accept the mdspan multi-dimensional array view for representing data in higher dimensions similar to the ndarray in the Numpy Python library. RAFT also contains the corresponding owning mdarray structure, which simplifies the allocation and management of multi-dimensional data in both host and device (GPU) memory.
The mdarray forms a convenience layer over RMM and can be constructed in RAFT using a number of different helper functions:
#include <raft/core/device_mdarray.hpp>
int n_rows = 10;
int n_cols = 10;
auto scalar = raft::make_device_scalar<float>(handle, 1.0);
auto vector = raft::make_device_vector<float>(handle, n_cols);
auto matrix = raft::make_device_matrix<float>(handle, n_rows, n_cols);
C++ Example
Most of the primitives in RAFT accept a raft::device_resources object for the management of resources which are expensive to create, such CUDA streams, stream pools, and handles to other CUDA libraries like cublas and cusolver.
The example below demonstrates creating a RAFT handle and using it with device_matrix and device_vector to allocate memory, generating random clusters, and computing
pairwise Euclidean distances with the NVIDIA cuVS library:
#include <raft/core/device_resources.hpp>
#include <raft/core/device_mdspan.hpp>
#include <raft/random/make_blobs.cuh>
#include <cuvs/distance/distance.hpp>
raft::device_resources handle;
int n_samples = 5000;
int n_features = 50;
float *input;
int *labels;
float *output;
...
// Allocate input, labels, and output pointers
...
auto input_view = raft::make_device_matrix_view(input, n_samples, n_features);
auto labels_view = raft::make_device_vector_view(labels, n_samples);
auto output_view = raft::make_device_matrix_view(output, n_samples, n_samples);
raft::random::make_blobs(handle, input_view, labels_view);
auto metric = cuvs::distance::DistanceType::L2SqrtExpanded;
cuvs::distance::pairwise_distance(handle, input_view, input_view, output_view, metric);
Python Example
The pylibraft package contains a Python API for RAFT algorithms and primitives. pylibraft integrates nicely into other libraries by being very lightweight with minimal dependencies and accepting any object that supports the __cuda_array_interface__, such as CuPy's ndarray. The number of RAFT algorithms exposed in this package is continuing to grow from release to release.
The example below demonstrates computing the pairwise Euclidean distances between CuPy arrays using the NVIDIA cuVS library. Note that CuPy is not a required dependency for pylibraft.
import cupy as cp
from cuvs.distance import pairwise_distance
n_samples = 5000
n_features = 50
in1 = cp.random.random_sample((n_samples, n_features), dtype=cp.float32)
in2 = cp.random.random_sample((n_samples, n_features), dtype=cp.float32)
output = pairwise_distance(in1, in2, metric="euclidean")
The output array in the above example is of type raft.common.device_ndarray, which supports cuda_array_interface making it interoperable with other libraries like CuPy, Numba, PyTorch and NVIDIA cuDF that also support it. CuPy supports DLPack, which also enables zero-copy conversion from raft.common.device_ndarray to JAX and Tensorflow.
Below is an example of converting the output pylibraft.device_ndarray to a CuPy array:
cupy_array = cp.asarray(output)
And converting to a PyTorch tensor:
import torch
torch_tensor = torch.as_tensor(output, device='cuda')
Or converting to an NVIDIA cuDF dataframe:
cudf_dataframe = cudf.DataFrame(output)
When the corresponding library has been installed and available in your environment, this conversion can also be done automatically by all RAFT compute APIs by setting a global configuration option:
import pylibraft.config
pylibraft.config.set_output_as("cupy") # All compute APIs will return cupy arrays
pylibraft.config.set_output_as("torch") # All compute APIs will return torch tensors
You can also specify a callable that accepts a pylibraft.common.device_ndarray and performs a custom conversion. The following example converts all output to numpy arrays:
pylibraft.config.set_output_as(lambda device_ndarray: return device_ndarray.copy_to_host())
pylibraft also supports writing to a pre-allocated output array so any __cuda_array_interface__ supported array can be written to in-place:
import cupy as cp
from cuvs.distance import pairwise_distance
n_samples = 5000
n_features = 50
in1 = cp.random.random_sample((n_samples, n_features), dtype=cp.float32)
in2 = cp.random.random_sample((n_samples, n_features), dtype=cp.float32)
output = cp.empty((n_samples, n_samples), dtype=cp.float32)
pairwise_distance(in1, in2, out=output, metric="euclidean")
Installing
RAFT's C++ and Python libraries can both be installed through Conda and the Python libraries through Pip.
Installing C++ and Python through Conda
The easiest way to install RAFT is through conda and several packages are provided.
libraft-headersC++ headerspylibraft(optional) Python libraryraft-dask(optional) Python library for deployment of multi-node multi-GPU algorithms that use the RAFTraft::commsabstraction layer in Dask clusters.
Use the following command, depending on your CUDA version, to install all of the RAFT packages with conda (replace rapidsai with rapidsai-nightly to install more up-to-date but less stable nightly packages). mamba is preferred over the conda command.
# CUDA 13
mamba install -c rapidsai -c conda-forge raft-dask pylibraft cuda-version=13.4
# CUDA 12
mamba install -c rapidsai -c conda-forge raft-dask pylibraft cuda-version=12.9
Note that the above commands will also install libraft-headers and libraft.
You can also install the conda packages individually using the mamba command above. For example, if you'd like to install RAFT's headers and pre-compiled shared library to use in your project:
# CUDA 13
mamba install -c rapidsai -c conda-forge libraft libraft-headers cuda-version=13.4
# CUDA 12
mamba install -c rapidsai -c conda-forge libraft libraft-headers cuda-version=12.9
Installing Python through Pip
pylibraft and raft-dask both have experimental packages that can be installed through pip:
# CUDA 13
pip install pylibraft-cu13
pip install raft-dask-cu13
# CUDA 12
pip install pylibraft-cu12
pip install raft-dask-cu12
These packages statically build RAFT's pre-compiled instantiations and so the C++ headers won't be readily available to use in your code.
The build instructions contain more details on building RAFT from source and including it in downstream projects. You can also find a more comprehensive version of the above CPM code snippet the Building RAFT C++ and Python from source section of the build instructions.
Contributing
If you are interested in contributing to the RAFT project, please read our Contributing guidelines. Refer to the Developer Guide for details on the developer guidelines, workflows, and principals.
References
When citing RAFT generally, please consider referencing this Github project.
@misc{nvidia_raft,
title={NVIDIA/raft: RAFT contains fundamental widely-used algorithms and primitives for data science, Graph and machine learning.},
url={https://github.com/NVIDIA/raft},
journal={GitHub},
publisher={NVIDIA},
author={NVIDIA},
year={2022}
}