19 #include <rmm/detail/error.hpp>
20 #include <rmm/detail/export.hpp>
21 #include <rmm/detail/format.hpp>
22 #include <rmm/logger.hpp>
30 #include <string_view>
32 namespace RMM_NAMESPACE {
51 template <
typename Upstream>
76 std::string
const& filename = get_default_filename(),
77 bool auto_flush =
false)
116 std::initializer_list<sink_ptr> sinks,
117 bool auto_flush =
false)
143 std::string
const& filename = get_default_filename(),
144 bool auto_flush =
false)
162 std::ostream& stream,
163 bool auto_flush =
false)
181 std::initializer_list<sink_ptr> sinks,
182 bool auto_flush =
false)
216 return std::string{
"Thread,Time,Action,Pointer,Size,Stream"};
228 auto* filename = std::getenv(
"RMM_LOG_FILE");
229 RMM_EXPECTS(filename !=
nullptr,
230 "RMM logging requested without an explicit file name, but RMM_LOG_FILE is unset");
231 return std::string{filename};
235 static auto make_logger(std::ostream& stream) {
return std::make_shared<logger>(
"RMM", stream); }
237 static auto make_logger(std::string
const& filename)
239 return std::make_shared<logger>(
"RMM", filename);
242 static auto make_logger(std::initializer_list<sink_ptr> sinks)
244 return std::make_shared<logger>(
"RMM", sinks);
247 logging_resource_adaptor(std::shared_ptr<logger> logger,
250 : logger_{logger}, upstream_{upstream}
252 if (auto_flush) { logger_->flush_on(level_enum::info); }
253 logger_->set_pattern(
"%v");
254 logger_->info(header());
255 logger_->set_pattern(
"%t,%H:%M:%S.%f,%v");
283 void* do_allocate(std::size_t bytes, cuda_stream_view stream)
override
286 auto const ptr = get_upstream_resource().allocate_async(bytes, stream);
287 logger_->info(
"allocate,%p,%zu,%s", ptr, bytes, rmm::detail::format_stream(stream));
291 "allocate failure,%p,%zu,%s",
nullptr, bytes, rmm::detail::format_stream(stream));
310 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream)
override
312 logger_->info(
"free,%p,%zu,%s", ptr, bytes, rmm::detail::format_stream(stream));
313 get_upstream_resource().deallocate_async(ptr, bytes, stream);
323 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
325 if (
this == &other) {
return true; }
326 auto const* cast =
dynamic_cast<logging_resource_adaptor<Upstream> const*
>(&other);
327 if (cast ==
nullptr) {
return false; }
328 return get_upstream_resource() == cast->get_upstream_resource();
331 std::shared_ptr<logger> logger_{};
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:94
Resource that uses Upstream to allocate memory and logs information about the requested allocation/de...
Definition: logging_resource_adaptor.hpp:52
logging_resource_adaptor(Upstream *upstream, std::initializer_list< 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:115
std::string header() const
Return the CSV header string.
Definition: logging_resource_adaptor.hpp:214
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:142
void flush()
Flush logger contents.
Definition: logging_resource_adaptor.hpp:207
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:75
static std::string get_default_filename()
Return the value of the environment variable RMM_LOG_FILE.
Definition: logging_resource_adaptor.hpp:226
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:96
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:161
logging_resource_adaptor(device_async_resource_ref upstream, std::initializer_list< 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:180
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