OpenMPI  0.1.1
openfabrics-verbs.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2010 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 
9 /** \file
10  * \brief Macros to help interaction between hwloc and OpenFabrics
11  * verbs.
12  *
13  * Applications that use both hwloc and OpenFabrics verbs may want to
14  * include this file so as to get topology information for OpenFabrics
15  * hardware.
16  *
17  */
18 
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 
34 /** \defgroup hwlocality_openfabrics OpenFabrics-Specific Functions
35  * @{
36  */
37 
38 /** \brief Get the CPU set of logical processors that are physically
39  * close to device \p ibdev.
40  *
41  * For the given OpenFabrics device \p ibdev, read the corresponding
42  * kernel-provided cpumap file and return the corresponding CPU set.
43  * This function is currently only implemented in a meaningful way for
44  * Linux; other systems will simply get a full cpuset.
45  */
46 static __hwloc_inline int
47 hwloc_ibv_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
48  struct ibv_device *ibdev, hwloc_cpuset_t set)
49 {
50 #ifdef HWLOC_LINUX_SYS
51  /* If we're on Linux, use the verbs-provided sysfs mechanism to
52  get the local cpus */
53 #define HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX 128
54  char path[HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX];
55  FILE *sysfile = NULL;
56 
57  sprintf(path, "/sys/class/infiniband/%s/device/local_cpus",
58  ibv_get_device_name(ibdev));
59  sysfile = fopen(path, "r");
60  if (!sysfile)
61  return -1;
62 
63  hwloc_linux_parse_cpumap_file(sysfile, set);
64 
65  fclose(sysfile);
66 #else
67  /* Non-Linux systems simply get a full cpuset */
69 #endif
70  return 0;
71 }
72 
73 /** @} */
74 
75 
76 #ifdef __cplusplus
77 } /* extern "C" */
78 #endif
79 
80 
81 #endif /* HWLOC_OPENFABRICS_VERBS_H */
HWLOC_DECLSPEC void hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t src)
Copy the contents of bitmap src into the already allocated bitmap dst.
static __hwloc_inline hwloc_const_cpuset_t __hwloc_attribute_pure hwloc_topology_get_complete_cpuset(hwloc_topology_t topology)
Get complete CPU set.
Definition: helper.h:729
Macros to help interaction between hwloc and Linux.
HWLOC_DECLSPEC int hwloc_linux_parse_cpumap_file(FILE *file, hwloc_cpuset_t set)
Convert a linux kernel cpumap file file into hwloc CPU set.
Definition: topology-linux.c:1332
static __hwloc_inline int hwloc_ibv_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused, struct ibv_device *ibdev, hwloc_cpuset_t set)
Get the CPU set of logical processors that are physically close to device ibdev.
Definition: openfabrics-verbs.h:47
Definition: private.h:56
Definition: cpuset.c:38