From 864b289da8da66965b99dd89bfb4cc40f873cb5e Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 23 Jul 2024 14:41:54 -0700 Subject: [PATCH 1/3] Deprecate adaptor factories. --- include/rmm/mr/device/limiting_resource_adaptor.hpp | 2 ++ include/rmm/mr/device/polymorphic_allocator.hpp | 3 +++ include/rmm/mr/device/statistics_resource_adaptor.hpp | 3 +++ include/rmm/mr/device/tracking_resource_adaptor.hpp | 2 ++ 4 files changed, 10 insertions(+) diff --git a/include/rmm/mr/device/limiting_resource_adaptor.hpp b/include/rmm/mr/device/limiting_resource_adaptor.hpp index aa2361d1f..df68c5100 100644 --- a/include/rmm/mr/device/limiting_resource_adaptor.hpp +++ b/include/rmm/mr/device/limiting_resource_adaptor.hpp @@ -189,6 +189,8 @@ class limiting_resource_adaptor final : public device_memory_resource { * @return The new limiting resource adaptor */ template +[[deprecated( + "make_limiting_adaptor is deprecated. Use the limiting_resource_adaptor constructor instead.")]] limiting_resource_adaptor make_limiting_adaptor(Upstream* upstream, std::size_t allocation_limit) { diff --git a/include/rmm/mr/device/polymorphic_allocator.hpp b/include/rmm/mr/device/polymorphic_allocator.hpp index 0b63b4691..5dd5037d7 100644 --- a/include/rmm/mr/device/polymorphic_allocator.hpp +++ b/include/rmm/mr/device/polymorphic_allocator.hpp @@ -302,6 +302,9 @@ bool operator!=(stream_allocator_adaptor const& lhs, stream_allocator_adaptor * @return A `stream_allocator_adaptor` wrapping `allocator` and `s` */ template +[[deprecated( + "make_stream_allocator_adaptor is deprecated. Use the stream_allocator_adaptor constructor " + "instead.")]] auto make_stream_allocator_adaptor(Allocator const& allocator, cuda_stream_view stream) { return stream_allocator_adaptor{allocator, stream}; diff --git a/include/rmm/mr/device/statistics_resource_adaptor.hpp b/include/rmm/mr/device/statistics_resource_adaptor.hpp index 3ee2315f2..35e329231 100644 --- a/include/rmm/mr/device/statistics_resource_adaptor.hpp +++ b/include/rmm/mr/device/statistics_resource_adaptor.hpp @@ -289,6 +289,9 @@ class statistics_resource_adaptor final : public device_memory_resource { * @return The new statistics resource adaptor */ template +[[deprecated( + "make_statistics_adaptor is deprecated. Use the statistics_resource_adaptor constructor " + "instead.")]] statistics_resource_adaptor make_statistics_adaptor(Upstream* upstream) { return statistics_resource_adaptor{upstream}; diff --git a/include/rmm/mr/device/tracking_resource_adaptor.hpp b/include/rmm/mr/device/tracking_resource_adaptor.hpp index d01d08b9c..7795eda82 100644 --- a/include/rmm/mr/device/tracking_resource_adaptor.hpp +++ b/include/rmm/mr/device/tracking_resource_adaptor.hpp @@ -283,6 +283,8 @@ class tracking_resource_adaptor final : public device_memory_resource { * @return The new tracking resource adaptor */ template +[[deprecated( + "make_tracking_adaptor is deprecated. Use the tracking_resource_adaptor constructor instead.")]] tracking_resource_adaptor make_tracking_adaptor(Upstream* upstream) { return tracking_resource_adaptor{upstream}; From d8139d4f95f5322dd333c0dfb4c1400e368b5400 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Tue, 23 Jul 2024 14:55:34 -0700 Subject: [PATCH 2/3] Also deprecate logging adaptor factory. --- include/rmm/mr/device/logging_resource_adaptor.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/rmm/mr/device/logging_resource_adaptor.hpp b/include/rmm/mr/device/logging_resource_adaptor.hpp index 61d00cafc..318807e0c 100644 --- a/include/rmm/mr/device/logging_resource_adaptor.hpp +++ b/include/rmm/mr/device/logging_resource_adaptor.hpp @@ -307,6 +307,9 @@ class logging_resource_adaptor final : public device_memory_resource { * @return The new logging resource adaptor */ template +[[deprecated( + "make_logging_adaptor is deprecated. Use the logging_resource_adaptor constructor " + "instead.")]] logging_resource_adaptor make_logging_adaptor( Upstream* upstream, std::string const& filename = logging_resource_adaptor::get_default_filename(), @@ -327,6 +330,9 @@ logging_resource_adaptor make_logging_adaptor( * @return The new logging resource adaptor */ template +[[deprecated( + "make_logging_adaptor is deprecated. Use the logging_resource_adaptor constructor " + "instead.")]] logging_resource_adaptor make_logging_adaptor(Upstream* upstream, std::ostream& stream, bool auto_flush = false) From 4e5a6198cef30224fd6e13d9a1f5e4219c49eda2 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Mon, 5 Aug 2024 13:44:23 -0700 Subject: [PATCH 3/3] Address feedback. --- README.md | 2 +- .../mr/device/limiting_resource_adaptor.hpp | 3 ++- .../mr/device/logging_resource_adaptor.hpp | 7 ++++-- .../rmm/mr/device/polymorphic_allocator.hpp | 5 +++-- .../mr/device/statistics_resource_adaptor.hpp | 3 ++- .../mr/device/tracking_resource_adaptor.hpp | 3 ++- tests/logger_tests.cpp | 14 ++++++------ .../device/stream_allocator_adaptor_tests.cpp | 22 +++++++++---------- 8 files changed, 33 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index e1d78458f..2117f40ee 100644 --- a/README.md +++ b/README.md @@ -478,7 +478,7 @@ rmm::cuda_stream stream; rmm::mr::polymorphic_allocator stream_alloc; // Constructs an adaptor that forwards all (de)allocations to `stream_alloc` on `stream`. -auto adapted = rmm::mr::make_stream_allocator_adaptor(stream_alloc, stream); +auto adapted = rmm::mr::stream_allocator_adaptor(stream_alloc, stream); // Allocates 100 bytes using `stream_alloc` on `stream` auto p = adapted.allocate(100); diff --git a/include/rmm/mr/device/limiting_resource_adaptor.hpp b/include/rmm/mr/device/limiting_resource_adaptor.hpp index df68c5100..76a5a31c1 100644 --- a/include/rmm/mr/device/limiting_resource_adaptor.hpp +++ b/include/rmm/mr/device/limiting_resource_adaptor.hpp @@ -190,7 +190,8 @@ class limiting_resource_adaptor final : public device_memory_resource { */ template [[deprecated( - "make_limiting_adaptor is deprecated. Use the limiting_resource_adaptor constructor instead.")]] + "make_limiting_adaptor is deprecated in RMM 24.10. Use the limiting_resource_adaptor constructor " + "instead.")]] limiting_resource_adaptor make_limiting_adaptor(Upstream* upstream, std::size_t allocation_limit) { diff --git a/include/rmm/mr/device/logging_resource_adaptor.hpp b/include/rmm/mr/device/logging_resource_adaptor.hpp index 318807e0c..493d6e89e 100644 --- a/include/rmm/mr/device/logging_resource_adaptor.hpp +++ b/include/rmm/mr/device/logging_resource_adaptor.hpp @@ -284,6 +284,9 @@ class logging_resource_adaptor final : public device_memory_resource { // make_logging_adaptor needs access to private get_default_filename template // NOLINTNEXTLINE(readability-redundant-declaration) + [[deprecated( + "make_logging_adaptor is deprecated in RMM 24.10. Use the logging_resource_adaptor constructor " + "instead.")]] friend logging_resource_adaptor make_logging_adaptor(T* upstream, std::string const& filename, bool auto_flush); @@ -308,7 +311,7 @@ class logging_resource_adaptor final : public device_memory_resource { */ template [[deprecated( - "make_logging_adaptor is deprecated. Use the logging_resource_adaptor constructor " + "make_logging_adaptor is deprecated in RMM 24.10. Use the logging_resource_adaptor constructor " "instead.")]] logging_resource_adaptor make_logging_adaptor( Upstream* upstream, @@ -331,7 +334,7 @@ logging_resource_adaptor make_logging_adaptor( */ template [[deprecated( - "make_logging_adaptor is deprecated. Use the logging_resource_adaptor constructor " + "make_logging_adaptor is deprecated in RMM 24.10. Use the logging_resource_adaptor constructor " "instead.")]] logging_resource_adaptor make_logging_adaptor(Upstream* upstream, std::ostream& stream, diff --git a/include/rmm/mr/device/polymorphic_allocator.hpp b/include/rmm/mr/device/polymorphic_allocator.hpp index 5dd5037d7..863ba6f62 100644 --- a/include/rmm/mr/device/polymorphic_allocator.hpp +++ b/include/rmm/mr/device/polymorphic_allocator.hpp @@ -166,7 +166,7 @@ bool operator!=(polymorphic_allocator const& lhs, polymorphic_allocator co * my_stream_ordered_allocator a{...}; * cuda_stream_view s = // create stream; * - * auto adapted = make_stream_allocator_adaptor(a, s); + * auto adapted = stream_allocator_adaptor(a, s); * * // Allocates storage for `n` int's on stream `s` * int * p = std::allocator_traits::allocate(adapted, n); @@ -303,7 +303,8 @@ bool operator!=(stream_allocator_adaptor const& lhs, stream_allocator_adaptor */ template [[deprecated( - "make_stream_allocator_adaptor is deprecated. Use the stream_allocator_adaptor constructor " + "make_stream_allocator_adaptor is deprecated in RMM 24.10. Use the stream_allocator_adaptor " + "constructor " "instead.")]] auto make_stream_allocator_adaptor(Allocator const& allocator, cuda_stream_view stream) { diff --git a/include/rmm/mr/device/statistics_resource_adaptor.hpp b/include/rmm/mr/device/statistics_resource_adaptor.hpp index 35e329231..cbf1b87d2 100644 --- a/include/rmm/mr/device/statistics_resource_adaptor.hpp +++ b/include/rmm/mr/device/statistics_resource_adaptor.hpp @@ -290,7 +290,8 @@ class statistics_resource_adaptor final : public device_memory_resource { */ template [[deprecated( - "make_statistics_adaptor is deprecated. Use the statistics_resource_adaptor constructor " + "make_statistics_adaptor is deprecated in RMM 24.10. Use the statistics_resource_adaptor " + "constructor " "instead.")]] statistics_resource_adaptor make_statistics_adaptor(Upstream* upstream) { diff --git a/include/rmm/mr/device/tracking_resource_adaptor.hpp b/include/rmm/mr/device/tracking_resource_adaptor.hpp index 7795eda82..0d3046973 100644 --- a/include/rmm/mr/device/tracking_resource_adaptor.hpp +++ b/include/rmm/mr/device/tracking_resource_adaptor.hpp @@ -284,7 +284,8 @@ class tracking_resource_adaptor final : public device_memory_resource { */ template [[deprecated( - "make_tracking_adaptor is deprecated. Use the tracking_resource_adaptor constructor instead.")]] + "make_tracking_adaptor is deprecated in RMM 24.10. Use the tracking_resource_adaptor constructor " + "instead.")]] tracking_resource_adaptor make_tracking_adaptor(Upstream* upstream) { return tracking_resource_adaptor{upstream}; diff --git a/tests/logger_tests.cpp b/tests/logger_tests.cpp index 5e3b2f899..643281d91 100644 --- a/tests/logger_tests.cpp +++ b/tests/logger_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -186,7 +186,7 @@ TEST(Adaptor, Factory) std::string filename{temp_dir.generate_path("test.txt")}; rmm::mr::cuda_memory_resource upstream; - auto log_mr = rmm::mr::make_logging_adaptor(&upstream, filename); + auto log_mr = rmm::mr::logging_resource_adaptor(&upstream, filename); auto const size0{99}; auto const size1{42}; @@ -219,14 +219,14 @@ TEST(Adaptor, EnvironmentPath) unsetenv("RMM_LOG_FILE"); // expect logging adaptor to fail if RMM_LOG_FILE is unset - EXPECT_THROW(rmm::mr::make_logging_adaptor(&upstream), rmm::logic_error); + EXPECT_THROW(rmm::mr::logging_resource_adaptor{&upstream}, rmm::logic_error); std::string filename{temp_dir.generate_path("test.txt")}; setenv("RMM_LOG_FILE", filename.c_str(), 1); // use log file location specified in environment variable RMM_LOG_FILE - auto log_mr = rmm::mr::make_logging_adaptor(&upstream); + auto log_mr = rmm::mr::logging_resource_adaptor(&upstream); auto const size{100}; @@ -252,7 +252,7 @@ TEST(Adaptor, AllocateFailure) std::string filename{temp_dir.generate_path("failure.txt")}; rmm::mr::cuda_memory_resource upstream; - auto log_mr = rmm::mr::make_logging_adaptor(&upstream, filename); + auto log_mr = rmm::mr::logging_resource_adaptor(&upstream, filename); auto const size0{99}; auto const size1{1_TiB}; @@ -281,7 +281,7 @@ TEST(Adaptor, STDOUT) rmm::mr::cuda_memory_resource upstream; - auto log_mr = rmm::mr::make_logging_adaptor(&upstream, std::cout); + auto log_mr = rmm::mr::logging_resource_adaptor(&upstream, std::cout); auto const size{100}; @@ -299,7 +299,7 @@ TEST(Adaptor, STDERR) rmm::mr::cuda_memory_resource upstream; - auto log_mr = rmm::mr::make_logging_adaptor(&upstream, std::cerr); + auto log_mr = rmm::mr::logging_resource_adaptor(&upstream, std::cerr); auto const size{100}; diff --git a/tests/mr/device/stream_allocator_adaptor_tests.cpp b/tests/mr/device/stream_allocator_adaptor_tests.cpp index 669fca5f5..72a014bfa 100644 --- a/tests/mr/device/stream_allocator_adaptor_tests.cpp +++ b/tests/mr/device/stream_allocator_adaptor_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ struct allocator_test : public ::testing::Test { TEST_F(allocator_test, factory) { using Adaptor = rmm::mr::stream_allocator_adaptor; - auto adapted = rmm::mr::make_stream_allocator_adaptor(allocator, stream); + auto adapted = rmm::mr::stream_allocator_adaptor(allocator, stream); static_assert((std::is_same::value)); EXPECT_EQ(adapted.underlying_allocator(), allocator); EXPECT_EQ(adapted.stream(), stream); @@ -42,7 +42,7 @@ TEST_F(allocator_test, factory) TEST_F(allocator_test, self_equality) { - auto adapted = rmm::mr::make_stream_allocator_adaptor(allocator, stream); + auto adapted = rmm::mr::stream_allocator_adaptor(allocator, stream); EXPECT_EQ(adapted, adapted); EXPECT_FALSE(adapted != adapted); } @@ -50,10 +50,10 @@ TEST_F(allocator_test, self_equality) TEST_F(allocator_test, equal_allocators) { rmm::mr::polymorphic_allocator alloc0; - auto adapted0 = rmm::mr::make_stream_allocator_adaptor(alloc0, stream); + auto adapted0 = rmm::mr::stream_allocator_adaptor(alloc0, stream); rmm::mr::polymorphic_allocator alloc1; - auto adapted1 = rmm::mr::make_stream_allocator_adaptor(alloc1, stream); + auto adapted1 = rmm::mr::stream_allocator_adaptor(alloc1, stream); EXPECT_EQ(adapted0, adapted1); EXPECT_FALSE(adapted0 != adapted1); @@ -63,11 +63,11 @@ TEST_F(allocator_test, unequal_resources) { rmm::mr::cuda_memory_resource mr0; rmm::mr::polymorphic_allocator alloc0{&mr0}; - auto adapted0 = rmm::mr::make_stream_allocator_adaptor(alloc0, stream); + auto adapted0 = rmm::mr::stream_allocator_adaptor(alloc0, stream); rmm::mr::managed_memory_resource mr1; rmm::mr::polymorphic_allocator alloc1{&mr1}; - auto adapted1 = rmm::mr::make_stream_allocator_adaptor(alloc1, stream); + auto adapted1 = rmm::mr::stream_allocator_adaptor(alloc1, stream); EXPECT_NE(adapted0, adapted1); } @@ -75,7 +75,7 @@ TEST_F(allocator_test, unequal_resources) TEST_F(allocator_test, copy_ctor_same_type) { rmm::mr::polymorphic_allocator alloc0; - auto adapted0 = rmm::mr::make_stream_allocator_adaptor(alloc0, stream); + auto adapted0 = rmm::mr::stream_allocator_adaptor(alloc0, stream); using Adaptor = rmm::mr::stream_allocator_adaptor; Adaptor adapted1{adapted0}; @@ -86,7 +86,7 @@ TEST_F(allocator_test, copy_ctor_same_type) TEST_F(allocator_test, copy_ctor_different_type) { rmm::mr::polymorphic_allocator alloc0; - auto adapted0 = rmm::mr::make_stream_allocator_adaptor(alloc0, stream); + auto adapted0 = rmm::mr::stream_allocator_adaptor(alloc0, stream); using Adaptor = rmm::mr::stream_allocator_adaptor>; Adaptor adapted1{adapted0}; @@ -96,7 +96,7 @@ TEST_F(allocator_test, copy_ctor_different_type) TEST_F(allocator_test, rebind) { - auto adapted = rmm::mr::make_stream_allocator_adaptor(allocator, stream); + auto adapted = rmm::mr::stream_allocator_adaptor(allocator, stream); using Rebound = std::allocator_traits::rebind_alloc; static_assert((std::is_same::value_type, double>::value)); static_assert( @@ -108,7 +108,7 @@ TEST_F(allocator_test, rebind) TEST_F(allocator_test, allocate_deallocate) { - auto adapted = rmm::mr::make_stream_allocator_adaptor(allocator, stream); + auto adapted = rmm::mr::stream_allocator_adaptor(allocator, stream); auto const size{1000}; auto* ptr = adapted.allocate(size); EXPECT_NE(ptr, nullptr);