Merge remote-tracking branch 'nccl/master' into develop
[ROCm/rccl commit: 84081064a0]
This commit is contained in:
@@ -11,14 +11,14 @@
|
||||
#include "nccl.h"
|
||||
#include "debug.h"
|
||||
#include "checks.h"
|
||||
#include "alloc.h"
|
||||
#include <stdlib.h>
|
||||
#include "archinfo.h"
|
||||
|
||||
// A few constraints to make the implementation easy
|
||||
#define MAX_STR_LEN 255
|
||||
#define MAX_ATTR_COUNT 16
|
||||
#define MAX_SUBS 512 //Changed the value from 32 to 512 for CPX mode
|
||||
#define MAX_NODES 8192 //Changed the value from 1024 to 8192 for CPX mode
|
||||
#define MAX_SUBS 512 //Changed the value from 128 to 512 for CPX mode
|
||||
|
||||
#define NODE_TYPE_NONE 0
|
||||
#define NODE_TYPE_OPEN 1
|
||||
@@ -39,8 +39,8 @@ struct ncclXmlNode {
|
||||
};
|
||||
|
||||
struct ncclXml {
|
||||
struct ncclXmlNode nodes[MAX_NODES];
|
||||
int maxIndex;
|
||||
int maxIndex, maxNodes;
|
||||
struct ncclXmlNode nodes[1];
|
||||
};
|
||||
|
||||
/* File functions */
|
||||
@@ -57,6 +57,11 @@ ncclResult_t ncclTopoFillNet(struct ncclXml* xml, const char* pciPath, const cha
|
||||
/* Remove unneeded parts */
|
||||
ncclResult_t ncclTopoTrimXml(struct ncclXml* xml);
|
||||
|
||||
/* Fuse multiple system XMLs into one, skipping duplicate CPUs */
|
||||
ncclResult_t ncclTopoFuseXml(struct ncclXml* dst, struct ncclXml* src);
|
||||
/* Relocate pointers in XML to (de-)serialize the structure */
|
||||
ncclResult_t ncclTopoConvertXml(struct ncclXml* xml, uintptr_t base, int exp);
|
||||
|
||||
ncclResult_t ncclTopoGetStrFromSys(const char* path, const char* fileName, char* strValue);
|
||||
|
||||
/**************/
|
||||
@@ -64,6 +69,17 @@ ncclResult_t ncclTopoGetStrFromSys(const char* path, const char* fileName, char*
|
||||
/* Functions */
|
||||
/**************/
|
||||
|
||||
static size_t xmlMemSize(int maxNodes) {
|
||||
return offsetof(struct ncclXml, nodes) + sizeof(struct ncclXmlNode)*maxNodes;
|
||||
}
|
||||
static ncclResult_t xmlAlloc(struct ncclXml** xml, int maxNodes) {
|
||||
char* mem;
|
||||
NCCLCHECK(ncclCalloc(&mem, xmlMemSize(maxNodes)));
|
||||
*xml = (struct ncclXml*)mem;
|
||||
(*xml)->maxNodes = maxNodes;
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
static ncclResult_t xmlGetAttrIndex(struct ncclXmlNode* node, const char* attrName, int* index) {
|
||||
*index = -1;
|
||||
const int nAttrs = node->nAttrs;
|
||||
@@ -105,6 +121,13 @@ static ncclResult_t xmlGetAttrIntDefault(struct ncclXmlNode* node, const char* a
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
static ncclResult_t xmlGetAttrLong(struct ncclXmlNode* node, const char* attrName, int64_t* value) {
|
||||
const char* str;
|
||||
NCCLCHECK(xmlGetAttrStr(node, attrName, &str));
|
||||
*value = strtol(str, NULL, 0);
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
|
||||
static ncclResult_t xmlGetAttrFloat(struct ncclXmlNode* node, const char* attrName, float* value) {
|
||||
const char* str;
|
||||
@@ -125,6 +148,18 @@ static ncclResult_t xmlFindTag(struct ncclXml* xml, const char* tagName, struct
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
static ncclResult_t xmlFindNextTag(struct ncclXml* xml, const char* tagName, struct ncclXmlNode* prev, struct ncclXmlNode** node) {
|
||||
*node = NULL;
|
||||
for (int i=prev-xml->nodes+1; i<xml->maxIndex; i++) {
|
||||
struct ncclXmlNode* n = xml->nodes+i;
|
||||
if (strcmp(n->name, tagName) == 0) {
|
||||
*node = n;
|
||||
return ncclSuccess;
|
||||
}
|
||||
}
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
static ncclResult_t xmlFindTagKv(struct ncclXml* xml, const char* tagName, struct ncclXmlNode** node, const char* attrName, const char* attrValue) {
|
||||
*node = NULL;
|
||||
for (int i=0; i<xml->maxIndex; i++) {
|
||||
@@ -192,6 +227,19 @@ static ncclResult_t xmlSetAttrFloat(struct ncclXmlNode* node, const char* attrNa
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
static ncclResult_t xmlSetAttrLong(struct ncclXmlNode* node, const char* attrName, const int64_t value) {
|
||||
int index;
|
||||
NCCLCHECK(xmlGetAttrIndex(node, attrName, &index));
|
||||
if (index == -1) {
|
||||
index = node->nAttrs++;
|
||||
strncpy(node->attrs[index].key, attrName, MAX_STR_LEN);
|
||||
node->attrs[index].key[MAX_STR_LEN] = '\0';
|
||||
}
|
||||
snprintf(node->attrs[index].value, MAX_STR_LEN, "%#lx", value);
|
||||
node->attrs[index].value[MAX_STR_LEN] = '\0';
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
static ncclResult_t xmlUnsetAttr(struct ncclXmlNode* node, const char* attrName) {
|
||||
int index;
|
||||
NCCLCHECK(xmlGetAttrIndex(node, attrName, &index));
|
||||
@@ -238,8 +286,8 @@ static ncclResult_t xmlGetSubKvInt(struct ncclXmlNode* node, const char* subName
|
||||
}
|
||||
|
||||
static ncclResult_t xmlAddNode(struct ncclXml* xml, struct ncclXmlNode* parent, const char* subName, struct ncclXmlNode** sub) {
|
||||
if (xml->maxIndex == MAX_NODES) {
|
||||
WARN("Error : too many XML nodes (max %d)", MAX_NODES);
|
||||
if (xml->maxIndex == xml->maxNodes) {
|
||||
WARN("Error : too many XML nodes (max %d)", xml->maxNodes);
|
||||
return ncclInternalError;
|
||||
}
|
||||
struct ncclXmlNode* s = xml->nodes+xml->maxIndex++;
|
||||
@@ -247,7 +295,13 @@ static ncclResult_t xmlAddNode(struct ncclXml* xml, struct ncclXmlNode* parent,
|
||||
s->nAttrs = 0;
|
||||
*sub = s;
|
||||
s->parent = parent;
|
||||
if (parent) parent->subs[parent->nSubs++] = s;
|
||||
if (parent) {
|
||||
if (parent->nSubs == MAX_SUBS) {
|
||||
WARN("Error : too many XML subnodes (max %d)", MAX_SUBS);
|
||||
return ncclInternalError;
|
||||
}
|
||||
parent->subs[parent->nSubs++] = s;
|
||||
}
|
||||
strncpy(s->name, subName, MAX_STR_LEN);
|
||||
s->name[MAX_STR_LEN] = '\0';
|
||||
return ncclSuccess;
|
||||
@@ -266,6 +320,29 @@ static ncclResult_t xmlRemoveNode(struct ncclXmlNode* node) {
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
static ncclResult_t xmlAddTree(struct ncclXml* dst, struct ncclXmlNode* parent, struct ncclXmlNode* srcNode) {
|
||||
if (dst->maxIndex == dst->maxNodes) {
|
||||
WARN("Error : too many XML nodes (max %d)", dst->maxNodes);
|
||||
return ncclInternalError;
|
||||
}
|
||||
struct ncclXmlNode* dstNode = dst->nodes+dst->maxIndex++;
|
||||
*dstNode = *srcNode;
|
||||
dstNode->parent = parent;
|
||||
if (parent) {
|
||||
if (parent->nSubs == MAX_SUBS) {
|
||||
WARN("Error : too many XML subnodes (max %d)", MAX_SUBS);
|
||||
return ncclInternalError;
|
||||
}
|
||||
parent->subs[parent->nSubs++] = dstNode;
|
||||
}
|
||||
dstNode->nSubs = 0;
|
||||
// Recursively copy the subtree(s)
|
||||
for (int i=0; i<srcNode->nSubs; i++)
|
||||
NCCLCHECK(xmlAddTree(dst, dstNode, srcNode->subs[i]));
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
|
||||
// Dictionary for STR -> INT conversions. No dictionary size information,
|
||||
// there needs to be a last element with str == NULL.
|
||||
struct kvDict {
|
||||
|
||||
مرجع در شماره جدید
Block a user