14#include "arcane/accelerator/core/internal/MemoryTracer.h"
16#include "arccore/base/PlatformUtils.h"
17#include "arccore/base/ArrayView.h"
18#include "arccore/base/String.h"
20#include "arccore/common/AllocatedMemoryInfo.h"
21#include "arccore/common/IMemoryAllocator.h"
28namespace Arcane::Accelerator::impl
44 const void* ptr = bytes.
data();
45 m_infos_map.insert(std::make_pair(ptr, Info{ bytes.
size(), name, stack_trace }));
48 void remove(
void* ptr, [[maybe_unused]]
const String& name, [[maybe_unused]]
const String& stack_trace, [[maybe_unused]]
Int64 timestamp)
50 auto x = m_infos_map.find(ptr);
51 if (x != m_infos_map.end())
55 std::pair<String, String> find(
const void* ptr)
57 auto x = m_infos_map.lower_bound(ptr);
58 if (x != m_infos_map.end())
59 return std::make_pair(x->second.name, x->second.stack);
65 std::map<const void*, Info> m_infos_map;
81 m_memory_tracer_mng.add(bytes, name, stack_trace, timestamp);
85notifyMemoryFree(
void* ptr,
const String& name,
const String& stack_trace,
Int64 timestamp)
88 m_memory_tracer_mng.remove(ptr, name, stack_trace, timestamp);
94std::pair<String, String> MemoryTracer::
95findMemory(
const void* ptr)
97 return m_memory_tracer_mng.find(ptr);
111void MemoryTracerWrapper::
112traceDeallocate(
const AllocatedMemoryInfo& mem_info,
const MemoryAllocationArgs& args)
117 void* ptr = mem_info.baseAddress();
120 std::ostringstream ostr;
121 if (m_trace_level >= 2)
122 ostr <<
"FREE_MANAGED=" << ptr <<
" size=" << mem_info.capacity() <<
" name=" << args.arrayName();
124 if (m_trace_level >= 3) {
126 if (m_trace_level >= 4) {
127 ostr <<
" stack=" << s;
130 impl::MemoryTracer::notifyMemoryFree(ptr, args.arrayName(), s, 0);
131 if (m_trace_level >= 2) {
133 std::cout << ostr.str();
140void MemoryTracerWrapper::
141traceAllocate(
void* p,
size_t new_size, MemoryAllocationArgs args)
148 std::ostringstream ostr;
149 if (m_trace_level >= 2)
150 ostr <<
"MALLOC_MANAGED=" << p <<
" size=" << new_size <<
" name=" << args.arrayName();
152 if (m_trace_level >= 3) {
154 if (m_trace_level >= 4) {
155 ostr <<
" stack=" << s;
158 Span<const std::byte> bytes(
reinterpret_cast<std::byte*
>(p), new_size);
159 impl::MemoryTracer::notifyMemoryAllocation(bytes, args.arrayName(), s, 0);
160 if (m_trace_level >= 2) {
162 std::cout << ostr.str();
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
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.