8 #include <rmm/detail/error.hpp>
9 #include <rmm/detail/export.hpp>
10 #include <rmm/detail/format.hpp>
11 #include <rmm/logger.hpp>
17 #include <initializer_list>
22 namespace RMM_NAMESPACE {
41 template <
typename Upstream>
66 std::string
const& filename = get_default_filename(),
67 bool auto_flush =
false)
106 std::initializer_list<rapids_logger::sink_ptr> sinks,
107 bool auto_flush =
false)
133 std::string
const& filename = get_default_filename(),
134 bool auto_flush =
false)
152 std::ostream& stream,
153 bool auto_flush =
false)
171 std::initializer_list<rapids_logger::sink_ptr> sinks,
172 bool auto_flush =
false)
206 return std::string{
"Thread,Time,Action,Pointer,Size,Stream"};
218 auto* filename = std::getenv(
"RMM_LOG_FILE");
219 RMM_EXPECTS(filename !=
nullptr,
220 "RMM logging requested without an explicit file name, but RMM_LOG_FILE is unset");
221 return std::string{filename};
225 static auto make_logger(std::ostream& stream)
227 return std::make_shared<rapids_logger::logger>(
"RMM", stream);
230 static auto make_logger(std::string
const& filename)
232 return std::make_shared<rapids_logger::logger>(
"RMM", filename);
235 static auto make_logger(std::initializer_list<rapids_logger::sink_ptr> sinks)
237 return std::make_shared<rapids_logger::logger>(
"RMM", sinks);
240 logging_resource_adaptor(std::shared_ptr<rapids_logger::logger> logger,
243 : logger_{logger}, upstream_{upstream}
245 if (auto_flush) { logger_->flush_on(rapids_logger::level_enum::info); }
246 logger_->set_pattern(
"%v");
247 logger_->info(header());
248 logger_->set_pattern(
"%t,%H:%M:%S.%f,%v");
276 void* do_allocate(std::size_t bytes, cuda_stream_view stream)
override
279 auto const ptr = get_upstream_resource().allocate(stream, bytes);
280 logger_->info(
"allocate,%p,%zu,%s", ptr, bytes, rmm::detail::format_stream(stream));
284 "allocate failure,%p,%zu,%s",
nullptr, bytes, rmm::detail::format_stream(stream));
303 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream) noexcept
override
305 logger_->info(
"free,%p,%zu,%s", ptr, bytes, rmm::detail::format_stream(stream));
306 get_upstream_resource().deallocate(stream, ptr, bytes);
316 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
318 if (
this == &other) {
return true; }
319 auto const* cast =
dynamic_cast<logging_resource_adaptor<Upstream> const*
>(&other);
320 if (cast ==
nullptr) {
return false; }
321 return get_upstream_resource() == cast->get_upstream_resource();
324 std::shared_ptr<rapids_logger::logger> logger_{};
Base class for all librmm device memory allocation.
Definition: device_memory_resource.hpp:83
Resource that uses Upstream to allocate memory and logs information about the requested allocation/de...
Definition: logging_resource_adaptor.hpp:42
std::string header() const
Return the CSV header string.
Definition: logging_resource_adaptor.hpp:204
logging_resource_adaptor(device_async_resource_ref upstream, std::string const &filename=get_default_filename(), bool auto_flush=false)
Construct a new logging resource adaptor using upstream to satisfy allocation requests and logging in...
Definition: logging_resource_adaptor.hpp:132
void flush()
Flush logger contents.
Definition: logging_resource_adaptor.hpp:197
logging_resource_adaptor(Upstream *upstream, std::string const &filename=get_default_filename(), bool auto_flush=false)
Construct a new logging resource adaptor using upstream to satisfy allocation requests and logging in...
Definition: logging_resource_adaptor.hpp:65
static std::string get_default_filename()
Return the value of the environment variable RMM_LOG_FILE.
Definition: logging_resource_adaptor.hpp:216
logging_resource_adaptor(logging_resource_adaptor &&) noexcept=default
Default move constructor.
logging_resource_adaptor(Upstream *upstream, std::ostream &stream, bool auto_flush=false)
Construct a new logging resource adaptor using upstream to satisfy allocation requests and logging in...
Definition: logging_resource_adaptor.hpp:86
logging_resource_adaptor(Upstream *upstream, std::initializer_list< rapids_logger::sink_ptr > sinks, bool auto_flush=false)
Construct a new logging resource adaptor using upstream to satisfy allocation requests and logging in...
Definition: logging_resource_adaptor.hpp:105
logging_resource_adaptor(device_async_resource_ref upstream, std::ostream &stream, bool auto_flush=false)
Construct a new logging resource adaptor using upstream to satisfy allocation requests and logging in...
Definition: logging_resource_adaptor.hpp:151
logging_resource_adaptor(device_async_resource_ref upstream, std::initializer_list< rapids_logger::sink_ptr > sinks, bool auto_flush=false)
Construct a new logging resource adaptor using upstream to satisfy allocation requests and logging in...
Definition: logging_resource_adaptor.hpp:170
device_async_resource_ref to_device_async_resource_ref_checked(Resource *res)
Convert pointer to memory resource into device_async_resource_ref, checking for nullptr
Definition: resource_ref.hpp:72
detail::cccl_async_resource_ref< cuda::mr::resource_ref< cuda::mr::device_accessible > > device_async_resource_ref
Alias for a cuda::mr::async_resource_ref with the property cuda::mr::device_accessible.
Definition: resource_ref.hpp:32