14#include "arcane/core/internal/MachineShMemWinMemoryAllocator.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/ITraceMng.h"
19#include "arcane/core/IParallelMng.h"
20#include "arcane/core/MachineShMemWinBase.h"
22#include "arccore/common/AllocatedMemoryInfo.h"
35MachineShMemWinMemoryAllocator::
49 return {
nullptr, 0 };
53 const Int64 new_size_with_offset = offset + new_size;
55#ifdef ARCANE_DEBUG_ALLOCATOR
56 m_pm->traceMng()->debug() <<
"(1/2) MachineShMemWinMemoryAllocator::allocate"
57 <<
" -- ptr.size() : " << new_size
58 <<
" -- offset : " << offset
59 <<
" -- win_size (offset+ptr.size()) : " << new_size_with_offset;
64 std::byte* addr_base = win_ptr->segmentView().data();
65 std::byte* addr_after_offset = addr_base + offset;
67 std::memcpy(addr_base, &win_ptr, offset);
69#ifdef ARCANE_DEBUG_ALLOCATOR
70 m_pm->traceMng()->debug() <<
"(2/2) MachineShMemWinMemoryAllocator::allocate"
71 <<
" -- addr_base : " << addr_base
72 <<
" -- addr_after_offset : " << addr_after_offset;
75 return { addr_after_offset, new_size };
92 const Int64 new_size_with_offset = offset + new_size;
97 win->
resize(new_size_with_offset);
100 std::byte* addr_after_offset = addr_base + offset;
102#ifdef ARCANE_DEBUG_ALLOCATOR
103 m_pm->traceMng()->debug() <<
"MachineShMemWinMemoryAllocator::reallocate"
104 <<
" -- old_size : " << d_old_size
105 <<
" -- old_addr_base : " << d_old_addr_base
106 <<
" -- new ptr.size() : " << new_size
107 <<
" -- offset : " << offset
108 <<
" -- win_size (offset+ptr.size()) : " << new_size_with_offset
109 <<
" -- addr_base : " << addr_base
110 <<
" -- addr_after_offset : " << addr_after_offset;
113 return { addr_after_offset, new_size };
119void MachineShMemWinMemoryAllocator::
130#ifdef ARCANE_DEBUG_ALLOCATOR
131 m_pm->traceMng()->debug() <<
"MachineShMemWinMemoryAllocator::deallocate"
132 <<
" -- ptr.size() : " << ptr.
size()
133 <<
" -- win_size (offset+ptr.size()) : " << win_ptr->
segmentView().
size()
146 return _windowBase(ptr)->machineRanks();
152void MachineShMemWinMemoryAllocator::
153barrier(AllocatedMemoryInfo ptr)
155 _windowBase(ptr)->barrier();
161Span<std::byte> MachineShMemWinMemoryAllocator::
162segmentView(AllocatedMemoryInfo ptr)
164 const Span<std::byte> view = _windowBase(ptr)->segmentView();
165 constexpr Int64 offset =
sizeof(MachineShMemWinBase*);
166 return view.subSpan(offset, view.size() - offset);
172Span<std::byte> MachineShMemWinMemoryAllocator::
173segmentView(AllocatedMemoryInfo ptr, Int32 rank)
175 const Span<std::byte> view = _windowBase(ptr)->segmentView(rank);
176 constexpr Int64 offset =
sizeof(MachineShMemWinBase*);
177 return view.subSpan(offset, view.size() - offset);
183MachineShMemWinBase* MachineShMemWinMemoryAllocator::
184_windowBase(AllocatedMemoryInfo ptr)
186 constexpr Int64 offset =
sizeof(MachineShMemWinBase*);
188 std::byte* addr_after_offset =
static_cast<std::byte*
>(ptr.baseAddress());
189 std::byte* addr_base = addr_after_offset - offset;
191 MachineShMemWinBase* win_ptr = *
reinterpret_cast<MachineShMemWinBase**
>(addr_base);
193#ifdef ARCANE_DEBUG_ALLOCATOR
194 std::cout <<
"MachineShMemWinMemoryAllocator::_windowBase"
195 <<
" -- ptr.size() : " << ptr.
size()
196 <<
" -- offset : " << offset
197 <<
" -- addr_base : " << addr_base
198 <<
" -- addr_after_offset : " << addr_after_offset << std::endl;
203 Int64 size_obj = win_ptr->segmentView().size();
204 if (size_obj != offset + ptr.size()) {
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Information about an allocated memory region.
void * baseAddress() const
Address of the start of the allocated region.
Int64 size() const
Size in bytes of the used memory region. (-1) if unknown.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface of the parallelism manager for a subdomain.
Class allowing the creation of a shared memory window between the subdomains of the same node.
void resize(Int64 new_nb_elem_segment)
Method to resize our segment.
Span< std::byte > segmentView()
Method to obtain a view of our segment.
AllocatedMemoryInfo allocate(MemoryAllocationArgs, Int64 new_size) override
Allocates memory for new_size bytes and returns the pointer.
Class containing information to specialize allocations.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
@ ReduceMax
Maximum of values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.