Build a GPU id string to be used for CUDA_VISIBLE_DEVICES.

def _cuda_get_gpu_spec_string(gpu_ids=None):
    """
    Build a GPU id string to be used for CUDA_VISIBLE_DEVICES.
    """

    if gpu_ids is None:
        return ''

    if isinstance(gpu_ids, list):
        return ','.join(str(gpu_id) for gpu_id in gpu_ids)

    if isinstance(gpu_ids, int):
        return str(gpu_ids)

    return gpu_ids