Fixed bug when running on a CPU device