Just add cudaDeviceSynchronize() after ‘forward()’.
(according to nvidia doc, cudaDeviceSynchronize() could be used to wait for GPU compute to finish)
However,  this command has no effect on the speed of the execution,just let cpu count the elapsed time correctly.