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 #include <hwloc/helper.h>
00023
00024 #include <cuda_runtime_api.h>
00025
00026
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030
00031
00038 static inline int
00039 hwloc_cudart_get_device_pci_ids(hwloc_topology_t topology ,
00040 int device, int *domain, int *bus, int *dev)
00041 {
00042 cudaError_t cerr;
00043 struct cudaDeviceProp prop;
00044
00045 cerr = cudaGetDeviceProperties(&prop, device);
00046 if (cerr) {
00047 errno = ENOSYS;
00048 return -1;
00049 }
00050
00051 #if CUDART_VERSION >= 4000
00052 *domain = prop.pciDomainID;
00053 #else
00054 *domain = 0;
00055 #endif
00056
00057 *bus = prop.pciBusID;
00058 *dev = prop.pciDeviceID;
00059
00060 return 0;
00061 }
00062
00071 static inline int
00072 hwloc_cudart_get_device_cpuset(hwloc_topology_t topology ,
00073 int device, hwloc_cpuset_t set)
00074 {
00075 #ifdef HWLOC_LINUX_SYS
00076
00077 #define HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX 128
00078 char path[HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX];
00079 FILE *sysfile = NULL;
00080 int domain, bus, dev;
00081 if (hwloc_cudart_get_device_pci_ids(topology, device, &domain, &bus, &dev))
00082 return -1;
00083
00084 sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", domain, bus, dev);
00085 sysfile = fopen(path, "r");
00086 if (!sysfile)
00087 return -1;
00088
00089 hwloc_linux_parse_cpumap_file(sysfile, set);
00090
00091 fclose(sysfile);
00092 #else
00093
00094 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00095 #endif
00096 return 0;
00097 }
00098
00105 static inline hwloc_obj_t
00106 hwloc_cudart_get_device_pcidev(hwloc_topology_t topology, int device)
00107 {
00108 int domain, bus, dev;
00109
00110 if (hwloc_cudart_get_device_pci_ids(topology, device, &domain, &bus, &dev))
00111 return NULL;
00112
00113 return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, 0);
00114 }
00115
00119 #ifdef __cplusplus
00120 }
00121 #endif
00122
00123
00124 #endif