Skip to content
Closed
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
861d194
For #669. Adding install target to gpu Makefile
cjnolet Jan 8, 2019
60d654f
Starting integration of raft
cjnolet Jun 3, 2022
d474bf3
Adding proper inherited member definitions
cjnolet Jun 3, 2022
8baee52
Updating raft ivf flat
cjnolet Jun 3, 2022
2eb94f1
adding raftIVFFlat implementation
cjnolet Jun 14, 2022
f7d4185
Isolating quantizer training
cjnolet Jun 14, 2022
26491cb
iAdding todos where we need to plug in raft functionality
cjnolet Jun 14, 2022
b4d08c4
Invocatino of index building has been compiled successfully. Still ne…
cjnolet Jun 17, 2022
bf876f9
Adding call to search.
cjnolet Jun 17, 2022
9b1fc84
Adding stubs for remaining calls that need to be made from RAFT side in
cjnolet Jul 1, 2022
884bfa5
iUpdating function calls for copyFrom to include populating the quant…
cjnolet Jul 1, 2022
0958d2e
Implement some helpers
achirkin Jul 4, 2022
b7144a9
Make it compile
achirkin Jul 5, 2022
38733bb
Make the tests to not crash... sometimes
achirkin Jul 6, 2022
881fbc3
Merge pull request #1 from achirkin/raft_ivf_flat
cjnolet Jul 28, 2022
173c459
Updates
cjnolet Aug 2, 2022
8b7afe0
Merge branch 'raft_ivf_flat' of github.com:cjnolet/faiss into raft_iv…
cjnolet Aug 2, 2022
548e0f0
More updates
cjnolet Aug 2, 2022
baa34d7
One test running so far.
cjnolet Aug 3, 2022
edc5991
Setting add_data_on_build = false;
cjnolet Aug 3, 2022
10f89b4
Copying centroids directly and adding some prints for the test outputs
cjnolet Aug 8, 2022
7c69020
reconstructions seems to be reasonable
cjnolet Aug 8, 2022
8be7746
iUpdates to tests to compare against brute force as ground truth
cjnolet Aug 9, 2022
933582a
Starting to look at resulting runtimes in raft ivf flat tests
cjnolet Aug 24, 2022
d2a6541
Adding timing info to raft test
cjnolet Aug 24, 2022
986407a
Updating for rapids-cmake updates and RAFT updates
cjnolet Aug 25, 2022
ae4ed98
Adding RaftIndexIVFPQ
cjnolet Oct 10, 2022
d8894b8
Merge branch 'main' into raft_integration
cjnolet Oct 10, 2022
410b2c6
Updates
cjnolet Oct 10, 2022
d7ca6b4
Adding FAISS_ENABLE_RAFT option to INSTALL.md
cjnolet Oct 10, 2022
9875dad
Making build.sh work for quick building of proposal
cjnolet Oct 10, 2022
60388dc
Merge branch 'main' into raft_integration
cjnolet Oct 11, 2022
c09d09b
Merging upstream
cjnolet Oct 11, 2022
0081ed9
Integrating more deeply with `use_raft` option in the index config that
cjnolet Oct 19, 2022
a7e0cdd
IVF Flat
cjnolet Oct 19, 2022
fbf7e34
More updates
cjnolet Oct 19, 2022
a9b6963
Getting things building again. Adding raft handle to gpu resources.
cjnolet Oct 20, 2022
b640ba8
Getting FAISS building again w/ RaftIVFFlat
cjnolet Oct 26, 2022
af6d1e9
Adding the append vectors to raft index IVF flat.
cjnolet Oct 26, 2022
545b3d2
Add ing flatindex for the fused l2 knn
cjnolet Oct 27, 2022
2ac5a5b
Validating dispatch of flatindex
cjnolet Oct 28, 2022
68944a5
1. Verified FlatIndex tests are passing (and using RAFT for k<=64 L2 …
cjnolet Nov 15, 2022
3a37031
Calling train() on copyFrom() with reconstructed vectors and filling in
cjnolet Nov 15, 2022
3f51425
IVFFlat gtests run through to completion without crash. Distances look
cjnolet Nov 15, 2022
db1801e
Some of the IVFFlat tests are passing.
cjnolet Nov 15, 2022
f0bbd41
CLeaning up the diff a bit
cjnolet Nov 16, 2022
f7da008
Removing the RaftIndex* files.
cjnolet Nov 16, 2022
5ab762b
Using current raft 22.12
cjnolet Nov 17, 2022
3684cd3
Checking in a little cleanup
cjnolet Nov 30, 2022
35a46b2
Disabling raft from pulling in nn dependencies (e.g. faiss)
cjnolet Jan 9, 2023
eb9f6e9
Merge branch 'main' into raft_integration
cjnolet Jan 9, 2023
e7bf2e5
Updating raft for 23.02. Still working on failing tests.
cjnolet Jan 11, 2023
a8e2ad0
Isolating differences in results- it looks like it's related to the s…
cjnolet Jan 12, 2023
f19fd00
Add and query results appear to match well. LargeBatch tests are fail…
cjnolet Jan 19, 2023
3ff97ab
Merge branch 'main' into raft_integration
cjnolet Jan 20, 2023
1d2baed
Merge branch 'main' into raft_integration
cjnolet Jan 24, 2023
6269ed1
Using facebook for licenses in cmake files
cjnolet Jan 24, 2023
b13593a
Adding small note to build.sh that the file is temporary.
cjnolet Jan 24, 2023
81fbe64
Merge branch 'main' into raft_integration
cjnolet Jan 27, 2023
333761c
Merge branch 'main' into raft_integration
cjnolet Jan 31, 2023
bc8885d
Fixing style
cjnolet Jan 31, 2023
093579b
Merge branch 'master' into raft_integration
cjnolet Jan 31, 2023
10f8080
Merge branch 'raft_integration' of github.com:cjnolet/faiss into raft…
cjnolet Jan 31, 2023
19f38d4
Second pass of fixing formatting
cjnolet Jan 31, 2023
17df798
Third pass at fixing format style
cjnolet Jan 31, 2023
2993441
Adding nvidia license for traceability
cjnolet Jan 31, 2023
5e7eb6d
Updates
cjnolet Feb 6, 2023
d1b0036
Merge remote-tracking branch 'faiss/main' into raft_integration
cjnolet Feb 6, 2023
ddc75ac
Merging
cjnolet Feb 7, 2023
4ada77c
Merge branch 'main' into raft_integration
cjnolet Feb 7, 2023
ccc3bad
Merge branch 'main' into raft_integration
cjnolet Feb 13, 2023
4ab77fe
Just integrating flat for now. Using USE_NVIDIA_RAFT variable
cjnolet Feb 14, 2023
5e10532
Setting cmake standard to 11 if raft is not enabled
cjnolet Feb 14, 2023
f24d1f8
Reverting some of the ivf changes
cjnolet Feb 14, 2023
c8eb265
Clang format
cjnolet Feb 14, 2023
f4fcc5c
More updates. Removing raft ivf flat for now
cjnolet Feb 14, 2023
67786b2
Removing gpu/makefile checked in by mistake
cjnolet Feb 14, 2023
76ea55f
Removing test_contrib.py (checked in by mistake)
cjnolet Feb 14, 2023
79a7e11
Removing testutils (checked in by mistake)
cjnolet Feb 14, 2023
f84573f
More formatting
cjnolet Feb 14, 2023
d14ff83
Adding new bfknn implementation to flatindex
cjnolet Feb 14, 2023
d46a379
So far things are looking good but we still have a little work to do …
cjnolet Feb 16, 2023
6000993
Integrating w/ GpuDistance.cu. Adding raft to gpudistance and flat in…
cjnolet Feb 18, 2023
8dc29d5
Implementing some review feedback
cjnolet Feb 22, 2023
51ee05b
Adding rmm gpu resources.
cjnolet Feb 22, 2023
c679a32
Integrating rmm gpu resources into standard gpu resources
cjnolet Mar 7, 2023
9b3121e
Making sure GpuIndexFlat is only using RAFT when it's supposed to
cjnolet Mar 8, 2023
eec4a21
Merge branch 'main' into integrate_raft_flat
cjnolet Mar 8, 2023
c3d3afa
Enabling remaining GpuDistance tests for RAFT. 3 failing tests remain:
cjnolet Mar 8, 2023
400ed47
Merge branch 'integrate_raft_flat' of github.com:cjnolet/faiss into i…
cjnolet Mar 8, 2023
a354d44
Almost all the Flat and Distance tests are passing!
cjnolet Mar 10, 2023
a984d83
More tests passing. Still need to investigate why L2_float16 flat tes…
cjnolet Mar 10, 2023
8a61c39
Reverting unecessary change in TestGpuIndexFlat.cpp
cjnolet Mar 11, 2023
9b21ce2
Adding nvidia license to all modified files for tracking.
cjnolet Mar 11, 2023
2074e1d
Merge branch 'main' into integrate_raft_flat
cjnolet Mar 11, 2023
2dac056
Merge branch 'main' into integrate_raft_flat
cjnolet Mar 29, 2023
eec1c06
Merge branch 'main' into integrate_raft_flat
cjnolet Apr 5, 2023
9cd4f62
Merge branch 'main' into integrate_raft_flat
algoriddle Apr 11, 2023
fc643b3
Update GpuIndexFlat.cu
algoriddle Apr 17, 2023
a5c0c97
Update TestGpuIndexFlat.cpp
algoriddle Apr 17, 2023
3c45f78
Merge branch 'main' into integrate_raft_flat
algoriddle Apr 17, 2023
7e28a8b
Changing fork/pinned tag to rapids 23.04
cjnolet Apr 17, 2023
7180c89
Merge branch 'integrate_raft_flat' of github.com:cjnolet/faiss into i…
cjnolet Apr 17, 2023
ff803ec
Merge branch 'main' into integrate_raft_flat
algoriddle May 2, 2023
44c0c5e
merging internal version
algoriddle May 2, 2023
b1c05d0
add untracked
algoriddle May 2, 2023
009f77c
Merge branch 'main' into pr_2707
algoriddle May 2, 2023
8545c07
remove build.sh
algoriddle May 2, 2023
c6386f6
code format
algoriddle May 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,44 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)

set(FAISS_LANGUAGES CXX)

if(FAISS_ENABLE_GPU)
list(APPEND FAISS_LANGUAGES CUDA)
endif()

if(FAISS_ENABLE_RAFT)
include(cmake/thirdparty/fetch_rapids.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-cuda)
include(rapids-export)
include(rapids-find)

rapids_cuda_init_architectures(faiss)
endif()

project(faiss
VERSION 1.7.3
DESCRIPTION "A library for efficient similarity search and clustering of dense vectors."
HOMEPAGE_URL "https://github.com/facebookresearch/faiss"
LANGUAGES CXX)
LANGUAGES ${FAISS_LANGUAGES})
include(GNUInstallDirs)

if(FAISS_ENABLE_RAFT)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 11)
endif()

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# Valid values are "generic", "avx2".
option(FAISS_OPT_LEVEL "" "generic")
option(FAISS_ENABLE_GPU "Enable support for GPU indexes." ON)
option(FAISS_ENABLE_RAFT "Enable RAFT for GPU indexes." OFF)
option(FAISS_ENABLE_PYTHON "Build Python extension." ON)
option(FAISS_ENABLE_C_API "Build C API." OFF)

Expand All @@ -28,6 +50,11 @@ if(FAISS_ENABLE_GPU)
enable_language(CUDA)
endif()

if(FAISS_ENABLE_RAFT)
rapids_cpm_init()
include(cmake/thirdparty/get_raft.cmake)
endif()

add_subdirectory(faiss)

if(FAISS_ENABLE_GPU)
Expand Down
3 changes: 3 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ Several options can be passed to CMake, among which:
values are `ON` and `OFF`),
- `-DFAISS_ENABLE_PYTHON=OFF` in order to disable building python bindings
(possible values are `ON` and `OFF`),
- `-DFAISS_ENABLE_RAFT=ON` in order to enable building the RAFT implementations
of the IVF-Flat and IVF-PQ GPU-accelerated indices (default is `OFF`, possible
values are `ON` and `OFF`)
- `-DBUILD_TESTING=OFF` in order to disable building C++ tests,
- `-DBUILD_SHARED_LIBS=ON` in order to build a shared library (possible values
are `ON` and `OFF`),
Expand Down
52 changes: 52 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# NOTE: This file is temporary for the proof-of-concept branch and will be removed before this PR is merged

BUILD_TYPE=Release
BUILD_DIR=build/

RAFT_REPO_REL=""
EXTRA_CMAKE_ARGS=""
set -e

if [[ ${RAFT_REPO_REL} != "" ]]; then
RAFT_REPO_PATH="`readlink -f \"${RAFT_REPO_REL}\"`"
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DCPM_raft_SOURCE=${RAFT_REPO_PATH}"
fi

if [ "$1" == "clean" ]; then
rm -rf build
exit 0
fi

if [ "$1" == "test" ]; then
make -C build -j test
exit 0
fi

if [ "$1" == "test-raft" ]; then
./build/faiss/gpu/test/TestRaftIndexIVFFlat
exit 0
fi

mkdir -p $BUILD_DIR
cd $BUILD_DIR

cmake \
-DFAISS_ENABLE_GPU=ON \
-DFAISS_ENABLE_RAFT=ON \
-DFAISS_ENABLE_PYTHON=OFF \
-DBUILD_TESTING=ON \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DFAISS_OPT_LEVEL=avx2 \
-DRAFT_NVTX=OFF \
-DCMAKE_CUDA_ARCHITECTURES="NATIVE" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_CUDA_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
${EXTRA_CMAKE_ARGS} \
../

cmake --build . -j12
12 changes: 12 additions & 0 deletions cmake/thirdparty/fetch_rapids.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set(RAPIDS_VERSION "23.02")

if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/FAISS_RAPIDS.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-${RAPIDS_VERSION}/RAPIDS.cmake
${CMAKE_CURRENT_BINARY_DIR}/FAISS_RAPIDS.cmake)
endif()
include(${CMAKE_CURRENT_BINARY_DIR}/FAISS_RAPIDS.cmake)
40 changes: 40 additions & 0 deletions cmake/thirdparty/get_raft.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set(RAFT_VERSION "${RAPIDS_VERSION}")
set(RAFT_FORK "benfred")
set(RAFT_PINNED_TAG "bfknn")#"branch-${RAPIDS_VERSION}")

function(find_and_configure_raft)
set(oneValueArgs VERSION FORK PINNED_TAG)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

#-----------------------------------------------------
# Invoke CPM find_package()
#-----------------------------------------------------
rapids_cpm_find(raft ${PKG_VERSION}
GLOBAL_TARGETS raft::raft
BUILD_EXPORT_SET faiss-exports
INSTALL_EXPORT_SET faiss-exports
CPM_ARGS
GIT_REPOSITORY https://github.com/${PKG_FORK}/raft.git
GIT_TAG ${PKG_PINNED_TAG}
SOURCE_SUBDIR cpp
OPTIONS
"BUILD_TESTS OFF"
"BUILD_BENCH OFF"
"RAFT_COMPILE_LIBRARIES OFF"
"RAFT_ENABLE_NN_DEPENDENCIES OFF"
)
endfunction()

# Change pinned tag here to test a commit in CI
# To use a different RAFT locally, set the CMake variable
# CPM_raft_SOURCE=/path/to/local/raft
find_and_configure_raft(VERSION ${RAFT_VERSION}.00
FORK ${RAFT_FORK}
PINNED_TAG ${RAFT_PINNED_TAG}
)
18 changes: 14 additions & 4 deletions faiss/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ set(FAISS_GPU_HEADERS
utils/warpselect/WarpSelectImpl.cuh
)

if(FAISS_ENABLE_RAFT)
list(APPEND FAISS_GPU_HEADERS
impl/RaftFlatIndex.cuh)
list(APPEND FAISS_GPU_SRC
impl/RaftFlatIndex.cu)

target_compile_definitions(faiss PUBLIC USE_NVIDIA_RAFT=1)
target_compile_definitions(faiss_avx2 PUBLIC USE_NVIDIA_RAFT=1)
endif()

# Export FAISS_GPU_HEADERS variable to parent scope.
set(FAISS_GPU_HEADERS ${FAISS_GPU_HEADERS} PARENT_SCOPE)

Expand All @@ -178,7 +188,7 @@ foreach(header ${FAISS_GPU_HEADERS})
endforeach()

find_package(CUDAToolkit REQUIRED)
target_link_libraries(faiss PRIVATE CUDA::cudart CUDA::cublas)
target_link_libraries(faiss_avx2 PRIVATE CUDA::cudart CUDA::cublas)
target_compile_options(faiss PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xfatbin=-compress-all>)
target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xfatbin=-compress-all>)
target_link_libraries(faiss PRIVATE CUDA::cudart CUDA::cublas $<$<BOOL:${FAISS_ENABLE_RAFT}>:raft::raft>)
target_link_libraries(faiss_avx2 PRIVATE CUDA::cudart CUDA::cublas $<$<BOOL:${FAISS_ENABLE_RAFT}>:raft::raft>)
target_compile_options(faiss PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xfatbin=-compress-all --expt-extended-lambda --expt-relaxed-constexpr>)
target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xfatbin=-compress-all --expt-extended-lambda --expt-relaxed-constexpr>)
90 changes: 84 additions & 6 deletions faiss/gpu/GpuDistance.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@
#include <faiss/gpu/utils/CopyUtils.cuh>
#include <faiss/gpu/utils/DeviceTensor.cuh>

#if defined USE_NVIDIA_RAFT
#include <faiss/gpu/impl/RaftUtils.h>
#include <raft/core/device_resources.hpp>
#include <raft/core/device_mdspan.hpp>
#include <raft/neighbors/brute_force.cuh>
#include <raft/core/error.hpp>
#include <raft/core/mdspan_types.hpp>
#define RAFT_NAME "raft"
#endif

namespace faiss {
namespace gpu {

#if defined USE_NVIDIA_RAFT
using namespace raft::distance;
using namespace raft::neighbors;
#endif

template <typename T>
void bfKnnConvert(GpuResourcesProvider* prov, const GpuDistanceParams& args) {
// Validate the input data
Expand Down Expand Up @@ -165,7 +180,6 @@ void bfKnnConvert(GpuResourcesProvider* prov, const GpuDistanceParams& args) {
tOutDistances,
tIntIndices,
args.ignoreOutDistances);

// Convert and copy int indices out
auto tOutIntIndices = toDeviceTemporary<int, 2>(
res,
Expand Down Expand Up @@ -193,13 +207,77 @@ void bfKnn(GpuResourcesProvider* res, const GpuDistanceParams& args) {
"limitation: both vectorType and queryType must currently "
"be the same (F32 or F16");

if (args.vectorType == DistanceDataType::F32) {
bfKnnConvert<float>(res, args);
} else if (args.vectorType == DistanceDataType::F16) {
bfKnnConvert<half>(res, args);
#if defined USE_NVIDIA_RAFT
// Note: For now, RAFT bfknn requires queries and vectors to be same layout
if(args.should_use_raft() && args.queriesRowMajor == args.vectorsRowMajor) {

DistanceType distance = faiss_to_raft(args.metric, false);

auto resImpl = res->getResources();
auto res_impl = resImpl.get();
raft::handle_t& handle = res_impl->getRaftHandleCurrentDevice();

idx_t dims = args.dims;
idx_t num_vectors = args.numVectors;
const float *vectors = reinterpret_cast<const float*>(args.vectors);
const float *queries = reinterpret_cast<const float*>(args.queries);
idx_t num_queries = args.numQueries;
int k = args.k;
float metric_arg = args.metricArg;
idx_t *out_indices = reinterpret_cast<idx_t*>(args.outIndices);
float *out_distances = reinterpret_cast<float*>(args.outDistances);

//args.queriesRowMajor ? raft::row_major : raft::col_major;


auto inds = raft::make_device_matrix_view<idx_t, idx_t>(
out_indices, num_queries, k);
auto dists = raft::make_device_matrix_view<float, idx_t>(
out_distances,
num_queries,
k);


if(args.queriesRowMajor) {
auto index = raft::make_device_matrix_view<const float, idx_t, raft::row_major>(vectors, num_vectors, dims);
auto search = raft::make_device_matrix_view<const float, idx_t, raft::row_major>(queries, num_queries, dims);

std::vector<raft::device_matrix_view<const float, idx_t, raft::row_major>> index_vec = {index};
// For now, use RAFT's fused KNN when k <= 64 and L2 metric is used
if (args.k <= 64 && args.metric == MetricType::METRIC_L2 && args.numVectors > 0) {
RAFT_LOG_INFO("Invoking flat fused_l2_knn");
brute_force::fused_l2_knn(handle, index, search, inds, dists, distance);
} else {
RAFT_LOG_INFO("Invoking flat bfknn");
brute_force::knn(handle, index_vec, search, inds, dists, k, distance, metric_arg);
}
} else {
auto index = raft::make_device_matrix_view<const float, idx_t, raft::col_major>(vectors, num_vectors, dims);
auto search = raft::make_device_matrix_view<const float, idx_t, raft::col_major>(queries, num_queries, dims);

std::vector<raft::device_matrix_view<const float, idx_t, raft::col_major>> index_vec = {index};
// For now, use RAFT's fused KNN when k <= 64 and L2 metric is used
if (args.k <= 64 && args.metric == MetricType::METRIC_L2 && args.numVectors > 0) {
RAFT_LOG_INFO("Invoking flat fused_l2_knn");
brute_force::fused_l2_knn(handle, index, search, inds, dists, distance);
} else {
RAFT_LOG_INFO("Invoking flat bfknn");
brute_force::knn(handle, index_vec, search, inds, dists, k, distance, metric_arg);
}
}
} else {
FAISS_THROW_MSG("unknown vectorType");
#else
if (args.vectorType == DistanceDataType::F32) {
bfKnnConvert<float>(res, args);
} else if (args.vectorType == DistanceDataType::F16) {
bfKnnConvert<half>(res, args);
} else {
FAISS_THROW_MSG("unknown vectorType");
}
#endif
#if defined USE_NVIDIA_RAFT
}
#endif
}

// legacy version
Expand Down
12 changes: 12 additions & 0 deletions faiss/gpu/GpuDistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ struct GpuDistanceParams {
/// Otherwise, an integer 0 <= device < numDevices indicates the device for
/// execution
int device;

/// Should the index dispatch down to RAFT?
bool use_raft = false;

bool should_use_raft() const {
#if defined USE_NVIDIA_RAFT
return use_raft;
#else
FAISS_THROW_IF_NOT_MSG(!use_raft, "RAFT has not been compiled into the current version so it cannot be used.");
#endif
}

};

/// A wrapper for gpu/impl/Distance.cuh to expose direct brute-force k-nearest
Expand Down
12 changes: 12 additions & 0 deletions faiss/gpu/GpuIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ struct GpuIndexConfig {
/// On Pascal and above (CC 6+) architectures, allows GPUs to use
/// more memory than is available on the GPU.
MemorySpace memorySpace;

/// Should the index dispatch down to RAFT?
bool use_raft = false;

bool should_use_raft() {
#if defined USE_NVIDIA_RAFT
return use_raft;
#else
FAISS_THROW_IF_NOT_MSG(!use_raft, "RAFT has not been compiled into the current version so it cannot be used.");
#endif
}

};

class GpuIndex : public faiss::Index {
Expand Down
Loading