ryujin 2.1.1 revision ee5cbcbf2346c1299c942d0e1f13b46449973c18
Loading...
Searching...
No Matches
computing_timer.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2026 by the ryujin authors
4//
5
6#pragma once
7
8#include <compile_time_options.h>
10#include <simd.h>
11
12#include <deal.II/base/timer.h>
13
14#include <map>
15#include <string>
16
17#ifdef DEBUG_OUTPUT
18#include <iostream>
19#endif
20
21namespace ryujin
22{
32 {
33 public:
47 class Scope
48 {
49 public:
53 Scope(const std::string &section)
54 : section_(section)
55 {
56 timers_[section_].start();
57#ifdef DEBUG_OUTPUT
58 std::cout << "{scoped timer} \"" << section_ << "\" started"
59 << std::endl;
60#endif
61 }
62
67 {
68#ifdef DEBUG_OUTPUT
69 std::cout << "{scoped timer} \"" << section_ << "\" stopped"
70 << std::endl;
71#endif
72 timers_[section_].stop();
73 }
74
75 private:
76 const std::string section_;
77 };
78
83 static dealii::Timer &timer(const std::string &section)
84 {
85 return timers_[section];
86 }
87
91 static const std::map<std::string, dealii::Timer> &timers()
92 {
93 return timers_;
94 }
95
99 static void reinit()
100 {
101 timers_.clear();
102 }
103
104 private:
105 static inline std::map<std::string, dealii::Timer> timers_;
106 };
107
108
109 /*
110 * An accumulator for the wall time spent executing compute kernels on the
111 * device.
112 *
113 * All device compute loops (defined in loop.h) launch a kernel and then
114 * fence the execution space, see gpu_loop(). The wall time spent in the
115 * launch and in the subsequent fence is thus a good proxy for the time
116 * the device is actually busy. (Some quick comparison with a profiler
117 * suggest a discrepancy of less than 5%.)
118 *
119 * @note We only measure compute loops with this class. Kokkos-internal
120 * operations, such as the deep copies, as well as the exchange buffer
121 * kernel of the SparseMatrix class, do not enter this calcuation.
122 * (Together they contribute about another 4% of device runtime.)
123 *
124 * @note This class is a singleton and not thread safe.
125 *
126 * @ingroup Miscellaneous
127 */
129 {
130 public:
135 class Scope
136 {
137 public:
139 {
140 timer_.start();
141 }
142
144 {
145 timer_.stop();
146 n_kernels_ += 1;
147 }
148 };
149
154 static double seconds()
155 {
156 return timer_.wall_time();
157 }
158
162 static std::uint64_t n_kernels()
163 {
164 return n_kernels_;
165 }
166
170 static void reinit()
171 {
172 timer_.reset();
173 n_kernels_ = 0;
174 }
175
176 private:
177 static inline dealii::Timer timer_;
178 static inline std::uint64_t n_kernels_ = 0;
179 };
180} // namespace ryujin
Scope(const std::string &section)
static dealii::Timer & timer(const std::string &section)
static const std::map< std::string, dealii::Timer > & timers()
static std::uint64_t n_kernels()
static double seconds()