16#include <DeviceMemory.h>
23#include <hip/hip_runtime.h>
27map_t DeviceMemory::memory_map_;
28size_t DeviceMemory::initial_free_ = 0;
36 size_t free=0, total=0;
39 cudaMemGetInfo(&free, &total);
42 auto err = hipMemGetInfo(&free, &total);
46 return print_total ? total : free;
51 initial_free_ = (initial_free_==0) ? free : initial_free_;
52 return initial_free_ - free;
60 if (memory_map_.empty())
return false;
61 auto it = memory_map_.find(ptr);
62 return (it != memory_map_.end());
72 if (ptr==
nullptr || memory_map_.empty())
77 for (
auto it = memory_map_.begin(); it != memory_map_.end(); ++it)
80 std::tie(bytes, device_ptr) = it->second;
86 if (ptr >= host_ptr && ptr <
static_cast<char *
>(host_ptr) + bytes)
87 return static_cast<char *
>(device_ptr) + (
static_cast<char *
>(ptr) -
static_cast<char *
>(host_ptr));
91 Process:: Journal() <<
"Error! Device address for host address " << ptrToString(ptr) <<
" not found:" << finl;
93 Process::exit(
"Error! Device address for host address not found. See log.");
102 if (ptr==
nullptr)
return;
104 if (statistics().is_gpu_verbose_on())
106 Process::Journal() <<
"Adding Host ptr: " << ptrToString(ptr) <<
" Device ptr: " << ptrToString(device_ptr)
107 <<
" bytes: " << bytes << finl;
118 if (statistics().is_gpu_verbose_on())
133 for (
const auto& block : memory_map_)
135 void* ptr = block.first;
136 std::tie(bytes, device_ptr) = block.second;
137 Process::Journal() <<
"Host ptr: " << ptrToString(ptr) <<
" Device ptr: " << ptrToString(device_ptr) <<
" bytes: " << bytes << finl;
static Sortie & Journal(int message_level=0)
Renvoie un objet statique de type Sortie qui sert de journal d'evenements.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
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 void del(void *ptr)
static size_t deviceMemGetInfo(bool)
static void * addrOnDevice(void *)