Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ProfilingInternal.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ProfilingInternal.h (C) 2000-2026 */
9/* */
10/* Internal classes for managing profiling. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_BASE_INTERNAL_PROFILINGINTERNAL_H
13#define ARCCORE_BASE_INTERNAL_PROFILINGINTERNAL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17// Note: this file is not available for Arcane users.
18// Therefore, it should not be included in a public header file.
19
20#include "arccore/base/String.h"
21#include "arccore/base/FixedArray.h"
22#include "arccore/base/Profiling.h"
23
24#include <map>
25#include <atomic>
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane::Impl
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
39struct ARCCORE_BASE_EXPORT ForLoopProfilingStat
40{
41 public:
42
44 void add(const ForLoopOneExecStat& s);
45
46 Int64 nbCall() const { return m_nb_call; }
47 Int64 nbChunk() const { return m_nb_chunk; }
48 Int64 execTime() const { return m_exec_time; }
49
50 private:
51
52 Int64 m_nb_call = 0;
53 Int64 m_nb_chunk = 0;
54 Int64 m_exec_time = 0;
55};
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
60class ARCCORE_BASE_EXPORT ForLoopStatInfoListImpl
61{
62 public:
63
64 void print(std::ostream& o);
65
66 public:
67
68 // TODO Use a hash for the map instead of a String to speed up comparisons
69 std::map<String, ForLoopProfilingStat> m_stat_map;
70};
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
78class ARCCORE_BASE_EXPORT ForLoopCumulativeStat
79{
80 public:
81
82 void merge(const ForLoopOneExecStat& s)
83 {
84 ++m_nb_loop_parallel_for;
85 m_nb_chunk_parallel_for += s.nbChunk();
86 m_total_time += s.execTime();
87 }
88
89 public:
90
91 Int64 nbLoopParallelFor() const { return m_nb_loop_parallel_for.load(); }
92 Int64 nbChunkParallelFor() const { return m_nb_chunk_parallel_for.load(); }
93 Int64 totalTime() const { return m_total_time.load(); }
94
95 private:
96
97 std::atomic<Int64> m_nb_loop_parallel_for = 0;
98 std::atomic<Int64> m_nb_chunk_parallel_for = 0;
99 std::atomic<Int64> m_total_time = 0;
100};
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
111class ARCCORE_BASE_EXPORT AcceleratorStatInfoList
112{
113 public:
114
117 {
118 public:
119
120 void merge(const MemoryTransferInfo& mem_info)
121 {
122 m_nb_byte += mem_info.m_nb_byte;
123 m_nb_call += mem_info.m_nb_call;
124 }
125
126 public:
127
128 Int64 m_nb_byte = 0;
129 Int64 m_nb_call = 0;
130 };
131
134 {
135 public:
136
137 void merge(const MemoryPageFaultInfo& mem_info)
138 {
139 m_nb_fault += mem_info.m_nb_fault;
140 m_nb_call += mem_info.m_nb_call;
141 }
142
143 public:
144
145 Int64 m_nb_fault = 0;
146 Int64 m_nb_call = 0;
147 };
148
149 enum class eMemoryTransferType
150 {
151 HostToDevice = 0,
152 DeviceToHost = 1
153 };
154 enum class eMemoryPageFaultType
155 {
156 Gpu = 0,
157 Cpu = 1
158 };
159
160 public:
161
162 void addMemoryTransfer(eMemoryTransferType type, Int64 nb_byte)
163 {
164 MemoryTransferInfo mem_info{ nb_byte, 1 };
165 m_managed_memory_transfer_list[(int)type].merge(mem_info);
166 }
167 const MemoryTransferInfo& memoryTransfer(eMemoryTransferType type) const
168 {
169 return m_managed_memory_transfer_list[(int)type];
170 }
171 void addMemoryPageFault(eMemoryPageFaultType type, Int64 nb_byte)
172 {
173 MemoryPageFaultInfo mem_info{ nb_byte, 1 };
174 m_managed_memory_page_fault_list[(int)type].merge(mem_info);
175 }
176 const MemoryPageFaultInfo& memoryPageFault(eMemoryPageFaultType type) const
177 {
178 return m_managed_memory_page_fault_list[(int)type];
179 }
180
181 public:
182
183 void print(std::ostream& ostr) const;
184
185 private:
186
187 // Must have the same number of elements as 'eMemoryTransfertType'
188 FixedArray<MemoryTransferInfo, 2> m_managed_memory_transfer_list;
189
190 // Must have the same number of elements as 'eMemoryPageFaultType'
191 FixedArray<MemoryPageFaultInfo, 2> m_managed_memory_page_fault_list;
192};
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
200extern "C++" ARCCORE_BASE_EXPORT void
201dumpProfilingStatistics(std::ostream& o);
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
206} // namespace Arcane::Impl
207
208/*---------------------------------------------------------------------------*/
209/*---------------------------------------------------------------------------*/
210
211#endif
Int32 print(ITraceMng *tm, bool is_no_continue=true)
Prints a message for an unknown exception.
Information on memory transfers between CPU and GPU.
Class to manage the profiling of a single loop execution.
Int64 execTime() const
Execution time (in nanoseconds).
Cumulative statistics on the number of executed loops.
std::int64_t Int64
Signed integer type of 64 bits.
Execution statistics of a loop.
void add(const ForLoopOneExecStat &s)
Adds the execution info of s.
Definition Profiling.cc:330