14 #ifndef HWLOC_OPENCL_H
15 #define HWLOC_OPENCL_H
18 #include "hwloc/autogen/config.h"
19 #include "hwloc/helper.h"
20 #ifdef HWLOC_LINUX_SYS
21 #include "hwloc/linux.h"
25 #include <OpenCL/cl.h>
51 #define HWLOC_CL_DEVICE_PCI_BUS_INFO_KHR 0x410F
54 #define HWLOC_CL_DEVICE_TOPOLOGY_AMD 0x4037
56 struct { cl_uint
type; cl_uint data[5]; } raw;
57 struct { cl_uint type; cl_char unused[17]; cl_char bus; cl_char device; cl_char
function; } pcie;
59 #define HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1
62 #define HWLOC_CL_DEVICE_PCI_BUS_ID_NV 0x4008
63 #define HWLOC_CL_DEVICE_PCI_SLOT_ID_NV 0x4009
64 #define HWLOC_CL_DEVICE_PCI_DOMAIN_ID_NV 0x400A
85 static __hwloc_inline
int
87 unsigned *domain,
unsigned *bus,
unsigned *dev,
unsigned *func)
91 cl_uint nvbus, nvslot, nvdomain;
94 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_BUS_INFO_KHR,
sizeof(khrbusinfo), &khrbusinfo, NULL);
95 if (CL_SUCCESS == clret) {
97 *bus = (
unsigned) khrbusinfo.
pci_bus;
103 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_TOPOLOGY_AMD,
sizeof(amdtopo), &amdtopo, NULL);
104 if (CL_SUCCESS == clret
105 && HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD == amdtopo.
raw.
type) {
108 *bus = (unsigned) (
unsigned char) amdtopo.
pcie.
bus;
109 *dev = (unsigned) (
unsigned char) amdtopo.
pcie.
device;
110 *func = (unsigned) (
unsigned char) amdtopo.
pcie.
function;
114 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_BUS_ID_NV,
sizeof(nvbus), &nvbus, NULL);
115 if (CL_SUCCESS == clret) {
116 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_SLOT_ID_NV,
sizeof(nvslot), &nvslot, NULL);
117 if (CL_SUCCESS == clret) {
118 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_DOMAIN_ID_NV,
sizeof(nvdomain), &nvdomain, NULL);
119 if (CL_SUCCESS == clret) {
127 *func = nvslot & 0x7;
155 static __hwloc_inline
int
157 cl_device_id device __hwloc_attribute_unused,
160 #if (defined HWLOC_LINUX_SYS)
162 #define HWLOC_OPENCL_DEVICE_SYSFS_PATH_MAX 128
163 char path[HWLOC_OPENCL_DEVICE_SYSFS_PATH_MAX];
164 unsigned pcidomain, pcibus, pcidev, pcifunc;
176 sprintf(path,
"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/local_cpus", pcidomain, pcibus, pcidev, pcifunc);
204 unsigned platform_index,
unsigned device_index)
206 unsigned x = (unsigned) -1, y = (
unsigned) -1;
211 && sscanf(osdev->
name,
"opencl%ud%u", &x, &y) == 2
212 && platform_index == x && device_index == y)
241 cl_device_id device __hwloc_attribute_unused)
244 unsigned pcidomain, pcibus, pcidevice, pcifunc;
254 if (strncmp(osdev->
name,
"opencl", 6))