Hardware Locality (hwloc) 1.3.1
|
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 domainid = 0; 00052 int deviceid; 00053 int busid; 00054 char path[HWLOC_CUDA_DEVICE_SYSFS_PATH_MAX]; 00055 FILE *sysfile = NULL; 00056 00057 #if CUDA_VERSION >= 4000 00058 cres = cuDeviceGetAttribute(&domainid, CU_DEVICE_ATTRIBUTE_PCI_DOMAIN_ID, cudevice); 00059 if (cres != CUDA_SUCCESS) { 00060 errno = ENOSYS; 00061 return -1; 00062 } 00063 #endif 00064 cres = cuDeviceGetAttribute(&busid, CU_DEVICE_ATTRIBUTE_PCI_BUS_ID, cudevice); 00065 if (cres != CUDA_SUCCESS) { 00066 errno = ENOSYS; 00067 return -1; 00068 } 00069 cres = cuDeviceGetAttribute(&deviceid, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, cudevice); 00070 if (cres != CUDA_SUCCESS) { 00071 errno = ENOSYS; 00072 return -1; 00073 } 00074 00075 sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", domainid, busid, deviceid); 00076 sysfile = fopen(path, "r"); 00077 if (!sysfile) 00078 return -1; 00079 00080 hwloc_linux_parse_cpumap_file(sysfile, set); 00081 00082 fclose(sysfile); 00083 #else 00084 /* Non-Linux systems simply get a full cpuset */ 00085 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology)); 00086 #endif 00087 return 0; 00088 } 00089 00093 #ifdef __cplusplus 00094 } /* extern "C" */ 00095 #endif 00096 00097 00098 #endif /* HWLOC_CUDA_H */