Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.6.2

  |   Home   |   Support   |   FAQ   |  
openfabrics-verbs.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2012 inria. All rights reserved.
4  * Copyright © 2009-2010 Université Bordeaux 1
5  * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
6  * See COPYING in top-level directory.
7  */
8 
19 #ifndef HWLOC_OPENFABRICS_VERBS_H
20 #define HWLOC_OPENFABRICS_VERBS_H
21 
22 #include <hwloc.h>
23 #include <hwloc/autogen/config.h>
24 #include <hwloc/linux.h>
25 
26 #include <infiniband/verbs.h>
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
48 static inline int
50  struct ibv_device *ibdev, hwloc_cpuset_t set)
51 {
52 #ifdef HWLOC_LINUX_SYS
53  /* If we're on Linux, use the verbs-provided sysfs mechanism to
54  get the local cpus */
55 #define HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX 128
56  char path[HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX];
57  FILE *sysfile = NULL;
58 
59  if (!hwloc_topology_is_thissystem(topology)) {
60  errno = EINVAL;
61  return -1;
62  }
63 
64  sprintf(path, "/sys/class/infiniband/%s/device/local_cpus",
65  ibv_get_device_name(ibdev));
66  sysfile = fopen(path, "r");
67  if (!sysfile)
68  return -1;
69 
70  hwloc_linux_parse_cpumap_file(sysfile, set);
71  if (hwloc_bitmap_iszero(set))
73 
74  fclose(sysfile);
75 #else
76  /* Non-Linux systems simply get a full cpuset */
78 #endif
79  return 0;
80 }
81 
98 static inline hwloc_obj_t
100  const char *ibname)
101 {
102  hwloc_obj_t osdev = NULL;
103  while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
105  && osdev->name && !strcmp(ibname, osdev->name))
106  return osdev;
107  }
108  return NULL;
109 }
110 
114 #ifdef __cplusplus
115 } /* extern "C" */
116 #endif
117 
118 
119 #endif /* HWLOC_OPENFABRICS_VERBS_H */