Skip to content

Commit 8f18158

Browse files
authoredNov 7, 2024··
Merge pull request #1741 from arcaneframework/dev/gg-use-one-kernel-to-initialize-new-items-from-pure
Use one kernel when initializing new ConstituentItem from global values
2 parents e92559a + d767dd9 commit 8f18158

8 files changed

+85
-80
lines changed
 

‎arcane/src/arcane/core/materials/internal/IMeshMaterialVariableInternal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ class ARCANE_CORE_EXPORT IMeshMaterialVariableInternal
184184
//! \internal
185185
virtual void copyBetweenPartialAndGlobal(const CopyBetweenPartialAndGlobalArgs& args) = 0;
186186

187-
//! \internal
188-
virtual void initializeNewItems(const ComponentItemListBuilder& list_builder, RunQueue& queue) = 0;
187+
//! Initialize les valeurs des nouveaux constituants avec la valeur zéro
188+
virtual void initializeNewItemsWithZero(const ComponentItemListBuilder& list_builder, RunQueue& queue) = 0;
189189

190190
//! Liste des 'VariableRef' associées à cette variable.
191191
virtual ConstArrayView<VariableRef*> variableReferenceList() const =0;

‎arcane/src/arcane/materials/IncrementalComponentModifier.cc

+58
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,64 @@ _addItemsToEnvironment(MeshEnvironment* env, MeshMaterial* mat,
318318
}
319319
}
320320

321+
/*---------------------------------------------------------------------------*/
322+
/*---------------------------------------------------------------------------*/
323+
324+
void IncrementalComponentModifier::
325+
_addItemsToIndexer(MeshMaterialVariableIndexer* var_indexer,
326+
SmallSpan<const Int32> local_ids)
327+
{
328+
// TODO Conserver l'instance au cours de toutes modifications
329+
ComponentItemListBuilder& list_builder = m_work_info.list_builder;
330+
list_builder.setIndexer(var_indexer);
331+
332+
const Int32 nb_id = local_ids.size();
333+
list_builder.preAllocate(nb_id);
334+
335+
_computeItemsToAdd(list_builder, local_ids);
336+
337+
if (traceMng()->verbosityLevel() >= 5)
338+
info() << "ADD_MATITEM_TO_INDEXER component=" << var_indexer->name()
339+
<< " nb_pure=" << list_builder.pureIndexes().size()
340+
<< " nb_partial=" << list_builder.partialIndexes().size()
341+
<< "\n pure=(" << list_builder.pureIndexes() << ")"
342+
<< "\n partial=(" << list_builder.partialIndexes() << ")";
343+
344+
// TODO: lors de cet appel, on connait le max de \a index_in_partial donc
345+
// on peut éviter de faire une réduction pour le recalculer.
346+
347+
var_indexer->endUpdateAdd(list_builder, m_queue);
348+
349+
// Redimensionne les variables
350+
_resizeVariablesIndexer(var_indexer->index());
351+
352+
// Maintenant que les nouveaux MatVar sont créés, il faut les
353+
// initialiser avec les bonnes valeurs.
354+
if (m_do_init_new_items) {
355+
IMeshMaterialMng* mm = m_material_mng;
356+
bool init_with_zero = mm->isDataInitialisationWithZero();
357+
358+
Accelerator::ProfileRegion ps(m_queue, "InitializeNewItems", 0xFFFF00);
359+
360+
if (init_with_zero) {
361+
RunQueue::ScopedAsync sc(&m_queue);
362+
auto func_zero = [&](IMeshMaterialVariable* mv) {
363+
mv->_internalApi()->initializeNewItemsWithZero(list_builder, m_queue);
364+
};
365+
functor::apply(mm, &IMeshMaterialMng::visitVariables, func_zero);
366+
m_queue.barrier();
367+
}
368+
else {
369+
SmallSpan<Int32> partial_indexes = list_builder.partialIndexes();
370+
SmallSpan<Int32> partial_local_ids = list_builder.partialLocalIds();
371+
372+
CopyBetweenPartialAndGlobalArgs args(var_indexer->index(), partial_local_ids,
373+
partial_indexes, true, true, m_queue);
374+
_copyBetweenPartialsAndGlobals(args);
375+
}
376+
}
377+
}
378+
321379
/*---------------------------------------------------------------------------*/
322380
/*---------------------------------------------------------------------------*/
323381
/*!

‎arcane/src/arcane/materials/IncrementalComponentModifier_Accelerator.cc

+9-43
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,15 @@ _computeCellsToTransformForEnvironments(SmallSpan<const Int32> ids)
251251
/*---------------------------------------------------------------------------*/
252252

253253
void IncrementalComponentModifier::
254-
_addItemsToIndexer(MeshMaterialVariableIndexer* var_indexer,
255-
SmallSpan<const Int32> local_ids)
254+
_computeItemsToAdd(ComponentItemListBuilder& list_builder, SmallSpan<const Int32> local_ids)
256255
{
257-
// TODO Conserver l'instance au cours de toutes modifications
258-
ComponentItemListBuilder& list_builder = m_work_info.list_builder;
259-
list_builder.setIndexer(var_indexer);
256+
SmallSpan<const bool> cells_is_partial = m_work_info.m_cells_is_partial;
257+
258+
Accelerator::GenericFilterer filterer(m_queue);
259+
260+
MeshMaterialVariableIndexer* var_indexer = list_builder.indexer();
260261

261-
const Int32 n = local_ids.size();
262-
list_builder.preAllocate(n);
262+
const Int32 nb_id = local_ids.size();
263263

264264
SmallSpan<Int32> pure_indexes = list_builder.pureIndexes();
265265
SmallSpan<Int32> partial_indexes = list_builder.partialIndexes();
@@ -268,10 +268,6 @@ _addItemsToIndexer(MeshMaterialVariableIndexer* var_indexer,
268268
Int32 nb_partial_added = 0;
269269
Int32 index_in_partial = var_indexer->maxIndexInMultipleArray();
270270

271-
SmallSpan<const bool> cells_is_partial = m_work_info.m_cells_is_partial;
272-
273-
Accelerator::GenericFilterer filterer(m_queue);
274-
275271
// TODO: pour l'instant on remplit en deux fois mais il serait
276272
// possible de le faire en une seule fois en utilisation l'algorithme de Partition.
277273
// Il faudrait alors inverser les éléments de la deuxième liste pour avoir
@@ -286,7 +282,7 @@ _addItemsToIndexer(MeshMaterialVariableIndexer* var_indexer,
286282
Int32 local_id = local_ids[input_index];
287283
pure_indexes[output_index] = local_id;
288284
};
289-
filterer.applyWithIndex(n, select_lambda, setter_lambda, A_FUNCINFO);
285+
filterer.applyWithIndex(nb_id, select_lambda, setter_lambda, A_FUNCINFO);
290286
nb_pure_added = filterer.nbOutputElement();
291287
}
292288
// Remplit la liste des mailles partielles
@@ -299,41 +295,11 @@ _addItemsToIndexer(MeshMaterialVariableIndexer* var_indexer,
299295
partial_indexes[output_index] = index_in_partial + output_index;
300296
partial_local_ids[output_index] = local_id;
301297
};
302-
filterer.applyWithIndex(n, select_lambda, setter_lambda, A_FUNCINFO);
298+
filterer.applyWithIndex(nb_id, select_lambda, setter_lambda, A_FUNCINFO);
303299
nb_partial_added = filterer.nbOutputElement();
304300
}
305301

306302
list_builder.resize(nb_pure_added, nb_partial_added);
307-
308-
if (traceMng()->verbosityLevel() >= 5)
309-
info() << "ADD_MATITEM_TO_INDEXER component=" << var_indexer->name()
310-
<< " nb_pure=" << list_builder.pureIndexes().size()
311-
<< " nb_partial=" << list_builder.partialIndexes().size()
312-
<< "\n pure=(" << list_builder.pureIndexes() << ")"
313-
<< "\n partial=(" << list_builder.partialIndexes() << ")";
314-
315-
// TODO: lors de cet appel, on connait le max de \a index_in_partial donc
316-
// on peut éviter de faire une réduction pour le recalculer.
317-
318-
var_indexer->endUpdateAdd(list_builder, m_queue);
319-
320-
// Maintenant que les nouveaux MatVar sont créés, il faut les
321-
// initialiser avec les bonnes valeurs.
322-
{
323-
_resizeVariablesIndexer(var_indexer->index());
324-
// TODO: Comme tout est indépendant par variable, on pourrait
325-
// éventuellement utiliser plusieurs files.
326-
if (m_do_init_new_items) {
327-
Accelerator::ProfileRegion ps(m_queue, "InitializeNewItems", 0xFFFF00);
328-
RunQueue::ScopedAsync sc(&m_queue);
329-
IMeshMaterialMng* mm = m_material_mng;
330-
auto func = [&](IMeshMaterialVariable* mv) {
331-
mv->_internalApi()->initializeNewItems(list_builder, m_queue);
332-
};
333-
functor::apply(mm, &IMeshMaterialMng::visitVariables, func);
334-
m_queue.barrier();
335-
}
336-
}
337303
}
338304

339305
/*---------------------------------------------------------------------------*/

‎arcane/src/arcane/materials/ItemMaterialVariableBaseT.H

+10-30
Original file line numberDiff line numberDiff line change
@@ -461,52 +461,32 @@ _copyBetweenPartialAndGlobal(const CopyBetweenPartialAndGlobalArgs& args)
461461
/*---------------------------------------------------------------------------*/
462462
/*---------------------------------------------------------------------------*/
463463

464-
template<typename Traits> void
464+
template <typename Traits> void
465465
ItemMaterialVariableBase<Traits>::
466-
_initializeNewItems(const ComponentItemListBuilder& list_builder, RunQueue& queue)
466+
_initializeNewItemsWithZero(const ComponentItemListBuilder& list_builder, RunQueue& queue)
467467
{
468468
MeshMaterialVariableIndexer* indexer = list_builder.indexer();
469469
Integer var_index = indexer->index();
470470
PrivatePartType* partial_var = m_vars[var_index + 1];
471471
if (!_isValidAndUsedAndGlobalUsed(partial_var))
472472
return;
473473

474-
bool init_with_zero = m_p->materialMng()->isDataInitialisationWithZero();
475-
476474
SmallSpan<const Int32> partial_indexes = list_builder.partialIndexes();
477475

478476
Integer nb_partial = partial_indexes.size();
479477

480-
// TODO: regarder s'il faut initialiser les mailles pure avec zéro.
481-
// En effet, normalement il n'y a pas de maille pure si on ajoute un matériau
482-
// (sauf lors de l'init).
483-
DataType zero = DataType();
484-
485-
auto command = makeCommand(queue);
486-
487478
ContainerSpanType partial_view = m_host_views[var_index + 1];
488-
ContainerSpanType pure_view = m_host_views[0];
489479

490480
ARCANE_CHECK_ACCESSIBLE_POINTER(queue, partial_indexes.data());
491481

492-
if (init_with_zero) {
493-
command << RUNCOMMAND_LOOP1(iter, nb_partial)
494-
{
495-
auto [i] = iter();
496-
Int32 index = partial_indexes[i];
497-
Traits::setValue(partial_view[index], zero);
498-
};
499-
}
500-
else {
501-
SmallSpan<const Int32> partial_local_ids = list_builder.partialLocalIds();
502-
ARCANE_CHECK_ACCESSIBLE_POINTER(queue, partial_local_ids.data());
503-
command << RUNCOMMAND_LOOP1(iter, nb_partial)
504-
{
505-
auto [i] = iter();
506-
Int32 index = partial_indexes[i];
507-
Traits::setValue(partial_view[index], pure_view[partial_local_ids[i]]);
508-
};
509-
}
482+
DataType zero = DataType();
483+
auto command = makeCommand(queue);
484+
command << RUNCOMMAND_LOOP1(iter, nb_partial)
485+
{
486+
auto [i] = iter();
487+
Int32 index = partial_indexes[i];
488+
Traits::setValue(partial_view[index], zero);
489+
};
510490
}
511491

512492
/*---------------------------------------------------------------------------*/

‎arcane/src/arcane/materials/MeshMaterialVariable.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ copyBetweenPartialAndGlobal(const CopyBetweenPartialAndGlobalArgs& args)
150150
/*---------------------------------------------------------------------------*/
151151

152152
void MeshMaterialVariablePrivate::
153-
initializeNewItems(const ComponentItemListBuilder& list_builder, RunQueue& queue)
153+
initializeNewItemsWithZero(const ComponentItemListBuilder& list_builder, RunQueue& queue)
154154
{
155-
m_variable->_initializeNewItems(list_builder, queue);
155+
m_variable->_initializeNewItemsWithZero(list_builder, queue);
156156
}
157157

158158
/*---------------------------------------------------------------------------*/

‎arcane/src/arcane/materials/MeshMaterialVariable.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class ARCANE_MATERIALS_EXPORT MeshMaterialVariable
152152
virtual void _restoreData(IMeshComponent* component,IData* data,Integer data_index,
153153
Int32ConstArrayView ids,bool allow_null_id) =0;
154154
virtual void _copyBetweenPartialAndGlobal(const CopyBetweenPartialAndGlobalArgs& args) = 0;
155-
virtual void _initializeNewItems(const ComponentItemListBuilder& list_builder, RunQueue& queue) = 0;
155+
virtual void _initializeNewItemsWithZero(const ComponentItemListBuilder& list_builder, RunQueue& queue) = 0;
156156
virtual void _syncReferences(bool update_views) = 0;
157157
virtual void _resizeForIndexer(ResizeVariableIndexerArgs& args) = 0;
158158

@@ -323,7 +323,7 @@ class ItemMaterialVariableBase
323323
ARCANE_MATERIALS_EXPORT
324324
void _copyBetweenPartialAndGlobal(const CopyBetweenPartialAndGlobalArgs& args) override;
325325
ARCANE_MATERIALS_EXPORT
326-
void _initializeNewItems(const ComponentItemListBuilder& list_builder, RunQueue& queue) override;
326+
void _initializeNewItemsWithZero(const ComponentItemListBuilder& list_builder, RunQueue& queue) override;
327327

328328
ARCANE_MATERIALS_EXPORT void fillPartialValuesWithGlobalValues() override;
329329
ARCANE_MATERIALS_EXPORT void

‎arcane/src/arcane/materials/internal/IncrementalComponentModifier.h

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class ARCANE_MATERIALS_EXPORT IncrementalComponentModifier
7979
void _removeItemsInGroup(ItemGroup cells,SmallSpan<const Int32> removed_ids);
8080
void _applyCopyBetweenPartialsAndGlobals(const CopyBetweenPartialAndGlobalArgs& args, RunQueue& queue);
8181
void _applyCopyVariableViews(RunQueue& queue);
82+
void _computeItemsToAdd(ComponentItemListBuilder& list_builder, SmallSpan<const Int32> local_ids);
8283

8384
private:
8485

‎arcane/src/arcane/materials/internal/MeshMaterialVariablePrivate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class MeshMaterialVariablePrivate
7474

7575
void copyBetweenPartialAndGlobal(const CopyBetweenPartialAndGlobalArgs& args) override;
7676

77-
void initializeNewItems(const ComponentItemListBuilder& list_builder, RunQueue& queue) override;
77+
void initializeNewItemsWithZero(const ComponentItemListBuilder& list_builder, RunQueue& queue) override;
7878

7979
ConstArrayView<VariableRef*> variableReferenceList() const override
8080
{

0 commit comments

Comments
 (0)
Please sign in to comment.