GEOS
MemoryInfos.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 #ifndef GEOS_COMMON_MEMORYINFO_HPP_
17 #define GEOS_COMMON_MEMORYINFO_HPP_
18 
19 #include "umpire/util/MemoryResourceTraits.hpp"
20 #include "common/DataTypes.hpp"
21 #include "common/logger/Logger.hpp"
23 #include <unistd.h>
24 #include <iostream>
25 #if defined( GEOS_USE_CUDA )
26 #include <cuda.h>
27 #endif
28 
29 namespace geos
30 {
31 
37 {
38 public:
39 
44  MemoryInfos( umpire::MemoryResourceTraits::resource_type resourceType );
45 
50  size_t getTotalMemory() const;
51 
56  size_t getAvailableMemory() const;
57 
63 private:
64 
66  size_t m_totalMemory;
68  size_t m_availableMemory;
70  bool m_physicalMemoryHandled;
71 };
72 
78 {
79 public:
80 
85 
90  { return m_umpireStatsLogReport; }
91 
97  { return m_umpireStatsCsvReport; }
98 
103  { return m_currentCycle; }
104 
109  void enableUmpireStatsLogReport( bool enable )
110  { m_umpireStatsLogReport = enable; }
111 
118  void enableUmpireStatsCsvReport( bool enable, string_view filename = "" );
119 
125  void setCurrentCycle( integer currentCycle )
126  { m_currentCycle = currentCycle; }
127 
132  void setCurrentTime( real64 currentTime )
133  { m_currentTime = currentTime; }
134 
140  void memoryStatsReport() const;
141 
142 private:
143 
145  std::unique_ptr< TableTextFormatter > m_memoryStatLogFormatter;
146 
148  std::unique_ptr< TableCSVFormatter > m_memoryStatCsvFormatter;
149 
151  bool m_umpireStatsLogReport;
152 
154  bool m_umpireStatsCsvReport;
155 
157  string m_umpireStatsCsvReportFilename;
158 
160  integer m_currentCycle;
161 
163  real64 m_currentTime;
164 
165 
167  MemoryLogging();
168 
169 };
170 
171 }
172 
173 #endif
Class to fetch and store memory information for different resource types.
Definition: MemoryInfos.hpp:37
MemoryInfos(umpire::MemoryResourceTraits::resource_type resourceType)
Constructor for MemoryInfos.
size_t getAvailableMemory() const
Get the available memory for the resource type.
bool isPhysicalMemoryHandled() const
Check if physical memory is handled.
size_t getTotalMemory() const
Get the total memory available for the resource type.
Singleton class keeping the application memory logging settings & features.
Definition: MemoryInfos.hpp:78
void memoryStatsReport() const
Output the umpire statistics according to settings set by enableUmpireStatsLogReport() and enableUmpi...
void setCurrentTime(real64 currentTime)
Set the Current Time, to identify each CSV entry.
bool isUmpireStatsCsvOutputEnabled() const
Definition: MemoryInfos.hpp:96
void setCurrentCycle(integer currentCycle)
Set the Current Cycle, to identify each CSV entry.
bool isUmpireStatsLogOutputEnabled() const
Definition: MemoryInfos.hpp:89
static MemoryLogging & getInstance()
integer getCurrentCycle() const
void enableUmpireStatsLogReport(bool enable)
void enableUmpireStatsCsvReport(bool enable, string_view filename="")
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:81
std::string_view string_view
String type.
Definition: DataTypes.hpp:93