Skip to content

Commit fe583c3

Browse files
authored
[CICD] Replace C++17 features with C++11 equivalents for RPM packaging (#495)
1 parent cc68810 commit fe583c3

4 files changed

Lines changed: 75 additions & 41 deletions

File tree

flagcx/core/reg_pool.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,18 @@ flagcxResult_t flagcxRegPool::registerBuffer(void *comm, void *data,
187187
}
188188
// Update regPool key to match new beginAddr
189189
auto &globalPool = regPool[GLOBAL_POOL_KEY];
190-
auto node = globalPool.extract(oldBegin);
191-
node.key() = beginAddr;
192-
globalPool.insert(std::move(node));
190+
auto nodeIt = globalPool.find(oldBegin);
191+
if (nodeIt == globalPool.end()) {
192+
WARN("registerBuffer: regPool key mismatch for oldBegin");
193+
return flagcxInternalError;
194+
}
195+
std::unique_ptr<flagcxRegItem> tmp = std::move(nodeIt->second);
196+
globalPool.erase(nodeIt);
197+
if (globalPool.count(beginAddr)) {
198+
WARN("registerBuffer: unexpected duplicate key at beginAddr");
199+
return flagcxInternalError;
200+
}
201+
globalPool.emplace(beginAddr, std::move(tmp));
193202
}
194203
// Extend forward if new buffer goes beyond existing range
195204
if (endAddr > existing->endAddr) {
@@ -208,12 +217,12 @@ flagcxResult_t flagcxRegPool::registerBuffer(void *comm, void *data,
208217

209218
// Not found: create new item in global pool
210219
auto &globalPool = regPool[GLOBAL_POOL_KEY];
211-
auto reg = std::make_unique<flagcxRegItem>();
220+
std::unique_ptr<flagcxRegItem> reg(new flagcxRegItem());
212221
reg->beginAddr = beginAddr;
213222
reg->endAddr = endAddr;
214223
reg->refCount = 1;
215-
auto [it2, didInsert] = globalPool.emplace(beginAddr, std::move(reg));
216-
flagcxRegItem *regPtr = it2->second.get();
224+
auto result = globalPool.emplace(beginAddr, std::move(reg));
225+
flagcxRegItem *regPtr = result.first->second.get();
217226

218227
// Map pages in global regMap
219228
mapRegItemPages(GLOBAL_POOL_KEY, regPtr);

flagcx/flagcx.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,10 +1141,10 @@ flagcxResult_t flagcxCommDeregister(const flagcxComm_t comm, void *handle) {
11411141
}
11421142
// Check if item is mapped under any non-global commKey
11431143
auto &globalMap = globalRegPool.getGlobalMap();
1144-
for (auto &[key, pageMap] : globalMap) {
1145-
if (key == flagcxRegPool::GLOBAL_POOL_KEY)
1144+
for (auto &entry : globalMap) {
1145+
if (entry.first == flagcxRegPool::GLOBAL_POOL_KEY)
11461146
continue;
1147-
if (pageMap.find(regItem->beginAddr) != pageMap.end()) {
1147+
if (entry.second.find(regItem->beginAddr) != entry.second.end()) {
11481148
WARN("flagcxCommDeregister: comm is nullptr but handle has "
11491149
"comm-specific regMap entries that require a valid comm");
11501150
return flagcxInvalidArgument;

flagcx/runner/c2c_algo.cc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ bool flagcxInterRankBufferInfoManager::checkIfPossibleToPush(int clusterId,
3737
int rank,
3838
size_t offset,
3939
size_t count) {
40-
if (auto clusterSearch = bufferInfos_.find(clusterId);
41-
clusterSearch != bufferInfos_.end()) {
42-
if (auto rankSearch = clusterSearch->second.find(rank);
43-
rankSearch != clusterSearch->second.end()) {
40+
auto clusterSearch = bufferInfos_.find(clusterId);
41+
if (clusterSearch != bufferInfos_.end()) {
42+
auto rankSearch = clusterSearch->second.find(rank);
43+
if (rankSearch != clusterSearch->second.end()) {
4444
auto infoList = rankSearch->second;
4545
for (auto info : infoList) {
4646
if ((offset < info.offset_ && offset + count > info.offset_) ||
@@ -59,10 +59,10 @@ bool flagcxInterRankBufferInfoManager::checkIfPossibleToSplitAndPush(
5959
int *pushMode) {
6060
size_t maxSplitCount = 0;
6161
int finalPushMode = 0; // 0: prePush, 1: postPush
62-
if (auto clusterSearch = bufferInfos_.find(clusterId);
63-
clusterSearch != bufferInfos_.end()) {
64-
if (auto rankSearch = clusterSearch->second.find(rank);
65-
rankSearch != clusterSearch->second.end()) {
62+
auto clusterSearch = bufferInfos_.find(clusterId);
63+
if (clusterSearch != bufferInfos_.end()) {
64+
auto rankSearch = clusterSearch->second.find(rank);
65+
if (rankSearch != clusterSearch->second.end()) {
6666
auto infoList = rankSearch->second;
6767
for (auto info : infoList) {
6868
if (offset < info.offset_ && offset + count > info.offset_) {
@@ -95,10 +95,10 @@ bool flagcxInterRankBufferInfoManager::checkIfPossibleToSplitAndPush(
9595

9696
bool flagcxInterRankBufferInfoManager::checkIsFull(int clusterId, int rank) {
9797
int rankCount = 0;
98-
if (auto clusterSearch = bufferInfos_.find(clusterId);
99-
clusterSearch != bufferInfos_.end()) {
100-
if (auto rankSearch = clusterSearch->second.find(rank);
101-
rankSearch != clusterSearch->second.end()) {
98+
auto clusterSearch = bufferInfos_.find(clusterId);
99+
if (clusterSearch != bufferInfos_.end()) {
100+
auto rankSearch = clusterSearch->second.find(rank);
101+
if (rankSearch != clusterSearch->second.end()) {
102102
auto infoList = rankSearch->second;
103103
for (auto info : infoList) {
104104
rankCount += info.count_;
@@ -113,10 +113,10 @@ bool flagcxInterRankBufferInfoManager::checkIsFull(int clusterId, int rank) {
113113

114114
bool flagcxInterRankBufferInfoManager::checkIsScheduled(int clusterId,
115115
int rank) {
116-
if (auto clusterSearch = bufferInfos_.find(clusterId);
117-
clusterSearch != bufferInfos_.end()) {
118-
if (auto rankSearch = clusterSearch->second.find(rank);
119-
rankSearch != clusterSearch->second.end()) {
116+
auto clusterSearch = bufferInfos_.find(clusterId);
117+
if (clusterSearch != bufferInfos_.end()) {
118+
auto rankSearch = clusterSearch->second.find(rank);
119+
if (rankSearch != clusterSearch->second.end()) {
120120
auto infoList = rankSearch->second;
121121
for (auto info : infoList) {
122122
if (!info.isScheduled_) {
@@ -130,10 +130,10 @@ bool flagcxInterRankBufferInfoManager::checkIsScheduled(int clusterId,
130130

131131
std::list<flagcxBufferInfo> &
132132
flagcxInterRankBufferInfoManager::getBufferInfoList(int clusterId, int rank) {
133-
if (auto clusterSearch = bufferInfos_.find(clusterId);
134-
clusterSearch != bufferInfos_.end()) {
135-
if (auto rankSearch = clusterSearch->second.find(rank);
136-
rankSearch != clusterSearch->second.end()) {
133+
auto clusterSearch = bufferInfos_.find(clusterId);
134+
if (clusterSearch != bufferInfos_.end()) {
135+
auto rankSearch = clusterSearch->second.find(rank);
136+
if (rankSearch != clusterSearch->second.end()) {
137137
return rankSearch->second;
138138
} else {
139139
clusterSearch->second[rank] = {};

flagcx/runner/include/c2c_ir.h

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <list>
1212
#include <map>
1313
#include <string>
14+
#include <type_traits>
1415
#include <unordered_map>
1516

1617
// Max line length for reading xml
@@ -116,10 +117,26 @@ inline void serializeHeteroFunc(FILE *file, size_t chunksize,
116117
fprintf(file, "%*s</HeteroFunc>\n", indent, "");
117118
}
118119

120+
// Overloaded dispatch helpers for serializeFunc2DVector (C++11-compatible
121+
// alternative to if constexpr)
122+
inline void serializeFunc(FILE *file, size_t chunksize,
123+
const flagcxC2cHomoFunc &func, int indent) {
124+
serializeHomoFunc(file, chunksize, func, indent);
125+
}
126+
127+
inline void serializeFunc(FILE *file, size_t chunksize,
128+
const flagcxC2cHeteroFunc &func, int indent) {
129+
serializeHeteroFunc(file, chunksize, func, indent);
130+
}
131+
119132
template <typename T>
120133
void serializeFunc2DVector(FILE *file, size_t chunksize,
121134
const std::vector<std::vector<T>> &steps,
122135
const char *tagName, int indent = 2) {
136+
static_assert(std::is_same<T, flagcxC2cHomoFunc>::value ||
137+
std::is_same<T, flagcxC2cHeteroFunc>::value,
138+
"serializeFunc2DVector only supports flagcxC2cHomoFunc or "
139+
"flagcxC2cHeteroFunc");
123140
fprintf(file, "%*s<%s>\n", indent, "", tagName);
124141
for (const auto &stepVec : steps) {
125142
if (stepVec.size() == 0) {
@@ -128,20 +145,34 @@ void serializeFunc2DVector(FILE *file, size_t chunksize,
128145
}
129146
fprintf(file, "%*s<Step>\n", indent + 2, "");
130147
for (const auto &func : stepVec) {
131-
if constexpr (std::is_same<T, flagcxC2cHomoFunc>::value) {
132-
serializeHomoFunc(file, chunksize, func, indent + 4);
133-
} else if constexpr (std::is_same<T, flagcxC2cHeteroFunc>::value) {
134-
serializeHeteroFunc(file, chunksize, func, indent + 4);
135-
}
148+
serializeFunc(file, chunksize, func, indent + 4);
136149
}
137150
fprintf(file, "%*s</Step>\n", indent + 2, "");
138151
}
139152
fprintf(file, "%*s</%s>\n", indent, "", tagName);
140153
}
141154

155+
// Overloaded dispatch helpers for readFunc2DVector (C++11-compatible
156+
// alternative to if constexpr)
157+
inline void readFuncStep(FILE *file, size_t chunksize, const char *line,
158+
std::vector<flagcxC2cHomoFunc> &step) {
159+
if (strstr(line, "<HomoFunc>"))
160+
step.emplace_back(file, chunksize);
161+
}
162+
163+
inline void readFuncStep(FILE *file, size_t chunksize, const char *line,
164+
std::vector<flagcxC2cHeteroFunc> &step) {
165+
if (strstr(line, "<HeteroFunc>"))
166+
step.emplace_back(file, chunksize);
167+
}
168+
142169
template <typename T>
143170
std::vector<std::vector<T>> readFunc2DVector(FILE *file, size_t chunksize,
144171
const char *tagName) {
172+
static_assert(std::is_same<T, flagcxC2cHomoFunc>::value ||
173+
std::is_same<T, flagcxC2cHeteroFunc>::value,
174+
"readFunc2DVector only supports flagcxC2cHomoFunc or "
175+
"flagcxC2cHeteroFunc");
145176
std::vector<std::vector<T>> result;
146177
char line[LINE_LEN];
147178

@@ -161,13 +192,7 @@ std::vector<std::vector<T>> readFunc2DVector(FILE *file, size_t chunksize,
161192
while (fgets(line, sizeof(line), file)) {
162193
if (strstr(line, "</Step>"))
163194
break;
164-
if constexpr (std::is_same<T, flagcxC2cHomoFunc>::value) {
165-
if (strstr(line, "<HomoFunc>"))
166-
step.emplace_back(file, chunksize);
167-
} else if constexpr (std::is_same<T, flagcxC2cHeteroFunc>::value) {
168-
if (strstr(line, "<HeteroFunc>"))
169-
step.emplace_back(file, chunksize);
170-
}
195+
readFuncStep(file, chunksize, line, step);
171196
}
172197
result.push_back(step);
173198
}

0 commit comments

Comments
 (0)