Same bug fix as the previous commit, but for CUDA