@@ -312,7 +312,12 @@ void StandardGpuResourcesImpl::initializeForDevice(int device) {
312
312
// If this is the first device that we're initializing, create our
313
313
// pinned memory allocation
314
314
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
+
316
321
pinnedMemAllocSize_ = pinnedMemSize_;
317
322
}
318
323
#else
@@ -490,7 +495,11 @@ void* StandardGpuResourcesImpl::allocMemory(const AllocRequest& req) {
490
495
491
496
} else if (adjReq.space == MemorySpace::Device) {
492
497
#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
+ }
494
503
#else
495
504
auto err = cudaMalloc (&p, adjReq.size );
496
505
@@ -516,7 +525,11 @@ void* StandardGpuResourcesImpl::allocMemory(const AllocRequest& req) {
516
525
#endif
517
526
} else if (adjReq.space == MemorySpace::Unified) {
518
527
#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
+ }
520
533
#else
521
534
auto err = cudaMallocManaged (&p, adjReq.size );
522
535
0 commit comments