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.
storage_initializer.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/storage_initializer.hpp
27 * \brief Definition for various functions for storage_initializer in operations
28 */
29
30#pragma once
31
36
37namespace tim
38{
39//
40//--------------------------------------------------------------------------------------//
41//
42///
43/// \struct tim::storage_initializer
44/// \brief This operation class is used for generic storage initalization
45///
46//
47//--------------------------------------------------------------------------------------//
48//
49template <typename T>
50auto
51invoke_preinit(int) -> decltype(std::declval<T>().preinit(), void())
52{
53 T::preinit();
54}
55//
56//--------------------------------------------------------------------------------------//
57//
58template <typename T>
59auto
61{}
62//
63//--------------------------------------------------------------------------------------//
64//
65template <typename T>
67 std::true_type)
68{
69 auto library_ctor = tim::get_env<bool>("TIMEMORY_LIBRARY_CTOR", true);
70 if(!library_ctor)
71 return storage_initializer{};
72
74 return storage_initializer{};
75
76 invoke_preinit<T>(0);
77
78 using storage_type = storage<T, typename T::value_type>;
79
80 static auto _master = (storage_type::master_instance(), storage_initializer{});
81 static thread_local auto _worker = (storage_type::instance(), storage_initializer{});
82 consume_parameters(_master);
83
84 return _worker;
85}
86//
87//--------------------------------------------------------------------------------------//
88//
89template <typename T>
91 std::false_type)
92{
93 return storage_initializer{};
94}
95//
96//--------------------------------------------------------------------------------------//
97//
98template <size_t Idx, enable_if_t<Idx != TIMEMORY_COMPONENTS_END>>
101{
102 return storage_initializer::get<component::enumerator_t<Idx>>();
103}
104//
105//--------------------------------------------------------------------------------------//
106//
107} // 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 invoke_preinit(int) -> decltype(std::declval< T >().preinit(), void())
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.
This provides an object that can initialize the storage opaquely, e.g.
Definition: declaration.hpp:98
static storage_initializer get()
trait that signifies that an implementation is enabled at runtime. The value returned from get() is f...