framework icon indicating copy to clipboard operation
framework copied to clipboard

Using memory pool to reuse allocated arrays and variables

Open DavidDureau opened this issue 2 years ago • 1 comments

Temporary arrays or variables are often used in simulation code but it implies numerous allocations/freeing at each time-step cycle.

In addition, when the cuda accelerator runtime is enabled, we have a lot of cudaMallocManaged/cudaFree calls and these calls are more expensive than the standard memory allocator ones.

Example:

{
  // allocated with cudaMallocManaged
  EnvironmentVariableCellReal var1(m_mesh_material_mng, "VarTmp1", IVariable::PTemporary);
  EnvironmentVariableCellReal var2(m_mesh_material_mng, "VarTmp2", IVariable::PTemporary);

  auto inout_var1 = ax::viewInOut(command, var1);
  auto inout_var2 = ax::viewInOut(command, var2);

  commandA << RUNCOMMAND_MAT_ENUMERATE(EnvCell, evi, ...)
  {
     inout_var1[*evi] = ...;
     inout_var2[*evi] = ...;
  };

  commandB << RUNCOMMAND_ENUMERATE(Cell, cid, ...)
  {
    m_arrB[cid] = inout_var1[cid] + inout_var2[cid];
    ....
  };
}
// var1 et var2 are freed with cudaFree

In consequence, could Arcane provide one or several memory pools to reuse allocated variables?

DavidDureau avatar Oct 16 '23 11:10 DavidDureau

Related to #112

grospelliergilles avatar Oct 17 '23 17:10 grospelliergilles

Done in various MR : #1684, #1685, #1686

grospelliergilles avatar Nov 25 '24 17:11 grospelliergilles