Hardware Locality (hwloc) 1.4

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List

cuda.h

    00001 /*
    00002  * Copyright © 2010 inria.  All rights reserved.
    00003  * Copyright © 2010-2011 Université Bordeaux 1
    00004  * Copyright © 2011 Cisco Systems, Inc.  All rights reserved.
    00005  * See COPYING in top-level directory.
    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 inline int
    00039 hwloc_cuda_get_device_pci_ids(hwloc_topology_t topology ,
    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
    00075 static inline int
    00076 hwloc_cuda_get_device_cpuset(hwloc_topology_t topology ,
    00077                              CUdevice cudevice, hwloc_cpuset_t set)
    00078 {
    00079 #ifdef HWLOC_LINUX_SYS
    00080   /* If we're on Linux, use the sysfs mechanism to get the local cpus */
    00081 #define HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX 128
    00082   char path[HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX];
    00083   FILE *sysfile = NULL;
    00084   int domainid, busid, deviceid;
    00085
    00086   if (hwloc_cuda_get_device_pci_ids(topology, cudevice, &domainid, &busid, &deviceid))
    00087     return -1;
    00088
    00089   sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", domainid, busid, deviceid);
    00090   sysfile = fopen(path, "r");
    00091   if (!sysfile)
    00092     return -1;
    00093
    00094   hwloc_linux_parse_cpumap_file(sysfile, set);
    00095
    00096   fclose(sysfile);
    00097 #else
    00098   /* Non-Linux systems simply get a full cpuset */
    00099   hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
    00100 #endif
    00101   return 0;
    00102 }
    00103
    00110 static inline hwloc_obj_t
    00111 hwloc_cuda_get_device_pcidev(hwloc_topology_t topology, CUdevice cudevice)
    00112 {
    00113   int domain, bus, dev;
    00114
    00115   if (hwloc_cuda_get_device_pci_ids(topology, cudevice, &domain, &bus, &dev))
    00116     return NULL;
    00117
    00118   return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, 0);
    00119 }
    00120
    00124 #ifdef __cplusplus
    00125 } /* extern "C" */
    00126 #endif
    00127
    00128
    00129 #endif /* HWLOC_CUDA_H */