Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00016 #ifndef HWLOC_CUDA_H
00017 #define HWLOC_CUDA_H
00018
00019 #include <hwloc.h>
00020 #include <hwloc/autogen/config.h>
00021 #include <hwloc/linux.h>
00022
00023 #include <cuda.h>
00024
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029
00030
00043 static inline int
00044 hwloc_cuda_get_device_cpuset(hwloc_topology_t topology ,
00045 CUdevice cudevice, hwloc_cpuset_t set)
00046 {
00047 #ifdef HWLOC_LINUX_SYS
00048
00049 #define HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX 128
00050 CUresult cres;
00051 int deviceid;
00052 int busid;
00053 char path[HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX];
00054 FILE *sysfile = NULL;
00055
00056 cres = cuDeviceGetAttribute(&busid, CU_DEVICE_ATTRIBUTE_PCI_BUS_ID, cudevice);
00057 if (cres != CUDA_SUCCESS) {
00058 errno = ENOSYS;
00059 return -1;
00060 }
00061 cres = cuDeviceGetAttribute(&deviceid, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, cudevice);
00062 if (cres != CUDA_SUCCESS) {
00063 errno = ENOSYS;
00064 return -1;
00065 }
00066
00067 sprintf(path, "/sys/bus/pci/devices/0000:%02x:%02x.0/local_cpus", busid, deviceid);
00068 sysfile = fopen(path, "r");
00069 if (!sysfile)
00070 return -1;
00071
00072 hwloc_linux_parse_cpumap_file(sysfile, set);
00073
00074 fclose(sysfile);
00075 #else
00076
00077 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00078 #endif
00079 return 0;
00080 }
00081
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088
00089
00090 #endif