19 #include <rmm/detail/error.hpp>
20 #include <rmm/detail/export.hpp>
21 #include <rmm/detail/format.hpp>
22 #include <rmm/logger.hpp>
28 #include <initializer_list>
33 namespace RMM_NAMESPACE {
52 template <
typename Upstream>
77 std::string
const& filename = get_default_filename(),
78 bool auto_flush =
false)
117 std::initializer_list<rapids_logger::sink_ptr> sinks,
118 bool auto_flush =
false)
144 std::string
const& filename = get_default_filename(),
145 bool auto_flush =
false)
163 std::ostream& stream,
164 bool auto_flush =
false)
182 std::initializer_list<rapids_logger::sink_ptr> sinks,
183 bool auto_flush =
false)
217 return std::string{
"Thread,Time,Action,Pointer,Size,Stream"};
229 auto* filename = std::getenv(
"RMM_LOG_FILE");
230 RMM_EXPECTS(filename !=
nullptr,
231 "RMM logging requested without an explicit file name, but RMM_LOG_FILE is unset");
232 return std::string{filename};
236 static auto make_logger(std::ostream& stream)
238 return std::make_shared<rapids_logger::logger>(
"RMM", stream);
241 static auto make_logger(std::string
const& filename)
243 return std::make_shared<rapids_logger::logger>(
"RMM", filename);
246 static auto make_logger(std::initializer_list<rapids_logger::sink_ptr> sinks)
248 return std::make_shared<rapids_logger::logger>(
"RMM", sinks);
251 logging_resource_adaptor(std::shared_ptr<rapids_logger::logger> logger,
254 : logger_{logger}, upstream_{upstream}
256 if (auto_flush) { logger_->flush_on(rapids_logger::level_enum::info); }
257 logger_->set_pattern(
"%v");
258 logger_->info(header());
259 logger_->set_pattern(
"%t,%H:%M:%S.%f,%v");
287 void* do_allocate(std::size_t bytes, cuda_stream_view stream)
override
290 auto const ptr = get_upstream_resource().allocate_async(bytes, stream);
291 logger_->info(
"allocate,%p,%zu,%s", ptr, bytes, rmm::detail::format_stream(stream));
295 "allocate failure,%p,%zu,%s",
nullptr, bytes, rmm::detail::format_stream(stream));
314 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream)
override
316 logger_->info(
"free,%p,%zu,%s", ptr, bytes, rmm::detail::format_stream(stream));
317 get_upstream_resource().deallocate_async(ptr, bytes, stream);
327 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
329 if (
this == &other) {
return true; }
330 auto const* cast =
dynamic_cast<logging_resource_adaptor<Upstream> const*
>(&other);
331 if (cast ==
nullptr) {
return false; }
332 return get_upstream_resource() == cast->get_upstream_resource();
335 std::shared_ptr<rapids_logger::logger> logger_{};
Base class for all librmm device memory allocation.
Definition: device_memory_resource.hpp:93
Resource that uses Upstream to allocate memory and logs information about the requested allocation/de...
Definition: logging_resource_adaptor.hpp:53
std::string header() const
Return the CSV header string.
Definition: logging_resource_adaptor.hpp:215
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:143
void flush()
Flush logger contents.
Definition: logging_resource_adaptor.hpp:208
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:76
static std::string get_default_filename()
Return the value of the environment variable RMM_LOG_FILE.
Definition: logging_resource_adaptor.hpp:227
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:97
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:116
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:162
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:181
cuda::mr::async_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:41
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:79