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

Support multiple output sinks in logging_resource_adaptor #791

Merged
merged 1 commit into from
Jun 2, 2021
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
11 changes: 11 additions & 0 deletions include/rmm/mr/device/logging_resource_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#pragma once

#include <spdlog/common.h>
#include <rmm/mr/device/device_memory_resource.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -107,6 +108,16 @@ class logging_resource_adaptor final : public device_memory_resource {
init_logger(auto_flush);
}

logging_resource_adaptor(Upstream* upstream,
spdlog::sinks_init_list sinks,
bool auto_flush = false)
: logger_{std::make_shared<spdlog::logger>("RMM", sinks)}, upstream_{upstream}
{
RMM_EXPECTS(nullptr != upstream, "Unexpected null upstream resource pointer.");

init_logger(auto_flush);
}

logging_resource_adaptor() = delete;
~logging_resource_adaptor() = default;
logging_resource_adaptor(logging_resource_adaptor const&) = delete;
Expand Down
30 changes: 30 additions & 0 deletions tests/logger_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,36 @@ TEST(Adaptor, FilenameConstructor)
expect_log_events(filename, expected_events);
}

TEST(Adaptor, MultiSinkConstructor)
{
std::string filename1{"logs/test_multi_1.txt"};
std::string filename2{"logs/test_multi_2.txt"};
rmm::mr::cuda_memory_resource upstream;

auto file_sink1 = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename1, true);
auto file_sink2 = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename2, true);

rmm::mr::logging_resource_adaptor<rmm::mr::cuda_memory_resource> log_mr{&upstream,
{file_sink1, file_sink2}};

auto p0 = log_mr.allocate(100);
auto p1 = log_mr.allocate(42);
log_mr.deallocate(p0, 100);
log_mr.deallocate(p1, 42);
log_mr.flush();

using rmm::detail::action;
using rmm::detail::event;

std::vector<event> expected_events{{action::ALLOCATE, 100, p0},
{action::ALLOCATE, 42, p1},
{action::FREE, 100, p0},
{action::FREE, 42, p1}};

expect_log_events(filename1, expected_events);
expect_log_events(filename2, expected_events);
}

TEST(Adaptor, Factory)
{
std::string filename{"logs/test2.txt"};
Expand Down