Skip to main content

gpuid_to_minor

Function gpuid_to_minor 

Source
fn gpuid_to_minor(gpu_id: u32) -> i32
Expand description

Map an RM gpuId to the /dev/nvidia minor that node_reachable needs: the id only carries a PCI address, not a device minor, so this bridges the two by scanning /proc/driver/nvidia/gpus, returning -1 when no match is found.

  1. Extract the PCI address from the id: the PCI address is encoded in gpuId >> 8, so want_bus is the low bus byte (gpuId >> 8) & 0xFF and want_full is the full gpuId >> 8 (domain folded in for larger ids).
  2. Match a /proc entry: each subdirectory is named by its PCI address domain:bus:slot.func in hex; split on : and . (expecting four fields) and parse the domain and bus. An entry matches when its bus equals want_bus or its combined (domain << 8) | bus equals want_full — the dual test covers ids that fold the domain in.
  3. Read the minor: from the matched entry’s information file, parse the Device Minor: N line and return N. The scan processes only the first matching directory (it breaks afterward) and returns -1 if no minor line is present.