Skip to content

Commit 0d96d15

Browse files
committed
[CL] Use cl_khr_pci_bus_info when available
Implement the `UR_DEVICE_INFO_PCI_ADDRESS` device query using the `cl_khr_pci_bus_info` extension when the device supports it.
1 parent c742ca4 commit 0d96d15

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

source/adapters/opencl/device.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,25 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10441044
CL_DEVICE_UUID_KHR, UUID.size(), UUID.data(), nullptr));
10451045
return ReturnValue(UUID);
10461046
}
1047+
case UR_DEVICE_INFO_PCI_ADDRESS: {
1048+
bool isKhrPciBusInfoSupported = false;
1049+
if (cl_adapter::checkDeviceExtensions(
1050+
cl_adapter::cast<cl_device_id>(hDevice), {"cl_khr_pci_bus_info"},
1051+
isKhrPciBusInfoSupported) != UR_RESULT_SUCCESS ||
1052+
!isKhrPciBusInfoSupported) {
1053+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
1054+
}
1055+
cl_device_pci_bus_info_khr PciBusInfo{};
1056+
CL_RETURN_ON_FAILURE(clGetDeviceInfo(
1057+
cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_PCI_BUS_INFO_KHR,
1058+
sizeof(PciBusInfo), &PciBusInfo, nullptr));
1059+
// PCI address in BDF format requires 13 bytes DOMA:BU:DE.F + null bytes
1060+
std::array<char, 13> PciAddr;
1061+
std::snprintf(PciAddr.data(), PciAddr.size(), "%.4x:%.2x:%.2x.%x",
1062+
PciBusInfo.pci_domain, PciBusInfo.pci_bus,
1063+
PciBusInfo.pci_device, PciBusInfo.pci_function);
1064+
return ReturnValue(PciAddr);
1065+
}
10471066

10481067
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS: {
10491068
return ReturnValue(false);
@@ -1054,7 +1073,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10541073
* the Registry. */
10551074
case UR_DEVICE_INFO_COMPONENT_DEVICES:
10561075
case UR_DEVICE_INFO_COMPOSITE_DEVICE:
1057-
case UR_DEVICE_INFO_PCI_ADDRESS:
10581076
case UR_DEVICE_INFO_GPU_EU_COUNT:
10591077
case UR_DEVICE_INFO_GPU_EU_SIMD_WIDTH:
10601078
case UR_DEVICE_INFO_GPU_EU_SLICES:

0 commit comments

Comments
 (0)