Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MeshMaterialSynchronizeBuffer.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MeshMaterialSynchronizeBuffer.cc (C) 2000-2024 */
9/* */
10/* Gestion des buffers pour la synchronisation de variables matériaux. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/materials/IMeshMaterialSynchronizeBuffer.h"
15
16#include "arcane/utils/UniqueArray.h"
17#include "arcane/utils/PlatformUtils.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane::Materials
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29class MultiBufferMeshMaterialSynchronizeBuffer
31{
32 public:
33
34 struct BufferInfo
35 {
36 explicit BufferInfo(IMemoryAllocator* allocator)
37 : m_send_buffer(allocator)
38 , m_receive_buffer(allocator)
39 {
40 }
41
42 void reset()
43 {
44 m_send_size = 0;
45 m_receive_size = 0;
46 m_send_buffer.clear();
47 m_receive_buffer.clear();
48 }
49 Int32 m_send_size = 0;
50 Int32 m_receive_size = 0;
51 UniqueArray<Byte> m_send_buffer;
52 UniqueArray<Byte> m_receive_buffer;
53 };
54
55 public:
56
57 explicit MultiBufferMeshMaterialSynchronizeBuffer(IMemoryAllocator* allocator)
58 : m_default_buffer_info(allocator)
59 {
60 }
61
62 Int32 nbRank() const override { return m_nb_rank; }
63 void setNbRank(Int32 nb_rank) override
64 {
65 m_nb_rank = nb_rank;
66 m_buffer_infos.resize(nb_rank,m_default_buffer_info);
67 for (auto& x : m_buffer_infos)
68 x.reset();
69 }
70 Span<Byte> sendBuffer(Int32 index) override
71 {
72 return m_buffer_infos[index].m_send_buffer;
73 }
74 void setSendBufferSize(Int32 index, Int32 new_size) override
75 {
76 m_buffer_infos[index].m_send_size = new_size;
77 }
79 {
80 return m_buffer_infos[index].m_receive_buffer;
81 }
82 void setReceiveBufferSize(Int32 index, Int32 new_size) override
83 {
84 m_buffer_infos[index].m_receive_size = new_size;
85 }
86 void allocate() override
87 {
88 m_total_size = 0;
89 for (auto& x : m_buffer_infos) {
90 x.m_send_buffer.resize(x.m_send_size);
91 x.m_receive_buffer.resize(x.m_receive_size);
92 m_total_size += x.m_send_size + x.m_receive_size;
93 }
94 }
95 Int64 totalSize() const override { return m_total_size; }
96
97 public:
98
99 Int32 m_nb_rank = 0;
100 Int64 m_total_size = 0;
101 BufferInfo m_default_buffer_info;
102 UniqueArray<BufferInfo> m_buffer_infos;
103};
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108class OneBufferMeshMaterialSynchronizeBuffer
110{
111 public:
112
114 {
115 void reset()
116 {
117 m_send_size = 0;
118 m_receive_size = 0;
119 m_send_index = 0;
120 m_receive_index = 0;
121 }
122
123 Span<Byte> sendBuffer(Span<Byte> full_buffer) const
124 {
125 return full_buffer.subspan(m_send_index,m_send_size);
126 }
127 Span<Byte> receiveBuffer(Span<Byte> full_buffer) const
128 {
129 return full_buffer.subspan(m_receive_index,m_receive_size);
130 }
131
132 Int32 m_send_size = 0;
133 Int32 m_receive_size = 0;
134 Int64 m_send_index = 0;
135 Int64 m_receive_index = 0;
136 };
137
138 public:
139
140 explicit OneBufferMeshMaterialSynchronizeBuffer(IMemoryAllocator* allocator)
141 : m_buffer(allocator){}
142
143 public:
144 Int32 nbRank() const override { return m_nb_rank; }
145 void setNbRank(Int32 nb_rank) override
146 {
147 m_nb_rank = nb_rank;
148 m_buffer_infos.resize(nb_rank);
149 for (auto& x : m_buffer_infos)
150 x.reset();
151 }
153 {
154 return m_buffer_infos[index].sendBuffer(m_buffer);
155 }
156 void setSendBufferSize(Int32 index, Int32 new_size) override
157 {
158 m_buffer_infos[index].m_send_size = new_size;
159 }
161 {
162 return m_buffer_infos[index].receiveBuffer(m_buffer);
163 }
164 void setReceiveBufferSize(Int32 index, Int32 new_size) override
165 {
166 m_buffer_infos[index].m_receive_size = new_size;
167 }
168 void allocate() override
169 {
170 Int64 total_send_size = 0;
171 Int64 total_receive_size = 0;
172 for (auto& x : m_buffer_infos) {
173 total_send_size += x.m_send_size;
174 total_receive_size += x.m_receive_size;
175 }
176 m_buffer.resize(total_send_size+total_receive_size);
177 Int64 send_index = 0;
178 Int64 receive_index = total_send_size;
179 for (auto& x : m_buffer_infos) {
180 x.m_send_index = send_index;
181 x.m_receive_index = receive_index;
182 send_index += x.m_send_size;
183 receive_index += x.m_receive_size;
184 }
185 }
186 Int64 totalSize() const override { return m_buffer.largeSize(); }
187
188 public:
189
190 Int32 m_nb_rank = 0;
191 UniqueArray<BufferInfo> m_buffer_infos;
192 UniqueArray<Byte> m_buffer;
193};
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198namespace impl
199{
201makeMultiBufferMeshMaterialSynchronizeBufferRef(eMemoryRessource memory_ressource)
202{
203 auto* a = MemoryUtils::getAllocator(memory_ressource);
206}
207
208extern "C++" ARCANE_MATERIALS_EXPORT Ref<IMeshMaterialSynchronizeBuffer>
209makeMultiBufferMeshMaterialSynchronizeBufferRef()
210{
211 return makeMultiBufferMeshMaterialSynchronizeBufferRef(eMemoryRessource::Host);
212}
213
214extern "C++" ARCANE_MATERIALS_EXPORT Ref<IMeshMaterialSynchronizeBuffer>
215makeOneBufferMeshMaterialSynchronizeBufferRef(eMemoryRessource memory_ressource)
216{
217 auto* a = MemoryUtils::getAllocator(memory_ressource);
218 auto* v = new OneBufferMeshMaterialSynchronizeBuffer(a);
220}
221}
222/*---------------------------------------------------------------------------*/
223/*---------------------------------------------------------------------------*/
224
225} // End namespace Arcane::Materials
226
227/*---------------------------------------------------------------------------*/
228/*---------------------------------------------------------------------------*/
Fonctions de gestion mémoire et des allocateurs.
Interface d'un allocateur pour la mémoire.
Interface des buffers pour la synchronisation de variables matériaux.
void allocate() override
Alloue la mémoire pour les buffers.
void setReceiveBufferSize(Int32 index, Int32 new_size) override
Positionne le nombre d'éléments pour le i-ème buffer de réception.
Span< Byte > sendBuffer(Int32 index) override
Buffer d'envoi pour le i-ème buffer.
void setNbRank(Int32 nb_rank) override
Positionne le nombre de rangs. Cela invalide les buffers d'envoi et de réception.
Int64 totalSize() const override
Taille totale allouée pour les buffers.
void setSendBufferSize(Int32 index, Int32 new_size) override
Positionne le nombre d'éléments pour le i-ème buffer d'envoi.
Span< Byte > receiveBuffer(Int32 index) override
Buffer d'envoi pour le i-\ème buffer.
Span< Byte > receiveBuffer(Int32 index) override
Buffer d'envoi pour le i-\ème buffer.
Int64 totalSize() const override
Taille totale allouée pour les buffers.
void allocate() override
Alloue la mémoire pour les buffers.
Span< Byte > sendBuffer(Int32 index) override
Buffer d'envoi pour le i-ème buffer.
void setReceiveBufferSize(Int32 index, Int32 new_size) override
Positionne le nombre d'éléments pour le i-ème buffer de réception.
void setNbRank(Int32 nb_rank) override
Positionne le nombre de rangs. Cela invalide les buffers d'envoi et de réception.
void setSendBufferSize(Int32 index, Int32 new_size) override
Positionne le nombre d'éléments pour le i-ème buffer d'envoi.
Référence à une instance.
Vue d'un tableau d'éléments de type T.
Definition Span.h:633
constexpr __host__ __device__ Span< T, DynExtent > subspan(Int64 abegin, Int64 asize) const
Sous-vue à partir de l'élément abegin et contenant asize éléments.
Definition Span.h:721
Vecteur 1D de données avec sémantique par valeur (style STL).
Active toujours les traces dans les parties Arcane concernant les matériaux.
ARCCORE_COMMON_EXPORT IMemoryAllocator * getAllocator(eMemoryResource mem_resource)
Allocateur par défaut pour la ressource mem_resource.
std::int64_t Int64
Type entier signé sur 64 bits.
MATERIALS_BEGIN_NAMESPACE class ARCANE_MATERIALS_EXPORT(64) SimdMatVarIndex
Indexeur SIMD sur un composant.
Arcane::eMemoryResource eMemoryRessource
Typedef pour la version Arcane historique (avec 2's')
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
std::int32_t Int32
Type entier signé sur 32 bits.