1
1
openmpi/opal/mca/hwloc/base/hwloc_base_dt.c

340 строки
11 KiB
C
Исходник Обычный вид История

/*
Per RFC, bring in the following changes: * Remove paffinity, maffinity, and carto frameworks -- they've been wholly replaced by hwloc. * Move ompi_mpi_init() affinity-setting/checking code down to ORTE. * Update sm, smcuda, wv, and openib components to no longer use carto. Instead, use hwloc data. There are still optimizations possible in the sm/smcuda BTLs (i.e., making multiple mpools). Also, the old carto-based code found out how many NUMA nodes were ''available'' -- not how many were used ''in this job''. The new hwloc-using code computes the same value -- it was not updated to calculate how many NUMA nodes are used ''by this job.'' * Note that I cannot compile the smcuda and wv BTLs -- I ''think'' they're right, but they need to be verified by their owners. * The openib component now does a bunch of stuff to figure out where "near" OpenFabrics devices are. '''THIS IS A CHANGE IN DEFAULT BEHAVIOR!!''' and still needs to be verified by OpenFabrics vendors (I do not have a NUMA machine with an OpenFabrics device that is a non-uniform distance from multiple different NUMA nodes). * Completely rewrite the OMPI_Affinity_str() routine from the "affinity" mpiext extension. This extension now understands hyperthreads; the output format of it has changed a bit to reflect this new information. * Bunches of minor changes around the code base to update names/types from maffinity/paffinity-based names to hwloc-based names. * Add some helper functions into the hwloc base, mainly having to do with the fact that we have the hwloc data reporting ''all'' topology information, but sometimes you really only want the (online | available) data. This commit was SVN r26391.
2012-05-07 18:52:54 +04:00
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/util/output.h"
#include "opal/dss/dss.h"
#include "opal/mca/hwloc/base/base.h"
int opal_hwloc_pack(opal_buffer_t *buffer, const void *src,
int32_t num_vals,
opal_data_type_t type)
{
/* NOTE: hwloc defines topology_t as a pointer to a struct! */
hwloc_topology_t t, *tarray = (hwloc_topology_t*)src;
int rc, i;
char *xmlbuffer=NULL;
int len;
struct hwloc_topology_support *support;
for (i=0; i < num_vals; i++) {
t = tarray[i];
/* extract an xml-buffer representation of the tree */
if (0 != hwloc_topology_export_xmlbuffer(t, &xmlbuffer, &len)) {
return OPAL_ERROR;
}
/* add to buffer */
if (OPAL_SUCCESS != (rc = opal_dss.pack(buffer, &xmlbuffer, 1, OPAL_STRING))) {
free(xmlbuffer);
return rc;
}
/* cleanup */
if (NULL != xmlbuffer) {
free(xmlbuffer);
}
This commit introduces a new "mindist" ORTE RMAPS mapper, as well as some relevant updates/new functionality in the opal/mca/hwloc and orte/mca/rmaps bases. This work was mainly developed by Mellanox, with a bunch of advice from Ralph Castain, and some minor advice from Brice Goglin and Jeff Squyres. Even though this is mainly Mellanox's work, Jeff is committing only for logistical reasons (he holds the hg+svn combo tree, and can therefore commit it directly back to SVN). ----- Implemented distance-based mapping algorithm as a new "mindist" component in the rmaps framework. It allows mapping processes by NUMA due to PCI locality information as reported by the BIOS - from the closest to device to furthest. To use this algorithm, specify: {{{mpirun --map-by dist:<device_name>}}} where <device_name> can be mlx5_0, ib0, etc. There are two modes provided: 1. bynode: load-balancing across nodes 1. byslot: go through slots sequentially (i.e., the first nodes are more loaded) These options are regulated by the optional ''span'' modifier; the command line parameter looks like: {{{mpirun --map-by dist:<device_name>,span}}} So, for example, if there are 2 nodes, each with 8 cores, and we'd like to run 10 processes, the mindist algorithm will place 8 processes to the first node and 2 to the second by default. But if you want to place 5 processes to each node, you can add a span modifier in your command line to do that. If there are two NUMA nodes on the node, each with 4 cores, and we run 6 processes, the mindist algorithm will try to find the NUMA closest to the specified device, and if successful, it will place 4 processes on that NUMA but leaving the remaining two to the next NUMA node. You can also specify the number of cpus per MPI process. This option is handled so that we map as many processes to the closest NUMA as we can (number of available processors at the NUMA divided by number of cpus per rank) and then go on with the next closest NUMA. The default binding option for this mapping is bind-to-numa. It works if you don't specify any binding policy. But if you specified binding level that was "lower" than NUMA (i.e hwthread, core, socket) it would bind to whatever level you specify. This commit was SVN r28552.
2013-05-22 17:04:40 +04:00
/* get the available support - hwloc unfortunately does
* not include this info in its xml export!
*/
2011-10-30 17:23:42 +04:00
support = (struct hwloc_topology_support*)hwloc_topology_get_support(t);
/* pack the discovery support */
if (OPAL_SUCCESS != (rc = opal_dss.pack(buffer, support->discovery,
sizeof(struct hwloc_topology_discovery_support),
OPAL_BYTE))) {
return rc;
}
/* pack the cpubind support */
if (OPAL_SUCCESS != (rc = opal_dss.pack(buffer, support->cpubind,
sizeof(struct hwloc_topology_cpubind_support),
OPAL_BYTE))) {
return rc;
}
/* pack the membind support */
if (OPAL_SUCCESS != (rc = opal_dss.pack(buffer, support->membind,
sizeof(struct hwloc_topology_membind_support),
OPAL_BYTE))) {
return rc;
}
}
return OPAL_SUCCESS;
}
int opal_hwloc_unpack(opal_buffer_t *buffer, void *dest,
int32_t *num_vals,
opal_data_type_t type)
{
/* NOTE: hwloc defines topology_t as a pointer to a struct! */
hwloc_topology_t t, *tarray = (hwloc_topology_t*)dest;
int rc=OPAL_SUCCESS, i, cnt, j;
char *xmlbuffer=NULL;
struct hwloc_topology_support *support;
for (i=0, j=0; i < *num_vals; i++) {
/* unpack the xml string */
cnt=1;
if (OPAL_SUCCESS != (rc = opal_dss.unpack(buffer, &xmlbuffer, &cnt, OPAL_STRING))) {
goto cleanup;
}
/* convert the xml */
if (0 != hwloc_topology_init(&t)) {
rc = OPAL_ERROR;
goto cleanup;
}
if (0 != hwloc_topology_set_xmlbuffer(t, xmlbuffer, strlen(xmlbuffer))) {
rc = OPAL_ERROR;
free(xmlbuffer);
hwloc_topology_destroy(t);
goto cleanup;
}
/* since we are loading this from an external source, we have to
* explicitly set a flag so hwloc sets things up correctly
*/
This commit introduces a new "mindist" ORTE RMAPS mapper, as well as some relevant updates/new functionality in the opal/mca/hwloc and orte/mca/rmaps bases. This work was mainly developed by Mellanox, with a bunch of advice from Ralph Castain, and some minor advice from Brice Goglin and Jeff Squyres. Even though this is mainly Mellanox's work, Jeff is committing only for logistical reasons (he holds the hg+svn combo tree, and can therefore commit it directly back to SVN). ----- Implemented distance-based mapping algorithm as a new "mindist" component in the rmaps framework. It allows mapping processes by NUMA due to PCI locality information as reported by the BIOS - from the closest to device to furthest. To use this algorithm, specify: {{{mpirun --map-by dist:<device_name>}}} where <device_name> can be mlx5_0, ib0, etc. There are two modes provided: 1. bynode: load-balancing across nodes 1. byslot: go through slots sequentially (i.e., the first nodes are more loaded) These options are regulated by the optional ''span'' modifier; the command line parameter looks like: {{{mpirun --map-by dist:<device_name>,span}}} So, for example, if there are 2 nodes, each with 8 cores, and we'd like to run 10 processes, the mindist algorithm will place 8 processes to the first node and 2 to the second by default. But if you want to place 5 processes to each node, you can add a span modifier in your command line to do that. If there are two NUMA nodes on the node, each with 4 cores, and we run 6 processes, the mindist algorithm will try to find the NUMA closest to the specified device, and if successful, it will place 4 processes on that NUMA but leaving the remaining two to the next NUMA node. You can also specify the number of cpus per MPI process. This option is handled so that we map as many processes to the closest NUMA as we can (number of available processors at the NUMA divided by number of cpus per rank) and then go on with the next closest NUMA. The default binding option for this mapping is bind-to-numa. It works if you don't specify any binding policy. But if you specified binding level that was "lower" than NUMA (i.e hwthread, core, socket) it would bind to whatever level you specify. This commit was SVN r28552.
2013-05-22 17:04:40 +04:00
if (0 != hwloc_topology_set_flags(t, HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM | HWLOC_TOPOLOGY_FLAG_IO_DEVICES)) {
free(xmlbuffer);
rc = OPAL_ERROR;
hwloc_topology_destroy(t);
goto cleanup;
}
/* now load the topology */
if (0 != hwloc_topology_load(t)) {
free(xmlbuffer);
rc = OPAL_ERROR;
hwloc_topology_destroy(t);
goto cleanup;
}
if (NULL != xmlbuffer) {
free(xmlbuffer);
}
This commit introduces a new "mindist" ORTE RMAPS mapper, as well as some relevant updates/new functionality in the opal/mca/hwloc and orte/mca/rmaps bases. This work was mainly developed by Mellanox, with a bunch of advice from Ralph Castain, and some minor advice from Brice Goglin and Jeff Squyres. Even though this is mainly Mellanox's work, Jeff is committing only for logistical reasons (he holds the hg+svn combo tree, and can therefore commit it directly back to SVN). ----- Implemented distance-based mapping algorithm as a new "mindist" component in the rmaps framework. It allows mapping processes by NUMA due to PCI locality information as reported by the BIOS - from the closest to device to furthest. To use this algorithm, specify: {{{mpirun --map-by dist:<device_name>}}} where <device_name> can be mlx5_0, ib0, etc. There are two modes provided: 1. bynode: load-balancing across nodes 1. byslot: go through slots sequentially (i.e., the first nodes are more loaded) These options are regulated by the optional ''span'' modifier; the command line parameter looks like: {{{mpirun --map-by dist:<device_name>,span}}} So, for example, if there are 2 nodes, each with 8 cores, and we'd like to run 10 processes, the mindist algorithm will place 8 processes to the first node and 2 to the second by default. But if you want to place 5 processes to each node, you can add a span modifier in your command line to do that. If there are two NUMA nodes on the node, each with 4 cores, and we run 6 processes, the mindist algorithm will try to find the NUMA closest to the specified device, and if successful, it will place 4 processes on that NUMA but leaving the remaining two to the next NUMA node. You can also specify the number of cpus per MPI process. This option is handled so that we map as many processes to the closest NUMA as we can (number of available processors at the NUMA divided by number of cpus per rank) and then go on with the next closest NUMA. The default binding option for this mapping is bind-to-numa. It works if you don't specify any binding policy. But if you specified binding level that was "lower" than NUMA (i.e hwthread, core, socket) it would bind to whatever level you specify. This commit was SVN r28552.
2013-05-22 17:04:40 +04:00
/* get the available support - hwloc unfortunately does
* not include this info in its xml import!
*/
support = (struct hwloc_topology_support*)hwloc_topology_get_support(t);
cnt = sizeof(struct hwloc_topology_discovery_support);
if (OPAL_SUCCESS != (rc = opal_dss.unpack(buffer, support->discovery, &cnt, OPAL_BYTE))) {
goto cleanup;
}
cnt = sizeof(struct hwloc_topology_cpubind_support);
if (OPAL_SUCCESS != (rc = opal_dss.unpack(buffer, support->cpubind, &cnt, OPAL_BYTE))) {
goto cleanup;
}
cnt = sizeof(struct hwloc_topology_membind_support);
if (OPAL_SUCCESS != (rc = opal_dss.unpack(buffer, support->membind, &cnt, OPAL_BYTE))) {
goto cleanup;
}
This commit introduces a new "mindist" ORTE RMAPS mapper, as well as some relevant updates/new functionality in the opal/mca/hwloc and orte/mca/rmaps bases. This work was mainly developed by Mellanox, with a bunch of advice from Ralph Castain, and some minor advice from Brice Goglin and Jeff Squyres. Even though this is mainly Mellanox's work, Jeff is committing only for logistical reasons (he holds the hg+svn combo tree, and can therefore commit it directly back to SVN). ----- Implemented distance-based mapping algorithm as a new "mindist" component in the rmaps framework. It allows mapping processes by NUMA due to PCI locality information as reported by the BIOS - from the closest to device to furthest. To use this algorithm, specify: {{{mpirun --map-by dist:<device_name>}}} where <device_name> can be mlx5_0, ib0, etc. There are two modes provided: 1. bynode: load-balancing across nodes 1. byslot: go through slots sequentially (i.e., the first nodes are more loaded) These options are regulated by the optional ''span'' modifier; the command line parameter looks like: {{{mpirun --map-by dist:<device_name>,span}}} So, for example, if there are 2 nodes, each with 8 cores, and we'd like to run 10 processes, the mindist algorithm will place 8 processes to the first node and 2 to the second by default. But if you want to place 5 processes to each node, you can add a span modifier in your command line to do that. If there are two NUMA nodes on the node, each with 4 cores, and we run 6 processes, the mindist algorithm will try to find the NUMA closest to the specified device, and if successful, it will place 4 processes on that NUMA but leaving the remaining two to the next NUMA node. You can also specify the number of cpus per MPI process. This option is handled so that we map as many processes to the closest NUMA as we can (number of available processors at the NUMA divided by number of cpus per rank) and then go on with the next closest NUMA. The default binding option for this mapping is bind-to-numa. It works if you don't specify any binding policy. But if you specified binding level that was "lower" than NUMA (i.e hwthread, core, socket) it would bind to whatever level you specify. This commit was SVN r28552.
2013-05-22 17:04:40 +04:00
/* pass it back */
tarray[i] = t;
/* track the number added */
j++;
}
cleanup:
*num_vals = j;
return rc;
}
int opal_hwloc_copy(hwloc_topology_t *dest, hwloc_topology_t src, opal_data_type_t type)
{
char *xml;
int len;
struct hwloc_topology_support *support, *destsupport;
if (0 != hwloc_topology_export_xmlbuffer(src, &xml, &len)) {
return OPAL_ERROR;
}
if (0 != hwloc_topology_init(dest)) {
free(xml);
return OPAL_ERROR;
}
if (0 != hwloc_topology_set_xmlbuffer(*dest, xml, len)) {
hwloc_topology_destroy(*dest);
free(xml);
return OPAL_ERROR;
}
if (0 != hwloc_topology_load(*dest)) {
hwloc_topology_destroy(*dest);
free(xml);
return OPAL_ERROR;
}
free(xml);
/* get the available support - hwloc unfortunately does
* not include this info in its xml support!
*/
support = (struct hwloc_topology_support*)hwloc_topology_get_support(src);
destsupport = (struct hwloc_topology_support*)hwloc_topology_get_support(*dest);
*destsupport = *support;
return OPAL_SUCCESS;
}
int opal_hwloc_compare(const hwloc_topology_t topo1,
const hwloc_topology_t topo2,
opal_data_type_t type)
{
hwloc_topology_t t1, t2;
unsigned d1, d2;
char *x1=NULL, *x2=NULL;
int l1, l2;
int s;
struct hwloc_topology_support *s1, *s2;
/* stop stupid compiler warnings */
t1 = (hwloc_topology_t)topo1;
t2 = (hwloc_topology_t)topo2;
/* do something quick first */
d1 = hwloc_topology_get_depth(t1);
d2 = hwloc_topology_get_depth(t2);
if (d1 > d2) {
return OPAL_VALUE1_GREATER;
} else if (d2 > d1) {
return OPAL_VALUE2_GREATER;
}
/* do the comparison the "cheat" way - get an xml representation
* of each tree, and strcmp!
*/
if (0 != hwloc_topology_export_xmlbuffer(t1, &x1, &l1)) {
return OPAL_EQUAL;
}
if (0 != hwloc_topology_export_xmlbuffer(t2, &x2, &l2)) {
free(x1);
return OPAL_EQUAL;
}
s = strcmp(x1, x2);
free(x1);
free(x2);
if (s > 0) {
return OPAL_VALUE1_GREATER;
} else if (s < 0) {
return OPAL_VALUE2_GREATER;
}
/* compare the available support - hwloc unfortunately does
* not include this info in its xml support!
*/
if (NULL == (s1 = (struct hwloc_topology_support*)hwloc_topology_get_support(t1)) ||
NULL == s1->cpubind || NULL == s1->membind) {
return OPAL_EQUAL;
}
if (NULL == (s2 = (struct hwloc_topology_support*)hwloc_topology_get_support(t2)) ||
NULL == s2->cpubind || NULL == s2->membind) {
return OPAL_EQUAL;
}
/* compare the fields we care about */
if (s1->cpubind->set_thisproc_cpubind != s2->cpubind->set_thisproc_cpubind ||
s1->cpubind->set_thisthread_cpubind != s2->cpubind->set_thisthread_cpubind ||
s1->membind->set_thisproc_membind != s2->membind->set_thisproc_membind ||
s1->membind->set_thisthread_membind != s2->membind->set_thisthread_membind) {
OPAL_OUTPUT_VERBOSE((5, opal_hwloc_base_framework.framework_output,
"hwloc:base:compare BINDING CAPABILITIES DIFFER"));
return OPAL_VALUE1_GREATER;
}
return OPAL_EQUAL;
}
#define OPAL_HWLOC_MAX_STRING 2048
static void print_hwloc_obj(char **output, char *prefix,
hwloc_topology_t topo, hwloc_obj_t obj)
{
hwloc_obj_t obj2;
char string[1024], *tmp, *tmp2, *pfx;
unsigned i;
struct hwloc_topology_support *support;
/* print the object type */
hwloc_obj_type_snprintf(string, 1024, obj, 1);
asprintf(&pfx, "\n%s\t", (NULL == prefix) ? "" : prefix);
asprintf(&tmp, "%sType: %s Number of child objects: %u%sName=%s",
(NULL == prefix) ? "" : prefix, string, obj->arity,
pfx, (NULL == obj->name) ? "NULL" : obj->name);
if (0 < hwloc_obj_attr_snprintf(string, 1024, obj, pfx, 1)) {
/* print the attributes */
asprintf(&tmp2, "%s%s%s", tmp, pfx, string);
free(tmp);
tmp = tmp2;
}
Per RFC, bring in the following changes: * Remove paffinity, maffinity, and carto frameworks -- they've been wholly replaced by hwloc. * Move ompi_mpi_init() affinity-setting/checking code down to ORTE. * Update sm, smcuda, wv, and openib components to no longer use carto. Instead, use hwloc data. There are still optimizations possible in the sm/smcuda BTLs (i.e., making multiple mpools). Also, the old carto-based code found out how many NUMA nodes were ''available'' -- not how many were used ''in this job''. The new hwloc-using code computes the same value -- it was not updated to calculate how many NUMA nodes are used ''by this job.'' * Note that I cannot compile the smcuda and wv BTLs -- I ''think'' they're right, but they need to be verified by their owners. * The openib component now does a bunch of stuff to figure out where "near" OpenFabrics devices are. '''THIS IS A CHANGE IN DEFAULT BEHAVIOR!!''' and still needs to be verified by OpenFabrics vendors (I do not have a NUMA machine with an OpenFabrics device that is a non-uniform distance from multiple different NUMA nodes). * Completely rewrite the OMPI_Affinity_str() routine from the "affinity" mpiext extension. This extension now understands hyperthreads; the output format of it has changed a bit to reflect this new information. * Bunches of minor changes around the code base to update names/types from maffinity/paffinity-based names to hwloc-based names. * Add some helper functions into the hwloc base, mainly having to do with the fact that we have the hwloc data reporting ''all'' topology information, but sometimes you really only want the (online | available) data. This commit was SVN r26391.
2012-05-07 18:52:54 +04:00
/* print the cpusets - apparently, some new HWLOC types don't
* have cpusets, so protect ourselves here
*/
if (NULL != obj->cpuset) {
hwloc_bitmap_snprintf(string, OPAL_HWLOC_MAX_STRING, obj->cpuset);
asprintf(&tmp2, "%s%sCpuset: %s", tmp, pfx, string);
free(tmp);
tmp = tmp2;
}
if (NULL != obj->online_cpuset) {
hwloc_bitmap_snprintf(string, OPAL_HWLOC_MAX_STRING, obj->online_cpuset);
asprintf(&tmp2, "%s%sOnline: %s", tmp, pfx, string);
free(tmp);
tmp = tmp2;
}
if (NULL != obj->allowed_cpuset) {
hwloc_bitmap_snprintf(string, OPAL_HWLOC_MAX_STRING, obj->allowed_cpuset);
asprintf(&tmp2, "%s%sAllowed: %s", tmp, pfx, string);
free(tmp);
tmp = tmp2;
}
if (HWLOC_OBJ_MACHINE == obj->type) {
/* root level object - add support values */
support = (struct hwloc_topology_support*)hwloc_topology_get_support(topo);
asprintf(&tmp2, "%s%sBind CPU proc: %s%sBind CPU thread: %s", tmp, pfx,
(support->cpubind->set_thisproc_cpubind) ? "TRUE" : "FALSE", pfx,
(support->cpubind->set_thisthread_cpubind) ? "TRUE" : "FALSE");
free(tmp);
tmp = tmp2;
asprintf(&tmp2, "%s%sBind MEM proc: %s%sBind MEM thread: %s", tmp, pfx,
(support->membind->set_thisproc_membind) ? "TRUE" : "FALSE", pfx,
(support->membind->set_thisthread_membind) ? "TRUE" : "FALSE");
free(tmp);
tmp = tmp2;
}
asprintf(&tmp2, "%s%s\n", (NULL == *output) ? "" : *output, tmp);
free(tmp);
free(pfx);
asprintf(&pfx, "%s\t", (NULL == prefix) ? "" : prefix);
for (i=0; i < obj->arity; i++) {
obj2 = obj->children[i];
/* print the object */
print_hwloc_obj(&tmp2, pfx, topo, obj2);
}
free(pfx);
if (NULL != *output) {
free(*output);
}
*output = tmp2;
}
int opal_hwloc_print(char **output, char *prefix, hwloc_topology_t src, opal_data_type_t type)
{
hwloc_obj_t obj;
char *tmp=NULL;
/* get root object */
obj = hwloc_get_root_obj(src);
/* print it */
print_hwloc_obj(&tmp, prefix, src, obj);
*output = tmp;
return OPAL_SUCCESS;
}