14#include "arcane/materials/internal/ConstituentItemVectorImpl.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/FatalErrorException.h"
19#include "arcane/core/materials/IMeshMaterialMng.h"
21#include "arcane/core/materials/internal/IMeshComponentInternal.h"
22#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
24#include "arcane/accelerator/core/RunQueue.h"
27#include "arcane/accelerator/Partitioner.h"
39ConstituentItemVectorImpl::
40ConstituentItemVectorImpl(IMeshComponent* component)
41: m_material_mng(component->materialMng())
42, m_component(component)
45, m_part_data(std::make_unique<MeshComponentPartData>(component, String()))
46, m_recompute_part_data_functor(this, &ConstituentItemVectorImpl::_recomputePartData)
49 if (component->isMaterial())
50 level = LEVEL_MATERIAL;
51 else if (component->isEnvironment())
52 level = LEVEL_ENVIRONMENT;
55 m_component_shared_info = m_material_mng->_internalApi()->componentItemSharedInfo(level);
56 m_constituent_list = std::make_unique<ConstituentItemLocalIdList>(m_component_shared_info, String());
57 m_part_data->setRecomputeFunctor(&m_recompute_part_data_functor);
63ConstituentItemVectorImpl::
64ConstituentItemVectorImpl(
const ComponentItemVectorView& rhs)
65: ConstituentItemVectorImpl(rhs.component())
67 RunQueue& queue = m_material_mng->_internalApi()->runQueue();
68 m_constituent_list->copy(rhs._constituentItemListView());
69 m_matvar_indexes.copy(rhs._matvarIndexes());
70 m_items_local_id.copy(rhs._internalLocalIds());
71 m_part_data->_setFromMatVarIndexes(rhs._matvarIndexes(), queue);
87 : m_use_new_impl(use_new_impl)
92 template <
typename ConstituentGetterLambda>
93 void setItems(ConstituentItemVectorImpl* vector_impl,
94 ConstituentGetterLambda constituent_getter_lambda,
99 bool m_use_new_impl =
true;
105template <
typename ConstituentGetterLambda>
void
106ConstituentItemVectorImpl::SetItemHelper::
107setItems(ConstituentItemVectorImpl* vector_impl, ConstituentGetterLambda constituent_getter_lambda,
112 SmallSpan<Int32> items_local_id = vector_impl->m_items_local_id.smallSpan();
114 const bool is_env = vector_impl->m_component->isEnvironment();
115 const Int32 component_id = vector_impl->m_component->id();
117 const Int32 nb_pure = vector_impl->m_nb_pure;
119 Int32 pure_index = 0;
120 Int32 impure_index = nb_pure;
122 const Int32 nb_id = local_ids.
size();
126 auto setter_unselected = [=] ARCCORE_HOST_DEVICE(Int32, Int32) {
128 auto generic_setter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 index,
ComponentCell cc) {
131 item_indexes[index] = cii;
132 matvar_indexes[index] = idx;
137 if (m_use_new_impl) {
139 auto select_pure = [=] ARCCORE_HOST_DEVICE(Int32 index) {
146 auto select_impure = [=] ARCCORE_HOST_DEVICE(Int32 index) {
147 ComponentCell cc = constituent_getter_lambda(index);
150 return (cc._varIndex().arrayIndex() != 0);
152 auto setter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
153 ComponentCell cc = constituent_getter_lambda(index);
155 generic_setter_lambda(output_index, cc);
157 auto setter_pure = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
158 setter_lambda(index, output_index);
160 auto setter_impure = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
161 setter_lambda(index, output_index + nb_pure);
164 generic_partitioner.applyWithIndex(nb_id, setter_pure, setter_impure, setter_unselected,
165 select_pure, select_impure, A_FUNCINFO);
173 AllEnvCell all_env_cell = *iallenvcell;
174 for (EnvCell ec : all_env_cell.subEnvItems()) {
175 if (ec.componentId() == component_id) {
176 MatVarIndex idx = ec._varIndex();
177 ConstituentItemIndex cii = ec._constituentItemIndex();
178 Int32& base_index = (idx.arrayIndex() == 0) ? pure_index : impure_index;
179 item_indexes[base_index] = cii;
180 matvar_indexes[base_index] = idx;
181 items_local_id[base_index] = all_env_cell.globalCellId();
190 AllEnvCell all_env_cell = *iallenvcell;
191 for (EnvCell env_cell : all_env_cell.subEnvItems()) {
192 for (MatCell mc : env_cell.subMatItems()) {
193 if (mc.componentId() == component_id) {
194 MatVarIndex idx = mc._varIndex();
195 ConstituentItemIndex cii = mc._constituentItemIndex();
196 Int32& base_index = (idx.arrayIndex() == 0) ? pure_index : impure_index;
197 item_indexes[base_index] = cii;
198 matvar_indexes[base_index] = idx;
199 items_local_id[base_index] = all_env_cell.globalCellId();
217void ConstituentItemVectorImpl::
218_setItems(SmallSpan<const Int32> local_ids)
220 const bool do_new_impl = m_material_mng->_internalApi()->isUseAcceleratorForConstituentItemVector();
222 RunQueue queue = m_material_mng->_internalApi()->runQueue();
225 _computeNbPureAndImpure(local_ids, queue);
227 _computeNbPureAndImpureLegacy(local_ids);
229 const Int32 nb_pure = m_nb_pure;
230 const Int32 nb_impure = m_nb_impure;
231 const Int32 total_nb_pure_and_impure = nb_pure + nb_impure;
238 m_constituent_list->resize(total_nb_pure_and_impure);
244 m_matvar_indexes.resize(total_nb_pure_and_impure);
245 m_items_local_id.resize(total_nb_pure_and_impure);
247 const bool is_env = m_component->isEnvironment();
248 AllEnvCellVectorView all_env_cell_view = m_material_mng->view(local_ids);
249 const Int32 component_id = m_component->id();
252 auto env_component_getter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 index) -> ComponentCell {
253 AllEnvCell all_env_cell = all_env_cell_view[index];
254 for (EnvCell ec : all_env_cell.subEnvItems()) {
255 if (ec.componentId() == component_id)
262 auto mat_component_getter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 index) -> ComponentCell {
263 AllEnvCell all_env_cell = all_env_cell_view[index];
264 for (EnvCell ec : all_env_cell.subEnvItems()) {
265 for (MatCell mc : ec.subMatItems())
266 if (mc.componentId() == component_id)
273 SetItemHelper helper(do_new_impl);
275 helper.setItems(
this, env_component_getter_lambda, local_ids, queue);
277 helper.setItems(
this, mat_component_getter_lambda, local_ids, queue);
281 const bool do_lazy_evaluation =
true;
282 if (do_lazy_evaluation)
283 m_part_data->setNeedRecompute();
285 _recomputePartData();
291void ConstituentItemVectorImpl::
292_computeNbPureAndImpure(SmallSpan<const Int32> local_ids, RunQueue& queue)
294 IMeshComponent* component = m_component;
295 const bool is_env = component->isEnvironment();
296 AllEnvCellVectorView all_env_cell_view = m_material_mng->view(local_ids);
297 const Int32 component_id = m_component->id();
300 Accelerator::ReducerSum2<Int32> nb_pure(command);
301 Accelerator::ReducerSum2<Int32> nb_impure(command);
307 for (EnvCell ec : all_env_cell.subEnvItems()) {
308 if (ec.componentId() == component_id) {
309 MatVarIndex idx = ec._varIndex();
310 if (idx.arrayIndex() == 0)
313 nb_impure.combine(1);
321 for (EnvCell env_cell : all_env_cell.subEnvItems()) {
322 for (MatCell mc : env_cell.subMatItems()) {
323 if (mc.componentId() == component_id) {
324 MatVarIndex idx = mc._varIndex();
325 if (idx.arrayIndex() == 0)
328 nb_impure.combine(1);
335 m_nb_pure = nb_pure.reducedValue();
336 m_nb_impure = nb_impure.reducedValue();
344void ConstituentItemVectorImpl::
345_computeNbPureAndImpureLegacy(SmallSpan<const Int32> local_ids)
347 IMeshComponent* component = m_component;
348 const bool is_env = component->isEnvironment();
349 AllEnvCellVectorView all_env_cell_view = m_material_mng->view(local_ids);
350 const Int32 component_id = m_component->id();
358 AllEnvCell all_env_cell = *iallenvcell;
359 for (EnvCell ec : all_env_cell.subEnvItems()) {
360 if (ec.componentId() == component_id) {
361 MatVarIndex idx = ec._varIndex();
362 if (idx.arrayIndex() == 0)
372 AllEnvCell all_env_cell = *iallenvcell;
373 for (EnvCell env_cell : all_env_cell.subEnvItems()) {
374 for (MatCell mc : env_cell.subMatItems()) {
375 if (mc.componentId() == component_id) {
376 MatVarIndex idx = mc._varIndex();
377 if (idx.arrayIndex() == 0)
388 m_nb_impure = nb_impure;
394void ConstituentItemVectorImpl::
398 auto mvi_pure_view = m_matvar_indexes.subView(0, m_nb_pure);
399 auto mvi_impure_view = m_matvar_indexes.subView(m_nb_pure, m_nb_impure);
400 m_part_data->_setFromMatVarIndexes(mvi_pure_view, mvi_impure_view);
406ComponentItemVectorView ConstituentItemVectorImpl::
409 return { m_component, m_matvar_indexes,
410 m_constituent_list->view(), m_items_local_id };
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Types et fonctions pour gérer les synchronisations sur les accélérateurs.
Types et macros pour gérer les boucles sur les accélérateurs.
Types et macros pour gérer les énumérations des matériaux et milieux sur les accélérateurs.
#define RUNCOMMAND_MAT_ENUMERATE(ConstituentItemNameType, iter_name, env_or_mat_container,...)
Macro pour itérer sur un matériau ou un milieu.
Algorithme générique de partitionnement d'une liste.
File d'exécution pour un accélérateur.
Helper pour positionner les entités du vecteur.
Représente un composant d'une maille multi-matériau.
__host__ __device__ CellLocalId globalCellId() const
localId() de la maille globale
__host__ __device__ bool null() const
Indique s'il s'agit de la maille nulle.
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.
Vue d'un tableau d'éléments de type T.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
Active toujours les traces dans les parties Arcane concernant les matériaux.
IMemoryAllocator * getDefaultDataAllocator()
Allocateur par défaut pour les données.