title: How do I discover the PCIe bus topology and slot numbers on the board?
body: <p>For example, when I use multi-GPU system with CUDA C/C++ and GPUDirect 2.0 P2P, and I use nested PCI-Express Switches, as shown on picture, then I must know how many switches between any two GPUs by their PCI Bus ID, to optimize data transfer and distribution of calculation. </p>
  
  <p>Or if I already know hardware PCIe topology with PCIe-switches, then I must know, to which hardware PCIe slot on board is connected any GPU card.
  <a href="https://i.stack.imgur.com/X49Qj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X49Qj.jpg" alt="enter image description here"></a></p>
  
  <p>As I know, even if I already know hardware PCIe topology with PCIe-switches, then these identifiers is not hard-bound to PCIe slots on the board, and these IDs may change and be different from run to run of system: </p>
  
  <ul>
  <li>CUDA device_id</li>
  <li>nvidia-smi/nvml GPU id</li>
  <li>PCI Bus ID </li>
  </ul>
  
  <p>What is the best way to discover the topology of the PCIe bus with detailed device tree and the number of PCIe slot on the board <strong>on Windows and Linux</strong>?</p>