Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.2.2

  |   Home   |   Support   |   FAQ   |  
cuda.h
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2010 INRIA.  All rights reserved.
00003  * Copyright © 2010 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 
00023 #include <cuda.h>
00024 
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 
00043 static inline int
00044 hwloc_cuda_get_device_cpuset(hwloc_topology_t topology ,
00045                              CUdevice cudevice, hwloc_cpuset_t set)
00046 {
00047 #ifdef HWLOC_LINUX_SYS
00048   /* If we're on Linux, use the sysfs mechanism to get the local cpus */
00049 #define HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX 128
00050   CUresult cres;
00051   int deviceid;
00052   int busid;
00053   char path[HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX];
00054   FILE *sysfile = NULL;
00055 
00056   cres = cuDeviceGetAttribute(&busid, CU_DEVICE_ATTRIBUTE_PCI_BUS_ID, cudevice);
00057   if (cres != CUDA_SUCCESS) {
00058     errno = ENOSYS;
00059     return -1;
00060   }
00061   cres = cuDeviceGetAttribute(&deviceid, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, cudevice);
00062   if (cres != CUDA_SUCCESS) {
00063     errno = ENOSYS;
00064     return -1;
00065   }
00066 
00067   sprintf(path, "/sys/bus/pci/devices/0000:%02x:%02x.0/local_cpus", busid, deviceid);
00068   sysfile = fopen(path, "r");
00069   if (!sysfile)
00070     return -1;
00071 
00072   hwloc_linux_parse_cpumap_file(sysfile, set);
00073 
00074   fclose(sysfile);
00075 #else
00076   /* Non-Linux systems simply get a full cpuset */
00077   hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00078 #endif
00079   return 0;
00080 }
00081 
00085 #ifdef __cplusplus
00086 } /* extern "C" */
00087 #endif
00088 
00089 
00090 #endif /* HWLOC_CUDA_H */