Skip to content

Commit e89c4b2

Browse files
[arcane,tests] Ajoute test pour les 'RUNCOMMAND_MAT_ENUMERATE' sur les MatCell.
1 parent bb82c82 commit e89c4b2

File tree

3 files changed

+113
-26
lines changed

3 files changed

+113
-26
lines changed

arcane/ceapart/src/arcane/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if (ARCANE_HAS_ACCELERATOR_API)
88
AdiProjectionModule.cc
99
CartesianMeshTestUtils.cc
1010
MeshMaterialSyncUnitTest.cc
11+
MaterialHeatTestModule.cc
1112
)
1213
arcane_accelerator_add_source_files(${ARCANE_ACCELERATOR_SOURCES})
1314
endif()

arcane/ceapart/src/arcane/tests/MaterialHeatTestModule.cc

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* MaterialHeatTestModule.cc (C) 2000-2023 */
8+
/* MaterialHeatTestModule.cc (C) 2000-2024 */
99
/* */
1010
/* Module de test des matériaux. */
1111
/*---------------------------------------------------------------------------*/
@@ -29,6 +29,13 @@
2929
#include "arcane/materials/MeshMaterialModifier.h"
3030
#include "arcane/materials/ComponentItemVectorView.h"
3131

32+
#include "arcane/accelerator/core/IAcceleratorMng.h"
33+
#include "arcane/accelerator/core/RunCommand.h"
34+
#include "arcane/accelerator/core/RunQueue.h"
35+
#include "arcane/accelerator/VariableViews.h"
36+
#include "arcane/accelerator/MaterialVariableViews.h"
37+
#include "arcane/accelerator/RunCommandMaterialEnumerate.h"
38+
3239
#include "arcane/tests/ArcaneTestGlobal.h"
3340
#include "arcane/tests/MaterialHeatTest_axl.h"
3441

@@ -49,7 +56,7 @@ using namespace Arcane::Materials;
4956
class MaterialHeatTestModule
5057
: public ArcaneMaterialHeatTestObject
5158
{
52-
private:
59+
public:
5360

5461
//! Caractéristiques de l'objet qui chauffe (disque ou sphère)
5562
struct HeatObject
@@ -120,7 +127,9 @@ class MaterialHeatTestModule
120127
void _computeGlobalTemperature();
121128
void _computeCellsToAdd(const HeatObject& heat_object, MaterialWorkArray& wa);
122129
void _computeCellsToRemove(const HeatObject& heat_object, MaterialWorkArray& wa);
130+
public:
123131
void _addHeat(const HeatObject& heat_object);
132+
private:
124133
void _addCold(const HeatObject& heat_object);
125134
void _initNewCells(const HeatObject& heat_object, MaterialWorkArray& wa);
126135
void _compute();
@@ -157,9 +166,11 @@ MaterialHeatTestModule::
157166
void MaterialHeatTestModule::
158167
buildInit()
159168
{
169+
ProfilingRegistry::setProfilingLevel(2);
170+
160171
// La création des milieux et des matériaux doit se faire dans un point
161172
// d'entrée de type 'build' pour que la liste des variables créés par les
162-
// milieux et les matériaux soit accessible dans le post-traitement.
173+
// milieux et les matériaux soit accessibles dans le post-traitement.
163174
info() << "MaterialHeatTestModule::buildInit()";
164175

165176
Materials::IMeshMaterialMng* mm = IMeshMaterialMng::getReference(defaultMesh());
@@ -378,18 +389,23 @@ _addHeat(const HeatObject& heat_object)
378389
const Real heat_radius_norm = heat_object.radius * heat_object.radius;
379390

380391
IMeshMaterial* current_mat = heat_object.material;
392+
RunQueue* queue = this->acceleratorMng()->defaultQueue();
393+
auto command = makeCommand(queue);
394+
395+
auto in_cell_center = viewIn(command, m_cell_center);
396+
auto inout_mat_temperature = viewInOut(command, m_mat_temperature);
381397

382398
//! Chauffe les mailles déjà présentes dans le matériau
383-
ENUMERATE_MATCELL (imatcell, current_mat) {
384-
MatCell mc = *imatcell;
385-
Cell cell = mc.globalCell();
386-
Real3 center = m_cell_center[cell];
399+
command << RUNCOMMAND_MAT_ENUMERATE(MatAndGlobalCell, iter, current_mat)
400+
{
401+
auto [matcell, cell] = iter();
402+
Real3 center = in_cell_center[cell];
387403
Real distance2 = (center - heat_center).squareNormL2();
388404
if (distance2 < heat_radius_norm) {
389405
Real to_add = heat_value / (1.0 + distance2);
390-
m_mat_temperature[mc] += to_add;
406+
inout_mat_temperature[matcell] += to_add;
391407
}
392-
}
408+
};
393409
}
394410

395411
/*---------------------------------------------------------------------------*/

arcane/src/arcane/tests/accelerator/MeshMaterialAcceleratorUnitTest.cc

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class MeshMaterialAcceleratorUnitTest
113113
UniqueArray<Int32> m_env1_partial_value_index;
114114
CellGroup m_sub_env_group1;
115115

116-
void _initializeVariables();
116+
void _initializeVariables(ComponentItemVectorView component);
117117

118118
public:
119119

@@ -124,7 +124,9 @@ class MeshMaterialAcceleratorUnitTest
124124
void _executeTest2(Integer nb_z);
125125
void _executeTest3(Integer nb_z);
126126
void _executeTest4(Integer nb_z);
127-
void _checkValues();
127+
void _executeTest5(Integer nb_z,MatCellVectorView mat);
128+
void _checkEnvValues1();
129+
void _checkMatValues1();
128130
void _checkEnvironmentValues();
129131
};
130132

@@ -322,7 +324,7 @@ executeTest()
322324
<< " nb_unknown=" << nb_unknown
323325
<< " nb_z=" << nb_z << " nb_z2=" << nb_z2;
324326

325-
_initializeVariables();
327+
_initializeVariables(m_env1->envView());
326328
EnvCellVector sub_ev1(m_sub_env_group1,m_env1);
327329
{
328330
_executeTest1(nb_z,m_env1->envView());
@@ -337,13 +339,18 @@ executeTest()
337339
{
338340
_executeTest4(nb_z);
339341
}
342+
{
343+
IMeshEnvironment* env2 = m_mm_mng->environments()[1];
344+
IMeshMaterial* mat2 = env2->materials()[1];
345+
_executeTest5(nb_z,mat2->matView());
346+
}
340347
}
341348

342349
/*---------------------------------------------------------------------------*/
343350
/*---------------------------------------------------------------------------*/
344351

345352
void MeshMaterialAcceleratorUnitTest::
346-
_initializeVariables()
353+
_initializeVariables(ComponentItemVectorView component)
347354
{
348355
MaterialVariableCellReal& a_ref(m_mat_a_ref);
349356
MaterialVariableCellReal& b_ref(m_mat_b_ref);
@@ -356,8 +363,9 @@ _initializeVariables()
356363
MaterialVariableCellReal& c(m_mat_c);
357364
MaterialVariableCellReal& d(m_mat_d);
358365
MaterialVariableCellReal& e(m_mat_e);
366+
bool is_env = component.component()->isEnvironment();
359367

360-
ENUMERATE_ENVCELL(i,m_env1){
368+
ENUMERATE_COMPONENTCELL(i,component){
361369
Real z = (Real)i.index();
362370
b_ref[i] = z*2.3;
363371
c_ref[i] = z*3.1;
@@ -369,23 +377,25 @@ _initializeVariables()
369377
c[i] = c_ref[i];
370378
d[i] = d_ref[i];
371379
e[i] = e_ref[i];
372-
m_env_a[i] = a_ref[i];
373-
m_env_b[i] = b_ref[i];
374-
m_env_c[i] = c_ref[i];
380+
if (is_env){
381+
m_env_a[i] = a_ref[i];
382+
m_env_b[i] = b_ref[i];
383+
m_env_c[i] = c_ref[i];
384+
}
375385
}
376386
}
377387

378388
/*---------------------------------------------------------------------------*/
379389
/*---------------------------------------------------------------------------*/
380390
/*!
381-
* \brief Test du RUNCOMMAND_ENUMERATE(EnvCell, ...
391+
* \brief Test du RUNCOMMAND_MAT_ENUMERATE(EnvCell, ...
382392
* avec en paramètres l'environnement et cherchant à accèder
383393
* aux variables multimat par l'envcell (i.e. le MatVarIndex en fait)
384394
*/
385395
void MeshMaterialAcceleratorUnitTest::
386396
_executeTest1(Integer nb_z,EnvCellVectorView env1)
387397
{
388-
_initializeVariables();
398+
_initializeVariables(m_env1->envView());
389399

390400
// Ref CPU
391401
for (Integer z=0, iz=nb_z; z<iz; ++z) {
@@ -412,7 +422,48 @@ _executeTest1(Integer nb_z,EnvCellVectorView env1)
412422
}
413423
}
414424

415-
_checkValues();
425+
_checkEnvValues1();
426+
}
427+
428+
/*---------------------------------------------------------------------------*/
429+
/*---------------------------------------------------------------------------*/
430+
/*!
431+
* \brief Test du RUNCOMMAND_MAT_ENUMERATE(MatCell, ...
432+
* avec en paramètres l'environnement et cherchant à accèder
433+
* aux variables multimat par l'envcell (i.e. le MatVarIndex en fait)
434+
*/
435+
void MeshMaterialAcceleratorUnitTest::
436+
_executeTest5(Integer nb_z,MatCellVectorView mat1)
437+
{
438+
info() << "Execute Test 5";
439+
_initializeVariables(mat1);
440+
441+
// Ref CPU
442+
for (Integer z=0, iz=nb_z; z<iz; ++z) {
443+
ENUMERATE_MATCELL(i,mat1){
444+
m_mat_a_ref[i] = m_mat_b_ref[i] + m_mat_c_ref[i] * m_mat_d_ref[i] + m_mat_e_ref[i];
445+
}
446+
}
447+
448+
// GPU
449+
{
450+
auto queue = makeQueue(m_runner);
451+
auto cmd = makeCommand(queue);
452+
453+
auto out_a = ax::viewOut(cmd, m_mat_a);
454+
auto in_b = ax::viewIn(cmd, m_mat_b);
455+
auto in_c = ax::viewIn(cmd, m_mat_c);
456+
auto in_d = ax::viewIn(cmd, m_mat_d);
457+
auto in_e = ax::viewIn(cmd, m_mat_e);
458+
459+
for (Integer z=0, iz=nb_z; z<iz; ++z) {
460+
cmd << RUNCOMMAND_MAT_ENUMERATE(MatCell, evi, mat1) {
461+
out_a[evi] = in_b[evi] + in_c[evi] * in_d[evi] + in_e[evi];
462+
};
463+
}
464+
}
465+
466+
_checkMatValues1();
416467
}
417468

418469
/*---------------------------------------------------------------------------*/
@@ -501,7 +552,7 @@ _executeTest2(Integer nb_z)
501552
}
502553
}
503554

504-
_checkValues();
555+
_checkEnvValues1();
505556
_checkEnvironmentValues();
506557
}
507558

@@ -573,7 +624,7 @@ _executeTest3(Integer nb_z)
573624
}
574625
}
575626

576-
_checkValues();
627+
_checkEnvValues1();
577628
}
578629

579630
/*---------------------------------------------------------------------------*/
@@ -648,7 +699,7 @@ _executeTest4(Integer nb_z)
648699
}
649700
}
650701

651-
_checkValues();
702+
_checkEnvValues1();
652703

653704
// Some further functions testing, not really usefull here, but it improves cover
654705
AllCellToAllEnvCell *useless(nullptr);
@@ -746,7 +797,7 @@ _executeTest4(Integer nb_z)
746797
}
747798
}
748799

749-
_checkValues();
800+
_checkEnvValues1();
750801
}
751802

752803
/*---------------------------------------------------------------------------*/
@@ -772,7 +823,7 @@ void _checkOneValue(Real value,Real ref_value,const char* var_name)
772823
/*---------------------------------------------------------------------------*/
773824

774825
void MeshMaterialAcceleratorUnitTest::
775-
_checkValues()
826+
_checkEnvValues1()
776827
{
777828
ValueChecker vc(A_FUNCINFO);
778829
ENUMERATE_ENV(ienv, m_mm_mng) {
@@ -790,6 +841,25 @@ _checkValues()
790841
/*---------------------------------------------------------------------------*/
791842
/*---------------------------------------------------------------------------*/
792843

844+
void MeshMaterialAcceleratorUnitTest::
845+
_checkMatValues1()
846+
{
847+
ValueChecker vc(A_FUNCINFO);
848+
ENUMERATE_MAT(imat, m_mm_mng) {
849+
IMeshMaterial* mat = *imat;
850+
ENUMERATE_MATCELL(imat,mat) {
851+
_checkOneValue(m_mat_a[imat], m_mat_a_ref[imat],"Test1_mat_a");
852+
_checkOneValue(m_mat_b[imat], m_mat_b_ref[imat],"Test1_mat_b");
853+
_checkOneValue(m_mat_c[imat], m_mat_c_ref[imat],"Test1_mat_c");
854+
_checkOneValue(m_mat_d[imat], m_mat_d_ref[imat],"Test1_mat_d");
855+
_checkOneValue(m_mat_e[imat], m_mat_e_ref[imat],"Test1_mat_e");
856+
}
857+
}
858+
}
859+
860+
/*---------------------------------------------------------------------------*/
861+
/*---------------------------------------------------------------------------*/
862+
793863
void MeshMaterialAcceleratorUnitTest::
794864
_checkEnvironmentValues()
795865
{

0 commit comments

Comments
 (0)