Finished Cuda porting, there could be many potential bugs.