fix Cuda code for energy minimization