Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.3.3

  |   Home   |   Support   |   FAQ   |  
cudart.h
1 /*
2  * Copyright © 2010 inria. All rights reserved.
3  * Copyright © 2010 Université Bordeaux 1
4  * Copyright © 2011 Cisco Systems, Inc. All rights reserved.
5  * See COPYING in top-level directory.
6  */
7 
16 #ifndef HWLOC_CUDART_H
17 #define HWLOC_CUDART_H
18 
19 #include <hwloc.h>
20 #include <hwloc/autogen/config.h>
21 #include <hwloc/linux.h>
22 
23 #include <cuda_runtime_api.h>
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 
43 static inline int
45  int device, hwloc_cpuset_t set)
46 {
47 #ifdef HWLOC_LINUX_SYS
48  /* If we're on Linux, use the sysfs mechanism to get the local cpus */
49 #define HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX 128
50  cudaError_t cerr;
51  struct cudaDeviceProp prop;
52  char path[HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX];
53  FILE *sysfile = NULL;
54  int pciDomainID = 0;
55 
56  cerr = cudaGetDeviceProperties(&prop, device);
57  if (cerr) {
58  errno = ENOSYS;
59  return -1;
60  }
61 
62 #if CUDART_VERSION >= 4000
63  pciDomainID = prop.pciDomainID;
64 #endif
65 
66  sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", pciDomainID, prop.pciBusID, prop.pciDeviceID);
67  sysfile = fopen(path, "r");
68  if (!sysfile)
69  return -1;
70 
71  hwloc_linux_parse_cpumap_file(sysfile, set);
72 
73  fclose(sysfile);
74 #else
75  /* Non-Linux systems simply get a full cpuset */
77 #endif
78  return 0;
79 }
80 
84 #ifdef __cplusplus
85 } /* extern "C" */
86 #endif
87 
88 
89 #endif /* HWLOC_CUDART_H */