00001
00002
00003
00004
00005
00006
00015 #ifndef HWLOC_CUDART_H
00016 #define HWLOC_CUDART_H
00017
00018 #include <hwloc.h>
00019 #include <hwloc/config.h>
00020 #include <hwloc/linux.h>
00021
00022 #include <cuda_runtime_api.h>
00023
00024
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028
00029
00042 static __hwloc_inline int
00043 hwloc_cudart_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
00044 int device, hwloc_cpuset_t set)
00045 {
00046 #ifdef HWLOC_LINUX_SYS
00047
00048 #define HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX 128
00049 cudaError_t cerr;
00050 struct cudaDeviceProp prop;
00051 char path[HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX];
00052 FILE *sysfile = NULL;
00053
00054 cerr = cudaGetDeviceProperties(&prop, device);
00055 if (cerr) {
00056 errno = ENOSYS;
00057 return -1;
00058 }
00059
00060 sprintf(path, "/sys/bus/pci/devices/0000:%02x:%02x.0/local_cpus", prop.pciBusID, prop.pciDeviceID);
00061 sysfile = fopen(path, "r");
00062 if (!sysfile)
00063 return -1;
00064
00065 hwloc_linux_parse_cpumap_file(sysfile, set);
00066
00067 fclose(sysfile);
00068 #else
00069
00070 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00071 #endif
00072 return 0;
00073 }
00074
00078 #ifdef __cplusplus
00079 }
00080 #endif
00081
00082
00083 #endif