Skip to content

Commit

Permalink
Use FAISS with RMM (#363)
Browse files Browse the repository at this point in the history
Answers rapidsai/cuml#2821

Authors:
  - Victor Lafargue (https://github.com/viclafargue)
  - Corey J. Nolet (https://github.com/cjnolet)

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)

URL: #363
  • Loading branch information
viclafargue authored Jan 19, 2022
1 parent 40bb4bc commit 73585f4
Show file tree
Hide file tree
Showing 9 changed files with 747 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cpp/include/raft/spatial/knn/ann.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "detail/ann_quantized_faiss.cuh"

#include <faiss/gpu/GpuIndex.h>
#include <faiss/gpu/StandardGpuResources.h>
#include <raft/spatial/knn/faiss_mr.hpp>

#include <raft/mr/device/buffer.hpp>

Expand Down
4 changes: 2 additions & 2 deletions cpp/include/raft/spatial/knn/ann_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <raft/linalg/distance_type.h>

#include <faiss/gpu/GpuIndex.h>
#include <faiss/gpu/StandardGpuResources.h>
#include <raft/spatial/knn/faiss_mr.hpp>

namespace raft {
namespace spatial {
Expand All @@ -30,7 +30,7 @@ struct knnIndex {
raft::distance::DistanceType metric;
float metricArg;

faiss::gpu::StandardGpuResources* gpu_res;
raft::spatial::knn::RmmGpuResources* gpu_res;
int device;
~knnIndex()
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/raft/spatial/knn/detail/ann_quantized_faiss.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

#include <label/classlabels.cuh>
#include <raft/distance/distance.hpp>
#include <raft/spatial/knn/faiss_mr.hpp>

#include <faiss/gpu/GpuDistance.h>
#include <faiss/gpu/GpuIndexFlat.h>
#include <faiss/gpu/GpuIndexIVFFlat.h>
#include <faiss/gpu/GpuIndexIVFPQ.h>
#include <faiss/gpu/GpuIndexIVFScalarQuantizer.h>
#include <faiss/gpu/GpuResources.h>
#include <faiss/gpu/StandardGpuResources.h>
#include <faiss/gpu/utils/Limits.cuh>
#include <faiss/gpu/utils/Select.cuh>
#include <faiss/gpu/utils/Tensor.cuh>
Expand Down Expand Up @@ -126,7 +126,7 @@ void approx_knn_build_index(raft::handle_t& handle,
int device;
RAFT_CUDA_TRY(cudaGetDevice(&device));

faiss::gpu::StandardGpuResources* gpu_res = new faiss::gpu::StandardGpuResources();
raft::spatial::knn::RmmGpuResources* gpu_res = new raft::spatial::knn::RmmGpuResources();
gpu_res->noTempMemory();
gpu_res->setDefaultStream(device, handle.get_stream());
index->gpu_res = gpu_res;
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/raft/spatial/knn/detail/haversine_distance.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

#include <faiss/gpu/GpuDistance.h>
#include <faiss/gpu/GpuResources.h>
#include <faiss/gpu/StandardGpuResources.h>
#include <faiss/gpu/utils/Limits.cuh>
#include <faiss/gpu/utils/Select.cuh>
#include <faiss/utils/Heap.h>

#include <raft/handle.hpp>
#include <raft/linalg/distance_type.h>
#include <raft/spatial/knn/faiss_mr.hpp>

namespace raft {
namespace spatial {
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/raft/spatial/knn/detail/knn_brute_force_faiss.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <faiss/gpu/GpuDistance.h>
#include <faiss/gpu/GpuResources.h>
#include <faiss/gpu/StandardGpuResources.h>
#include <faiss/gpu/utils/Limits.cuh>
#include <faiss/gpu/utils/Select.cuh>
#include <faiss/utils/Heap.h>
Expand All @@ -33,6 +32,7 @@
#include <iostream>
#include <raft/handle.hpp>
#include <raft/linalg/distance_type.h>
#include <raft/spatial/knn/faiss_mr.hpp>
#include <set>
#include <thrust/iterator/transform_iterator.h>

Expand Down Expand Up @@ -324,7 +324,7 @@ void brute_force_knn_impl(
default:
faiss::MetricType m = build_faiss_metric(metric);

faiss::gpu::StandardGpuResources gpu_res;
raft::spatial::knn::RmmGpuResources gpu_res;

gpu_res.noTempMemory();
gpu_res.setDefaultStream(device, stream);
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/raft/spatial/knn/detail/selection_faiss.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#pragma once

#include <raft/cudart_utils.h>
#include <raft/spatial/knn/faiss_mr.hpp>

#include <faiss/gpu/GpuDistance.h>
#include <faiss/gpu/GpuIndexFlat.h>
#include <faiss/gpu/GpuResources.h>
#include <faiss/gpu/StandardGpuResources.h>
#include <faiss/gpu/utils/Limits.cuh>
#include <faiss/gpu/utils/Select.cuh>
#include <faiss/utils/Heap.h>
Expand Down
Loading

0 comments on commit 73585f4

Please sign in to comment.