mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-12 02:13:36 +00:00
pyfaiss_gpu_cuvs_2602: cuVS faiss Python for aarch64/GH200 (26.02, CUDA 12.4)
Summary:
## Why
The OSS ANN IVF-PQ benchmark (P2423918422) needs a cuVS-enabled faiss Python module on aarch64/GH200, but the only such target (`pyfaiss_gpu_cuvs`) is built against cuVS 26.06, which requires CUDA 13.3 — not available on the fbcode/warm base. The full `third-party/cuvs:cuvs` also can't build on ARM64 at all: cuCollections needs `cub/device/device_for.cuh`, which is absent from the ARM64 CUDA toolkit.
This diff adds a cuVS 26.02 faiss Python variant (built against `faiss_cuvs_2602`, IVF-PQ subset) plus a benchmark caller pinned to CUDA 12.4, so the GPU filtered IVF-PQ path is usable on GH200 with no CUDA 13.3 dependency.
## Changes
**New target + arch portability (needed for the aarch64 IVF-PQ subset)**
- `faiss/python/defs.bzl` + `faiss/python/BUCK`: new `pyfaiss_gpu_cuvs_2602` variant — deps `//faiss/gpu:faiss_cuvs_2602` (cuVS 26.02; the aarch64 `cuvs-ivfpq-2602` subset is IVF-PQ only, omitting CAGRA / cuVS-flat / ivf_sq), built with `-DFAISS_ENABLE_CUVS=ON -DFAISS_CUVS_NO_CAGRA`. `FAISS_CUVS_NO_CAGRA` is unconditional because (a) `faiss_cuvs_2602` exposes no `GpuIndexCagra` on aarch64, and (b) `swig_flags` is a plain list that `swig_library` iterates at parse time, so it cannot be an arch `select`. New target, so the existing x86 `pyfaiss_gpu_cuvs` (26.06, with CAGRA) is unchanged.
- `faiss/gpu/GpuDistance.cu`: gate the cuVS brute_force branch in `bfKnn` with `#if defined(USE_NVIDIA_CUVS) && !defined(FAISS_CUVS_NO_FLAT)`. Without it, `GpuDistance.cu` references `cuvs::neighbors::brute_force::*` (absent from the aarch64 cuvs-ivfpq subset) → undefined symbols when any executable links `faiss_cuvs` / `faiss_cuvs_2602` on aarch64. Architecture-dependent (unrelated to CUDA version); x86 unchanged, aarch64 falls back to faiss's own kernels (mirrors `GpuIndexFlat::resetIndex_`).
- `faiss/python/swigfaiss.swig`: the three CAGRA binding blocks now gate on `#if defined(FAISS_ENABLE_CUVS) && !defined(FAISS_CUVS_NO_CAGRA)`, so a `FAISS_CUVS_NO_CAGRA` build skips them and the wrapper doesn't reference undefined `GpuIndexCagra` symbols. x86 `pyfaiss_gpu_cuvs` keeps full CAGRA bindings.
**Caller pin (intended 12.4 runtime for GH200)**
- `admarket/lib/ranking/quark/csrc/ann/benchmark/{BUCK,cuvs_ivfpq_2602_smoke.py}`: a benchmark caller driving cuVS GPU filtered IVF-PQ through `pyfaiss_gpu_cuvs_2602`, pinned via `modifiers = ["ovr_config//third-party/cuda/constraints:12.4"]`. Pinning the caller keeps its runtime on the 26.02-intended pre-13 toolkit (also the cleaner match for a driver-13.0-max GH200).
**Vendored 26.02 build-under-13.x hardening (needed for CI diff signals)**
These are required because the caller `modifiers` pin only binds the build's *top-level* target: CI/BTD builds the affected targets directly (`pyfaiss_gpu_cuvs_2602-py-ext`, `faiss_cuvs_2602`, `rmm-2602`) as their own roots, at the **default toolkit (13.x)**, where the 26.02 sources compile their CUDA-13 code paths.
- `third-party/rmm/v26.02.00/src/cpp/src/prefetch.cpp`: add the missing inner braces to the `cudaMemLocation` aggregate init (the compiler's own suggestion; matches how newer RMM writes it). At 13.x the `CUDART_VERSION >= 13000` branch otherwise trips clang21 `-Werror,-Wmissing-braces`. This is a surgical, upstream-correct fix — preferred over a blanket `-w` on the target, and verified sufficient: `rmm-2602` builds clean at the default 13.x with no other warnings in its compiled sources.
- `faiss/gpu/BUCK`: add `-Wno-deprecated-dynamic-exception-spec` to `faiss_cuvs_2602`'s `compiler_flags` and `-Xcompiler=-Wno-deprecated-dynamic-exception-spec` to its `nvcc_flags`, matching the sibling 26.06 `faiss_cuvs` target. Unlike the rmm case this cannot be patched in our source: the warning originates in CUDA 13.3's `crt/host_runtime.h` (`atexit(...) throw()`), an NVIDIA system header. The flag lets `faiss_cuvs_2602` build at 13.x; the caller pin still governs the actual 12.4 runtime.
## Result
GH200/aarch64 cuVS IVF-PQ (incl. bitmap-filtered search) is available at cuVS 26.02, with the benchmark pinned to CUDA 12.4 at runtime and all affected targets building under the CI-default 13.x toolkit.
Differential Revision: D112825740
fbshipit-source-id: df1d0a080ff9b5bdb3f4b82b40d27e9ac04e6b7b
This commit is contained in:
committed by
meta-codesync[bot]
parent
7d4bb39f7e
commit
6227323ffd
@@ -233,7 +233,10 @@ void bfKnn(GpuResourcesProvider* prov, const GpuDistanceParams& args) {
|
||||
"limitation: both vectorType and queryType must currently "
|
||||
"be the same (F32 / F16 / BF16");
|
||||
|
||||
#if defined USE_NVIDIA_CUVS
|
||||
// cuVS brute-force (flat) lives in the full cuVS build only; the aarch64
|
||||
// cuvs-ivfpq subset omits neighbors/brute_force, so FAISS_CUVS_NO_FLAT compiles
|
||||
// this branch out and bfKnn falls back to faiss's own kernels below.
|
||||
#if defined(USE_NVIDIA_CUVS) && !defined(FAISS_CUVS_NO_FLAT)
|
||||
// Note: For now, cuVS bfknn requires queries and vectors to be same layout
|
||||
if (should_use_cuvs(args) && args.queriesRowMajor == args.vectorsRowMajor &&
|
||||
args.outIndicesType == IndicesDataType::I64 &&
|
||||
|
||||
@@ -437,7 +437,10 @@ int64_t cast_cudastream_t_to_integer(hipStream_t x) {
|
||||
|
||||
#else // FAISS_ENABLE_ROCM
|
||||
|
||||
#ifdef FAISS_ENABLE_CUVS
|
||||
// CAGRA is absent from the aarch64 cuVS build (cuvs-ivfpq subset), so gate the
|
||||
// CAGRA bindings on FAISS_CUVS_NO_CAGRA too, else the wrapper references
|
||||
// undefined GpuIndexCagra symbols when linked against the aarch64 faiss_cuvs.
|
||||
#if defined(FAISS_ENABLE_CUVS) && !defined(FAISS_CUVS_NO_CAGRA)
|
||||
%shared_ptr(faiss::gpu::IVFPQBuildCagraConfig);
|
||||
%shared_ptr(faiss::gpu::IVFPQSearchCagraConfig);
|
||||
|
||||
@@ -447,7 +450,7 @@ int64_t cast_cudastream_t_to_integer(hipStream_t x) {
|
||||
#include <faiss/gpu/GpuIndexBinaryCagra.h>
|
||||
|
||||
%}
|
||||
#endif // FAISS_ENABLE_CUVS
|
||||
#endif // FAISS_ENABLE_CUVS && !FAISS_CUVS_NO_CAGRA
|
||||
|
||||
typedef CUstream_st* cudaStream_t;
|
||||
|
||||
@@ -774,7 +777,7 @@ void gpu_sync_all_devices()
|
||||
%include <faiss/gpu/GpuIndicesOptions.h>
|
||||
%include <faiss/gpu/GpuClonerOptions.h>
|
||||
%include <faiss/gpu/GpuIndex.h>
|
||||
#ifdef FAISS_ENABLE_CUVS
|
||||
#if defined(FAISS_ENABLE_CUVS) && !defined(FAISS_CUVS_NO_CAGRA)
|
||||
// IVFPQSearchCagraConfig.lut_dtype and .internal_distance_dtype are typed as
|
||||
// cudaDataType_t (a C enum from <library_types.h>). Without an int typemap
|
||||
// SWIG generates accessors that read/write a cudaDataType_t* SwigPyObject,
|
||||
@@ -931,7 +934,7 @@ typedef int cudaDataType_t;
|
||||
DOWNCAST ( IndexSVSIVF )
|
||||
#endif // FAISS_ENABLE_SVS
|
||||
#ifdef GPU_WRAPPER
|
||||
#ifdef FAISS_ENABLE_CUVS
|
||||
#if defined(FAISS_ENABLE_CUVS) && !defined(FAISS_CUVS_NO_CAGRA)
|
||||
DOWNCAST_GPU ( GpuIndexCagra )
|
||||
DOWNCAST_GPU ( GpuIndexBinaryCagra )
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user