* Sets the value of linked variables * * @param name Name of the variable currently being modified * @param value New value of the variable being modified * * This function updates the values of variables linked to the current modified * variable. */
| 357 | * variable. |
| 358 | */ |
| 359 | bool FlagRegistry::UpdateLinkedFlags(const std::string& name, |
| 360 | const std::string& value) { |
| 361 | if (HasFlag(name)) { |
| 362 | // Flags_name does not has linked flags |
| 363 | if (!linked_flags_.count(name)) { |
| 364 | return true; |
| 365 | } |
| 366 | Flag* f = flags_[name]; |
| 367 | std::string default_value = Value2String(f->default_value_, f->type_); |
| 368 | // If the value equals to default_value we will not set the linked flags |
| 369 | if (value == default_value) { |
| 370 | return true; |
| 371 | } |
| 372 | // Update the related flags |
| 373 | for (auto iter : linked_flags_[name]) { |
| 374 | std::string linked_flag_name = iter.first; |
| 375 | std::string linked_flag_value = iter.second; |
| 376 | if (HasFlag(linked_flag_name)) { |
| 377 | flags_[linked_flag_name]->SetValueFromString(linked_flag_value); |
| 378 | } else { |
| 379 | return false; |
| 380 | } |
| 381 | } |
| 382 | // Custom rule for Flags |
| 383 | if (name == "dump_api_and_gradnode_python_stack_dir") { |
| 384 | std::string fwd_path; |
| 385 | std::string bwd_path; |
| 386 | if (value.back() == '/') { |
| 387 | fwd_path = value + "api_call_stack"; |
| 388 | bwd_path = value + "gradnode_call_stack"; |
| 389 | } else { |
| 390 | fwd_path = value + "/api_call_stack"; |
| 391 | bwd_path = value + "/gradnode_call_stack"; |
| 392 | } |
| 393 | flags_["dump_api_python_stack_path"]->SetValueFromString(fwd_path); |
| 394 | flags_["dump_grad_node_forward_stack_path"]->SetValueFromString(bwd_path); |
| 395 | } |
| 396 | } else { |
| 397 | return false; |
| 398 | } |
| 399 | return true; |
| 400 | } |
| 401 | |
| 402 | bool FlagRegistry::HasFlag(const std::string& name) const { |
| 403 | return flags_.find(name) != flags_.end(); |
no test coverage detected