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.
configure.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/configure.hpp
26 * \headerfile runtime/configure.hpp "timemory/runtime/configure.hpp"
27 * Provides implementation for initialize, enumerate_components which regularly
28 * change as more features are added
29 *
30 */
31
32#pragma once
33
34#include "timemory/enum.h"
37
38#include <initializer_list>
39#include <string>
40#include <unordered_set>
41#include <utility>
42#include <vector>
43
44namespace tim
45{
46//======================================================================================//
47
48template <typename Bundle, typename EnumT, typename... Args>
49void
50configure(std::initializer_list<EnumT> components, Args&&... args)
51{
52 configure<Bundle>(std::vector<EnumT>(components), std::forward<Args>(args)...);
53}
54
55//--------------------------------------------------------------------------------------//
56
57template <typename Bundle, typename... Args>
58void
59configure(const std::initializer_list<std::string>& components, Args&&... args)
60{
61 configure<Bundle>(enumerate_components(components), std::forward<Args>(args)...);
62}
63
64//--------------------------------------------------------------------------------------//
65//
66/// this is for initializing with a container of string
67//
68template <typename Bundle, typename... ExtraArgs,
69 template <typename, typename...> class Container, typename... Args>
70void
71configure(const Container<std::string, ExtraArgs...>& components, Args&&... args)
72{
73 configure<Bundle>(enumerate_components(components), std::forward<Args>(args)...);
74}
75
76//--------------------------------------------------------------------------------------//
77//
78/// this is for initializing with a string
79//
80template <typename Bundle, typename... Args>
81void
82configure(const std::string& components, Args&&... args)
83{
85 std::forward<Args>(args)...);
86}
87
88//--------------------------------------------------------------------------------------//
89
90template <
91 typename Bundle, template <typename, typename...> class Container, typename Intp,
92 typename... ExtraArgs, typename... Args,
93 typename std::enable_if<std::is_integral<Intp>::value ||
94 std::is_same<Intp, TIMEMORY_NATIVE_COMPONENT>::value,
95 int>::type>
96void
97configure(const Container<Intp, ExtraArgs...>& components, Args&&... args)
98{
99 for(auto itr : components)
100 runtime::configure<Bundle>(itr, std::forward<Args>(args)...);
101}
102
103//--------------------------------------------------------------------------------------//
104
105template <typename Bundle, template <typename, typename...> class Container,
106 typename... ExtraArgs, typename... Args>
107void
108configure(const Container<const char*, ExtraArgs...>& components, Args&&... args)
109{
110 std::unordered_set<std::string> _components;
111 for(auto itr : components)
112 _components.insert(std::string(itr));
113 configure<Bundle>(_components, std::forward<Args>(args)...);
114}
115
116//--------------------------------------------------------------------------------------//
117
118template <typename Bundle, typename... Args>
119void
120configure(const int ncomponents, const int* components, Args&&... args)
121{
122 for(int i = 0; i < ncomponents; ++i)
123 runtime::configure<Bundle>(components[i], std::forward<Args>(args)...);
124}
125
126//======================================================================================//
127
128} // namespace tim
129
130//======================================================================================//
Definition: kokkosp.cpp:39
void configure(std::initializer_list< EnumT > components, Args &&... args)
Definition: configure.hpp:50
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
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