15 #ifndef HWLOC_OPENCL_H
16 #define HWLOC_OPENCL_H
19 #include "hwloc/autogen/config.h"
20 #include "hwloc/helper.h"
21 #ifdef HWLOC_LINUX_SYS
22 #include "hwloc/linux.h"
26 #include <OpenCL/cl.h>
52 #define HWLOC_CL_DEVICE_PCI_BUS_INFO_KHR 0x410F
55 #define HWLOC_CL_DEVICE_TOPOLOGY_AMD 0x4037
57 struct { cl_uint
type; cl_uint data[5]; } raw;
58 struct { cl_uint type; cl_char unused[17]; cl_char bus; cl_char device; cl_char
function; } pcie;
60 #define HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1
63 #define HWLOC_CL_DEVICE_PCI_BUS_ID_NV 0x4008
64 #define HWLOC_CL_DEVICE_PCI_SLOT_ID_NV 0x4009
65 #define HWLOC_CL_DEVICE_PCI_DOMAIN_ID_NV 0x400A
86 static __hwloc_inline
int
88 unsigned *domain,
unsigned *bus,
unsigned *dev,
unsigned *func)
92 cl_uint nvbus, nvslot, nvdomain;
95 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_BUS_INFO_KHR,
sizeof(khrbusinfo), &khrbusinfo, NULL);
96 if (CL_SUCCESS == clret) {
98 *bus = (
unsigned) khrbusinfo.
pci_bus;
104 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_TOPOLOGY_AMD,
sizeof(amdtopo), &amdtopo, NULL);
105 if (CL_SUCCESS == clret
106 && HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD == amdtopo.
raw.
type) {
109 *bus = (unsigned) (
unsigned char) amdtopo.
pcie.
bus;
110 *dev = (unsigned) (
unsigned char) amdtopo.
pcie.
device;
111 *func = (unsigned) (
unsigned char) amdtopo.
pcie.
function;
115 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_BUS_ID_NV,
sizeof(nvbus), &nvbus, NULL);
116 if (CL_SUCCESS == clret) {
117 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_SLOT_ID_NV,
sizeof(nvslot), &nvslot, NULL);
118 if (CL_SUCCESS == clret) {
119 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_DOMAIN_ID_NV,
sizeof(nvdomain), &nvdomain, NULL);
120 if (CL_SUCCESS == clret) {
128 *func = nvslot & 0x7;
156 static __hwloc_inline
int
158 cl_device_id device __hwloc_attribute_unused,
161 #if (defined HWLOC_LINUX_SYS)
163 #define HWLOC_OPENCL_DEVICE_SYSFS_PATH_MAX 128
164 char path[HWLOC_OPENCL_DEVICE_SYSFS_PATH_MAX];
165 unsigned pcidomain, pcibus, pcidev, pcifunc;
177 sprintf(path,
"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/local_cpus", pcidomain, pcibus, pcidev, pcifunc);
205 unsigned platform_index,
unsigned device_index)
207 unsigned x = (unsigned) -1, y = (
unsigned) -1;
212 && sscanf(osdev->
name,
"opencl%ud%u", &x, &y) == 2
213 && platform_index == x && device_index == y)
242 cl_device_id device __hwloc_attribute_unused)
245 unsigned pcidomain, pcibus, pcidevice, pcifunc;
255 if (strncmp(osdev->
name,
"opencl", 6))