I’ve done something similar to this. I used a moving window (over the grid) to implement an algorithm which assigned terrain types (valleys, peaks, slopes and flat and so on) to DEM data.
Unfortunately I’ve lost the code. But from memory I used grdfilter and grdmath. It’s easy enough to do moving window averages using grdfilter, but to do a moving window RMS you’d probably need to do a bit of manipulation of your data using grdmath.