14#include "arcane/utils/FatalErrorException.h"
15#include "arcane/utils/ValueChecker.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/ArraySimdPadder.h"
18#include "arcane/utils/IFunctor.h"
20#include "arcane/core/IItemFamily.h"
22#include "arcane/core/materials/IMeshComponent.h"
23#include "arcane/core/materials/ComponentItemInternal.h"
24#include "arcane/core/materials/ComponentPartItemVectorView.h"
25#include "arcane/core/materials/internal/IMeshComponentInternal.h"
27#include "arcane/materials/internal/MeshComponentPartData.h"
29#include "arcane/accelerator/Filter.h"
41MeshComponentPartData::
42MeshComponentPartData(IMeshComponent* component,
const String& debug_name)
43: TraceAccessor(component->traceMng())
44, m_component(component)
45, m_impure_var_idx(component->_internalApi()->variableIndexerIndex() + 1)
49 IMemoryAllocator* allocator = platform::getDefaultDataAllocator();
50 for (Integer i = 0; i < 2; ++i) {
51 m_value_indexes[i] = UniqueArray<Int32>(allocator);
52 m_items_internal_indexes[i] = UniqueArray<Int32>(allocator);
54 if (!debug_name.empty()) {
55 String base_name = String(
"MeshComponentPartData") + debug_name;
56 for (Integer i = 0; i < 2; ++i) {
57 m_value_indexes[i].setDebugName(base_name +
"ValueIndexes" + String::fromNumber(i));
58 m_items_internal_indexes[i].setDebugName(base_name +
"ValueIndexes" + String::fromNumber(i));
74void MeshComponentPartData::
75_notifyValueIndexesChanged(RunQueue* queue)
77 FixedArray<Span<Int32>, 2> indexes;
78 indexes[0] = m_value_indexes[0].span();
79 indexes[1] = m_value_indexes[1].span();
81 bool is_need_padding =
false;
82 for (Int32 i = 0; i < 2; ++i)
83 is_need_padding |= ArraySimdPadder::isNeedPadding(Span<const Int32>(indexes[i]));
93 ArraySimdPadder::applySimdPaddingView(indexes[i]);
97 ArraySimdPadder::applySimdPaddingView(indexes[0]);
98 ArraySimdPadder::applySimdPaddingView(indexes[1]);
105void MeshComponentPartData::
106_setFromMatVarIndexes(ConstArrayView<MatVarIndex> matvar_indexes, RunQueue& queue)
108 Int32 nb_index = matvar_indexes.size();
110 Int32Array& pure_indexes = m_value_indexes[(Int32)eMatPart::Pure];
111 Int32Array& impure_indexes = m_value_indexes[(Int32)eMatPart::Impure];
113 Int32Array& pure_internal_indexes = m_items_internal_indexes[(Int32)eMatPart::Pure];
114 Int32Array& impure_internal_indexes = m_items_internal_indexes[(Int32)eMatPart::Impure];
116 pure_indexes.
resize(nb_index);
117 pure_internal_indexes.resize(nb_index);
121 info(4) <<
"BEGIN_BUILD_PART_DATA_FOR_COMPONENT c=" << m_component->name();
122 Accelerator::GenericFilterer filterer(queue);
126 SmallSpan<Int32> pure_indexes_view(pure_indexes.view());
127 SmallSpan<Int32> pure_internal_indexes_view(pure_internal_indexes.view());
129 auto is_pure_lambda = [=] ARCCORE_HOST_DEVICE(Int32 i) ->
bool {
130 return matvar_indexes[i].arrayIndex() == 0;
132 auto setter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 i, Int32 output_index) {
133 pure_indexes_view[output_index] = matvar_indexes[i].valueIndex();
134 pure_internal_indexes_view[output_index] = i;
136 filterer.applyWithIndex(nb_index, is_pure_lambda, setter_lambda, A_FUNCINFO);
137 Int32 nb_out = filterer.nbOutputElement();
138 pure_indexes.resize(nb_out);
139 pure_internal_indexes.resize(nb_out);
140 nb_impure = nb_index - nb_out;
143 impure_indexes.resize(nb_impure);
144 impure_internal_indexes.resize(nb_impure);
147 SmallSpan<Int32> impure_indexes_view(impure_indexes.view());
148 SmallSpan<Int32> impure_internal_indexes_view(impure_internal_indexes.view());
149 auto is_impure_lambda = [=] ARCCORE_HOST_DEVICE(Int32 i) ->
bool {
150 return matvar_indexes[i].arrayIndex() != 0;
152 auto setter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 i, Int32 output_index) {
153 impure_indexes_view[output_index] = matvar_indexes[i].valueIndex();
154 impure_internal_indexes_view[output_index] = i;
156 filterer.applyWithIndex(nb_index, is_impure_lambda, setter_lambda, A_FUNCINFO);
157 filterer.nbOutputElement();
160 info(4) <<
"BUILD_PART_DATA_FOR_COMPONENT c=" << m_component->name()
161 <<
" nb_pure=" << pure_indexes.size()
162 <<
" nb_impure=" << impure_indexes.size();
164 _notifyValueIndexesChanged(&queue);
170void MeshComponentPartData::
171_setFromMatVarIndexes(ConstArrayView<MatVarIndex> globals,
172 ConstArrayView<MatVarIndex> multiples)
174 Integer nb_global = globals.size();
175 Integer nb_multiple = multiples.size();
178 const auto mat_part =
static_cast<Int32
>(eMatPart::Pure);
181 for (Integer i = 0; i < nb_global; ++i)
182 idx[i] = globals[i].valueIndex();
186 const auto mat_part =
static_cast<Int32
>(eMatPart::Impure);
189 for (Integer i = 0; i < nb_multiple; ++i)
190 idx[i] = multiples[i].valueIndex();
193 _notifyValueIndexesChanged(
nullptr);
199void MeshComponentPartData::
200_setConstituentListView(
const ConstituentItemLocalIdListView& v)
202 m_constituent_list_view = v;
208void MeshComponentPartData::
211 info(4) <<
"CHECK_VALID_COMPONENT_PART_DATA c=" << m_component->name();
212 _checkNeedRecompute();
213 ValueChecker vc(A_FUNCINFO);
215 for (Integer i = 0; i < 2; ++i) {
216 Int32 var_idx = (i == 0) ? 0 : m_impure_var_idx;
219 Integer nb_item = indexes.size();
220 vc.areEqual(nb_item, item_indexes.size(),
"Indexes size");
221 for (Integer k = 0; k < nb_item; ++k) {
222 MatVarIndex mvi(var_idx, indexes[k]);
223 MatVarIndex component_mvi = m_constituent_list_view._matVarIndex(item_indexes[k]);
224 if (mvi != component_mvi) {
225 info() <<
"Bad MatVarIndex i=" << i <<
" k=" << k
226 <<
" mvi=" << mvi <<
" component_mvi=" << component_mvi;
232 ARCANE_FATAL(
"Bad component part data nb_error={0}", nb_error);
238void MeshComponentPartData::
241 if (!m_is_need_recompute)
243 if (!m_compute_functor)
245 m_compute_functor->executeFunctor();
246 m_is_need_recompute =
false;
252ComponentPartItemVectorView MeshComponentPartData::
253partView(eMatPart part)
255 _checkNeedRecompute();
256 const auto mat_part =
static_cast<Int32
>(part);
259 Int32 var_idx = (part == eMatPart::Pure) ? 0 : impureVarIdx();
260 return { m_component, var_idx, value_indexes,
261 item_indexes, m_constituent_list_view, part };
267ComponentPurePartItemVectorView MeshComponentPartData::
270 _checkNeedRecompute();
271 const auto mat_part =
static_cast<Int32
>(eMatPart::Pure);
274 return { m_component, value_indexes,
275 item_indexes, m_constituent_list_view };
281ComponentImpurePartItemVectorView MeshComponentPartData::
284 _checkNeedRecompute();
285 const auto mat_part =
static_cast<Int32
>(eMatPart::Impure);
288 const Int32 var_idx = impureVarIdx();
289 return { m_component, var_idx, value_indexes,
290 item_indexes, m_constituent_list_view };
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Types et macros pour gérer les boucles sur les accélérateurs.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
Boucle sur accélérateur avec arguments supplémentaires pour les réductions.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
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.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Array< Int32 > Int32Array
Tableau dynamique à une dimension d'entiers 32 bits.
Int32 Integer
Type représentant un entier.