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>
45 #define HWLOC_CL_DEVICE_TOPOLOGY_AMD 0x4037
47 struct { cl_uint
type; cl_uint data[5]; } raw;
48 struct { cl_uint type; cl_char unused[17]; cl_char bus; cl_char device; cl_char
function; } pcie;
50 #define HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1
53 #define HWLOC_CL_DEVICE_PCI_BUS_ID_NV 0x4008
54 #define HWLOC_CL_DEVICE_PCI_SLOT_ID_NV 0x4009
55 #define HWLOC_CL_DEVICE_PCI_DOMAIN_ID_NV 0x400A
73 static __hwloc_inline
int
75 unsigned *domain,
unsigned *bus,
unsigned *dev,
unsigned *func)
78 cl_uint nvbus, nvslot, nvdomain;
81 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_TOPOLOGY_AMD,
sizeof(amdtopo), &amdtopo, NULL);
82 if (CL_SUCCESS == clret
83 && HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD == amdtopo.
raw.
type) {
85 *bus = (unsigned) amdtopo.
pcie.
bus;
91 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_BUS_ID_NV,
sizeof(nvbus), &nvbus, NULL);
92 if (CL_SUCCESS == clret) {
93 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_SLOT_ID_NV,
sizeof(nvslot), &nvslot, NULL);
94 if (CL_SUCCESS == clret) {
95 clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_DOMAIN_ID_NV,
sizeof(nvdomain), &nvdomain, NULL);
96 if (CL_SUCCESS == clret) {
104 *func = nvslot & 0x7;
129 static __hwloc_inline
int
131 cl_device_id device __hwloc_attribute_unused,
134 #if (defined HWLOC_LINUX_SYS)
136 #define HWLOC_OPENCL_DEVICE_SYSFS_PATH_MAX 128
137 char path[HWLOC_OPENCL_DEVICE_SYSFS_PATH_MAX];
138 unsigned pcidomain, pcibus, pcidev, pcifunc;
150 sprintf(path,
"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/local_cpus", pcidomain, pcibus, pcidev, pcifunc);
178 unsigned platform_index,
unsigned device_index)
180 unsigned x = (unsigned) -1, y = (
unsigned) -1;
185 && sscanf(osdev->
name,
"opencl%ud%u", &x, &y) == 2
186 && platform_index == x && device_index == y)
214 cl_device_id device __hwloc_attribute_unused)
217 unsigned pcidomain, pcibus, pcidevice, pcifunc;
227 if (strncmp(osdev->
name,
"opencl", 6))