code: def get_ordered_devices():
      
  
      libcudart = get_libcudart()
  
      devices = {}
      for i in range(0, get_installed_devices()):
          gpu = get_device_properties(i)
  
          pciBusId = ctypes.create_string_buffer(64)
          libcudart.cudaDeviceGetPCIBusId(ctypes.byref(pciBusId), 64, i)
          full_id = pciBusId.value.decode('utf-8')
          gpu['fullId'] = full_id
          devices[full_id] = gpu
  
      ordered = []
  
      i = 0
      for key in sorted(devices):
          devices[key]['id'] = i
          ordered.append(devices[key])
          i += 1
  
      del libcudart
  
      return ordered
docs: Default CUDA_DEVICE_ORDER is not compatible with nvidia-docker.
      Nvidia-Docker is using CUDA_DEVICE_ORDER=PCI_BUS_ID.
  
      https://github.com/NVIDIA/nvidia-docker/wiki/nvidia-docker#gpu-isolation