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 #include <hwloc/helper.h>
00023
00024 #include <cuda.h>
00025
00026
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030
00031
00038 static __hwloc_inline int
00039 hwloc_cuda_get_device_pci_ids(hwloc_topology_t topology __hwloc_attribute_unused,
00040 CUdevice cudevice, int *domain, int *bus, int *dev)
00041 {
00042 CUresult cres;
00043
00044 #if CUDA_VERSION >= 4000
00045 cres = cuDeviceGetAttribute(domain, CU_DEVICE_ATTRIBUTE_PCI_DOMAIN_ID, cudevice);
00046 if (cres != CUDA_SUCCESS) {
00047 errno = ENOSYS;
00048 return -1;
00049 }
00050 #else
00051 *domain = 0;
00052 #endif
00053 cres = cuDeviceGetAttribute(bus, CU_DEVICE_ATTRIBUTE_PCI_BUS_ID, cudevice);
00054 if (cres != CUDA_SUCCESS) {
00055 errno = ENOSYS;
00056 return -1;
00057 }
00058 cres = cuDeviceGetAttribute(dev, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, cudevice);
00059 if (cres != CUDA_SUCCESS) {
00060 errno = ENOSYS;
00061 return -1;
00062 }
00063
00064 return 0;
00065 }
00066
00077 static __hwloc_inline int
00078 hwloc_cuda_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
00079 CUdevice cudevice, hwloc_cpuset_t set)
00080 {
00081 #ifdef HWLOC_LINUX_SYS
00082
00083 #define HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX 128
00084 char path[HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX];
00085 FILE *sysfile = NULL;
00086 int domainid, busid, deviceid;
00087
00088 if (hwloc_cuda_get_device_pci_ids(topology, cudevice, &domainid, &busid, &deviceid))
00089 return -1;
00090
00091 sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", domainid, busid, deviceid);
00092 sysfile = fopen(path, "r");
00093 if (!sysfile)
00094 return -1;
00095
00096 hwloc_linux_parse_cpumap_file(sysfile, set);
00097 if (hwloc_bitmap_iszero(set))
00098 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00099
00100 fclose(sysfile);
00101 #else
00102
00103 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00104 #endif
00105 return 0;
00106 }
00107
00116 static __hwloc_inline hwloc_obj_t
00117 hwloc_cuda_get_device_pcidev(hwloc_topology_t topology, CUdevice cudevice)
00118 {
00119 int domain, bus, dev;
00120
00121 if (hwloc_cuda_get_device_pci_ids(topology, cudevice, &domain, &bus, &dev))
00122 return NULL;
00123
00124 return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, 0);
00125 }
00126
00130 #ifdef __cplusplus
00131 }
00132 #endif
00133
00134
00135 #endif