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.
compiler.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
28
29#define TIMEMORY_STR_HELPER(x) #x
30#define TIMEMORY_STR(x) TIMEMORY_STR_HELPER(x)
31
32//======================================================================================//
33//
34// Compiler
35//
36//======================================================================================//
37
38// clang compiler
39#if defined(__clang__) && !defined(TIMEMORY_CLANG_COMPILER)
40# define TIMEMORY_CLANG_COMPILER 1
41#endif
42
43//--------------------------------------------------------------------------------------//
44
45// GNU compiler
46#if defined(__GNUC__) && !defined(TIMEMORY_CLANG_COMPILER) && \
47 !defined(TIMEMORY_GNU_COMPILER)
48# if(__GNUC__ <= 4 && __GNUC_MINOR__ < 9)
49# warning "GCC compilers < 4.9 have been known to have compiler errors"
50# define TIMEMORY_GNU_COMPILER 1
51# elif(__GNUC__ >= 4 && __GNUC_MINOR__ >= 9) || __GNUC__ >= 5
52# define TIMEMORY_GNU_COMPILER
53# endif
54#endif
55
56//--------------------------------------------------------------------------------------//
57
58// Intel compiler
59#if defined(__INTEL_COMPILER) && !defined(TIMEMORY_INTEL_COMPILER)
60# define TIMEMORY_INTEL_COMPILER 1
61# if __INTEL_COMPILER < 1500
62# warning "Intel compilers < 1500 have been known to have compiler errors"
63# endif
64#endif
65
66//--------------------------------------------------------------------------------------//
67
68// nvcc compiler
69#if defined(__NVCC__) && !defined(TIMEMORY_NVCC_COMPILER)
70# define TIMEMORY_NVCC_COMPILER 1
71#endif
72
73//--------------------------------------------------------------------------------------//
74
75// cuda compilation mode
76#if defined(__CUDACC__) && !defined(TIMEMORY_CUDACC)
77# define TIMEMORY_CUDACC 1
78#endif
79
80//--------------------------------------------------------------------------------------//
81
82// cuda architecture
83#if !defined(TIMEMORY_CUDA_ARCH)
84# if defined(__CUDA_ARCH__)
85# define TIMEMORY_CUDA_ARCH __CUDA_ARCH__
86# else
87# define TIMEMORY_CUDA_ARCH 0
88# endif
89#endif
90
91//--------------------------------------------------------------------------------------//
92
93// cuda support for 16-bit floating point
94#if defined(TIMEMORY_CUDACC) && (TIMEMORY_CUDACC > 0) && (TIMEMORY_CUDA_ARCH < 600) && \
95 (TIMEMORY_CUDA_ARCH > 0)
96# if defined(TIMEMORY_USE_CUDA_HALF)
97# pragma message "Half precision not supported on CUDA arch: " TIMEMORY_STR( \
98 TIMEMORY_CUDA_ARCH)
99# endif
100#endif
101
102//--------------------------------------------------------------------------------------//
103
104// hcc or hip-clang compiler
105#if(defined(__HCC__) || (defined(__clang__) && defined(__HIP__))) && \
106 !defined(TIMEMORY_HIP_COMPILER)
107# define TIMEMORY_HIP_COMPILER 1
108#endif
109
110//--------------------------------------------------------------------------------------//
111
112// hip compilation mode
113#if defined(__HIPCC__) && !defined(TIMEMORY_HIPCC)
114# define TIMEMORY_HIPCC 1
115#endif
116
117//--------------------------------------------------------------------------------------//
118
119// gpu compilation mode (may be host or device code)
120#if(defined(__CUDACC__) || defined(__HIPCC__)) && !defined(TIMEMORY_GPUCC)
121# define TIMEMORY_GPUCC 1
122#endif
123
124//--------------------------------------------------------------------------------------//
125
126// cuda compilation - device code
127#if defined(__CUDA_ARCH__) && !defined(TIMEMORY_CUDA_DEVICE_COMPILE)
128# define TIMEMORY_CUDA_DEVICE_COMPILE 1
129#endif
130
131//--------------------------------------------------------------------------------------//
132
133// hip compilation - device code
134#if defined(__HIP_DEVICE_COMPILE__) && !defined(TIMEMORY_HIP_DEVICE_COMPILE)
135# define TIMEMORY_HIP_DEVICE_COMPILE 1
136#endif
137
138//--------------------------------------------------------------------------------------//
139
140// gpu compiler - device code
141#if(defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)) && \
142 !defined(TIMEMORY_GPU_DEVICE_COMPILE)
143# define TIMEMORY_GPU_DEVICE_COMPILE 1
144#endif
145
146//--------------------------------------------------------------------------------------//
147
148// assume openmp target is enabled
149// #if defined(TIMEMORY_CUDACC) && defined(_OPENMP) && !defined(TIMEMORY_OPENMP_TARGET)
150// # define TIMEMORY_OPENMP_TARGET 1
151// #endif
152
153//--------------------------------------------------------------------------------------//
154
155// MSVC compiler
156#if defined(_MSC_VER) && _MSC_VER > 0 && !defined(TIMEMORY_MSVC_COMPILER)
157# define TIMEMORY_MSVC_COMPILER 1
158#endif
159
160//======================================================================================//
161//
162// Demangling
163//
164//======================================================================================//
165
166#if(defined(TIMEMORY_GNU_COMPILER) || defined(TIMEMORY_CLANG_COMPILER) || \
167 defined(TIMEMORY_INTEL_COMPILER) || defined(TIMEMORY_NVCC_COMPILER) || \
168 defined(TIMEMORY_HIP_COMPILER)) && \
169 defined(TIMEMORY_UNIX)
170# if !defined(TIMEMORY_ENABLE_DEMANGLE)
171# define TIMEMORY_ENABLE_DEMANGLE 1
172# endif
173#endif
174
175//======================================================================================//
176//
177// WINDOWS WARNINGS
178//
179//======================================================================================//
180
181#if defined(TIMEMORY_MSVC_COMPILER) && !defined(TIMEMORY_MSVC_WARNINGS)
182
183# pragma warning(disable : 4003) // not enough actual params
184# pragma warning(disable : 4061) // enum in switch of enum not explicitly handled
185# pragma warning(disable : 4068) // unknown pragma
186# pragma warning(disable : 4127) // conditional expr is constant
187# pragma warning(disable : 4129) // unrecognized char escape
188# pragma warning(disable : 4146) // unsigned
189# pragma warning(disable : 4217) // locally defined symbol
190# pragma warning(disable : 4244) // possible loss of data
191# pragma warning(disable : 4251) // needs to have dll-interface to be used
192# pragma warning(disable : 4242) // possible loss of data (assignment)
193# pragma warning(disable : 4244) // conversion from 'double' to 'LONGLONG'
194# pragma warning(disable : 4245) // signed/unsigned mismatch (init conversion)
195# pragma warning(disable : 4267) // possible loss of data (implicit conversion)
196# pragma warning(disable : 4305) // truncation from 'double' to 'float'
197# pragma warning(disable : 4355) // this used in base member init list
198# pragma warning(disable : 4365) // signed/unsigned mismatch
199# pragma warning(disable : 4464) // relative include path contains '..'
200# pragma warning(disable : 4522) // multiple assignment operators specified
201# pragma warning(disable : 4625) // copy ctor implicitly defined as deleted
202# pragma warning(disable : 4626) // copy assign implicitly defined as deleted
203# pragma warning(disable : 4661) // no suitable definition for template inst
204# pragma warning(disable : 4700) // uninitialized local variable used
205# pragma warning(disable : 4710) // function not inlined
206# pragma warning(disable : 4711) // function selected for auto inline expansion
207# pragma warning(disable : 4786) // ID truncated to '255' char in debug info
208# pragma warning(disable : 4820) // bytes padded after data member
209# pragma warning(disable : 4834) // discarding return value with 'nodiscard'
210# pragma warning(disable : 4996) // function may be unsafe
211# pragma warning(disable : 5219) // implicit conversion; possible loss of data
212# pragma warning(disable : 5026) // move ctor implicitly defined as deleted
213# pragma warning(disable : 5027) // move assign implicitly defined as deleted
214# pragma warning(disable : 26495) // Always initialize member variable
215
216#endif
217
218//======================================================================================//
219//
220// DISABLE WINDOWS MIN/MAX macros
221//
222//======================================================================================//
223
224#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
225
226# if !defined(NOMINMAX)
227# define NOMINMAX
228# endif
229
230#endif