Skip to content

Commit 5b46576

Browse files
authored
Fix bug in pinned_memory_resource with CCCL 3.1.x. (#2058)
## Description Closes #2057. This fix only affects builds with CCCL 3.1.0+. ## Checklist - [x] I am familiar with the [Contributing Guidelines](https://github.com/rapidsai/rmm/blob/HEAD/CONTRIBUTING.md). - [x] New or existing tests cover these changes. - [x] The documentation is up to date with these changes.
1 parent 278d559 commit 5b46576

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

cpp/include/rmm/mr/host/pinned_memory_resource.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ class pinned_memory_resource final : public host_memory_resource {
152152
#if CCCL_MAJOR_VERSION > 3 || (CCCL_MAJOR_VERSION == 3 && CCCL_MINOR_VERSION >= 1)
153153

154154
public:
155+
// Explicitly inherit the allocate and deallocate functions from the host_memory_resource class.
156+
// Due to inheritance and name hiding rules, we need to declare these with "using" when we
157+
// override allocate and deallocate for CCCL 3.1.0+ compatibility.
158+
using host_memory_resource::allocate;
159+
using host_memory_resource::deallocate;
160+
155161
/**
156162
* @brief Pretend to support the allocate_async interface, falling back to stream 0
157163
*

cpp/tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ ConfigureTest(LIMITING_TEST mr/device/limiting_mr_tests.cpp)
183183
# host mr_ref tests
184184
ConfigureTest(HOST_MR_REF_TEST mr/host/mr_ref_tests.cpp)
185185

186+
# pinned mr tests
187+
ConfigureTest(PINNED_MR_TEST mr/host/pinned_mr_tests.cpp)
188+
186189
# pinned pool mr tests
187190
ConfigureTest(PINNED_POOL_MR_TEST mr/host/pinned_pool_mr_tests.cpp)
188191

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2025, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
#include <rmm/mr/host/pinned_memory_resource.hpp>
16+
17+
#include <cuda_runtime_api.h>
18+
19+
#include <gtest/gtest.h>
20+
21+
namespace rmm::test {
22+
namespace {
23+
24+
// Returns true if a pointer points to pinned host memory.
25+
inline bool is_pinned_memory(void* ptr)
26+
{
27+
cudaPointerAttributes attributes{};
28+
if (cudaSuccess != cudaPointerGetAttributes(&attributes, ptr)) { return false; }
29+
return attributes.type == cudaMemoryTypeHost;
30+
}
31+
32+
} // namespace
33+
34+
// Issue 2057: Ensure the inherited host_memory_resource overload allocate(bytes) is usable
35+
TEST(PinnedMemoryResource, AllocateBytesOverload)
36+
{
37+
rmm::mr::pinned_memory_resource mr;
38+
39+
void* ptr{nullptr};
40+
EXPECT_NO_THROW(ptr = mr.allocate(128));
41+
EXPECT_NE(nullptr, ptr);
42+
EXPECT_TRUE(is_pinned_memory(ptr));
43+
EXPECT_NO_THROW(mr.deallocate(ptr, 128));
44+
}
45+
46+
} // namespace rmm::test

0 commit comments

Comments
 (0)