Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.7

  |   Home   |   Support   |   FAQ   |  
intel-mic.h
1 /*
2  * Copyright © 2013 Inria. All rights reserved.
3  * See COPYING in top-level directory.
4  */
5 
13 #ifndef HWLOC_INTEL_MIC_H
14 #define HWLOC_INTEL_MIC_H
15 
16 #include <hwloc.h>
17 #include <hwloc/autogen/config.h>
18 #include <hwloc/helper.h>
19 #ifdef HWLOC_LINUX_SYS
20 #include <hwloc/linux.h>
21 #include <dirent.h>
22 #include <string.h>
23 #endif
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
53 static inline int
55  int idx ,
56  hwloc_cpuset_t set)
57 {
58 #ifdef HWLOC_LINUX_SYS
59  /* If we're on Linux, use the sysfs mechanism to get the local cpus */
60 #define HWLOC_INTEL_MIC_DEVICE_SYSFS_PATH_MAX 128
61  char path[HWLOC_INTEL_MIC_DEVICE_SYSFS_PATH_MAX];
62  DIR *sysdir = NULL;
63  FILE *sysfile = NULL;
64  struct dirent *dirent;
65  unsigned pcibus, pcidev, pcifunc;
66 
67  if (!hwloc_topology_is_thissystem(topology)) {
68  errno = EINVAL;
69  return -1;
70  }
71 
72  sprintf(path, "/sys/class/mic/mic%d", idx);
73  sysdir = opendir(path);
74  if (!sysdir)
75  return -1;
76 
77  while ((dirent = readdir(sysdir)) != NULL) {
78  if (sscanf(dirent->d_name, "pci_%02x:%02x.%02x", &pcibus, &pcidev, &pcifunc) == 3) {
79  sprintf(path, "/sys/class/mic/mic%d/pci_%02x:%02x.%02x/local_cpus", idx, pcibus, pcidev, pcifunc);
80  sysfile = fopen(path, "r");
81  if (!sysfile) {
82  closedir(sysdir);
83  return -1;
84  }
85 
86  hwloc_linux_parse_cpumap_file(sysfile, set);
87  if (hwloc_bitmap_iszero(set))
89 
90  fclose(sysfile);
91  break;
92  }
93  }
94 
95  closedir(sysdir);
96 #else
97  /* Non-Linux systems simply get a full cpuset */
99 #endif
100  return 0;
101 }
102 
116 static inline hwloc_obj_t
118  unsigned idx)
119 {
120  hwloc_obj_t osdev = NULL;
121  while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
122  if (HWLOC_OBJ_OSDEV_COPROC == osdev->attr->osdev.type
123  && osdev->name
124  && !strncmp("mic", osdev->name, 3)
125  && atoi(osdev->name + 3) == (int) idx)
126  return osdev;
127  }
128  return NULL;
129 }
130 
134 #ifdef __cplusplus
135 } /* extern "C" */
136 #endif
137 
138 
139 #endif /* HWLOC_INTEL_MIC_H */