MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / ParseSbpParallelFromString

Function ParseSbpParallelFromString

oneflow/core/job/sbp_parallel.cpp:217–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217bool ParseSbpParallelFromString(const std::string& sbp_str, SbpParallel* sbp_parallel) {
218 bool success = false;
219 if (sbp_str.length() >= 1) {
220 if (sbp_str == "B") {
221 sbp_parallel->mutable_broadcast_parallel();
222 success = true;
223 } else if (sbp_str == "P") {
224 sbp_parallel->mutable_partial_sum_parallel();
225 success = true;
226 } else if (sbp_str[0] == 'S') {
227 if (sbp_str.length() >= 4 && sbp_str[1] == '(' && sbp_str[sbp_str.length() - 1] == ')') {
228 int split_axis = 0;
229 if (sbp_str.length() == 4) {
230 split_axis = sbp_str[2] - '0';
231 if (split_axis >= 0 && split_axis <= 9) { success = true; }
232 } else {
233 std::string split_axis_str = sbp_str.substr(2, sbp_str.length() - 3);
234 if (std::all_of(split_axis_str.cbegin(), split_axis_str.cend(),
235 [](char ch) { return std::isdigit(ch); })) {
236 size_t pos = 0;
237 split_axis = std::stoi(split_axis_str, &pos);
238 if (pos == split_axis_str.length()) { success = true; }
239 }
240 }
241 if (success) { sbp_parallel->mutable_split_parallel()->set_axis(split_axis); }
242 }
243 }
244 }
245 return success;
246}
247
248std::string SbpParallelToString(const SbpParallel& sbp_parallel) {
249 return SbpToString(sbp_parallel);

Callers 13

InferNdSbpMethod · 0.85
InferSbpSignatureMethod · 0.85
InferNdSbpMethod · 0.85
GetNdSbpSignatureListMethod · 0.85
ConvertNdSbpToPsigMethod · 0.85
FOR_RANGEFunction · 0.85
FOR_RANGEFunction · 0.85
IsValidSbpParallelStringFunction · 0.85
ParseNdSbpFromLongStringFunction · 0.85
ParseNdSbpFromStringListFunction · 0.85
FOR_RANGEFunction · 0.85

Calls 3

cbeginMethod · 0.80
cendMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected