33 #ifndef GKO_CORE_LOGGER_HPP_ 34 #define GKO_CORE_LOGGER_HPP_ 43 #include <ginkgo/core/base/std_extensions.hpp> 44 #include <ginkgo/core/base/types.hpp> 45 #include <ginkgo/core/base/utils.hpp> 52 template <
typename ValueType>
57 class PolymorphicObject;
59 class stopping_status;
103 static constexpr mask_type all_events_mask = ~mask_type{0};
126 #define GKO_LOGGER_REGISTER_EVENT(_id, _event_name, ...) \ 128 virtual void on_##_event_name(__VA_ARGS__) const {} \ 131 template <size_type Event, typename... Params> \ 132 xstd::enable_if_t<Event == _id && (_id < event_count_max)> on( \ 133 Params &&... params) const \ 135 if (enabled_events_ & (mask_type{1} << _id)) { \ 136 this->on_##_event_name(std::forward<Params>(params)...); \ 139 static constexpr size_type _event_name{_id}; \ 140 static constexpr mask_type _event_name##_mask{mask_type{1} << _id}; 148 GKO_LOGGER_REGISTER_EVENT(0, allocation_started,
const Executor *exec,
158 GKO_LOGGER_REGISTER_EVENT(1, allocation_completed,
const Executor *exec,
160 const uintptr &location)
168 GKO_LOGGER_REGISTER_EVENT(2, free_started,
const Executor *exec,
169 const uintptr &location)
177 GKO_LOGGER_REGISTER_EVENT(3, free_completed,
const Executor *exec,
178 const uintptr &location)
189 GKO_LOGGER_REGISTER_EVENT(4, copy_started,
const Executor *exec_from,
190 const Executor *exec_to,
const uintptr &loc_from,
191 const uintptr &loc_to,
const size_type &num_bytes)
202 GKO_LOGGER_REGISTER_EVENT(5, copy_completed,
const Executor *exec_from,
203 const Executor *exec_to,
const uintptr &loc_from,
204 const uintptr &loc_to,
const size_type &num_bytes)
212 GKO_LOGGER_REGISTER_EVENT(6, operation_launched,
const Executor *exec,
226 GKO_LOGGER_REGISTER_EVENT(7, operation_completed,
const Executor *exec,
235 GKO_LOGGER_REGISTER_EVENT(8, polymorphic_object_create_started,
245 GKO_LOGGER_REGISTER_EVENT(9, polymorphic_object_create_completed,
257 GKO_LOGGER_REGISTER_EVENT(10, polymorphic_object_copy_started,
269 GKO_LOGGER_REGISTER_EVENT(11, polymorphic_object_copy_completed,
280 GKO_LOGGER_REGISTER_EVENT(12, polymorphic_object_deleted,
290 GKO_LOGGER_REGISTER_EVENT(13, linop_apply_started,
const LinOp *A,
300 GKO_LOGGER_REGISTER_EVENT(14, linop_apply_completed,
const LinOp *A,
312 GKO_LOGGER_REGISTER_EVENT(15, linop_advanced_apply_started,
const LinOp *A,
325 GKO_LOGGER_REGISTER_EVENT(16, linop_advanced_apply_completed,
336 GKO_LOGGER_REGISTER_EVENT(17, linop_factory_generate_started,
347 GKO_LOGGER_REGISTER_EVENT(18, linop_factory_generate_completed,
362 GKO_LOGGER_REGISTER_EVENT(19, criterion_check_started,
366 const uint8 &stopping_id,
367 const bool &set_finalized)
385 GKO_LOGGER_REGISTER_EVENT(
388 const uint8 &stopping_id,
const bool &set_finalized,
390 const bool &all_converged)
401 GKO_LOGGER_REGISTER_EVENT(21, iteration_complete,
const LinOp *solver,
403 const LinOp *x =
nullptr,
404 const LinOp *tau =
nullptr)
407 #undef GKO_LOGGER_REGISTER_EVENT 412 static constexpr mask_type executor_events_mask =
413 allocation_started_mask | allocation_completed_mask |
414 free_started_mask | free_completed_mask | copy_started_mask |
420 static constexpr mask_type operation_events_mask =
421 operation_launched_mask | operation_completed_mask;
426 static constexpr mask_type polymorphic_object_events_mask =
427 polymorphic_object_create_started_mask |
428 polymorphic_object_create_completed_mask |
429 polymorphic_object_copy_started_mask |
430 polymorphic_object_copy_completed_mask |
431 polymorphic_object_deleted_mask;
436 static constexpr mask_type linop_events_mask =
437 linop_apply_started_mask | linop_apply_completed_mask |
438 linop_advanced_apply_started_mask | linop_advanced_apply_completed_mask;
443 static constexpr mask_type linop_factory_events_mask =
444 linop_factory_generate_started_mask |
445 linop_factory_generate_completed_mask;
450 static constexpr mask_type criterion_events_mask =
451 criterion_check_started_mask | criterion_check_completed_mask;
468 explicit Logger(std::shared_ptr<const gko::Executor> exec,
469 const mask_type &enabled_events = all_events_mask)
470 : exec_{exec}, enabled_events_{enabled_events}
474 std::shared_ptr<const Executor> exec_;
475 mask_type enabled_events_;
493 virtual void add_logger(std::shared_ptr<const Logger> logger) = 0;
504 virtual void remove_logger(
const Logger *logger) = 0;
520 template <
typename ConcreteLoggable,
typename PolymorphicBase = Loggable>
523 void add_logger(std::shared_ptr<const Logger> logger)
override 525 loggers_.push_back(logger);
530 auto idx = find_if(begin(loggers_), end(loggers_),
531 [&logger](std::shared_ptr<const Logger> l) {
532 return lend(l) == logger;
534 if (idx != end(loggers_)) {
543 template <
size_type Event,
typename... Params>
544 void log(Params &&... params)
const 546 for (
auto &logger : loggers_) {
547 logger->template on<Event>(std::forward<Params>(params)...);
551 std::vector<std::shared_ptr<const Logger>> loggers_;
559 #endif // GKO_CORE_LOGGER_HPP_ Definition: logger.hpp:90
constexpr size_type byte_size
Number of bits in a byte.
Definition: types.hpp:185
void remove_logger(const Logger *logger) override
Removes a logger from the list of subscribed loggers.
Definition: logger.hpp:528
A LinOpFactory represents a higher order mapping which transforms one linear operator into another...
Definition: lin_op.hpp:356
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
std::uint64_t uint64
64-bit unsigned integral type.
Definition: types.hpp:140
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition: polymorphic_object.hpp:67
EnableLogging is a mixin which should be inherited by any class which wants to enable logging...
Definition: logger.hpp:521
void add_logger(std::shared_ptr< const Logger > logger) override
Adds a new logger to the list of subscribed loggers.
Definition: logger.hpp:523
OutOfBoundsError is thrown if a memory access is detected to be out-of-bounds.
Definition: exception.hpp:297
Definition: lin_op.hpp:134
Loggable class is an interface which should be implemented by classes wanting to support logging...
Definition: logger.hpp:484
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:123
Operations can be used to define functionalities whose implementations differ among devices...
Definition: executor.hpp:173
An Array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the Arr...
Definition: array.hpp:63
std::enable_if< detail::have_ownership< Pointer >), detail::pointee< Pointer > * >::type lend(const Pointer &p)
Returns a non-owning (plain) pointer to the object pointed to by p.
Definition: utils.hpp:249
The Criterion class is a base class for all stopping criteria.
Definition: criterion.hpp:63
The first step in using the Ginkgo library consists of creating an executor.
Definition: executor.hpp:410