timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
fwd.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25#pragma once
26
30
31#include <cassert>
32#include <cmath>
33#include <limits>
34#include <utility>
35
36namespace tim
37{
38namespace math
39{
40template <typename Tp>
41bool
42is_finite(const Tp& val)
43{
44#if defined(TIMEMORY_WINDOWS)
45 const Tp _infv = std::numeric_limits<Tp>::infinity();
46 const Tp _inf = (val < 0.0) ? -_infv : _infv;
47 return (val == val && val != _inf);
48#else
49 return std::isfinite(val);
50#endif
51}
52
53template <typename Tp>
54TIMEMORY_INLINE Tp abs(Tp);
55
56template <typename Tp>
57TIMEMORY_INLINE Tp sqrt(Tp);
58
59template <typename Tp>
60TIMEMORY_INLINE Tp
61pow(Tp, double);
62
63template <typename Tp>
64TIMEMORY_INLINE Tp sqr(Tp);
65
66template <typename Tp>
67TIMEMORY_INLINE Tp
68min(const Tp&, const Tp&);
69
70template <typename Tp>
71TIMEMORY_INLINE Tp
72max(const Tp&, const Tp&);
73
74template <typename Tp, typename Up = Tp>
75TIMEMORY_INLINE void
76assign(Tp&, Up&&);
77
78template <typename Tp, typename Up = Tp,
80TIMEMORY_INLINE Tp&
81 plus(Tp&, const Up&);
82
83template <typename Tp, typename Up = Tp,
85TIMEMORY_INLINE Tp&
86 minus(Tp&, const Up&);
87
88template <typename Tp, typename Up = Tp,
90TIMEMORY_INLINE Tp&
91 multiply(Tp&, const Up&);
92
93template <typename Tp, typename Up = Tp,
95TIMEMORY_INLINE Tp&
96 divide(Tp&, const Up&);
97
98template <typename Tp>
99TIMEMORY_INLINE Tp
100percent_diff(const Tp&, const Tp&);
101
102} // namespace math
103
104inline namespace stl
105{
106//--------------------------------------------------------------------------------------//
107//
108// operator +=
109//
110//--------------------------------------------------------------------------------------//
111
112template <typename Tp, size_t N, typename Other>
113std::array<Tp, N>&
114operator+=(std::array<Tp, N>&, Other&&);
115
116template <typename Lhs, typename Rhs, typename Other>
117std::pair<Lhs, Rhs>&
118operator+=(std::pair<Lhs, Rhs>&, Other&&);
119
120template <typename Tp, typename... _Extra, typename Other>
121std::vector<Tp, _Extra...>&
122operator+=(std::vector<Tp, _Extra...>&, Other&&);
123
124template <typename... Types, typename Other>
125std::tuple<Types...>&
126operator+=(std::tuple<Types...>&, Other&&);
127
128//--------------------------------------------------------------------------------------//
129//
130// operator -=
131//
132//--------------------------------------------------------------------------------------//
133
134template <typename Tp, size_t N>
135std::array<Tp, N>&
136operator-=(std::array<Tp, N>&, const std::array<Tp, N>&);
137
138template <typename Lhs, size_t N, typename Rhs,
140std::array<Lhs, N>&
141operator-=(std::array<Lhs, N>&, const Rhs&);
142
143template <typename Lhs, typename Rhs>
144std::pair<Lhs, Rhs>&
145operator-=(std::pair<Lhs, Rhs>&, const std::pair<Lhs, Rhs>&);
146
147template <typename Lhs, typename Rhs, typename ArithT,
149std::pair<Lhs, Rhs>&
150operator-=(std::pair<Lhs, Rhs>&, const ArithT&);
151
152template <typename Tp, typename... _Extra>
153std::vector<Tp, _Extra...>&
154operator-=(std::vector<Tp, _Extra...>&, const std::vector<Tp, _Extra...>&);
155
156template <typename Lhs, typename Rhs, typename... _Extra,
158std::vector<Lhs, _Extra...>&
159operator-=(std::vector<Lhs, _Extra...>&, const Rhs&);
160
161template <typename... Types>
162std::tuple<Types...>&
163operator-=(std::tuple<Types...>&, const std::tuple<Types...>&);
164
165template <typename... Lhs, typename Rhs,
167std::tuple<Lhs...>&
168operator-=(std::tuple<Lhs...>&, const Rhs&);
169
170//--------------------------------------------------------------------------------------//
171//
172// operator *=
173//
174//--------------------------------------------------------------------------------------//
175
176template <typename Tp, size_t N>
177std::array<Tp, N>&
178operator*=(std::array<Tp, N>&, const std::array<Tp, N>&);
179
180template <typename Lhs, size_t N, typename Rhs,
182std::array<Lhs, N>&
183operator*=(std::array<Lhs, N>&, const Rhs&);
184
185template <typename Lhs, typename Rhs>
186std::pair<Lhs, Rhs>&
187operator*=(std::pair<Lhs, Rhs>&, const std::pair<Lhs, Rhs>&);
188
189template <typename Lhs, typename Rhs, typename ArithT,
191std::pair<Lhs, Rhs>&
192operator*=(std::pair<Lhs, Rhs>&, const ArithT&);
193
194template <typename Tp, typename... _Extra>
195std::vector<Tp, _Extra...>&
196operator*=(std::vector<Tp, _Extra...>&, const std::vector<Tp, _Extra...>&);
197
198template <typename Lhs, typename Rhs, typename... _Extra,
200std::vector<Lhs, _Extra...>&
201operator*=(std::vector<Lhs, _Extra...>&, const Rhs&);
202
203template <typename... Types>
204std::tuple<Types...>&
205operator*=(std::tuple<Types...>&, const std::tuple<Types...>&);
206
207template <typename... Lhs, typename Rhs,
209std::tuple<Lhs...>&
210operator*=(std::tuple<Lhs...>&, const Rhs&);
211
212//--------------------------------------------------------------------------------------//
213//
214// operator /=
215//
216//--------------------------------------------------------------------------------------//
217
218template <typename Tp, size_t N>
219std::array<Tp, N>&
220operator/=(std::array<Tp, N>&, const std::array<Tp, N>&);
221
222template <typename Lhs, size_t N, typename Rhs,
224std::array<Lhs, N>&
225operator/=(std::array<Lhs, N>&, const Rhs&);
226
227template <typename Lhs, typename Rhs>
228std::pair<Lhs, Rhs>&
229operator/=(std::pair<Lhs, Rhs>&, const std::pair<Lhs, Rhs>&);
230
231template <typename Lhs, typename Rhs, typename ArithT,
233std::pair<Lhs, Rhs>&
234operator/=(std::pair<Lhs, Rhs>&, const ArithT&);
235
236template <typename Tp, typename... _Extra>
237std::vector<Tp, _Extra...>&
238operator/=(std::vector<Tp, _Extra...>&, const std::vector<Tp, _Extra...>&);
239
240template <typename Lhs, typename Rhs, typename... _Extra,
242std::vector<Lhs, _Extra...>&
243operator/=(std::vector<Lhs, _Extra...>&, const Rhs&);
244
245template <typename... Types>
246std::tuple<Types...>&
247operator/=(std::tuple<Types...>&, const std::tuple<Types...>&);
248
249template <typename... Lhs, typename Rhs,
251std::tuple<Lhs...>&
252operator/=(std::tuple<Lhs...>&, const Rhs&);
253
254//--------------------------------------------------------------------------------------//
255//
256// operator * (fundamental)
257// operator / (fundamental)
258//
259//--------------------------------------------------------------------------------------//
260
261template <typename Lhs, typename Rhs,
263Lhs operator*(Lhs, const Rhs&);
264
265template <typename Lhs, typename Rhs,
267Lhs
268operator/(Lhs, const Rhs&);
269
270//--------------------------------------------------------------------------------------//
271//
272// operator +
273//
274//--------------------------------------------------------------------------------------//
275
276template <typename Tp, size_t N>
277std::array<Tp, N>
278operator+(std::array<Tp, N> lhs, const std::array<Tp, N>& rhs);
279
280template <typename... Types>
281std::tuple<Types...>
282operator+(std::tuple<Types...> lhs, const std::tuple<Types...>& rhs);
283
284template <typename Lhs, typename Rhs>
285std::pair<Lhs, Rhs>
286operator+(std::pair<Lhs, Rhs> lhs, const std::pair<Lhs, Rhs>& rhs);
287
288template <typename Tp, typename... Extra>
289std::vector<Tp, Extra...>
290operator+(std::vector<Tp, Extra...> lhs, const std::vector<Tp, Extra...>& rhs);
291
292//--------------------------------------------------------------------------------------//
293//
294// operator -
295//
296//--------------------------------------------------------------------------------------//
297
298template <typename Tp, size_t N>
299std::array<Tp, N>
300operator-(std::array<Tp, N> lhs, const std::array<Tp, N>& rhs);
301
302template <typename... Types>
303std::tuple<Types...>
304operator-(std::tuple<Types...> lhs, const std::tuple<Types...>& rhs);
305
306template <typename Lhs, typename Rhs>
307std::pair<Lhs, Rhs>
308operator-(std::pair<Lhs, Rhs> lhs, const std::pair<Lhs, Rhs>& rhs);
309
310template <typename Tp, typename... Extra>
311std::vector<Tp, Extra...>
312operator-(std::vector<Tp, Extra...> lhs, const std::vector<Tp, Extra...>& rhs);
313
314//--------------------------------------------------------------------------------------//
315//
316// operator *
317//
318//--------------------------------------------------------------------------------------//
319
320template <typename Tp, size_t N>
321std::array<Tp, N> operator*(std::array<Tp, N> lhs, const std::array<Tp, N>& rhs);
322
323template <typename... Types>
324std::tuple<Types...> operator*(std::tuple<Types...> lhs, const std::tuple<Types...>& rhs);
325
326template <typename Lhs, typename Rhs>
327std::pair<Lhs, Rhs> operator*(std::pair<Lhs, Rhs> lhs, const std::pair<Lhs, Rhs>& rhs);
328
329template <typename Tp, typename... Extra>
330std::vector<Tp, Extra...> operator*(std::vector<Tp, Extra...> lhs,
331 const std::vector<Tp, Extra...>& rhs);
332
333//--------------------------------------------------------------------------------------//
334//
335// operator /
336//
337//--------------------------------------------------------------------------------------//
338
339template <typename Tp, size_t N>
340std::array<Tp, N>
341operator/(std::array<Tp, N> lhs, const std::array<Tp, N>& rhs);
342
343template <typename... Types>
344std::tuple<Types...>
345operator/(std::tuple<Types...> lhs, const std::tuple<Types...>& rhs);
346
347template <typename Lhs, typename Rhs>
348std::pair<Lhs, Rhs>
349operator/(std::pair<Lhs, Rhs> lhs, const std::pair<Lhs, Rhs>& rhs);
350
351template <typename Tp, typename... Extra>
352std::vector<Tp, Extra...>
353operator/(std::vector<Tp, Extra...> lhs, const std::vector<Tp, Extra...>& rhs);
354
355} // namespace stl
356} // namespace tim
357
358//--------------------------------------------------------------------------------------//
359// dummy overloads for std::tuple<>, type_list<>, null_type
360//
361#define TIMEMORY_MATH_NULL_TYPE_OVERLOAD(TYPE) \
362 namespace tim \
363 { \
364 namespace math \
365 { \
366 TIMEMORY_INLINE TYPE abs(TYPE) { return TYPE{}; } \
367 TIMEMORY_INLINE TYPE sqrt(TYPE) { return TYPE{}; } \
368 TIMEMORY_INLINE TYPE pow(TYPE, double) { return TYPE{}; } \
369 TIMEMORY_INLINE TYPE sqr(TYPE) { return TYPE{}; } \
370 TIMEMORY_INLINE TYPE min(const TYPE&, const TYPE&) { return TYPE{}; } \
371 TIMEMORY_INLINE TYPE max(const TYPE&, const TYPE&) { return TYPE{}; } \
372 TIMEMORY_INLINE void assign(TYPE&, TYPE&&) {} \
373 TIMEMORY_INLINE TYPE& plus(TYPE& lhs, const TYPE&) { return lhs; } \
374 TIMEMORY_INLINE TYPE& minus(TYPE& lhs, const TYPE&) { return lhs; } \
375 TIMEMORY_INLINE TYPE& multiply(TYPE& lhs, const TYPE&) { return lhs; } \
376 TIMEMORY_INLINE TYPE& divide(TYPE& lhs, const TYPE&) { return lhs; } \
377 TIMEMORY_INLINE TYPE percent_diff(const TYPE&, const TYPE&) { return TYPE{}; } \
378 template <typename Up> \
379 TIMEMORY_INLINE TYPE& plus(TYPE& lhs, Up&&) \
380 { \
381 return lhs; \
382 } \
383 template <typename Up> \
384 TIMEMORY_INLINE TYPE& minus(TYPE& lhs, Up&&) \
385 { \
386 return lhs; \
387 } \
388 template <typename Up> \
389 TIMEMORY_INLINE TYPE& multiply(TYPE& lhs, Up&&) \
390 { \
391 return lhs; \
392 } \
393 template <typename Up> \
394 TIMEMORY_INLINE TYPE& divide(TYPE& lhs, Up&&) \
395 { \
396 return lhs; \
397 } \
398 TIMEMORY_INLINE TYPE& divide(TYPE& lhs, uint64_t) { return lhs; } \
399 TIMEMORY_INLINE TYPE& divide(TYPE& lhs, int64_t) { return lhs; } \
400 } \
401 }
402
406
407#if defined(TIMEMORY_WINDOWS)
408namespace std
409{
410template <typename Lhs, typename Rhs>
411const pair<Lhs, Rhs>
412operator-(pair<Lhs, Rhs>, const pair<Lhs, Rhs>&);
413
414template <typename... Types>
415const tuple<Types...>
416operator-(tuple<Types...>, const tuple<Types...>&);
417
418} // namespace std
419#endif
#define TIMEMORY_MATH_NULL_TYPE_OVERLOAD(TYPE)
Definition: fwd.hpp:361
STL namespace.
Tp max(const Tp &, const Tp &)
Definition: max.hpp:112
Tp min(const Tp &, const Tp &)
Definition: min.hpp:112
type_list abs(type_list<>)
Definition: fwd.hpp:405
Tp & plus(Tp &, const Up &)
Definition: plus.hpp:106
Tp pow(Tp, double)
Definition: pow.hpp:83
type_list sqr(type_list<>)
Definition: fwd.hpp:405
auto divide(Tp &_lhs, Up _rhs, type_list<>,...) -> decltype(_lhs/=_rhs, void())
Definition: divide.hpp:43
void assign(Tp &_lhs, Up &&_rhs)
Definition: assign.hpp:43
Tp & minus(Tp &, const Up &)
Definition: minus.hpp:98
Tp & multiply(Tp &, const Up &)
Definition: multiply.hpp:140
Tp percent_diff(const Tp &, const Tp &)
bool is_finite(const Tp &val)
Definition: fwd.hpp:42
type_list sqrt(type_list<>)
Definition: fwd.hpp:405
std::vector< Tp, Extra... > operator-(std::vector< Tp, Extra... > lhs, const std::vector< Tp, Extra... > &rhs)
Definition: stl.hpp:397
std::array< Tp, N > & operator+=(std::array< Tp, N > &, Other &&)
std::array< Tp, N > & operator/=(std::array< Tp, N > &, const std::array< Tp, N > &)
Definition: stl.hpp:172
std::array< Tp, N > operator-(std::array< Tp, N > lhs, const std::array< Tp, N > &rhs)
Definition: stl.hpp:367
Lhs operator/(Lhs, const Rhs &)
Definition: stl.hpp:310
Lhs operator*(Lhs, const Rhs &)
Definition: stl.hpp:295
std::array< Tp, N > & operator*=(std::array< Tp, N > &, const std::array< Tp, N > &)
Definition: stl.hpp:134
std::array< Tp, N > & operator-=(std::array< Tp, N > &, const std::array< Tp, N > &)
Definition: stl.hpp:96
std::array< Tp, N > operator+(std::array< Tp, N > lhs, const std::array< Tp, N > &rhs)
Definition: stl.hpp:323
Definition: kokkosp.cpp:39
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
Definition: types.hpp:190
bool isfinite(const Tp &arg)
Definition: utility.hpp:104
lightweight tuple-alternative for meta-programming logic
Definition: types.hpp:233
this is a placeholder type for optional type-traits. It is used as the default type for the type-trai...
Definition: types.hpp:225