Port launch_calculator and helper code to work in __host__ or __device__ functions.