TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
DeviceMemory.h
1/****************************************************************************
2* Copyright (c) 2025, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef DeviceMemory_included
17#define DeviceMemory_included
18
19#include <Array_base.h>
20#include <ctime>
21#include <string>
22#include <sstream>
23#include <map>
24#include <unordered_map>
25#include <tuple>
26
27// Map host ptr, size, DataLocation, Ddevice ptr
28using map_t = std::unordered_map<void*, std::tuple<int, void*>>;
29
31{
32public:
33
34 DeviceMemory() = delete;
35
36 static size_t allocatedBytesOnDevice();
37 static size_t deviceMemGetInfo(bool);
38 static map_t& getMemoryMap() { return memory_map_; };
39 static bool isAllocatedOnDevice(void *);
40 static void* addrOnDevice(void*);
41 static void add(void * ptr, void * device_ptr, trustIdType bytes);
42 static void del(void * ptr);
43 static void printMemoryMap();
44 static trustIdType internal_items_size_;
45 static int nb_pas_dt_; // can't reference Schema_temps_base cause Kernel/Utilitaires...
46 static bool warning(trustIdType nb_items);
47
48private:
49 static map_t memory_map_; // Define a map to track memory allocations on device
50 static size_t initial_free_;
51};
52
53#endif
54
55
56
57
58
59
static bool isAllocatedOnDevice(void *)
static size_t allocatedBytesOnDevice()
static void add(void *ptr, void *device_ptr, trustIdType bytes)
static void printMemoryMap()
static map_t & getMemoryMap()
static bool warning(trustIdType nb_items)
static trustIdType internal_items_size_
static int nb_pas_dt_
static void del(void *ptr)
static size_t deviceMemGetInfo(bool)
DeviceMemory()=delete
static void * addrOnDevice(void *)