14#include "arcane/accelerator/core/internal/MemoryTracer.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/ValueConvert.h"
18#include "arcane/utils/ArrayView.h"
19#include "arcane/utils/String.h"
20#include "arcane/utils/IMemoryAllocator.h"
27namespace Arcane::Accelerator::impl
43 const void* ptr = bytes.
data();
44 m_infos_map.insert(std::make_pair(ptr, Info{ bytes.
size(), name, stack_trace }));
47 void remove(
void* ptr, [[maybe_unused]]
const String& name, [[maybe_unused]]
const String& stack_trace, [[maybe_unused]]
Int64 timestamp)
49 auto x = m_infos_map.find(ptr);
50 if (x != m_infos_map.end())
54 std::pair<String, String> find(
const void* ptr)
56 auto x = m_infos_map.lower_bound(ptr);
57 if (x != m_infos_map.end())
58 return std::make_pair(x->second.name, x->second.stack);
64 std::map<const void*, Info> m_infos_map;
80 m_memory_tracer_mng.add(bytes, name, stack_trace, timestamp);
84notifyMemoryFree(
void* ptr,
const String& name,
const String& stack_trace,
Int64 timestamp)
87 m_memory_tracer_mng.remove(ptr, name, stack_trace, timestamp);
93std::pair<String, String> MemoryTracer::
94findMemory(
const void* ptr)
96 return m_memory_tracer_mng.find(ptr);
110void MemoryTracerWrapper::
111traceDeallocate(
const AllocatedMemoryInfo& mem_info,
const MemoryAllocationArgs& args)
116 void* ptr = mem_info.baseAddress();
119 std::ostringstream ostr;
120 if (m_trace_level >= 2)
121 ostr <<
"FREE_MANAGED=" << ptr <<
" size=" << mem_info.capacity() <<
" name=" << args.arrayName();
123 if (m_trace_level >= 3) {
124 s = platform::getStackTrace();
125 if (m_trace_level >= 4) {
126 ostr <<
" stack=" << s;
129 impl::MemoryTracer::notifyMemoryFree(ptr, args.arrayName(), s, 0);
130 if (m_trace_level >= 2) {
132 std::cout << ostr.str();
139void MemoryTracerWrapper::
140traceAllocate(
void* p,
size_t new_size, MemoryAllocationArgs args)
147 std::ostringstream ostr;
148 if (m_trace_level >= 2)
149 ostr <<
"MALLOC_MANAGED=" << p <<
" size=" << new_size <<
" name=" << args.arrayName();
151 if (m_trace_level >= 3) {
152 s = platform::getStackTrace();
153 if (m_trace_level >= 4) {
154 ostr <<
" stack=" << s;
157 Span<const std::byte> bytes(
reinterpret_cast<std::byte*
>(p), new_size);
158 impl::MemoryTracer::notifyMemoryAllocation(bytes, args.arrayName(), s, 0);
159 if (m_trace_level >= 2) {
161 std::cout << ostr.str();
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
Vue d'un tableau d'éléments de type T.
Chaîne de caractères unicode.
std::int64_t Int64
Type entier signé sur 64 bits.