Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "plf_debug_config.h"
12 : #include "env_config_v2.h"
13 : #include "config_plf_log.h"
14 : #include <sstream>
15 :
16 : namespace Hccl {
17 :
18 22 : static u64 ParseDebugConfig(const char* envName, u64 domainMask)
19 : {
20 22 : char* env = getenv(envName);
21 22 : if (env == nullptr) {
22 15 : return 0;
23 : }
24 7 : std::string configDup(env);
25 :
26 7 : bool invert = (!configDup.empty() && configDup.front() == '^');
27 : // 第一个字符是'^', 使用取反模式,用户配置的项关闭,未配置的项打开
28 7 : u64 result = invert ? domainMask : 0ULL;
29 7 : if (invert) {
30 1 : configDup.erase(configDup.begin()); // 去掉'^'符号
31 : }
32 :
33 7 : std::istringstream stream(configDup);
34 7 : std::string subConfig;
35 13 : while (std::getline(stream, subConfig, ',')) {
36 7 : if (subConfig.empty()) {
37 0 : continue;
38 : }
39 7 : u64 mask = 0;
40 7 : if (((domainMask & PLF_TASK) != 0) && strcasecmp(subConfig.c_str(), "TASK") == 0) {
41 4 : mask = PLF_TASK;
42 3 : } else if (((domainMask & PLF_ALG) != 0) && strcasecmp(subConfig.c_str(), "ALG") == 0) {
43 0 : mask = PLF_ALG;
44 3 : } else if (((domainMask & PLF_RES) != 0) && strcasecmp(subConfig.c_str(), "RESOURCE") == 0) {
45 0 : mask = PLF_RES;
46 3 : } else if (((domainMask & PLF_DATA_OP) != 0) && strcasecmp(subConfig.c_str(), "DATA_OP") == 0) {
47 2 : mask = PLF_DATA_OP;
48 : } else {
49 3 : HCCL_ERROR("%s:%s subConfig:%s is not supported", envName, env, subConfig.c_str());
50 1 : return 0;
51 : }
52 6 : result = invert ? (result & ~mask) : (result | mask);
53 : }
54 18 : HCCL_RUN_INFO("[HCCL_ENV] %s set by [%s] to [0x%llx]", envName, env, result);
55 6 : return result;
56 7 : }
57 :
58 11 : void EnvPlfDebugConfig::Parse()
59 : {
60 11 : plfDebugConfig_ = ParseDebugConfig("HCCL_DEBUG_CONFIG", PLF_TASK | PLF_ALG | PLF_RES);
61 11 : plfDebugConfig_ |= ParseDebugConfig("HCOMM_DEBUG_CONFIG", PLF_TASK | PLF_DATA_OP);
62 33 : HCCL_RUN_INFO("[HCCL_ENV] plfDebugConfig set to [0x%llx]", plfDebugConfig_);
63 11 : }
64 :
65 30 : u64 EnvPlfDebugConfig::GetConfigValue() const { return plfDebugConfig_; }
66 :
67 24 : u64 GetPlfDebugConfigValue() { return EnvConfig::GetInstance().GetPlfDebugConfig().GetConfigValue(); }
68 :
69 : } // namespace Hccl
|