00001
00002
00003
00004
00005
00006
00007
00016 #ifndef HWLOC_CUDART_H
00017 #define HWLOC_CUDART_H
00018
00019 #include <hwloc.h>
00020 #include <hwloc/autogen/config.h>
00021 #include <hwloc/linux.h>
00022
00023 #include <cuda_runtime_api.h>
00024
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029
00030
00043 static __hwloc_inline int
00044 hwloc_cudart_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
00045 int device, hwloc_cpuset_t set)
00046 {
00047 #ifdef HWLOC_LINUX_SYS
00048
00049 #define HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX 128
00050 cudaError_t cerr;
00051 struct cudaDeviceProp prop;
00052 char path[HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX];
00053 FILE *sysfile = NULL;
00054 int pciDomainID = 0;
00055
00056 cerr = cudaGetDeviceProperties(&prop, device);
00057 if (cerr) {
00058 errno = ENOSYS;
00059 return -1;
00060 }
00061
00062 #if CUDART_VERSION >= 4000
00063 pciDomainID = prop.pciDomainID;
00064 #endif
00065
00066 sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", pciDomainID, prop.pciBusID, prop.pciDeviceID);
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