Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 "profiling_manager_pub.h"
12 : #include "hccl_comm_pub.h"
13 : #include "hccl/hcom.h"
14 : #include "hcom_host_profiling.h"
15 : #include "adapter_prof.h"
16 : #include "hccl/hccl_types.h"
17 :
18 : using namespace hccl;
19 2 : extern HcclResult HcommProfilingReportKernel(uint64_t beginTime, const char *profName)
20 : {
21 2 : std::string profNames(profName);
22 2 : uint64_t endTime = hrtMsprofSysCycleTime();
23 2 : uint32_t threadId = SalGetTid();
24 4 : return ProfilingManagerPub::CallMsprofReportNodeInfo(beginTime, endTime, profName, threadId);
25 2 : }
26 :
27 : // 上报acl host
28 0 : extern HcclResult HcommProfilingReportOp(HcomProInfo profInfo)
29 : {
30 : // 数据恢复
31 0 : HcclCMDType cmdTypeTemp = static_cast<HcclCMDType>(profInfo.cmdType);
32 0 : HcclDataType dataTypeTemp = static_cast<HcclDataType>(profInfo.dataType);
33 0 : uint64_t groupName = hrtMsprofGetHashId(profInfo.commName, strlen(profInfo.commName));
34 0 : std::string algTypeStr(profInfo.algType);
35 :
36 0 : AlgType algType;
37 0 : CHK_PRT_RET(TransferStrToAlgType(algTypeStr, algType) == false,
38 : HCCL_ERROR("[%s] Fail to transfer [%s] to AlgType", __func__, algTypeStr.c_str()), HCCL_E_PARA);
39 :
40 0 : HCCL_INFO("[%s] cmdType[%u], dataType[%u], groupName[%llu], groupNameStr[%s], algTypeStr[%s], blockDim[%u]",
41 : __func__, cmdTypeTemp, dataTypeTemp, groupName, profInfo.commName, profInfo.algType, profInfo.blockDim);
42 :
43 0 : CHK_RET_AND_PRINT_IDE(ProfilingManagerPub::CallMsprofReportHostApi(cmdTypeTemp, profInfo.beginTime, profInfo.dataCount, dataTypeTemp, algType,
44 : groupName, profInfo.blockDim), profInfo.commName);
45 0 : return HCCL_SUCCESS;
46 0 : }
47 :
48 0 : extern HcclResult HcommProfilingRegThread(HcomProInfo profInfo, ThreadHandle *threads) {
49 0 : CHK_PTR_NULL(threads);
50 0 : std::string identifier(profInfo.commName);
51 0 : std::string tag(profInfo.tag);
52 0 : HCCL_PROFILER_ADD_GROUPRANK(identifier, profInfo.rankSize, profInfo.userRank);
53 0 : if (profInfo.isAiv) {
54 0 : HCCL_PROFILER_ADD_TAG_AIV(tag, identifier, GetWorkflowMode());
55 : } else {
56 0 : HCCL_PROFILER_ADD_TAG(tag, identifier, GetWorkflowMode());
57 : }
58 :
59 0 : uint32_t mainStreamId = reinterpret_cast<Thread*>(threads[0])->GetStream()->id();
60 0 : HCCL_INFO("[%s] mainStreamId[%u], identifier[%s], tag[%s]", __func__, mainStreamId, profInfo.commName, profInfo.tag);
61 0 : HCCL_PROFILER_ADD_OPDATA_OP(profInfo.tag, profInfo.dataCount, nullptr, nullptr, static_cast<HcclDataType>(profInfo.dataType),
62 : profInfo.root, profInfo.commName, HcclReduceOp::HCCL_REDUCE_RESERVED);
63 :
64 0 : std::string algTypeStr(profInfo.algType);
65 0 : AlgType algType;
66 0 : CHK_PRT_RET(TransferStrToAlgType(algTypeStr, algType) == false,
67 : HCCL_ERROR("[%s] Fail to transfer [%s] to AlgType", __func__, algTypeStr.c_str()), HCCL_E_PARA);
68 0 : HCCL_PROFILER_ADD_STREAM_BY_STREAMID(mainStreamId, tag, 0, algType);
69 :
70 0 : if (((GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) &&
71 0 : !hccl::ProfilingManagerPub::GetAdditionInfoState() &&
72 0 : !hccl::ProfilingManagerPub::GetTaskApiState()) &&
73 0 : !profInfo.isCapture) {
74 0 : return HCCL_SUCCESS;
75 : }
76 : // 从流信息profiling开关打开的话再注册
77 0 : for (u32 streamIndex = 1; streamIndex <= profInfo.slaveThreadNum; streamIndex++) {
78 0 : uint32_t slaveStreamId = reinterpret_cast<Thread*>(threads[streamIndex])->GetStream()->id();
79 0 : HCCL_INFO("[%s] slaveStreamId[%u]", __func__, slaveStreamId);
80 0 : HCCL_PROFILER_ADD_STREAM_BY_STREAMID(slaveStreamId, profInfo.tag, streamIndex, algType);
81 : }
82 0 : return HCCL_SUCCESS;
83 0 : }
84 :
85 0 : extern HcclResult HcommProfilingUnRegThread(HcomProInfo profInfo, ThreadHandle *threads) {
86 0 : CHK_PTR_NULL(threads);
87 0 : std::string tag(profInfo.tag);
88 0 : std::string identifier(profInfo.commName);
89 :
90 0 : HCCL_PROFILER_DEL_TAG(tag);
91 0 : HCCL_PROFILER_DEL_GROUPRANK(identifier);
92 :
93 0 : uint32_t mainStreamId = reinterpret_cast<Thread*>(threads[0])->GetStream()->id();
94 0 : HCCL_PROFILER_DEL_STREAM_BY_STREAMID(mainStreamId);
95 0 : HCCL_PROFILER_DEL_OPDATA(tag);
96 0 : if (((GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) &&
97 0 : !hccl::ProfilingManagerPub::GetAdditionInfoState() &&
98 0 : !hccl::ProfilingManagerPub::GetTaskApiState()) &&
99 0 : !profInfo.isCapture) {
100 0 : return HCCL_SUCCESS;
101 : }
102 :
103 0 : for (u32 streamIndex = 1; streamIndex <= profInfo.slaveThreadNum; streamIndex++) {
104 0 : uint32_t slaveStreamId = reinterpret_cast<Thread*>(threads[streamIndex])->GetStream()->id();
105 0 : HCCL_INFO("[%s] slaveStreamId[%u]", __func__, slaveStreamId);
106 0 : HCCL_PROFILER_DEL_STREAM_BY_STREAMID(slaveStreamId);
107 : }
108 0 : return HCCL_SUCCESS;
109 0 : }
110 :
111 0 : extern uint64_t HcommGetProfilingSysCycleTime()
112 : {
113 0 : DevType devType = DevType::DEV_TYPE_COUNT;
114 0 : CHK_RET(hrtGetDeviceType(devType));
115 0 : if (devType != DevType::DEV_TYPE_950 && devType != DevType::DEV_TYPE_960) {
116 0 : return hrtMsprofSysCycleTime();
117 : }
118 0 : return Hccl::DlProfFunction::GetInstance().dlMsprofSysCycleTime();
119 : }
|