13#include "arcane/core/internal/MachineShMemWinMemoryAllocator.h"
15#include "arcane/utils/FatalErrorException.h"
16#include "arcane/utils/ITraceMng.h"
18#include "arcane/core/IParallelMng.h"
19#include "arcane/core/MachineShMemWinBase.h"
21#include "arccore/common/AllocatedMemoryInfo.h"
34MachineShMemWinMemoryAllocator::
48 return {
nullptr, 0 };
52 const Int64 new_size_with_offset = offset + new_size;
54#ifdef ARCANE_DEBUG_ALLOCATOR
55 m_pm->traceMng()->debug() <<
"(1/2) MachineShMemWinMemoryAllocator::allocate"
56 <<
" -- ptr.size() : " << new_size
57 <<
" -- offset : " << offset
58 <<
" -- win_size (offset+ptr.size()) : " << new_size_with_offset;
63 std::byte* addr_base = win_ptr->segmentView().data();
64 std::byte* addr_after_offset = addr_base + offset;
66 std::memcpy(addr_base, &win_ptr, offset);
68#ifdef ARCANE_DEBUG_ALLOCATOR
69 m_pm->traceMng()->debug() <<
"(2/2) MachineShMemWinMemoryAllocator::allocate"
70 <<
" -- addr_base : " << addr_base
71 <<
" -- addr_after_offset : " << addr_after_offset;
74 return { addr_after_offset, new_size };
91 const Int64 new_size_with_offset = offset + new_size;
96 win->
resize(new_size_with_offset);
99 std::byte* addr_after_offset = addr_base + offset;
101#ifdef ARCANE_DEBUG_ALLOCATOR
102 m_pm->traceMng()->debug() <<
"MachineShMemWinMemoryAllocator::reallocate"
103 <<
" -- old_size : " << d_old_size
104 <<
" -- old_addr_base : " << d_old_addr_base
105 <<
" -- new ptr.size() : " << new_size
106 <<
" -- offset : " << offset
107 <<
" -- win_size (offset+ptr.size()) : " << new_size_with_offset
108 <<
" -- addr_base : " << addr_base
109 <<
" -- addr_after_offset : " << addr_after_offset;
112 return { addr_after_offset, new_size };
118void MachineShMemWinMemoryAllocator::
129#ifdef ARCANE_DEBUG_ALLOCATOR
130 m_pm->traceMng()->debug() <<
"MachineShMemWinMemoryAllocator::deallocate"
131 <<
" -- ptr.size() : " << ptr.
size()
132 <<
" -- win_size (offset+ptr.size()) : " << win_ptr->
segmentView().
size()
145 return _windowBase(ptr)->machineRanks();
151void MachineShMemWinMemoryAllocator::
152barrier(AllocatedMemoryInfo ptr)
154 _windowBase(ptr)->barrier();
160Span<std::byte> MachineShMemWinMemoryAllocator::
161segmentView(AllocatedMemoryInfo ptr)
163 const Span<std::byte> view = _windowBase(ptr)->segmentView();
164 constexpr Int64 offset =
sizeof(MachineShMemWinBase*);
165 return view.subSpan(offset, view.size() - offset);
171Span<std::byte> MachineShMemWinMemoryAllocator::
172segmentView(AllocatedMemoryInfo ptr, Int32 rank)
174 const Span<std::byte> view = _windowBase(ptr)->segmentView(rank);
175 constexpr Int64 offset =
sizeof(MachineShMemWinBase*);
176 return view.subSpan(offset, view.size() - offset);
182MachineShMemWinBase* MachineShMemWinMemoryAllocator::
183_windowBase(AllocatedMemoryInfo ptr)
185 constexpr Int64 offset =
sizeof(MachineShMemWinBase*);
187 std::byte* addr_after_offset =
static_cast<std::byte*
>(ptr.baseAddress());
188 std::byte* addr_base = addr_after_offset - offset;
190 MachineShMemWinBase* win_ptr = *
reinterpret_cast<MachineShMemWinBase**
>(addr_base);
192#ifdef ARCANE_DEBUG_ALLOCATOR
193 std::cout <<
"MachineShMemWinMemoryAllocator::_windowBase"
194 <<
" -- ptr.size() : " << ptr.
size()
195 <<
" -- offset : " << offset
196 <<
" -- addr_base : " << addr_base
197 <<
" -- addr_after_offset : " << addr_after_offset << std::endl;
202 Int64 size_obj = win_ptr->segmentView().size();
203 if (size_obj != offset + ptr.size()) {
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Informations sur une zone mémoire allouée.
void * baseAddress() const
Adresse du début de la zone allouée.
Int64 size() const
Taille en octets de la zone mémoire utilisée. (-1) si inconnue.
Vue constante d'un tableau de type T.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Interface du gestionnaire de parallélisme pour un sous-domaine.
Classe permettant de créer une fenêtre mémoire partagée entre les sous-domaines d'un même noeud.
void resize(Int64 new_nb_elem_segment)
Méthode permettant de redimensionner notre segment.
Span< std::byte > segmentView()
Méthode permettant d'obtenir une vue sur notre segment.
AllocatedMemoryInfo allocate(MemoryAllocationArgs, Int64 new_size) override
Alloue de la mémoire pour new_size octets et retourne le pointeur.
Classe contenant des informations pour spécialiser les allocations.
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.
@ ReduceMax
Maximum des valeurs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.