[mpich2-commits] r5531 - in mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc: include/hwloc tests

balaji at mcs.anl.gov balaji at mcs.anl.gov
Thu Oct 22 11:35:20 CDT 2009


Author: balaji
Date: 2009-10-22 11:35:20 -0500 (Thu, 22 Oct 2009)
New Revision: 5531

Added:
   mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc/include/hwloc/openfabrics-verbs.h
   mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc/tests/openfabrics-verbs.c
Log:
Missed two files in hwloc from the 0.9.1rc2 release because of my
git-svn setup inexperience.

Added: mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc/include/hwloc/openfabrics-verbs.h
===================================================================
--- mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc/include/hwloc/openfabrics-verbs.h	                        (rev 0)
+++ mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc/include/hwloc/openfabrics-verbs.h	2009-10-22 16:35:20 UTC (rev 5531)
@@ -0,0 +1,66 @@
+/*
+ * Copyright © 2009 CNRS, INRIA, Université Bordeaux 1
+ * Copyright © 2009 Cisco Systems, Inc.  All rights reserved.
+ * See COPYING in top-level directory.
+ */
+
+/** \file
+ * \brief Macros to help interaction between hwloc and OpenFabrics
+ * verbs.
+ *
+ * Applications that use both hwloc and OpenFabrics verbs may want to
+ * include this file so as to get topology information for OpenFabrics
+ * hardware.
+ *
+ */
+
+#ifndef HWLOC_OPENFABRICS_VERBS_H
+#define HWLOC_OPENFABRICS_VERBS_H
+
+#include <hwloc.h>
+#include <hwloc/linux.h>
+
+#include <infiniband/verbs.h>
+
+/** \defgroup hwloc_openfabrics OpenFabrics-Specific Functions
+ * @{
+ */
+
+/** \brief Get the CPU set of logical processors that are physically
+ * close to device \p ibdev.
+ *
+ * For the given OpenFabrics device \p ibdev, read the corresponding
+ * kernel-provided cpumap file and return the corresponding CPU set.
+ * This function is currently only implemented in a meaningful way for
+ * Linux; other systems will simply get a full cpuset.
+ */
+static __inline hwloc_cpuset_t
+hwloc_ibv_get_device_cpuset(struct ibv_device *ibdev)
+{
+#if defined(LINUX_SYS)
+  /* If we're on Linux, use the verbs-provided sysfs mechanism to
+     get the local cpus */
+#define HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX 128
+  char path[HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX];
+  FILE *sysfile = NULL;
+  hwloc_cpuset_t set;
+
+  sprintf(path, "/sys/class/infiniband/%s/device/local_cpus",
+	  ibv_get_device_name(ibdev));
+  sysfile = fopen(path, "r");
+  if (!sysfile)
+    return NULL;
+
+  set = hwloc_linux_parse_cpumap_file(sysfile);
+
+  fclose(sysfile);
+  return set;
+#else
+  /* Non-Linux systems simply get a full cpuset */
+  return hwloc_cpuset_dup(hwloc_get_system_obj(topology)->cpuset);
+#endif
+}
+
+/** @} */
+
+#endif /* HWLOC_OPENFABRICS_VERBS_H */

Added: mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc/tests/openfabrics-verbs.c
===================================================================
--- mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc/tests/openfabrics-verbs.c	                        (rev 0)
+++ mpich2/trunk/src/pm/hydra/tools/bind/hwloc/hwloc/tests/openfabrics-verbs.c	2009-10-22 16:35:20 UTC (rev 5531)
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2009 CNRS, INRIA, Université Bordeaux 1
+ * Copyright © 2009 Cisco Systems, Inc.  All rights reserved.
+ * See COPYING in top-level directory.
+ */
+
+#include <stdio.h>
+#include <assert.h>
+#include <infiniband/verbs.h>
+#include <hwloc.h>
+#include <private/config.h>
+#include <hwloc/openfabrics-verbs.h>
+
+/* check the ibverbs helpers */
+
+int main(int argc, char **argv)
+{
+  struct ibv_device **dev_list, *dev;
+  int count, i;
+
+  dev_list = ibv_get_device_list(&count);
+  if (!dev_list) {
+    fprintf(stderr, "ibv_get_device_list failed\n");
+    return 0;
+  }
+  printf("ibv_get_device_list found %d devices\n", count);
+
+  for(i=0; i<count; i++) {
+    hwloc_cpuset_t set;
+    dev = dev_list[i];
+
+    set = hwloc_ibv_get_device_cpuset(dev);
+    if (!set) {
+      printf("failed to get cpuset for device %d (%s)\n",
+	     i, ibv_get_device_name(dev));
+    } else {
+      char *cpuset_string = NULL;
+      hwloc_cpuset_asprintf(&cpuset_string, set);
+      printf("got cpuset %s for device %d (%s)\n",
+	     cpuset_string, i, ibv_get_device_name(dev));
+      free(cpuset_string);
+      hwloc_cpuset_free(set);
+    }
+  }
+
+  ibv_free_device_list(dev_list);
+
+  return 0;
+}



More information about the mpich2-commits mailing list