Hi,
The max pooling layer uses the maximum value out of all the ones in the kernel. So the gradient is 1 for the selected value and 0 for all the others.
So during the backward, the gradient of the output is (multiplied by 1 and) set to the selected value. All the others are set to 0.
To do so, it uses the indices returned by the forward pass.
The cpu implementation is here 136 with gradInput initialized to zeros.