Annotate thrust::distance with __host__ __device__.
Annotate temporary_array's members with __host__ __device__.