14#include "arcane/impl/internal/DataSynchronizeBuffer.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/internal/MemoryBuffer.h"
19#include "arcane/impl/DataSynchronizeInfo.h"
20#include "arcane/impl/internal/IBufferCopier.h"
22#include "arcane/accelerator/core/Runner.h"
23#include "arcane/utils/FixedArray.h"
24#include "arcane/utils/ITraceMng.h"
40 constexpr Int64 ALIGNEMENT_SIZE = 64;
43 Int64 modulo = original_size % ALIGNEMENT_SIZE;
44 Int64 new_size = original_size;
46 new_size += (ALIGNEMENT_SIZE - modulo);
47 if ((new_size % ALIGNEMENT_SIZE) != 0)
51 void _checkAlignment(
const void* address)
53 auto a =
reinterpret_cast<intptr_t
>(address);
54 intptr_t max_align =
alignof(std::max_align_t);
55 intptr_t modulo = a % max_align;
57 ARCANE_FATAL(
"Address '{0}' is not aligned (align={1}, modulo={2})", address, max_align, modulo);
68 for (
Int32 i = 0; i < nb_rank; ++i)
80 for (
Int32 i = 0; i < nb_rank; ++i)
147 const Int32 nb_item = m_buffer_info->nbItem(rank_index);
157 return m_buffer_info->localIds(index);
175 m_buffer_info = buffer_info;
177 const Int32 nb_data = datatype_sizes.
size();
178 const Int32 nb_rank = buffer_info->nbRank();
184 Int64 data_offset = 0;
186 for (
Int32 i = 0; i < nb_rank; ++i) {
188 Int64 local_buf_nb_byte = 0;
189 for (
Int32 d = 0; d < nb_data; ++d) {
193 const Int64 nb_byte = _applyPadding(nb_item * datatype_sizes[d]);
195 local_buf_nb_byte += nb_byte;
196 data_offset += nb_byte;
209DataSynchronizeBufferBase::
211: m_sync_info(sync_info)
212, m_buffer_copier(copier)
222 return m_sync_info->targetRank(index);
231 m_buffer_copier->barrier();
244 m_nb_rank = m_sync_info->size();
271 Int64 total_compare_buffer = 0;
272 if (m_is_compare_sync_values)
275 Int64 total_size = total_ghost_buffer + total_share_buffer + total_compare_buffer;
278 Int64 share_offset = total_ghost_buffer;
279 Int64 check_sync_offset = share_offset + total_share_buffer;
282 auto s1 = buffer_span.
subspan(0, share_offset);
284 auto s2 = buffer_span.
subspan(share_offset, total_share_buffer);
286 if (m_is_compare_sync_values) {
287 auto s3 = buffer_span.
subspan(check_sync_offset, total_ghost_buffer);
307 m_buffer_copier->copyFromBufferAsync(indexes, local_buffer, var_values);
321 m_buffer_copier->copyToBufferAsync(indexes, local_buffer, var_values);
330 m_is_compare_sync_values = is_compare_sync;
334 if (is_compare_sync) {
338 for (
Int32 i = 0; i < nb_rank; ++i) {
341 m_buffer_copier->copyToBufferAsync(indexes, local_buffer, var_values);
362 if (!m_is_compare_sync_values)
368 Int64 reference_size = reference_bytes.
size();
369 Int64 receive_size = receive_bytes.
size();
370 if (reference_size != receive_size)
371 ARCANE_FATAL(
"Incoherent buffer size ref={0} receive={1}", reference_size, receive_size);
375 bool is_same = std::memcmp(reference_bytes.
data(), receive_bytes.
data(), reference_size) == 0;
405 Int32 data_index = 0;
408 _checkAlignment(local_buffer.
data());
410 copier->copyFromBufferAsync(local_ids, local_buffer, var_values);
425 Int32 data_index = 0;
428 _checkAlignment(local_buffer.
data());
430 copier->copyToBufferAsync(local_ids, local_buffer, var_values);
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Constant view on a contiguous memory region containing fixed-size elements.
constexpr SpanType bytes() const
View in byte form.
constexpr const std::byte * data() const
Pointer to the memory region.
Int64 localBufferSize(Int32 rank_index) const
Size (in bytes) of the local buffer for rank rank_index.
Int64 displacement(Int32 rank_index) const
Displacement in globalBuffer() for the index-th rank.
ConstArrayView< Int32 > localIds(Int32 index) const
Local IDs of entities for rank index.
Int64 m_total_size
Total size (in bytes) of the buffer.
SmallArray< Int64 > m_local_buffer_size
Size (in bytes) of each local buffer.
MutableMemoryView m_memory_view
View onto the memory area of the buffer.
MutableMemoryView localBuffer(Int32 rank_index) const
Buffer for the index-th rank.
ConstArrayView< Int32 > m_datatype_sizes
Size (in bytes) of the type of each data item.
UniqueArray2< Int64 > m_displacements
Offset (in bytes) in globalBuffer() for each data item.
MutableMemoryView dataLocalBuffer(Int32 rank_index, Int32 data_index) const
Buffer for the index-th rank and the data_index-th data item.
void setGlobalBuffer(MutableMemoryView v)
Positions the global buffer.
void initialize(ConstArrayView< Int32 > datatype_sizes, const DataSynchronizeBufferInfoList *buffer_info)
Initializes the buffer information.
void barrier() final
Waits until the copies (copySendAsync() and copyReceiveAsync()) are finished.
Int32 targetRank(Int32 index) const final
Target rank of the index-th rank.
void _allocateBuffers()
Calculates and allocates the buffers necessary for sends and receives for 1D variable synchronization...
BufferInfo m_compare_sync_buffer_info
Buffer for testing if synchronization modified the values of ghost cells.
Int32 nbRank() const final
Number of ranks.
BufferInfo m_share_buffer_info
Buffer for all data of shared entities used for sending.
void _compute(ConstArrayView< Int32 > datatype_sizes)
Computes the information for the synchronization.
BufferInfo m_ghost_buffer_info
Buffer for all data of ghost entities used for reception.
Ref< MemoryBuffer > m_memory
Buffer containing the concatenated data for sending and receiving.
Information for sending (share) or receiving (ghost) messages.
Int32 nbItem(Int32 index) const
Number of entities for rank index.
Information necessary to synchronize entities across a group.
Information about the result of a synchronization.
void barrier() override
Blocks until the copies are finished.
Interface for copying elements between two regions with indexing.
virtual void barrier()=0
Waits until the copies (copySendAsync() and copyReceiveAsync()) are finished.
virtual void copyAllSend()
Copies all data into the send buffer.
virtual void copyAllReceive()
Copies all data from the receive buffer.
virtual void copyReceiveAsync(Int32 index)=0
Copies into the data from the receive buffer of the index-th rank.
virtual void copySendAsync(Int32 index)=0
Copies the data of the index-th rank into the send buffer.
virtual Int32 nbRank() const =0
Number of ranks.
SmallArray< Int32 > m_datatype_sizes
Array containing the sizes of the data types.
void prepareSynchronize(bool is_compare_sync) override
void copyReceiveAsync(Int32 rank_index) final
Copies into the data from the receive buffer of the index-th rank.
SmallArray< MutableMemoryView > m_data_views
View onto the data variables.
void copySendAsync(Int32 rank_index) final
Copies the data of the index-th rank into the send buffer.
Mutable view on a contiguous memory region containing fixed-size elements.
constexpr Int32 datatypeSize() const
Size of the associated data type (1 by default).
constexpr std::byte * data() const
Pointer to the memory region.
constexpr SpanType bytes() const
View in byte form.
Reference to an instance.
DataSynchronizeResult finalizeSynchronize()
Finalizes the synchronization.
void prepareSynchronize(bool is_compare_sync) override
Prepares the synchronization.
FixedArray< Int32, 1 > m_datatype_sizes
Array containing the sizes of the data types.
void copyReceiveAsync(Int32 index) final
Copies into the data from the receive buffer of the index-th rank.
void copySendAsync(Int32 index) final
Copies the data of the index-th rank into the send buffer.
MutableMemoryView dataView()
Memory area containing the values of the data to be synchronized.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
constexpr __host__ __device__ bool empty() const noexcept
Returns true if the array is empty (zero dimension).
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
View of an array of elements of type T.
constexpr __host__ __device__ Span< T, DynExtent > subspan(Int64 abegin, Int64 asize) const
Sub-view starting from element abegin and containing asize elements.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
MutableMemoryView makeMutableMemoryView(void *ptr, Int32 datatype_size, Int64 nb_element)
Creates a mutable memory view.
std::int64_t Int64
Signed integer type of 64 bits.
@ Different
Different values before and after synchronization.
@ Same
Same values before and after synchronization.
std::int32_t Int32
Signed integer type of 32 bits.