Skip to content

Commit 0af7299

Browse files
committed
Fix segfault calling rmmGetInfo when uninitialized
When RMM is uninitialized (e.g. due to calling rmmFinalize()) a call to rmmGetInfo can segfault in rmm::detail::mr::device_memory_resource::get_mem_info() with an invalid instance. This commit fixes the segfault by adding a check to rmmGetInfo() which ensures that RMM is initialized before proceeding to call get_mem_info().
1 parent 62182a3 commit 0af7299

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/rmm.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ rmmError_t rmmGetAllocationOffset(ptrdiff_t *offset,
116116
// with the stream.
117117
rmmError_t rmmGetInfo(size_t *freeSize, size_t *totalSize, cudaStream_t stream)
118118
{
119+
if (!rmmIsInitialized(nullptr))
120+
return RMM_ERROR_NOT_INITIALIZED;
119121
try {
120122
std::pair<size_t,size_t> memInfo = rmm::mr::get_default_resource()->get_mem_info( stream);
121123
*freeSize = memInfo.first;

tests/memory_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ TYPED_TEST(MemoryManagerUninitializedTest, UninitializedAllocateFree) {
8686
ASSERT_FAILURE(RMM_FREE(a, stream));
8787
}
8888

89+
TYPED_TEST(MemoryManagerUninitializedTest, GetInfoUninitialized) {
90+
size_t free, total;
91+
ASSERT_FAILURE(rmmGetInfo(&free, &total, stream));
92+
}
93+
8994

9095
// Init / Finalize tests
9196

0 commit comments

Comments
 (0)