static ncclResult_t ofi_pciPath()

in src/nccl_ofi_net.c [1088:1135]


static ncclResult_t ofi_pciPath(int dev, char** path)
{
	ncclResult_t ret = ncclSuccess;
	struct fi_info* prov = NULL;
	struct fid_nic *nic_info = NULL;
	struct fi_pci_attr *pci = NULL;
	char device_path[] = "/sys/class/pci_bus/0000:00/../../0000:00:00.00";

	prov = get_nic_info(dev, ofi_info_list);
	if (prov == NULL) {
		NCCL_OFI_INFO(NCCL_INIT | NCCL_NET,
			      "Unable to find provider for dev %d", dev);
		ret = ncclSystemError;
		goto exit;
	}

	nic_info = (struct fid_nic *)prov->nic;
	if (nic_info == NULL) {
		NCCL_OFI_INFO(NCCL_INIT | NCCL_NET,
			      "No NIC info for dev %d", dev);
		ret = ncclSystemError;
		goto exit;
	}

	if (nic_info->bus_attr->bus_type != FI_BUS_PCI) {
		NCCL_OFI_INFO(NCCL_INIT | NCCL_NET,
			      "Invalid type of PCI bus returned %d",
			      nic_info->bus_attr->bus_type);
		ret = ncclSystemError;
		goto exit;
	}

	pci = &nic_info->bus_attr->attr.pci;
	sprintf(device_path,
		"/sys/class/pci_bus/%04x:%02x/../../%04x:%02x:%02x.%01x",
		pci->domain_id, pci->bus_id,
		pci->domain_id, pci->bus_id, pci->device_id, pci->function_id);

	*path = realpath(device_path, NULL);
	if (*path == NULL) {
		NCCL_OFI_WARN("pciPath: Could not find real path of %s",
			      device_path);
		ret = ncclSystemError;
	}

exit:
	return ret;
}