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.
attributes.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#pragma once
26
30
31//======================================================================================//
32//
33#if !defined(TIMEMORY_ATTRIBUTE)
34# if defined(TIMEMORY_MSVC_COMPILER)
35# define TIMEMORY_ATTRIBUTE(...) __declspec(__VA_ARGS__)
36# else
37# define TIMEMORY_ATTRIBUTE(...) __attribute__((__VA_ARGS__))
38# endif
39#endif
40
41//======================================================================================//
42//
43#if !defined(TIMEMORY_ALWAYS_INLINE)
44# if defined(TIMEMORY_MSVC_COMPILER)
45# define TIMEMORY_ALWAYS_INLINE __forceinline
46# else
47# define TIMEMORY_ALWAYS_INLINE TIMEMORY_ATTRIBUTE(always_inline) inline
48# endif
49#endif
50
51#if !defined(TIMEMORY_INLINE)
52# define TIMEMORY_INLINE TIMEMORY_ALWAYS_INLINE
53#endif
54
55//======================================================================================//
56//
57#if !defined(TIMEMORY_NODISCARD)
58# if defined(CXX17)
59# define TIMEMORY_NODISCARD [[nodiscard]]
60# else
61# define TIMEMORY_NODISCARD
62# endif
63#endif
64
65//======================================================================================//
66//
67#if !defined(TIMEMORY_FLATTEN)
68# if !defined(TIMEMORY_MSVC_COMPILER)
69# define TIMEMORY_FLATTEN [[gnu::flatten]]
70# else
71# define TIMEMORY_FLATTEN
72# endif
73#endif
74
75//======================================================================================//
76//
77#if !defined(TIMEMORY_HOT)
78# if !defined(TIMEMORY_MSVC_COMPILER)
79# define TIMEMORY_HOT TIMEMORY_ATTRIBUTE(hot)
80# else
81# define TIMEMORY_HOT
82# endif
83#endif
84
85//======================================================================================//
86//
87#if !defined(TIMEMORY_COLD)
88# if !defined(TIMEMORY_MSVC_COMPILER)
89# define TIMEMORY_COLD TIMEMORY_ATTRIBUTE(cold)
90# else
91# define TIMEMORY_COLD
92# endif
93#endif
94
95//======================================================================================//
96//
97#if !defined(TIMEMORY_CONST)
98# define TIMEMORY_CONST [[gnu::const]]
99#endif
100
101//======================================================================================//
102//
103#if !defined(TIMEMORY_DEPRECATED)
104# define TIMEMORY_DEPRECATED(...) [[gnu::deprecated(__VA_ARGS__)]]
105#endif
106
107//======================================================================================//
108//
109#if !defined(TIMEMORY_EXTERN_VISIBLE)
110# define TIMEMORY_EXTERN_VISIBLE [[gnu::externally_visible]]
111#endif
112
113//======================================================================================//
114//
115#if !defined(TIMEMORY_HIDDEN)
116# if !defined(TIMEMORY_MSVC_COMPILER)
117# define TIMEMORY_HIDDEN TIMEMORY_ATTRIBUTE(visibility("hidden"))
118# else
119# define TIMEMORY_HIDDEN
120# endif
121#endif
122
123//======================================================================================//
124//
125#if !defined(TIMEMORY_ALIAS)
126# define TIMEMORY_ALIAS(...) [[gnu::alias(__VA_ARGS__)]]
127#endif
128
129//======================================================================================//
130//
131#if !defined(TIMEMORY_NOINLINE)
132# define TIMEMORY_NOINLINE TIMEMORY_ATTRIBUTE(noinline)
133#endif
134
135//======================================================================================//
136//
137#if !defined(TIMEMORY_NOCLONE)
138# if defined(TIMEMORY_GNU_COMPILER)
139# define TIMEMORY_NOCLONE TIMEMORY_ATTRIBUTE(noclone)
140# else
141# define TIMEMORY_NOCLONE
142# endif
143#endif
144
145//======================================================================================//
146//
147#if !defined(TIMEMORY_DATA_ALIGNMENT)
148# define TIMEMORY_DATA_ALIGNMENT 8
149#endif
150
151#if !defined(TIMEMORY_PACKED_ALIGNMENT)
152# if defined(_WIN32) // Windows 32- and 64-bit
153# define TIMEMORY_PACKED_ALIGNMENT __declspec(align(TIMEMORY_DATA_ALIGNMENT))
154# elif defined(__GNUC__) // GCC
155# define TIMEMORY_PACKED_ALIGNMENT \
156 __attribute__((__packed__)) __attribute__((aligned(TIMEMORY_DATA_ALIGNMENT)))
157# else // all other compilers
158# define TIMEMORY_PACKED_ALIGNMENT
159# endif
160#endif
161
162//======================================================================================//
163// device decorators
164//
165#if defined(__CUDACC__) || defined(__HIPCC__)
166# define TIMEMORY_LAMBDA __host__ __device__
167# define TIMEMORY_HOST_LAMBDA __host__
168# define TIMEMORY_HOST_FUNCTION __host__
169# define TIMEMORY_DEVICE_LAMBDA __device__
170# define TIMEMORY_DEVICE_FUNCTION __device__
171# define TIMEMORY_GLOBAL_FUNCTION __global__
172# define TIMEMORY_HOST_DEVICE_FUNCTION __host__ __device__
173# define TIMEMORY_DEVICE_INLINE __device__ __inline__
174# define TIMEMORY_GLOBAL_INLINE __global__ __inline__
175# define TIMEMORY_HOST_DEVICE_INLINE __host__ __device__ __inline__
176#else
177# define TIMEMORY_LAMBDA
178# define TIMEMORY_HOST_LAMBDA
179# define TIMEMORY_HOST_FUNCTION
180# define TIMEMORY_DEVICE_LAMBDA
181# define TIMEMORY_DEVICE_FUNCTION
182# define TIMEMORY_GLOBAL_FUNCTION
183# define TIMEMORY_HOST_DEVICE_FUNCTION
184# define TIMEMORY_DEVICE_INLINE inline
185# define TIMEMORY_GLOBAL_INLINE inline
186# define TIMEMORY_HOST_DEVICE_INLINE inline
187#endif