Move calculation of beta and theta_sum to the device