Skip to content

Commit 3888f9b

Browse files
cjnoletfacebook-github-bot
authored andcommitted
Using expanded distance forms in RaftFlatIndex.cu (facebookresearch#3021)
Summary: This is a minor bug that comes with a perf impact. The classic FAISS `FlatIndex` always uses expanded form of distance computation even though an argument `exactDistances` is provided. `RaftFlatIndex` was using this argument to determine whether the computation should be exhaustive. This PR includes one additional change to eagerly initialize the `cublas_handle` on the `device_resources` instance when it's created. Pull Request resolved: facebookresearch#3021 Reviewed By: pemazare Differential Revision: D48739660 Pulled By: mdouze fbshipit-source-id: a361334eb243df86c169c69d24bb10fed8876ee9
1 parent fef49a6 commit 3888f9b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

faiss/gpu/StandardGpuResources.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ raft::device_resources& StandardGpuResourcesImpl::getRaftHandle(int device) {
432432
// Make sure we are using the stream the user may have already assigned
433433
// to the current GpuResources
434434
raftHandles_.emplace(std::make_pair(device, getDefaultStream(device)));
435+
436+
// Initialize cublas handle
437+
raftHandles_[device].get_cublas_handle();
435438
}
436439

437440
// Otherwise, our base default handle

faiss/gpu/impl/RaftUtils.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ inline raft::distance::DistanceType faiss_to_raft(
3636
case MetricType::METRIC_INNER_PRODUCT:
3737
return raft::distance::DistanceType::InnerProduct;
3838
case MetricType::METRIC_L2:
39-
return exactDistance ? raft::distance::DistanceType::L2Unexpanded
40-
: raft::distance::DistanceType::L2Expanded;
39+
return raft::distance::DistanceType::L2Expanded;
4140
case MetricType::METRIC_L1:
4241
return raft::distance::DistanceType::L1;
4342
case MetricType::METRIC_Linf:

0 commit comments

Comments
 (0)