Ginkgo Generated from branch based on main. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
 
Loading...
Searching...
No Matches
performance_hint.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_LOG_PERFORMANCE_HINT_HPP_
6#define GKO_PUBLIC_CORE_LOG_PERFORMANCE_HINT_HPP_
7
8
9#include <fstream>
10#include <iostream>
11#include <unordered_map>
12
13#include <ginkgo/core/log/logger.hpp>
14
15
16namespace gko {
17namespace log {
18
19
29class PerformanceHint : public Logger {
30public:
32 const size_type& num_bytes,
33 const uintptr& location) const override;
34
35 void on_free_completed(const Executor* exec,
36 const uintptr& location) const override;
37
38 void on_copy_completed(const Executor* from, const Executor* to,
39 const uintptr& location_from,
40 const uintptr& location_to,
41 const size_type& num_bytes) const override;
42
47 void print_status() const;
48
61 static std::unique_ptr<PerformanceHint> create(
62 std::ostream& os = std::cerr, size_type allocation_size_limit = 16,
63 size_type copy_size_limit = 16, size_type histogram_max_size = 1024)
64 {
65 return std::unique_ptr<PerformanceHint>(new PerformanceHint(
66 os, allocation_size_limit, copy_size_limit, histogram_max_size));
67 }
68
69protected:
70 explicit PerformanceHint(std::ostream& os, size_type allocation_size_limit,
71 size_type copy_size_limit,
72 size_type histogram_max_size)
73 : Logger(mask_),
74 os_(&os),
75 allocation_size_limit_{allocation_size_limit},
76 copy_size_limit_{copy_size_limit},
77 histogram_max_size_{histogram_max_size}
78 {}
79
80private:
81 // set a breakpoint here if you want to see where the output comes from!
82 std::ostream& log() const;
83
84 std::ostream* os_;
85 mutable std::unordered_map<uintptr_t, size_type> allocation_sizes_;
86 mutable std::unordered_map<size_type, int> allocation_histogram_;
87 mutable std::unordered_map<uintptr_t, int> copy_src_histogram_;
88 mutable std::unordered_map<uintptr_t, int> copy_dst_histogram_;
89 size_type allocation_size_limit_;
90 size_type copy_size_limit_;
91 size_type histogram_max_size_;
92 static constexpr Logger::mask_type mask_ =
93 Logger::allocation_completed_mask | Logger::free_completed_mask |
94 Logger::copy_completed_mask;
95 static constexpr const char* prefix_ = "[PERFORMANCE] >>> ";
96};
97
98
99} // namespace log
100} // namespace gko
101
102
103#endif // GKO_PUBLIC_CORE_LOG_PERFORMANCE_HINT_HPP_
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:615
Definition logger.hpp:76
PerformanceHint is a Logger which analyzes the performance of the application and outputs hints for u...
Definition performance_hint.hpp:29
void print_status() const
Writes out the cross-executor writes and allocations that have been stored so far.
void on_free_completed(const Executor *exec, const uintptr &location) const override
Executor's free completed event.
void on_allocation_completed(const Executor *exec, const size_type &num_bytes, const uintptr &location) const override
Executor's allocation completed event.
static std::unique_ptr< PerformanceHint > create(std::ostream &os=std::cerr, size_type allocation_size_limit=16, size_type copy_size_limit=16, size_type histogram_max_size=1024)
Creates a PerformanceHint logger.
Definition performance_hint.hpp:61
void on_copy_completed(const Executor *from, const Executor *to, const uintptr &location_from, const uintptr &location_to, const size_type &num_bytes) const override
Executor's copy completed event.
The logger namespace .
Definition convergence.hpp:22
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:141
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:89