diff --git a/cpp/include/rmm/detail/cccl_adaptors.hpp b/cpp/include/rmm/detail/cccl_adaptors.hpp index dc8fb4132..d8f6999e0 100644 --- a/cpp/include/rmm/detail/cccl_adaptors.hpp +++ b/cpp/include/rmm/detail/cccl_adaptors.hpp @@ -5,7 +5,6 @@ #pragma once #include -#include #include #include #include diff --git a/cpp/include/rmm/detail/cuda_memory_resource.hpp b/cpp/include/rmm/detail/cuda_memory_resource.hpp deleted file mode 100644 index 23c21a10f..000000000 --- a/cpp/include/rmm/detail/cuda_memory_resource.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION. - * SPDX-License-Identifier: Apache-2.0 - */ -#pragma once - -#include - -#if CCCL_MAJOR_VERSION < 3 || (CCCL_MAJOR_VERSION == 3 && CCCL_MINOR_VERSION < 2) -#error "RMM requires CCCL version 3.2 or newer." -#endif - -#include - -#include - -namespace RMM_NAMESPACE { -namespace detail { -namespace polyfill { - -template -inline constexpr bool resource = cuda::mr::synchronous_resource; -template -inline constexpr bool resource_with = cuda::mr::synchronous_resource_with; -template -inline constexpr bool async_resource = cuda::mr::resource; -template -inline constexpr bool async_resource_with = cuda::mr::resource_with; - -} // namespace polyfill -} // namespace detail -} // namespace RMM_NAMESPACE diff --git a/cpp/include/rmm/detail/export.hpp b/cpp/include/rmm/detail/export.hpp index f1dbc0866..8dff6e22a 100644 --- a/cpp/include/rmm/detail/export.hpp +++ b/cpp/include/rmm/detail/export.hpp @@ -5,6 +5,12 @@ #pragma once +#include + +#if CCCL_MAJOR_VERSION < 3 || (CCCL_MAJOR_VERSION == 3 && CCCL_MINOR_VERSION < 3) +#error "RMM requires CCCL version 3.3 or newer." +#endif + // Macros used for defining symbol visibility, only GLIBC is supported #if (defined(__GNUC__) && !defined(__MINGW32__) && !defined(__MINGW64__)) #define RMM_EXPORT __attribute__((visibility("default"))) diff --git a/cpp/include/rmm/mr/cuda_async_managed_memory_resource.hpp b/cpp/include/rmm/mr/cuda_async_managed_memory_resource.hpp index 3582108a2..1437b0ca0 100644 --- a/cpp/include/rmm/mr/cuda_async_managed_memory_resource.hpp +++ b/cpp/include/rmm/mr/cuda_async_managed_memory_resource.hpp @@ -118,12 +118,12 @@ class cuda_async_managed_memory_resource final : public device_memory_resource { }; // static property checks -static_assert(rmm::detail::polyfill::resource); -static_assert(rmm::detail::polyfill::async_resource); -static_assert(rmm::detail::polyfill::resource_with); -static_assert(rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::synchronous_resource); +static_assert(cuda::mr::resource); +static_assert(cuda::mr::synchronous_resource_with); +static_assert( + cuda::mr::resource_with); /** @} */ // end of group } // namespace mr diff --git a/cpp/include/rmm/mr/device_memory_resource.hpp b/cpp/include/rmm/mr/device_memory_resource.hpp index e90c90996..36779eb18 100644 --- a/cpp/include/rmm/mr/device_memory_resource.hpp +++ b/cpp/include/rmm/mr/device_memory_resource.hpp @@ -6,11 +6,12 @@ #include #include -#include #include #include #include +#include + #include #include @@ -276,12 +277,11 @@ class device_memory_resource { }; // static property checks -static_assert(rmm::detail::polyfill::resource); -static_assert(rmm::detail::polyfill::async_resource); -static_assert( - rmm::detail::polyfill::resource_with); +static_assert(cuda::mr::synchronous_resource); +static_assert(cuda::mr::resource); static_assert( - rmm::detail::polyfill::async_resource_with); + cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::resource_with); /** @} */ // end of group } // namespace mr diff --git a/cpp/include/rmm/mr/is_resource_adaptor.hpp b/cpp/include/rmm/mr/is_resource_adaptor.hpp index 2e8447743..34da2d9c0 100644 --- a/cpp/include/rmm/mr/is_resource_adaptor.hpp +++ b/cpp/include/rmm/mr/is_resource_adaptor.hpp @@ -1,12 +1,12 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ #pragma once -#include #include +#include #include namespace RMM_NAMESPACE { @@ -29,7 +29,7 @@ template inline constexpr bool is_resource_adaptor< Resource, cuda::std::void_t().get_upstream_resource())>> = - rmm::detail::polyfill::resource; + cuda::mr::synchronous_resource; /** @} */ // end of group } // namespace mr diff --git a/cpp/include/rmm/mr/pinned_host_memory_resource.hpp b/cpp/include/rmm/mr/pinned_host_memory_resource.hpp index a80128159..684786457 100644 --- a/cpp/include/rmm/mr/pinned_host_memory_resource.hpp +++ b/cpp/include/rmm/mr/pinned_host_memory_resource.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -132,9 +131,9 @@ class pinned_host_memory_resource final : public device_memory_resource { } }; -static_assert(rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::resource_with); /** @} */ // end of group } // namespace mr diff --git a/cpp/include/rmm/mr/system_memory_resource.hpp b/cpp/include/rmm/mr/system_memory_resource.hpp index 132ad934b..b2c646d5f 100644 --- a/cpp/include/rmm/mr/system_memory_resource.hpp +++ b/cpp/include/rmm/mr/system_memory_resource.hpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ #pragma once @@ -154,10 +154,8 @@ class system_memory_resource final : public device_memory_resource { }; // static property checks -static_assert( - rmm::detail::polyfill::async_resource_with); -static_assert( - rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::resource_with); +static_assert(cuda::mr::resource_with); /** @} */ // end of group } // namespace mr } // namespace RMM_NAMESPACE diff --git a/cpp/include/rmm/mr/thrust_allocator_adaptor.hpp b/cpp/include/rmm/mr/thrust_allocator_adaptor.hpp index 6ed9c8539..80194a18e 100644 --- a/cpp/include/rmm/mr/thrust_allocator_adaptor.hpp +++ b/cpp/include/rmm/mr/thrust_allocator_adaptor.hpp @@ -1,12 +1,11 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include -#include #include #include #include diff --git a/cpp/tests/device_scalar_tests.cpp b/cpp/tests/device_scalar_tests.cpp index a2bed1712..a3a3d275c 100644 --- a/cpp/tests/device_scalar_tests.cpp +++ b/cpp/tests/device_scalar_tests.cpp @@ -1,10 +1,9 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ #include -#include #include #include #include diff --git a/cpp/tests/mock_resource.hpp b/cpp/tests/mock_resource.hpp index 0bd81ae7b..b65d1ea4d 100644 --- a/cpp/tests/mock_resource.hpp +++ b/cpp/tests/mock_resource.hpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2022-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ #pragma once @@ -21,7 +21,6 @@ class mock_resource : public rmm::mr::device_memory_resource { }; // static property checks -static_assert( - rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::resource_with); } // namespace rmm::test diff --git a/cpp/tests/mr/adaptor_tests.cpp b/cpp/tests/mr/adaptor_tests.cpp index 49024d3f4..4229ae613 100644 --- a/cpp/tests/mr/adaptor_tests.cpp +++ b/cpp/tests/mr/adaptor_tests.cpp @@ -5,7 +5,6 @@ #include "../byte_literals.hpp" -#include #include #include #include @@ -13,7 +12,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -38,12 +40,20 @@ using adaptors = ::testing::Types, thread_safe_resource_adaptor>; // static property checks -static_assert(rmm::detail::polyfill::resource_with, - cuda::mr::device_accessible>); -static_assert(rmm::detail::polyfill::resource_with); -static_assert(rmm::detail::polyfill::resource_with); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::synchronous_resource_with, + cuda::mr::device_accessible>); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::synchronous_resource_with); template struct AdaptorTest : public ::testing::Test { diff --git a/cpp/tests/mr/arena_mr_tests.cpp b/cpp/tests/mr/arena_mr_tests.cpp index 318935f47..599af4667 100644 --- a/cpp/tests/mr/arena_mr_tests.cpp +++ b/cpp/tests/mr/arena_mr_tests.cpp @@ -45,8 +45,7 @@ class mock_memory_resource : public rmm::mr::device_memory_resource { }; // static property checks -static_assert( - rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::resource_with); using rmm::mr::detail::arena::block; using rmm::mr::detail::arena::byte_span; diff --git a/cpp/tests/mr/cuda_async_mr_tests.cpp b/cpp/tests/mr/cuda_async_mr_tests.cpp index c46ee91ee..fb1034a37 100644 --- a/cpp/tests/mr/cuda_async_mr_tests.cpp +++ b/cpp/tests/mr/cuda_async_mr_tests.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ @@ -16,9 +16,8 @@ namespace { using cuda_async_mr = rmm::mr::cuda_async_memory_resource; // static property checks -static_assert(rmm::detail::polyfill::resource_with); -static_assert( - rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::resource_with); class AsyncMRTest : public ::testing::Test { protected: diff --git a/cpp/tests/mr/cuda_async_view_mr_tests.cpp b/cpp/tests/mr/cuda_async_view_mr_tests.cpp index 3475bac1c..5ee0a5879 100644 --- a/cpp/tests/mr/cuda_async_view_mr_tests.cpp +++ b/cpp/tests/mr/cuda_async_view_mr_tests.cpp @@ -1,10 +1,9 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ #include -#include #include #include @@ -16,10 +15,8 @@ namespace { using cuda_async_view_mr = rmm::mr::cuda_async_view_memory_resource; // static property checks -static_assert( - rmm::detail::polyfill::resource_with); -static_assert( - rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::resource_with); TEST(PoolTest, UsePool) { diff --git a/cpp/tests/mr/host_mr_ref_tests.cpp b/cpp/tests/mr/host_mr_ref_tests.cpp index ff87abee9..73e330546 100644 --- a/cpp/tests/mr/host_mr_ref_tests.cpp +++ b/cpp/tests/mr/host_mr_ref_tests.cpp @@ -1,12 +1,11 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ #include "../byte_literals.hpp" #include -#include #include #include @@ -81,8 +80,8 @@ struct MRRefTest : public ::testing::Test { using resources = ::testing::Types; // static property checks -static_assert(rmm::detail::polyfill::resource_with); +static_assert(cuda::mr::synchronous_resource_with); TYPED_TEST_SUITE(MRRefTest, resources); diff --git a/cpp/tests/mr/system_mr_tests.cu b/cpp/tests/mr/system_mr_tests.cu index 6e28818bb..5ff49e274 100644 --- a/cpp/tests/mr/system_mr_tests.cu +++ b/cpp/tests/mr/system_mr_tests.cu @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION. * SPDX-License-Identifier: Apache-2.0 */ @@ -48,14 +48,14 @@ void touch_on_gpu(void* ptr, std::size_t size) using system_mr = rmm::mr::system_memory_resource; // static property checks -static_assert(rmm::detail::polyfill::resource_with); -static_assert(rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::resource_with); using headroom_mr = rmm::mr::sam_headroom_memory_resource; // static property checks -static_assert(rmm::detail::polyfill::resource_with); -static_assert(rmm::detail::polyfill::async_resource_with); +static_assert(cuda::mr::synchronous_resource_with); +static_assert(cuda::mr::resource_with); class SystemMRTest : public ::testing::Test { protected: diff --git a/python/rmm/rmm/tests/test_binning_memory_resource.py b/python/rmm/rmm/tests/test_binning_memory_resource.py index 91a7a65ca..cffbe91df 100644 --- a/python/rmm/rmm/tests/test_binning_memory_resource.py +++ b/python/rmm/rmm/tests/test_binning_memory_resource.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION. # SPDX-License-Identifier: Apache-2.0 """Tests for BinningMemoryResource.""" @@ -15,28 +15,8 @@ import rmm -@pytest.mark.parametrize("dtype", _dtypes) -@pytest.mark.parametrize("nelem", _nelems) -@pytest.mark.parametrize("alloc", _allocs) -@pytest.mark.parametrize( - "upstream_mr", - [ - lambda: rmm.mr.CudaMemoryResource(), - lambda: rmm.mr.ManagedMemoryResource(), - lambda: rmm.mr.PoolMemoryResource( - rmm.mr.CudaMemoryResource(), 1 << 20 - ), - ] - + ( - [ - lambda: rmm.mr.SystemMemoryResource(), - lambda: rmm.mr.SamHeadroomMemoryResource(headroom=1 << 20), - ] - if _SYSTEM_MEMORY_SUPPORTED - else [] - ), -) -def test_binning_memory_resource(dtype, nelem, alloc, upstream_mr): +def _make_binning_mr(upstream_mr): + """Build a BinningMemoryResource from the given upstream factory.""" upstream = upstream_mr() # Add fixed-size bins 256KiB, 512KiB, 1MiB, 2MiB, 4MiB @@ -47,7 +27,44 @@ def test_binning_memory_resource(dtype, nelem, alloc, upstream_mr): cuda_mr = rmm.mr.CudaMemoryResource() mr.add_bin(1 << 10, fixed_mr) # 1KiB bin mr.add_bin(1 << 23, cuda_mr) # 8MiB bin + return mr + + +_UPSTREAM_MRS = [ + lambda: rmm.mr.CudaMemoryResource(), + lambda: rmm.mr.ManagedMemoryResource(), + lambda: rmm.mr.PoolMemoryResource(rmm.mr.CudaMemoryResource(), 1 << 20), +] + ( + [ + lambda: rmm.mr.SystemMemoryResource(), + lambda: rmm.mr.SamHeadroomMemoryResource(headroom=1 << 20), + ] + if _SYSTEM_MEMORY_SUPPORTED + else [] +) + + +# Create the BinningMemoryResource once per upstream_mr (class-scoped), +# avoiding the expensive ManagedMemoryResource/FixedSizeMemoryResource slab +# allocation on every test invocation. +@pytest.fixture(scope="class", params=_UPSTREAM_MRS) +def binning_mr(request): + """Create the BinningMemoryResource once per upstream_mr.""" + return _make_binning_mr(request.param) + + +class TestBinningMemoryResource: + @pytest.fixture(autouse=True) + def _apply_mr(self, binning_mr): + """Set the device resource before each test.""" + rmm.mr.set_current_device_resource(binning_mr) - rmm.mr.set_current_device_resource(mr) - assert rmm.mr.get_current_device_resource_type() is type(mr) - array_tester(dtype, nelem, alloc) + @pytest.mark.parametrize("dtype", _dtypes) + @pytest.mark.parametrize("nelem", _nelems) + @pytest.mark.parametrize("alloc", _allocs) + def test_binning_memory_resource(self, binning_mr, dtype, nelem, alloc): + assert ( + rmm.mr.get_current_device_resource_type() + is rmm.mr.BinningMemoryResource + ) + array_tester(dtype, nelem, alloc)