Stabilize cached Z4C CUDA sync after regrid

This commit is contained in:
2026-05-01 20:04:04 +08:00
parent 30b778daa3
commit 531b31e8db
5 changed files with 833 additions and 79 deletions

View File

@@ -1,9 +1,10 @@
#ifdef newc
#include <sstream>
#include <cstdio>
#include <map>
using namespace std;
#ifdef newc
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <map>
using namespace std;
#else
#include <stdio.h>
#include <map.h>
@@ -215,6 +216,29 @@ bool fill_z4c_cuda_views(Block *cg, MyList<var> *vars,
return idx == Z4C_CUDA_STATE_COUNT && vars == 0;
}
bool z4c_cuda_keep_resident_after_step(int lev, int trfls_in, int analysis_lev)
{
static int keep_all_levels = -1;
if (keep_all_levels < 0)
{
const char *env = getenv("AMSS_CUDA_KEEP_ALL_LEVELS");
keep_all_levels = (env && atoi(env) != 0) ? 1 : 0;
}
static int enabled = -1;
if (enabled < 0)
{
const char *env = getenv("AMSS_CUDA_Z4C_KEEP_RESIDENT_AFTER_STEP");
enabled = (env && atoi(env) != 0) ? 1 : 0;
}
if (!enabled)
return false;
if (lev == analysis_lev)
return false;
if (keep_all_levels)
return true;
return lev < trfls_in;
}
void z4c_cuda_download_level_state(MyList<Patch> *PatL, MyList<var> *vars, int myrank, bool release_ctx)
{
MyList<Patch> *Pp = PatL;
@@ -693,7 +717,10 @@ void Z4c_class::Step(int lev, int YN)
}
}
z4c_cuda_download_level_state(GH->PatL[lev], SynchList_cor, myrank, true);
{
const bool keep_resident = z4c_cuda_keep_resident_after_step(lev, trfls, a_lev);
z4c_cuda_download_level_state(GH->PatL[lev], SynchList_cor, myrank, !keep_resident);
}
#if (RPS == 0)
RestrictProlong(lev, YN, BB);