Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
performance_hint.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_LOG_PERFORMANCE_HINT_HPP_
34#define GKO_PUBLIC_CORE_LOG_PERFORMANCE_HINT_HPP_
35
36
37#include <fstream>
38#include <iostream>
39#include <unordered_map>
40
41
42#include <ginkgo/core/log/logger.hpp>
43
44
45namespace gko {
46namespace log {
47
48
58class PerformanceHint : public Logger {
59public:
61 const size_type& num_bytes,
62 const uintptr& location) const override;
63
64 void on_free_completed(const Executor* exec,
65 const uintptr& location) const override;
66
69 const uintptr& location_to,
70 const size_type& num_bytes) const override;
71
76 void print_status() const;
77
90 static std::unique_ptr<PerformanceHint> create(
91 std::ostream& os = std::cerr, size_type allocation_size_limit = 16,
93 {
94 return std::unique_ptr<PerformanceHint>(new PerformanceHint(
96 }
97
98protected:
99 explicit PerformanceHint(std::ostream& os, size_type allocation_size_limit,
102 : Logger(mask_),
103 os_(&os),
104 allocation_size_limit_{allocation_size_limit},
105 copy_size_limit_{copy_size_limit},
106 histogram_max_size_{histogram_max_size}
107 {}
108
109private:
110 // set a breakpoint here if you want to see where the output comes from!
111 std::ostream& log() const;
112
113 std::ostream* os_;
114 mutable std::unordered_map<uintptr_t, size_type> allocation_sizes_;
115 mutable std::unordered_map<size_type, int> allocation_histogram_;
116 mutable std::unordered_map<uintptr_t, int> copy_src_histogram_;
117 mutable std::unordered_map<uintptr_t, int> copy_dst_histogram_;
118 size_type allocation_size_limit_;
119 size_type copy_size_limit_;
120 size_type histogram_max_size_;
121 static constexpr Logger::mask_type mask_ =
122 Logger::allocation_completed_mask | Logger::free_completed_mask |
123 Logger::copy_completed_mask;
124 static constexpr const char* prefix_ = "[PERFORMANCE] >>> ";
125};
126
127
128} // namespace log
129} // namespace gko
130
131
132#endif // GKO_PUBLIC_CORE_LOG_PERFORMANCE_HINT_HPP_
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:644
Definition logger.hpp:104
PerformanceHint is a Logger which analyzes the performance of the application and outputs hints for u...
Definition performance_hint.hpp:58
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:90
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 Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:172
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120