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.
types.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/** \file runtime/types.hpp
26 * \headerfile runtime/types.hpp "timemory/runtime/types.hpp"
27 * Declarations
28 *
29 */
30
31#pragma once
32
34#include "timemory/enum.h"
37
38#include <initializer_list>
39#include <string>
40
41namespace tim
42{
43//--------------------------------------------------------------------------------------//
44//
45/// description:
46/// use this function to generate an array of enumerations from a list of string
47/// that can be subsequently used to initialize an auto_list or a component_list
48///
49/// usage:
50/// using namespace tim::component;
51/// using optional_t = tim::auto_list<wall_clock, cpu_clock, cpu_util, cuda_event>;
52///
53/// auto obj = new optional_t(__FUNCTION__, __LINE__);
54/// tim::initialize(*obj, tim::enumerate_components({ "cpu_clock", "cpu_util"}));
55///
56template <typename StringT, typename... ExtraArgs,
57 template <typename, typename...> class Container>
58std::vector<TIMEMORY_COMPONENT>
59enumerate_components(const Container<StringT, ExtraArgs...>& component_names);
60
61template <typename... ExtraArgs>
62std::set<TIMEMORY_COMPONENT>
63enumerate_components(const std::set<std::string, ExtraArgs...>& component_names);
64
65std::set<TIMEMORY_COMPONENT>
66enumerate_components(const std::initializer_list<std::string>& component_names);
67
68//--------------------------------------------------------------------------------------//
69//
70/// description:
71/// use this function to initialize a auto_list or component_list from a list
72/// of enumerations
73//
74/// usage:
75/// using namespace tim::component;
76/// using optional_t = tim::auto_list<wall_clock, cpu_clock, cpu_util, cuda_event>;
77//
78/// auto obj = new optional_t(__FUNCTION__, __LINE__);
79/// tim::initialize(*obj, { CPU_CLOCK, CPU_UTIL });
80//
81/// typename... ExtraArgs
82/// required because of extra "hidden" template parameters in STL containers
83//
84template <
85 template <typename...> class CompList, typename... CompTypes,
86 template <typename, typename...> class Container, typename Intp,
87 typename... ExtraArgs,
88 typename std::enable_if<std::is_integral<Intp>::value ||
89 std::is_same<Intp, TIMEMORY_NATIVE_COMPONENT>::value,
90 int>::type = 0>
91void
92initialize(CompList<CompTypes...>& obj, const Container<Intp, ExtraArgs...>& components);
93
94template <typename T, typename... Args>
95void
96initialize(T* obj, Args&&... args)
97{
98 if(obj)
99 initialize(*obj, std::forward<Args>(args)...);
100}
101
102//--------------------------------------------------------------------------------------//
103//
104/// description:
105/// use this function to insert tools into a bundle
106//
107/// usage:
108/// using namespace tim::component;
109/// using optional_t = tim::auto_tuple<user_global_bundle>;
110//
111/// auto obj = new optional_t(__FUNCTION__, __LINE__);
112/// tim::insert(obj.get<user_global_bundle>(), { CPU_CLOCK, CPU_UTIL });
113//
114/// typename... ExtraArgs
115/// required because of extra "hidden" template parameters in STL containers
116//
117template <
118 size_t Idx, typename Type, template <size_t, typename> class Bundle,
119 template <typename, typename...> class Container, typename Intp,
120 typename... ExtraArgs,
121 typename std::enable_if<std::is_integral<Intp>::value ||
122 std::is_same<Intp, TIMEMORY_NATIVE_COMPONENT>::value,
123 int>::type = 0>
124void
125insert(Bundle<Idx, Type>& obj, const Container<Intp, ExtraArgs...>& components);
126
127template <typename T, typename... Args>
128void
129insert(T* obj, Args&&... args)
130{
131 if(obj)
132 insert(*obj, std::forward<Args>(args)...);
133}
134
135//--------------------------------------------------------------------------------------//
136//
137/// description:
138/// use this function to insert tools into a bundle
139//
140/// usage:
141/// using namespace tim::component;
142/// using optional_t = tim::auto_tuple<user_global_bundle>;
143///
144/// tim::configure<user_global_bundle>({ CPU_CLOCK, CPU_UTIL });
145///
146/// auto obj = new optional_t(__FUNCTION__, __LINE__);
147//
148/// typename... ExtraArgs
149/// required because of extra "hidden" template parameters in STL containers
150//
151template <
152 typename Bundle_t, template <typename, typename...> class Container, typename Intp,
153 typename... ExtraArgs, typename... Args,
154 typename std::enable_if<std::is_integral<Intp>::value ||
155 std::is_same<Intp, TIMEMORY_NATIVE_COMPONENT>::value,
156 int>::type = 0>
157void
158configure(const Container<Intp, ExtraArgs...>& components, Args&&...);
159
160template <typename Bundle, typename EnumT = int, typename... Args>
161void
162configure(std::initializer_list<EnumT> components, Args&&... args);
163
164template <typename Bundle, typename... Args>
165void
166configure(const std::initializer_list<std::string>& components, Args&&... args);
167
168template <typename Bundle, typename... ExtraArgs,
169 template <typename, typename...> class Container, typename... Args>
170void
171configure(const Container<std::string, ExtraArgs...>& components, Args&&... args);
172
173template <typename Bundle, typename... Args>
174void
175configure(const std::string& components, Args&&... args);
176
177template <typename Bundle, template <typename, typename...> class Container,
178 typename... ExtraArgs, typename... Args>
179void
180configure(const Container<const char*, ExtraArgs...>& components, Args&&... args);
181
182template <typename Bundle, typename... Args>
183void
184configure(int ncomponents, const int* components, Args&&... args);
185
186//======================================================================================//
187
188namespace runtime
189{
190//
191template <typename Tp, typename Arg, typename... Args>
192void
193initialize(Tp& obj, int idx, Arg&&, Args&&...);
194//
195template <typename Tp, typename Arg, typename... Args>
196void
197insert(Tp& obj, int idx, Arg&&, Args&&...);
198//
199template <typename Tp, typename Arg, typename... Args>
200void
201configure(int idx, Arg&&, Args&&... args);
202//
203template <typename Tp, typename Arg, typename... Args>
204void
205configure(Tp& obj, int idx, Arg&&, Args&&... args);
206//
207int
208enumerate(const std::string& key);
209//
210int
211enumerate(const char* key);
212//
213template <typename Tp>
214void
215initialize(Tp& obj, int idx);
216//
217template <typename Tp>
218void
219insert(Tp& obj, int idx);
220//
221template <typename Tp>
222void
223configure(int idx);
224//
225template <typename Tp>
226void
227configure(Tp& obj, int idx);
228//
229template <typename Tp>
230void
231insert(Tp& obj, int idx, scope::config _scope);
232//
233template <typename Tp>
234void
235configure(int idx, scope::config _scope);
236//
237template <typename Tp>
238void
239configure(Tp& obj, int idx, scope::config _scope);
240//
241} // namespace runtime
242
243//======================================================================================//
244
245namespace env
246{
247//--------------------------------------------------------------------------------------//
248
249template <template <typename...> class CompList, typename... CompTypes,
250 typename std::enable_if<sizeof...(CompTypes) != 0, int>::type = 0>
251void
252initialize(CompList<CompTypes...>& obj, const std::string& env_var,
253 const std::string& default_env)
254{
255 auto env_result = tim::get_env(env_var, default_env);
257}
258
259//--------------------------------------------------------------------------------------//
260
261template <template <typename...> class CompList, typename... CompTypes,
262 typename std::enable_if<sizeof...(CompTypes) == 0, int>::type = 0>
263void
264initialize(CompList<CompTypes...>&, const std::string&, const std::string&)
265{}
266
267//--------------------------------------------------------------------------------------//
268
269template <typename T, typename... Args>
270void
271initialize(T* obj, Args&&... args)
272{
273 if(obj)
274 initialize(*obj, std::forward<Args>(args)...);
275}
276
277//--------------------------------------------------------------------------------------//
278
279template <size_t Idx, typename Type, template <size_t, typename> class Bundle>
280void
281insert(Bundle<Idx, Type>& obj, const std::string& env_var, const std::string& default_env)
282{
283 auto env_result = tim::get_env(env_var, default_env);
285}
286
287//--------------------------------------------------------------------------------------//
288
289template <typename T, typename... Args>
290void
291insert(T* obj, Args&&... args)
292{
293 if(obj)
294 insert(*obj, std::forward<Args>(args)...);
295}
296
297//--------------------------------------------------------------------------------------//
298
299template <typename Bundle, typename... Args>
300void
301configure(const std::string& env_var, const std::string& default_env, Args&&... args)
302{
303 auto env_result = tim::get_env(env_var, default_env);
304 tim::configure<Bundle>(enumerate_components(tim::delimit(env_result)),
305 std::forward<Args>(args)...);
306}
307
308//--------------------------------------------------------------------------------------//
309
310} // namespace env
311
312} // namespace tim
void insert(Bundle< Idx, Type > &obj, const std::string &env_var, const std::string &default_env)
Definition: types.hpp:281
void initialize(CompList< CompTypes... > &obj, const std::string &env_var, const std::string &default_env)
Definition: types.hpp:252
void configure(const std::string &env_var, const std::string &default_env, Args &&... args)
Definition: types.hpp:301
_reported insert(_hash_id)
int enumerate(const std::string &key)
Definition: properties.hpp:258
void insert(Tp &obj, int idx, Arg &&arg, Args &&... args)
Definition: properties.hpp:229
void initialize(Tp &obj, int idx, Arg &&arg, Args &&... args)
Definition: properties.hpp:219
void configure(int idx, Arg &&arg, Args &&... args)
Definition: properties.hpp:239
Definition: kokkosp.cpp:39
void configure(std::initializer_list< EnumT > components, Args &&... args)
Definition: configure.hpp:50
void initialize(CompList< CompTypes... > &obj, std::initializer_list< EnumT > components)
Definition: initialize.hpp:53
std::vector< TIMEMORY_COMPONENT > enumerate_components(const Container< StringT, ExtraArgs... > &component_names)
description: use this function to generate an array of enumerations from a list of string that can be...
Definition: enumerate.hpp:62
Tp get_env(const std::string &env_id, Tp _default, bool _store)
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
components
Definition: settings.cpp:1700
ContainerT delimit(const std::string &line, const std::string &delimiters="\"',;: ", PredicateT &&predicate=[](const std::string &s) -> std::string { return s;})
Definition: delimit.hpp:68
this data type encodes the options of storage scope. The default is hierarchical (tree) scope....
Definition: types.hpp:453