Ported the gpu code