9.1
general documentation
cs_profiling.h
Go to the documentation of this file.
1#pragma once
2
3/*============================================================================
4 * Building with profiling annotations.
5 *============================================================================*/
6
7/*
8 This file is part of code_saturne, a general-purpose CFD tool.
9
10 Copyright (C) 1998-2025 EDF S.A.
11
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 2 of the License, or (at your option) any later
15 version.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
24 Street, Fifth Floor, Boston, MA 02110-1301, USA.
25*/
26
27/*----------------------------------------------------------------------------*/
28
29// Numeric values for different profiling libraries.
30
32#define CS_PROFILING_NONE 0
33
35#define CS_PROFILING_NVTX 1
36
37// No profiling library is used by default.
38#ifndef CS_PROFILING
39#define CS_PROFILING CS_PROFILING_NONE
40#endif
41
42// Make sure NVTX profiling is used in host code only, not CUDA.
43#if defined(__CUDA_ARCH__)
44#undef CS_PROFILING
45#define CS_PROFILING CS_PROFILING_NONE
46#endif
47
48#define CS_COMBINE_DETAIL(x, y) x##y
49#define CS_COMBINE(x, y) CS_COMBINE_DETAIL(x, y)
50
51#define CS_STRINGIFY_DETAIL(x) #x
52#define CS_STRINGIFY(x) CS_STRINGIFY_DETAIL(x)
53
54#if CS_PROFILING == CS_PROFILING_NONE
55
56/*----------------------------------------------------------------------------
57 * Default: no profiling library
58 *----------------------------------------------------------------------------*/
59
60// Start profiling, when activated y code.
61#define CS_PROFILE_START()
62
63// Stop profiling, when activated y code.
64#define CS_PROFILE_STOP()
65
67#define CS_PROFILE_FUNC_RANGE()
68
70#define CS_PROFILE_RANGE(range_name)
71
73#define CS_PROFILE_MARK_LINE()
74
75/*----------------------------------------------------------------------------
76 * Profiling with NVIDIA NVTX3
77 *----------------------------------------------------------------------------*/
78
79#elif CS_PROFILING == CS_PROFILING_NVTX
80
81#include <cuda_profiler_api.h>
82
83#include <nvtx3/nvtx3.hpp>
84// #include <nvToolsExt.h>
85
86// Start profiling, when activated y code.
87#define CS_PROFILE_START() {cudaProfilerStart();}
88
89// Stop profiling, when activated y code.
90#define CS_PROFILE_STOP() {cudaProfilerStop();}
91
93#ifndef __CUDA_ARCH__
94#define CS_PROFILE_FUNC_RANGE() NVTX3_FUNC_RANGE()
95#else
96#define CS_PROFILE_FUNC_RANGE()
97#endif
98
100#define CS_PROFILE_RANGE(range_name) \
101 nvtx3::scoped_range CS_COMBINE(__cs__profile_range_, __LINE__){ \
102 range_name " (" __FILE__ ":" CS_STRINGIFY(__LINE__) ")" \
103 };
104
106#define CS_PROFILE_MARK_LINE() nvtx3::mark(__FILE__ ":" CS_STRINGIFY(__LINE__))
107
108#endif
109
110/*----------------------------------------------------------------------------*/