GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSRAMManager.hh
Go to the documentation of this file.
1 #ifndef GUARD_GGEMS_TOOLS_GGEMSRAMMANAGER_HH
2 #define GUARD_GGEMS_TOOLS_GGEMSRAMMANAGER_HH
3 
4 // ************************************************************************
5 // * This file is part of GGEMS. *
6 // * *
7 // * GGEMS is free software: you can redistribute it and/or modify *
8 // * it under the terms of the GNU General Public License as published by *
9 // * the Free Software Foundation, either version 3 of the License, or *
10 // * (at your option) any later version. *
11 // * *
12 // * GGEMS is distributed in the hope that it will be useful, *
13 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 // * GNU General Public License for more details. *
16 // * *
17 // * You should have received a copy of the GNU General Public License *
18 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
19 // * *
20 // ************************************************************************
21 
34 #ifdef _MSC_VER
35 #pragma warning(disable: 4251) // Deleting warning exporting STL members!!!
36 #endif
37 
38 #include <vector>
39 #include <unordered_map>
40 
42 #include "GGEMS/global/GGEMSExport.hh"
43 
44 typedef std::unordered_map<std::string, GGsize> AllocatedMemoryUMap;
50 class GGEMS_EXPORT GGEMSRAMManager
51 {
52  private:
56  GGEMSRAMManager(void);
57 
61  ~GGEMSRAMManager(void);
62 
63  public:
70  {
71  static GGEMSRAMManager instance;
72  return instance;
73  }
74 
80  GGEMSRAMManager(GGEMSRAMManager const& ram_manager) = delete;
81 
87  GGEMSRAMManager& operator=(GGEMSRAMManager const& ram_manager) = delete;
88 
94  GGEMSRAMManager(GGEMSRAMManager const&& ram_manager) = delete;
95 
101  GGEMSRAMManager& operator=(GGEMSRAMManager const&& ram_manager) = delete;
102 
107  void PrintRAMStatus(void) const;
108 
116  inline bool IsEnoughAvailableRAMMemory(GGsize const& index, GGsize const& size) const
117  {
118  if (size + allocated_ram_[index] < max_available_ram_[index]) return true;
119  else return false;
120  }
121 
129  inline bool IsBufferSizeCorrect(GGsize const& index, GGsize const& size) const
130  {
131  if (size < max_buffer_size_[index]) return true;
132  else return false;
133  }
134 
142  void IncrementRAMMemory(std::string const& class_name, GGsize const& index, GGsize const& size);
143 
151  void DecrementRAMMemory(std::string const& class_name, GGsize const& index, GGsize const& size);
152 
157  void Clean(void);
158 
159  private:
165 };
166 
172 extern "C" GGEMS_EXPORT GGEMSRAMManager* get_instance_ggems_ram_manager(void);
173 
179 extern "C" GGEMS_EXPORT void print_infos_ram_manager(GGEMSRAMManager* ram_manager);
180 
181 #endif // End of GUARD_GGEMS_TOOLS_GGEMSRAMMANAGER_HH
print_infos_ram_manager
void print_infos_ram_manager(GGEMSRAMManager *ram_manager)
Print information about RAM memory.
Definition: GGEMSRAMManager.cc:193
GGEMSRAMManager
GGEMS class handling RAM memory.
Definition: GGEMSRAMManager.hh:51
GGEMSRAMManager::number_detected_devices_
GGsize number_detected_devices_
Definition: GGEMSRAMManager.hh:160
GGEMSRAMManager::GetInstance
static GGEMSRAMManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSRAMManager.hh:69
GGEMSRAMManager::operator=
GGEMSRAMManager & operator=(GGEMSRAMManager const &&ram_manager)=delete
Avoid copy of the class by rvalue reference.
GGsize
#define GGsize
Definition: GGEMSTypes.hh:252
GGEMSRAMManager::GGEMSRAMManager
GGEMSRAMManager(GGEMSRAMManager const &&ram_manager)=delete
Avoid copy of the class by rvalue reference.
GGEMSRAMManager::allocated_ram_
GGsize * allocated_ram_
Definition: GGEMSRAMManager.hh:161
get_instance_ggems_ram_manager
GGEMSRAMManager * get_instance_ggems_ram_manager(void)
Get the GGEMSRAMManager pointer for python user.
Definition: GGEMSRAMManager.cc:184
GGEMSTypes.hh
Redefining types for OpenCL device and host.
GGEMSRAMManager::IsEnoughAvailableRAMMemory
bool IsEnoughAvailableRAMMemory(GGsize const &index, GGsize const &size) const
Checking available RAM memory on device.
Definition: GGEMSRAMManager.hh:116
GGEMSRAMManager::allocated_memories_
AllocatedMemoryUMap * allocated_memories_
Definition: GGEMSRAMManager.hh:164
GGEMSRAMManager::operator=
GGEMSRAMManager & operator=(GGEMSRAMManager const &ram_manager)=delete
Avoid assignement of the class by reference.
GGEMSRAMManager::GGEMSRAMManager
GGEMSRAMManager(GGEMSRAMManager const &ram_manager)=delete
Avoid copy of the class by reference.
GGEMSRAMManager::max_available_ram_
GGsize * max_available_ram_
Definition: GGEMSRAMManager.hh:162
GGEMSRAMManager::max_buffer_size_
GGsize * max_buffer_size_
Definition: GGEMSRAMManager.hh:163
AllocatedMemoryUMap
std::unordered_map< std::string, GGsize > AllocatedMemoryUMap
Definition: GGEMSRAMManager.hh:44
GGEMSRAMManager::IsBufferSizeCorrect
bool IsBufferSizeCorrect(GGsize const &index, GGsize const &size) const
Check the size of buffer depending on device limit, false if buffer size if too big.
Definition: GGEMSRAMManager.hh:129