def get_preferred_gpu(gpu_indices, preferred):
    """Move preferred GPU on a first position if it is available."""
    for gpu in reversed(preferred):
        if gpu in gpu_indices:
            gpu_indices.remove(gpu)
            gpu_indices = [gpu, ] + gpu_indices
    return gpu_indices