framework
framework copied to clipboard
Using memory pool to reuse allocated arrays and variables
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?
Related to #112
Done in various MR : #1684, #1685, #1686