Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate adaptor factories. #1626

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ rmm::cuda_stream stream;
rmm::mr::polymorphic_allocator<int> 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);
Expand Down
3 changes: 3 additions & 0 deletions include/rmm/mr/device/limiting_resource_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class limiting_resource_adaptor final : public device_memory_resource {
* @return The new limiting resource adaptor
*/
template <typename Upstream>
[[deprecated(
"make_limiting_adaptor is deprecated in RMM 24.10. Use the limiting_resource_adaptor constructor "
"instead.")]]
limiting_resource_adaptor<Upstream> make_limiting_adaptor(Upstream* upstream,
std::size_t allocation_limit)
{
Expand Down
9 changes: 9 additions & 0 deletions include/rmm/mr/device/logging_resource_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ class logging_resource_adaptor final : public device_memory_resource {
// make_logging_adaptor needs access to private get_default_filename
template <typename T>
// 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<T> make_logging_adaptor(T* upstream,
std::string const& filename,
bool auto_flush);
Expand All @@ -307,6 +310,9 @@ class logging_resource_adaptor final : public device_memory_resource {
* @return The new logging resource adaptor
*/
template <typename Upstream>
[[deprecated(
bdice marked this conversation as resolved.
Show resolved Hide resolved
"make_logging_adaptor is deprecated in RMM 24.10. Use the logging_resource_adaptor constructor "
"instead.")]]
logging_resource_adaptor<Upstream> make_logging_adaptor(
Upstream* upstream,
std::string const& filename = logging_resource_adaptor<Upstream>::get_default_filename(),
Expand All @@ -327,6 +333,9 @@ logging_resource_adaptor<Upstream> make_logging_adaptor(
* @return The new logging resource adaptor
*/
template <typename Upstream>
[[deprecated(
"make_logging_adaptor is deprecated in RMM 24.10. Use the logging_resource_adaptor constructor "
"instead.")]]
logging_resource_adaptor<Upstream> make_logging_adaptor(Upstream* upstream,
std::ostream& stream,
bool auto_flush = false)
Expand Down
6 changes: 5 additions & 1 deletion include/rmm/mr/device/polymorphic_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool operator!=(polymorphic_allocator<T> const& lhs, polymorphic_allocator<U> co
* my_stream_ordered_allocator<int> 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<decltype(adapted)>::allocate(adapted, n);
Expand Down Expand Up @@ -302,6 +302,10 @@ bool operator!=(stream_allocator_adaptor<A> const& lhs, stream_allocator_adaptor
* @return A `stream_allocator_adaptor` wrapping `allocator` and `s`
*/
template <typename Allocator>
[[deprecated(
"make_stream_allocator_adaptor is deprecated in RMM 24.10. Use the stream_allocator_adaptor "
"constructor "
"instead.")]]
bdice marked this conversation as resolved.
Show resolved Hide resolved
auto make_stream_allocator_adaptor(Allocator const& allocator, cuda_stream_view stream)
{
return stream_allocator_adaptor<Allocator>{allocator, stream};
Expand Down
4 changes: 4 additions & 0 deletions include/rmm/mr/device/statistics_resource_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ class statistics_resource_adaptor final : public device_memory_resource {
* @return The new statistics resource adaptor
*/
template <typename Upstream>
[[deprecated(
"make_statistics_adaptor is deprecated in RMM 24.10. Use the statistics_resource_adaptor "
"constructor "
"instead.")]]
statistics_resource_adaptor<Upstream> make_statistics_adaptor(Upstream* upstream)
{
return statistics_resource_adaptor<Upstream>{upstream};
Expand Down
3 changes: 3 additions & 0 deletions include/rmm/mr/device/tracking_resource_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ class tracking_resource_adaptor final : public device_memory_resource {
* @return The new tracking resource adaptor
*/
template <typename Upstream>
[[deprecated(
"make_tracking_adaptor is deprecated in RMM 24.10. Use the tracking_resource_adaptor constructor "
"instead.")]]
tracking_resource_adaptor<Upstream> make_tracking_adaptor(Upstream* upstream)
{
return tracking_resource_adaptor<Upstream>{upstream};
Expand Down
14 changes: 7 additions & 7 deletions tests/logger_tests.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};

Expand All @@ -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};
Expand Down Expand Up @@ -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};

Expand All @@ -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};

Expand Down
22 changes: 11 additions & 11 deletions tests/mr/device/stream_allocator_adaptor_tests.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -34,26 +34,26 @@ struct allocator_test : public ::testing::Test {
TEST_F(allocator_test, factory)
{
using Adaptor = rmm::mr::stream_allocator_adaptor<decltype(allocator)>;
auto adapted = rmm::mr::make_stream_allocator_adaptor(allocator, stream);
auto adapted = rmm::mr::stream_allocator_adaptor(allocator, stream);
static_assert((std::is_same<decltype(adapted), Adaptor>::value));
EXPECT_EQ(adapted.underlying_allocator(), allocator);
EXPECT_EQ(adapted.stream(), stream);
}

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);
}

TEST_F(allocator_test, equal_allocators)
{
rmm::mr::polymorphic_allocator<int> alloc0;
auto adapted0 = rmm::mr::make_stream_allocator_adaptor(alloc0, stream);
auto adapted0 = rmm::mr::stream_allocator_adaptor(alloc0, stream);

rmm::mr::polymorphic_allocator<int> 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);
Expand All @@ -63,19 +63,19 @@ TEST_F(allocator_test, unequal_resources)
{
rmm::mr::cuda_memory_resource mr0;
rmm::mr::polymorphic_allocator<int> 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<int> 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);
}

TEST_F(allocator_test, copy_ctor_same_type)
{
rmm::mr::polymorphic_allocator<int> 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<decltype(alloc0)>;
Adaptor adapted1{adapted0};
Expand All @@ -86,7 +86,7 @@ TEST_F(allocator_test, copy_ctor_same_type)
TEST_F(allocator_test, copy_ctor_different_type)
{
rmm::mr::polymorphic_allocator<int> 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<rmm::mr::polymorphic_allocator<double>>;
Adaptor adapted1{adapted0};
Expand All @@ -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<decltype(adapted)>::rebind_alloc<double>;
static_assert((std::is_same<std::allocator_traits<Rebound>::value_type, double>::value));
static_assert(
Expand All @@ -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);
Expand Down
Loading