Skip to content

Commit

Permalink
enable RAFT under the hood of GPU FAISS (facebookresearch#2840)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: facebookresearch#2840

Reviewed By: wickedfoo, mdouze

Differential Revision: D45054274

fbshipit-source-id: 87889a30e209431908f488035bcf01a4b2bb2eee
  • Loading branch information
Alexandr Guzhva authored and facebook-github-bot committed May 9, 2023
1 parent 3219e3d commit 81f2709
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions faiss/gpu/StandardGpuResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ void StandardGpuResourcesImpl::initializeForDevice(int device) {
// If this is the first device that we're initializing, create our
// pinned memory allocation
if (defaultStreams_.empty() && pinnedMemSize_ > 0) {
pinnedMemAlloc_ = pmr->allocate(pinnedMemSize_);
try {
pinnedMemAlloc_ = pmr->allocate(pinnedMemSize_);
} catch (const std::bad_alloc& rmm_ex) {
FAISS_THROW_MSG("CUDA memory allocation error");
}

pinnedMemAllocSize_ = pinnedMemSize_;
}
#else
Expand Down Expand Up @@ -490,7 +495,11 @@ void* StandardGpuResourcesImpl::allocMemory(const AllocRequest& req) {

} else if (adjReq.space == MemorySpace::Device) {
#if defined USE_NVIDIA_RAFT
p = cmr->allocate(adjReq.size, adjReq.stream);
try {
p = cmr->allocate(adjReq.size, adjReq.stream);
} catch (const std::bad_alloc& rmm_ex) {
FAISS_THROW_MSG("CUDA memory allocation error");
}
#else
auto err = cudaMalloc(&p, adjReq.size);

Expand All @@ -516,7 +525,11 @@ void* StandardGpuResourcesImpl::allocMemory(const AllocRequest& req) {
#endif
} else if (adjReq.space == MemorySpace::Unified) {
#if defined USE_NVIDIA_RAFT
p = mmr->allocate(adjReq.size, adjReq.stream);
try {
p = mmr->allocate(adjReq.size, adjReq.stream);
} catch (const std::bad_alloc& rmm_ex) {
FAISS_THROW_MSG("CUDA memory allocation error");
}
#else
auto err = cudaMallocManaged(&p, adjReq.size);

Expand Down
2 changes: 1 addition & 1 deletion faiss/gpu/test/test_gpu_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_ivfsq_cpu_coarse(self):

self.assertGreaterEqual(knn_intersection_measure(i_c, i_g), 0.9)

self.assertTrue(np.allclose(d_g, d_c, rtol=5e-5, atol=5e-5))
self.assertTrue(np.allclose(d_g, d_c, rtol=2e-4, atol=2e-4))

def test_ivfpq_cpu_coarse(self):
res = faiss.StandardGpuResources()
Expand Down

0 comments on commit 81f2709

Please sign in to comment.