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.
compose.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/**
26 * \file timemory/operations/types/compose.hpp
27 * \brief Definition for various functions for compose in operations
28 */
29
30#pragma once
31
35
36namespace tim
37{
38namespace operation
39{
40//
41//--------------------------------------------------------------------------------------//
42//
43///
44/// \struct tim::operation::compose
45/// \brief The purpose of this operation class is operating on two components to compose
46/// a result, e.g. use system-clock and user-clock to get a cpu-clock
47///
48//
49//--------------------------------------------------------------------------------------//
50//
51template <typename RetType, typename LhsType, typename RhsType>
52struct compose
53{
54 using ret_value_type = typename RetType::value_type;
55 using lhs_value_type = typename LhsType::value_type;
56 using rhs_value_type = typename RhsType::value_type;
57
58 using ret_base_type = typename RetType::base_type;
59 using lhs_base_type = typename LhsType::base_type;
60 using rhs_base_type = typename RhsType::base_type;
61
63
64 static_assert(std::is_same<ret_value_type, lhs_value_type>::value,
65 "Value types of RetType and LhsType are different!");
66
67 static_assert(std::is_same<lhs_value_type, rhs_value_type>::value,
68 "Value types of LhsType and RhsType are different!");
69
70 static RetType generate(const lhs_base_type& lhs, const rhs_base_type& rhs)
71 {
72 RetType ret;
73 ret.set_is_running(false);
74 ret.set_is_on_stack(false);
75 ret.set_is_transient(lhs.get_is_transient() && rhs.get_is_transient());
76 ret.laps = std::min(lhs.laps, rhs.laps);
77 ret.value = (lhs.value + rhs.value);
78 ret.accum = (lhs.accum + rhs.accum);
79 return ret;
80 }
81
82 template <typename Func, typename... Args>
83 static RetType generate(const lhs_base_type& lhs, const rhs_base_type& rhs,
84 const Func& func, Args&&... args)
85 {
86 RetType ret(std::forward<Args>(args)...);
87 ret.set_is_running(false);
88 ret.set_is_on_stack(false);
89 ret.set_is_transient(lhs.get_is_transient() && rhs.get_is_transient());
90 ret.laps = std::min(lhs.laps, rhs.laps);
91 ret.value = func(lhs.value, rhs.value);
92 ret.accum = func(lhs.accum, rhs.accum);
93 return ret;
94 }
95};
96//
97//--------------------------------------------------------------------------------------//
98//
99} // namespace operation
100} // namespace tim
::tim::statistics< Tp > min(::tim::statistics< Tp > lhs, const Tp &rhs)
Definition: statistics.hpp:329
Definition: kokkosp.cpp:39
The declaration for the types for operations without definitions.
Include the macros for operations.
Declare the operations types.
The purpose of this operation class is operating on two components to compose a result,...
Definition: compose.hpp:53
typename RhsType::value_type rhs_value_type
Definition: compose.hpp:56
typename LhsType::value_type lhs_value_type
Definition: compose.hpp:55
typename RetType::base_type ret_base_type
Definition: compose.hpp:58
TIMEMORY_DELETED_OBJECT(compose) static_assert(std
Definition: compose.hpp:62
typename RhsType::base_type rhs_base_type
Definition: compose.hpp:60
static RetType generate(const lhs_base_type &lhs, const rhs_base_type &rhs)
Definition: compose.hpp:70
static RetType generate(const lhs_base_type &lhs, const rhs_base_type &rhs, const Func &func, Args &&... args)
Definition: compose.hpp:83
typename RetType::value_type ret_value_type
Definition: compose.hpp:54
typename LhsType::base_type lhs_base_type
Definition: compose.hpp:59