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)
43, m_matvar_indexes(platform::getDefaultDataAllocator())
44, m_items_local_id(platform::getDefaultDataAllocator())
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 RunQueue queue = m_material_mng->_internalApi()->runQueue();
222 _computeNbPureAndImpure(local_ids, queue);
224 const Int32 nb_pure = m_nb_pure;
225 const Int32 nb_impure = m_nb_impure;
226 const Int32 total_nb_pure_and_impure = nb_pure + nb_impure;
233 m_constituent_list->resize(total_nb_pure_and_impure);
239 m_matvar_indexes.resize(total_nb_pure_and_impure);
240 m_items_local_id.resize(total_nb_pure_and_impure);
242 const bool is_env = m_component->isEnvironment();
243 AllEnvCellVectorView all_env_cell_view = m_material_mng->view(local_ids);
244 const Int32 component_id = m_component->id();
247 auto env_component_getter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 index) -> ComponentCell {
248 AllEnvCell all_env_cell = all_env_cell_view[index];
249 for (EnvCell ec : all_env_cell.subEnvItems()) {
250 if (ec.componentId() == component_id)
257 auto mat_component_getter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 index) -> ComponentCell {
258 AllEnvCell all_env_cell = all_env_cell_view[index];
259 for (EnvCell ec : all_env_cell.subEnvItems()) {
260 for (MatCell mc : ec.subMatItems())
261 if (mc.componentId() == component_id)
268 const bool do_new = m_material_mng->_internalApi()->isUseAcceleratorForConstituentItemVector();
269 SetItemHelper helper(do_new);
271 helper.setItems(
this, env_component_getter_lambda, local_ids, queue);
273 helper.setItems(
this, mat_component_getter_lambda, local_ids, queue);
277 const bool do_lazy_evaluation =
true;
278 if (do_lazy_evaluation)
279 m_part_data->setNeedRecompute();
281 _recomputePartData();
287void ConstituentItemVectorImpl::
288_computeNbPureAndImpure(SmallSpan<const Int32> local_ids, RunQueue& queue)
290 IMeshComponent* component = m_component;
291 const bool is_env = component->isEnvironment();
292 AllEnvCellVectorView all_env_cell_view = m_material_mng->view(local_ids);
293 const Int32 component_id = m_component->id();
296 Accelerator::ReducerSum2<Int32> nb_pure(command);
297 Accelerator::ReducerSum2<Int32> nb_impure(command);
303 for (EnvCell ec : all_env_cell.subEnvItems()) {
304 if (ec.componentId() == component_id) {
305 MatVarIndex idx = ec._varIndex();
306 if (idx.arrayIndex() == 0)
309 nb_impure.combine(1);
317 for (EnvCell env_cell : all_env_cell.subEnvItems()) {
318 for (MatCell mc : env_cell.subMatItems()) {
319 if (mc.componentId() == component_id) {
320 MatVarIndex idx = mc._varIndex();
321 if (idx.arrayIndex() == 0)
324 nb_impure.combine(1);
331 m_nb_pure = nb_pure.reducedValue();
332 m_nb_impure = nb_impure.reducedValue();
338void ConstituentItemVectorImpl::
342 auto mvi_pure_view = m_matvar_indexes.subView(0, m_nb_pure);
343 auto mvi_impure_view = m_matvar_indexes.subView(m_nb_pure, m_nb_impure);
344 m_part_data->_setFromMatVarIndexes(mvi_pure_view, mvi_impure_view);
350ComponentItemVectorView ConstituentItemVectorImpl::
353 return { m_component, m_matvar_indexes,
354 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(MatItemNameType, iter_name, env_or_mat_vector,...)
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.
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.
Helper pour positionner les entités du vecteur.
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.