Missing PCI function field in cudaDeviceProp

Hello. The CUDA runtime API cudaDeviceProp struct (queried using cudaGetDeviceProperties) contains the pciDomainId, pciBusID and pciDeviceId fields, but does not provide the PCI function (a “pciFunctionId” field is missing) which is necessary to build the full PCI ID [domain]:[bus]:[device].[function].

Is the missing PCI function field necessary to bind the PCI ID to a unique GPU index?

I am asking also because, strangely, the related function cudaDeviceGetByPCIBusId allows not only the full format [domain]:[bus]:[device].[function] but also the partial format [domain]:[bus]:[device]. Does it mean that the PCI function field is not necessary? What device index will cudaDeviceGetByPCIBusId provide, using the latter format without [function], for a multi-function device? An error? A “random” GPU index among several corresponding to different PCI functions? Or it does not matter, namely it is guaranteed that at most one GPU index can match the partial [domain]:[bus]:[device]?

This is a bit blocking for me because, incidentally, I think there is a bug in cudaDeviceGetByPCIBusId (at least in CUDA 10) resulting in spurious pinned-memory allocations for default GPU (index = 0) at subsequent calls of cudaMalloc / cudaMallocHost even though a different GPU was assigned before performing the mallocs. So I am forced to use cudaGetDeviceProperties to link the GPU index to the PCI ID, and cannot use cudaDeviceGetByPCIBusId to do that. But cudaDeviceProp does not provide the cudaDeviceProp value, so I am stuck, unless [domain]:[bus]:[device] alone binds to a unique GPU index.

I hope I can find a solution. Thanks in advance.

No, it is not. A PCI function ID for example could be used to select the audio output associated with a GPU, as opposed to the GPU itself. You can discover these sorts of things by studying lspci output carefully. The function ID 0 will be what we think of as the GPU.

correct. the function ID .0 will be what we think of as “the GPU” at that bus/device. The function ID .1 (if it exists) corresponds usually to an audio output that would be used if you are for example using the GPU to drive an HDMI display, where HDMI contains not just the display output but an audio output as well.

In my experience datacenter-oriented GPUs (which typically show up as a 3D controller device in lspci output) will only “declare” a .0 function. For GPUs that declare both a .0 and a .1 function, the .1 function is usually an audio device, and those GPUs are usually GeForce or workstation GPUs, and their .0 function gets listed as a VGA controller and their .1 function get listed as “Audio device”.