Open MPI logo

Portable Hardware Locality (hwloc) Documentation: v1.7.2

  |   Home   |   Support   |   FAQ   |  
openfabrics-verbs.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2013 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 #ifdef HWLOC_LINUX_SYS
25 #include <hwloc/linux.h>
26 #endif
27 
28 #include <infiniband/verbs.h>
29 
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 
57 static __hwloc_inline int
58 hwloc_ibv_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
59  struct ibv_device *ibdev, hwloc_cpuset_t set)
60 {
61 #ifdef HWLOC_LINUX_SYS
62  /* If we're on Linux, use the verbs-provided sysfs mechanism to
63  get the local cpus */
64 #define HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX 128
65  char path[HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX];
66  FILE *sysfile = NULL;
67 
68  if (!hwloc_topology_is_thissystem(topology)) {
69  errno = EINVAL;
70  return -1;
71  }
72 
73  sprintf(path, "/sys/class/infiniband/%s/device/local_cpus",
74  ibv_get_device_name(ibdev));
75  sysfile = fopen(path, "r");
76  if (!sysfile)
77  return -1;
78 
79  hwloc_linux_parse_cpumap_file(sysfile, set);
80  if (hwloc_bitmap_iszero(set))
82 
83  fclose(sysfile);
84 #else
85  /* Non-Linux systems simply get a full cpuset */
87 #endif
88  return 0;
89 }
90 
105 static __hwloc_inline hwloc_obj_t
107  const char *ibname)
108 {
109  hwloc_obj_t osdev = NULL;
110  while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
112  && osdev->name && !strcmp(ibname, osdev->name))
113  return osdev;
114  }
115  return NULL;
116 }
117 
132 static __hwloc_inline hwloc_obj_t
134  struct ibv_device *ibdev)
135 {
136  if (!hwloc_topology_is_thissystem(topology)) {
137  errno = EINVAL;
138  return NULL;
139  }
140  return hwloc_ibv_get_device_osdev_by_name(topology, ibv_get_device_name(ibdev));
141 }
142 
146 #ifdef __cplusplus
147 } /* extern "C" */
148 #endif
149 
150 
151 #endif /* HWLOC_OPENFABRICS_VERBS_H */