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