• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List

cudart.h

00001 /*
00002  * Copyright © 2010 INRIA
00003  * Copyright © 2010 Université Bordeaux 1
00004  * See COPYING in top-level directory.
00005  */
00006 
00015 #ifndef HWLOC_CUDART_H
00016 #define HWLOC_CUDART_H
00017 
00018 #include <hwloc.h>
00019 #include <hwloc/config.h>
00020 #include <hwloc/linux.h>
00021 
00022 #include <cuda_runtime_api.h>
00023 
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 
00042 static inline int
00043 hwloc_cudart_get_device_cpuset(hwloc_topology_t topology ,
00044                                int device, hwloc_cpuset_t set)
00045 {
00046 #ifdef HWLOC_LINUX_SYS
00047   /* If we're on Linux, use the sysfs mechanism to get the local cpus */
00048 #define HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX 128
00049   cudaError_t cerr;
00050   struct cudaDeviceProp prop;
00051   char path[HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX];
00052   FILE *sysfile = NULL;
00053 
00054   cerr = cudaGetDeviceProperties(&prop, device);
00055   if (cerr) {
00056     errno = ENOSYS;
00057     return -1;
00058   }
00059 
00060   sprintf(path, "/sys/bus/pci/devices/0000:%02x:%02x.0/local_cpus", prop.pciBusID, prop.pciDeviceID);
00061   sysfile = fopen(path, "r");
00062   if (!sysfile)
00063     return -1;
00064 
00065   hwloc_linux_parse_cpumap_file(sysfile, set);
00066 
00067   fclose(sysfile);
00068 #else
00069   /* Non-Linux systems simply get a full cpuset */
00070   hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00071 #endif
00072   return 0;
00073 }
00074 
00078 #ifdef __cplusplus
00079 } /* extern "C" */
00080 #endif
00081 
00082 
00083 #endif /* HWLOC_CUDART_H */

Generated on Mon Jan 24 2011 17:12:07 for Hardware Locality (hwloc) by  doxygen 1.7.2