Skip to content

Commit ff4db1e

Browse files
committed
opencl.h: use the khronos PCI bus info extension when available
Added in OpenCL 3.0.7. Still an extension, but looks more portable and AMD and NVIDIA ones. It brings locality for Intel GPU OpenCL devices, and works at least for NVIDIA GPUs too. Refs #337 because hopefully it works Intel FPGA too. Signed-off-by: Brice Goglin <[email protected]>
1 parent 8f67418 commit ff4db1e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/hwloc/opencl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ extern "C" {
4141
*/
4242
/* Copyright (c) 2008-2018 The Khronos Group Inc. */
4343

44+
/* needs "cl_khr_pci_bus_info" device extension, but not strictly required for clGetDeviceInfo() */
45+
typedef struct {
46+
cl_uint pci_domain;
47+
cl_uint pci_bus;
48+
cl_uint pci_device;
49+
cl_uint pci_function;
50+
} hwloc_cl_device_pci_bus_info_khr;
51+
#define HWLOC_CL_DEVICE_PCI_BUS_INFO_KHR 0x410F
52+
4453
/* needs "cl_amd_device_attribute_query" device extension, but not strictly required for clGetDeviceInfo() */
4554
#define HWLOC_CL_DEVICE_TOPOLOGY_AMD 0x4037
4655
typedef union {
@@ -78,9 +87,19 @@ hwloc_opencl_get_device_pci_busid(cl_device_id device,
7887
unsigned *domain, unsigned *bus, unsigned *dev, unsigned *func)
7988
{
8089
hwloc_cl_device_topology_amd amdtopo;
90+
hwloc_cl_device_pci_bus_info_khr khrbusinfo;
8191
cl_uint nvbus, nvslot, nvdomain;
8292
cl_int clret;
8393

94+
clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_BUS_INFO_KHR, sizeof(khrbusinfo), &khrbusinfo, NULL);
95+
if (CL_SUCCESS == clret) {
96+
*domain = (unsigned) khrbusinfo.pci_domain;
97+
*bus = (unsigned) khrbusinfo.pci_bus;
98+
*dev = (unsigned) khrbusinfo.pci_device;
99+
*func = (unsigned) khrbusinfo.pci_function;
100+
return 0;
101+
}
102+
84103
clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_TOPOLOGY_AMD, sizeof(amdtopo), &amdtopo, NULL);
85104
if (CL_SUCCESS == clret
86105
&& HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD == amdtopo.raw.type) {

0 commit comments

Comments
 (0)