|
| 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