Skip to content

Commit 81f2709

Browse files
Alexandr Guzhvafacebook-github-bot
Alexandr Guzhva
authored andcommitted
enable RAFT under the hood of GPU FAISS (facebookresearch#2840)
Summary: Pull Request resolved: facebookresearch#2840 Reviewed By: wickedfoo, mdouze Differential Revision: D45054274 fbshipit-source-id: 87889a30e209431908f488035bcf01a4b2bb2eee
1 parent 3219e3d commit 81f2709

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

faiss/gpu/StandardGpuResources.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,12 @@ void StandardGpuResourcesImpl::initializeForDevice(int device) {
312312
// If this is the first device that we're initializing, create our
313313
// pinned memory allocation
314314
if (defaultStreams_.empty() && pinnedMemSize_ > 0) {
315-
pinnedMemAlloc_ = pmr->allocate(pinnedMemSize_);
315+
try {
316+
pinnedMemAlloc_ = pmr->allocate(pinnedMemSize_);
317+
} catch (const std::bad_alloc& rmm_ex) {
318+
FAISS_THROW_MSG("CUDA memory allocation error");
319+
}
320+
316321
pinnedMemAllocSize_ = pinnedMemSize_;
317322
}
318323
#else
@@ -490,7 +495,11 @@ void* StandardGpuResourcesImpl::allocMemory(const AllocRequest& req) {
490495

491496
} else if (adjReq.space == MemorySpace::Device) {
492497
#if defined USE_NVIDIA_RAFT
493-
p = cmr->allocate(adjReq.size, adjReq.stream);
498+
try {
499+
p = cmr->allocate(adjReq.size, adjReq.stream);
500+
} catch (const std::bad_alloc& rmm_ex) {
501+
FAISS_THROW_MSG("CUDA memory allocation error");
502+
}
494503
#else
495504
auto err = cudaMalloc(&p, adjReq.size);
496505

@@ -516,7 +525,11 @@ void* StandardGpuResourcesImpl::allocMemory(const AllocRequest& req) {
516525
#endif
517526
} else if (adjReq.space == MemorySpace::Unified) {
518527
#if defined USE_NVIDIA_RAFT
519-
p = mmr->allocate(adjReq.size, adjReq.stream);
528+
try {
529+
p = mmr->allocate(adjReq.size, adjReq.stream);
530+
} catch (const std::bad_alloc& rmm_ex) {
531+
FAISS_THROW_MSG("CUDA memory allocation error");
532+
}
520533
#else
521534
auto err = cudaMallocManaged(&p, adjReq.size);
522535

faiss/gpu/test/test_gpu_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_ivfsq_cpu_coarse(self):
189189

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

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

194194
def test_ivfpq_cpu_coarse(self):
195195
res = faiss.StandardGpuResources()

0 commit comments

Comments
 (0)