SIRIUS 7.5.0
Electronic structure library and applications
profiler.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2018 Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file profiler.hpp
21 *
22 * \brief A time-based profiler.
23 */
24
25#ifndef __PROFILER_HPP__
26#define __PROFILER_HPP__
27
28#include <mpi.h>
29#include <string>
30#if defined(__APEX)
31#include <apex_api.hpp>
32#endif
33#include "core/rt_graph.hpp"
34#if defined(SIRIUS_GPU) && defined(SIRIUS_CUDA_NVTX)
35#include "core/acc/nvtx_profiler.hpp"
36#endif
37
38namespace sirius {
39
40extern ::rt_graph::Timer global_rtgraph_timer;
41
42#if defined(SIRIUS_CUDA_NVTX)
43extern acc::nvtxprofiler::Timer global_nvtx_timer;
44#endif
45
46// TODO: add calls to apex and cudaNvtx
47
48#if defined(SIRIUS_PROFILE)
49#define PROFILER_CONCAT_IMPL(x, y) x##y
50#define PROFILER_CONCAT(x, y) PROFILER_CONCAT_IMPL(x, y)
51
52#if defined(SIRIUS_CUDA_NVTX)
53 #define PROFILE(identifier) \
54 acc::nvtxprofiler::ScopedTiming PROFILER_CONCAT(GeneratedScopedTimer, __COUNTER__)(identifier, global_nvtx_timer); \
55 ::rt_graph::ScopedTiming PROFILER_CONCAT(GeneratedScopedTimer, __COUNTER__)(identifier, global_rtgraph_timer);
56 #define PROFILE_START(identifier) \
57 global_nvtx_timer.start(identifier); \
58 global_rtgraph_timer.start(identifier);
59 #define PROFILE_STOP(identifier) \
60 global_rtgraph_timer.stop(identifier); \
61 global_nvtx_timer.stop(identifier);
62#else
63 #define PROFILE(identifier) \
64 ::rt_graph::ScopedTiming PROFILER_CONCAT(GeneratedScopedTimer, __COUNTER__)(identifier, global_rtgraph_timer);
65 #define PROFILE_START(identifier) \
66 global_rtgraph_timer.start(identifier);
67 #define PROFILE_STOP(identifier) \
68 global_rtgraph_timer.stop(identifier);
69#endif
70
71#else
72 #define PROFILE(...)
73 #define PROFILE_START(...)
74 #define PROFILE_STOP(...)
75#endif
76
77} // namespace sirius
78
79#endif
Namespace of the SIRIUS library.
Definition: sirius.f90:5