Arcane  4.1.11.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ComponentSimd.h
Aller à la documentation de ce fichier.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* ComponentSimd.h (C) 2000-2026 */
9/* */
10/* Support de la vectorisation pour les matériaux et milieux. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MATERIALS_COMPONENTSIMD_H
13#define ARCANE_MATERIALS_COMPONENTSIMD_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
22
25
26#include "arcane/materials/MatItem.h"
27#include "arcane/materials/MatItemEnumerator.h"
28#include "arcane/materials/ComponentPartItemVectorView.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33#ifdef __INTEL_COMPILER
34# define A_ALIGNED_64 __attribute__((align_value(64)))
35#else
36# define A_ALIGNED_64
37#endif
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42namespace Arcane::Materials
43{
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
50class ARCANE_MATERIALS_EXPORT ARCANE_ALIGNAS(64) SimdMatVarIndex
51{
52 public:
53 typedef SimdEnumeratorBase::SimdIndexType SimdIndexType;
54 public:
55
56 SimdMatVarIndex(Int32 array_index,SimdIndexType value_index)
57 : m_value_index(value_index), m_array_index(array_index)
58 {
59 }
60 SimdMatVarIndex(){}
61
62 public:
63
65 Int32 arrayIndex() const { return m_array_index; }
66
68 const SimdIndexType& valueIndex() const { return m_value_index; }
69
70 private:
71
72 SimdIndexType m_value_index;
73 Int32 m_array_index;
74};
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
82class ARCANE_MATERIALS_EXPORT ComponentPartSimdCellEnumerator
83: public SimdEnumeratorBase
84{
85 protected:
86 ComponentPartSimdCellEnumerator(IMeshComponent* component,Int32 component_part_index,
87 Int32ConstArrayView item_indexes)
88 : SimdEnumeratorBase(item_indexes), m_component_part_index(component_part_index), m_component(component)
89 {
90 }
91 public:
92 static ComponentPartSimdCellEnumerator create(ComponentPartItemVectorView v)
93 {
94 return ComponentPartSimdCellEnumerator(v.component(),v.componentPartIndex(),v.valueIndexes());
95 }
96 public:
97
98 SimdMatVarIndex _varIndex() const { return SimdMatVarIndex(m_component_part_index,*_currentSimdIndex()); }
99
100 operator SimdMatVarIndex() const
101 {
102 return _varIndex();
103 }
104
105 protected:
106 Integer m_component_part_index;
107 IMeshComponent* m_component;
108};
109
112{
113 return ComponentPartSimdCellEnumerator::create(v);
114}
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
119#define ENUMERATE_SIMD_COMPONENTCELL(iname,env) \
120 A_ENUMERATE_COMPONENTCELL(ComponentPartSimdCell,iname,env)
121
122/*---------------------------------------------------------------------------*/
123/*---------------------------------------------------------------------------*/
124
125template<typename Lambda> void
126simple_simd_env_loop(ComponentPartItemVectorView pure_items,
127 ComponentPartItemVectorView impure_items,
128 const Lambda& lambda)
129{
131 lambda(mvi);
132 }
133 ENUMERATE_SIMD_COMPONENTCELL(mvi,impure_items){
134 lambda(mvi);
135 }
136}
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
140
141class ARCANE_MATERIALS_EXPORT LoopFunctorEnvPartSimdCell
142{
143 public:
144 typedef const SimdMatVarIndex& IterType;
145 public:
146 LoopFunctorEnvPartSimdCell(ComponentPartItemVectorView pure_items,
147 ComponentPartItemVectorView impure_items)
148 : m_pure_items(pure_items), m_impure_items(impure_items){}
149 public:
150 static LoopFunctorEnvPartSimdCell create(const EnvCellVector& env);
151 static LoopFunctorEnvPartSimdCell create(IMeshEnvironment* env);
152 public:
153 template<typename Lambda>
154 void operator<<(Lambda&& lambda)
155 {
156 simple_simd_env_loop(m_pure_items,m_impure_items,lambda);
157 }
158 private:
159 ComponentPartItemVectorView m_pure_items;
160 ComponentPartItemVectorView m_impure_items;
161};
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
185#define ENUMERATE_COMPONENTITEM_LAMBDA(iter_type,iter,container)\
186 Arcane::Materials:: LoopFunctor ## iter_type :: create ( (container) ) << [=]( Arcane::Materials:: LoopFunctor ## iter_type :: IterType iter)
187
188/*---------------------------------------------------------------------------*/
189/*---------------------------------------------------------------------------*/
193class MatVariableViewBase
194{
195 public:
196 MatVariableViewBase(IMeshMaterialVariable* var) : m_variable(var)
197 {
198 }
199 public:
200 IMeshMaterialVariable* variable() const { return m_variable; }
201 private:
202 IMeshMaterialVariable* m_variable;
203};
204
205/*---------------------------------------------------------------------------*/
206/*---------------------------------------------------------------------------*/
210template<typename ItemType,typename DataType>
211class MatItemVariableScalarInViewT
212: public MatVariableViewBase
213{
214 private:
215
216 typedef MatVarIndex ItemIndexType;
217 typedef A_ALIGNED_64 DataType* DataTypeAlignedPtr;
218
219 public:
220
221 MatItemVariableScalarInViewT(IMeshMaterialVariable* var,ArrayView<DataType>* v)
222 : MatVariableViewBase(var), m_value(v), m_value0(v[0].unguardedBasePointer()){}
223
225 typename SimdTypeTraits<DataType>::SimdType
226 operator[](const SimdMatVarIndex& mvi) const
227 {
228 typedef typename SimdTypeTraits<DataType>::SimdType SimdType;
229 return SimdType(m_value[mvi.arrayIndex()].data(),mvi.valueIndex());
230 }
231
233 DataType operator[](ItemIndexType mvi) const
234 {
235 return this->m_value[mvi.arrayIndex()][mvi.valueIndex()];
236 }
237
239 DataType operator[](ComponentItemLocalId lid) const
240 {
241 return this->m_value[lid.localId().arrayIndex()][lid.localId().valueIndex()];
242 }
243
245 DataType operator[](PureMatVarIndex pmvi) const
246 {
247 return this->m_value0[pmvi.valueIndex()];
248 }
249
251 DataType value(ItemIndexType mvi) const
252 {
253 return this->m_value[mvi.arrayIndex()][mvi.valueIndex()];
254 }
255
256 DataType value0(PureMatVarIndex idx) const
257 {
258 return this->m_value0[idx.valueIndex()];
259 }
260
263 {
264 return this->operator[](mc._varIndex());
265 }
266
268 DataType operator[](EnvCellEnumerator mc) const
269 {
270 return this->operator[](mc._varIndex());
271 }
272
273 private:
274 ArrayView<DataType>* m_value;
275 DataTypeAlignedPtr m_value0;
276};
277
278/*---------------------------------------------------------------------------*/
279/*---------------------------------------------------------------------------*/
283template<typename ItemType,typename DataType>
284class MatItemVariableScalarOutViewT
285: public MatVariableViewBase
286{
287 private:
288
289 typedef MatVarIndex ItemIndexType;
290 typedef A_ALIGNED_64 DataType* DataTypeAlignedPtr;
291
292 public:
293
294 MatItemVariableScalarOutViewT(IMeshMaterialVariable* var,ArrayView<DataType>* v)
295 : MatVariableViewBase(var), m_value(v), m_value0(v[0].unguardedBasePointer()){}
296
298 SimdSetter<DataType> operator[](const SimdMatVarIndex& mvi) const
299 {
300 return SimdSetter<DataType>(m_value[mvi.arrayIndex()].data(),mvi.valueIndex());
301 }
302
304 DataType& operator[](ItemIndexType mvi) const
305 {
306 return this->m_value[mvi.arrayIndex()][mvi.valueIndex()];
307 }
308
310 DataType& operator[](ComponentItemLocalId lid) const
311 {
312 return this->m_value[lid.localId().arrayIndex()][lid.localId().valueIndex()];
313 }
314
315 DataType& operator[](PureMatVarIndex pmvi) const
316 {
317 return this->m_value0[pmvi.valueIndex()];
318 }
319
321 DataType& value(ItemIndexType mvi) const
322 {
323 return this->m_value[mvi.arrayIndex()][mvi.valueIndex()];
324 }
325
326 DataType& value0(PureMatVarIndex idx) const
327 {
328 return this->m_value0[idx.valueIndex()];
329 }
330
333 {
334 return this->operator[](mc._varIndex());
335 }
336
338 DataType& operator[](EnvCellEnumerator mc) const
339 {
340 return this->operator[](mc._varIndex());
341 }
342
343 private:
344 ArrayView<DataType>* m_value;
345 DataTypeAlignedPtr m_value0;
346};
347
348/*---------------------------------------------------------------------------*/
349/*---------------------------------------------------------------------------*/
353template<typename DataType>
359
360/*---------------------------------------------------------------------------*/
361/*---------------------------------------------------------------------------*/
365template<typename DataType>
371
372/*---------------------------------------------------------------------------*/
373/*---------------------------------------------------------------------------*/
374
375}
376
377/*---------------------------------------------------------------------------*/
378/*---------------------------------------------------------------------------*/
379
380#endif
#define ARCANE_ALIGNAS(value)
Macro pour garantir l'alignement d'une classe sur value octets.
Déclarations des types généraux de Arcane.
Vue en lecture sur une variable scalaire du maillage.
Vue en écriture sur une variable scalaire du maillage.
Vue modifiable d'un tableau d'un type T.
Enumérateur sur les constituants d'une maille.
Variable scalaire sur les mailles d'un matériau du maillage.
Vue sur une partie pure ou partielles des entités d'un composant.
Int32ConstArrayView valueIndexes() const
Liste des valueIndex() de la partie.
Enumérateur SIMD sur une sous-partie (pure ou partielle) d'un sous-ensemble des mailles d'un composan...
constexpr __host__ __device__ MatVarIndex localId() const
Index générique pour accéder aux valeurs d'une variable.
Enumérateur sur les mailles d'un milieu.
Vecteur sur les entités d'un milieu.
Interface d'un composant (matériau ou milieu) d'un maillage.
Interface d'une variable matériau d'un maillage.
Vue en lecture sur une variable scalaire du maillage.
SimdTypeTraits< DataType >::SimdType operator[](const SimdMatVarIndex &mvi) const
Opérateur d'accès vectoriel avec indirection.
DataType operator[](PureMatVarIndex pmvi) const
Opérateur d'accès pour l'entité item.
DataType operator[](ItemIndexType mvi) const
Opérateur d'accès pour l'entité item.
DataType operator[](CellComponentCellEnumerator mc) const
Valeur partielle de la variable pour l'itérateur mc.
DataType operator[](ComponentItemLocalId lid) const
Opérateur d'accès pour l'entité item.
DataType operator[](EnvCellEnumerator mc) const
Valeur partielle de la variable pour l'itérateur mc.
DataType value(ItemIndexType mvi) const
Opérateur d'accès pour l'entité item.
Vue en lecture sur une variable scalaire du maillage.
SimdSetter< DataType > operator[](const SimdMatVarIndex &mvi) const
Opérateur d'accès vectoriel avec indirection.
DataType & value(ItemIndexType mvi) const
Opérateur d'accès pour l'entité item.
DataType & operator[](ItemIndexType mvi) const
Opérateur d'accès pour l'entité item.
DataType & operator[](ComponentItemLocalId lid) const
Opérateur d'accès pour l'entité item.
DataType & operator[](CellComponentCellEnumerator mc) const
Valeur partielle de la variable pour l'itérateur mc.
DataType & operator[](EnvCellEnumerator mc) const
Valeur partielle de la variable pour l'itérateur mc.
Représente un index sur les variables matériaux et milieux.
constexpr __host__ __device__ Int32 arrayIndex() const
Retourne l'indice du tableau de valeur dans la liste des variables.
constexpr __host__ __device__ Int32 valueIndex() const
Retourne l'indice dans le tableau de valeur.
IMeshMaterialVariable * materialVariable() const
Variable matériau associée.
Index d'un Item matériaux pure dans une variable.
Objet permettant de positionner les valeurs d'un vecteur SIMD.
Definition SimdItem.h:320
#define ENUMERATE_COMPONENTITEM(ClassName_, iname, container,...)
Macro générique pour itérer sur les entités d'un matériau ou d'un milieu.
Active toujours les traces dans les parties Arcane concernant les matériaux.
MatItemVariableScalarOutViewT< Cell, DataType > viewOut(CellMaterialVariableScalarRef< DataType > &var)
Vue en écriture.
MatItemVariableScalarInViewT< Cell, DataType > viewIn(const CellMaterialVariableScalarRef< DataType > &var)
Vue en lecture.
ConstituentItemIndexedSelectionEnumerator< ComponentCellVectorView > arcaneImplCreateConstituentEnumerator(ComponentCell, ConstituentItemIndexedSelectionView< ComponentCellVectorView > container)
Enumérateur sur une sélection d'un constituant.
class ARCANE_MATERIALS_EXPORT(64) SimdMatVarIndex
Indexeur SIMD sur un composant.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:482
std::int32_t Int32
Type entier signé sur 32 bits.