I have a device array that stores scores as int32 values and another that stores flags as int8_t. The i-th score corresponds to the i-th game in my vectorized simulator and the i-th flag is nonzero if the i-th game needs to be restarted. The arrays are updated at each step of the simulation, and the terminated games are restarted.
How could I get an estimate of the average score of terminated games over the course of a simulation consisting 100k+ steps? Runtime performance matters more than “statistical correctness”.
In my prior host-only implementation I simply used an exponential moving average with the terminated scores, updated by a single worker thread at each simulation step.
A minimal version of my current kernel would be:
__global__ void reset_score(const int game_count, const int8_t *terminated_flags, int *scores)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx >= game_count)
return;
if (terminated_flags[idx] == 0)
return;
scores[idx] = 0;
return;
}