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.
init_storage.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/init_storage.hpp
27 * \brief Definition for various functions for init_storage in operations
28 */
29
30#pragma once
31
36
37namespace tim
38{
39namespace operation
40{
41//
42//--------------------------------------------------------------------------------------//
43//
44template <typename Tp>
45template <typename Up>
47{
48#if defined(TIMEMORY_DISABLE_COMPONENT_STORAGE_INIT)
49#else
50 using value_type = typename type::value_type;
51 base::storage::template base_instance<type, value_type>();
52#endif
53}
54//
55//--------------------------------------------------------------------------------------//
56//
57template <typename Tp>
58template <typename U, typename V>
61{
62#if defined(TIMEMORY_DISABLE_COMPONENT_STORAGE_INIT)
63 return get_type{ nullptr, false, false, false };
64#else
65 static thread_local auto _instance = []() {
67 return get_type{ nullptr, false, false, false };
68
69 using value_type = typename type::value_type;
70 auto this_inst = tim::base::storage::template base_instance<Tp, value_type>();
71 this_inst->initialize();
72 bool this_glob = true;
73 bool this_work = true;
74 bool this_data = this_inst->data_init();
75 return get_type{ this_inst, this_glob, this_work, this_data };
76 }();
77 return _instance;
78#endif
79}
80//
81//--------------------------------------------------------------------------------------//
82//
83template <typename Tp>
84template <typename U, typename V>
88 !std::is_same<typename U::storage_type, component::empty_storage>::value,
89 int>)
90{
91#if defined(TIMEMORY_DISABLE_COMPONENT_STORAGE_INIT)
92 return get_type{ nullptr, false, false, false };
93#else
94 static thread_local auto _instance = []() {
96 return get_type{ nullptr, false, false, false };
97
98 using value_type = typename type::value_type;
99 auto this_inst = tim::base::storage::template base_instance<Tp, value_type>();
100 this_inst->initialize();
101 return get_type{ this_inst, false, false, false };
102 }();
103 return _instance;
104#endif
105}
106//
107//--------------------------------------------------------------------------------------//
108//
109template <typename Tp>
110template <typename U, typename V>
114 std::is_same<typename U::storage_type, component::empty_storage>::value,
115 int>)
116{
117 return get_type{ nullptr, false, false, false };
118}
119//
120//--------------------------------------------------------------------------------------//
121//
122template <typename Tp>
123void
125{
127 return;
128
129#if defined(TIMEMORY_DISABLE_COMPONENT_STORAGE_INIT)
130#else
131 static thread_local auto _init = this_type::get();
132 consume_parameters(_init);
133#endif
134}
135//
136//--------------------------------------------------------------------------------------//
137//
138} // namespace operation
139} // namespace tim
Definition: kokkosp.cpp:39
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
Definition: types.hpp:190
auto get(const auto_bundle< Tag, Types... > &_obj)
void consume_parameters(ArgsT &&...)
Definition: types.hpp:285
The declaration for the types for operations without definitions.
Include the macros for operations.
Declare the operations types.
The declaration for the types for storage without definitions.
static get_type get(enable_if_t< trait::uses_value_storage< U, V >::value, int >=0)
std::tuple< pointer_t, bool, bool, bool > get_type
init_storage(enable_if_t< trait::uses_value_storage< Up >::value, int >=0)
trait that signifies that an implementation is enabled at runtime. The value returned from get() is f...
This trait is used to determine whether the (expensive) instantiation of the storage class happens.