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 "common.h"
14 : #include "hccl/hcom.h"
15 : #include "hccl/hccl_types.h"
16 : #include "hcom_device_profiling.h"
17 : #include "stream_pub.h"
18 : #ifdef CCL_KERNEL_AICPU
19 : #include "device/inc/profiling_manager_device.h"
20 : #endif
21 : using namespace hccl;
22 :
23 0 : extern HcclResult HcommProfilingInit(ThreadHandle *threads, u32 threadNum)
24 : {
25 : #ifdef CCL_KERNEL_AICPU
26 : bool profL0Open = dfx::ProfilingManager::IsProfL0On();
27 : bool profL1Open = dfx::ProfilingManager::IsProfL1On();
28 : HCCL_DEBUG("[%s] profL0Open:%d, profL1Open:%d", __func__, profL0Open, profL1Open);
29 : if (!profL1Open) {
30 : HCCL_INFO("[%s] L1 is off", __func__);
31 : return HCCL_SUCCESS;
32 : }
33 : for (u32 i = 0; i < threadNum; i++) {
34 : const SqeRingBuffer &sqeBuffer = GetStream(threads[i])->GetSqeContextPtr()->buffer;
35 : u16 taskId = sqeBuffer.tailSqeIdx;
36 : HCCL_DEBUG("[%s] thread id = [%u] task id = [%u]", __func__, GetStream(threads[i])->id(), taskId);
37 : CHK_RET(dfx::ProfilingManager::UpdateStartReportSqeIdx(GetStream(threads[i])->id(), taskId));
38 : }
39 : #else
40 0 : HCCL_INFO("[%s] not support, do nothing", __func__);
41 : #endif
42 0 : return HCCL_SUCCESS;
43 : }
44 :
45 0 : extern HcclResult HcommProfilingReportMainStreamAndFirstTask(ThreadHandle thread)
46 : {
47 : #ifdef CCL_KERNEL_AICPU
48 : bool profL0Open = dfx::ProfilingManager::IsProfL0On();
49 : bool profL1Open = dfx::ProfilingManager::IsProfL1On();
50 : HCCL_DEBUG("[%s] profL0Open:%d, profL1Open:%d", __func__, profL0Open, profL1Open);
51 : Stream *stream = GetStream(thread);
52 : if (stream == nullptr) {
53 : HCCL_ERROR("[%s] stream is nullptr", __func__);
54 : return HCCL_E_PTR;
55 : }
56 : HcclSqeContext *sqeContext = stream->GetSqeContextPtr();
57 : if (sqeContext == nullptr) {
58 : HCCL_ERROR("[%s] sqeContext is nullptr", __func__);
59 : return HCCL_E_PTR;
60 : }
61 : const SqeRingBuffer &sqeBuffer = sqeContext->buffer;
62 : uint16_t HEAD_TASK = 0;
63 : u16 taskId = sqeBuffer.tailSqeTaskId;
64 : HCCL_DEBUG("[%s] thread id = [%u] task id = [%u]", __func__, stream->id(), taskId);
65 : return dfx::ProfilingManager::ReportMainStreamTask(*stream, taskId, HEAD_TASK);
66 : #else
67 0 : HCCL_INFO("[%s] not support, do nothing", __func__);
68 : #endif
69 0 : return HCCL_SUCCESS;
70 : }
71 :
72 0 : extern HcclResult HcommProfilingReportMainStreamAndLastTask(ThreadHandle thread)
73 : {
74 : #ifdef CCL_KERNEL_AICPU
75 : const SqeRingBuffer &sqeBuffer = GetStream(thread)->GetSqeContextPtr()->buffer;
76 : uint16_t TAIL_TASK = 1;
77 : u16 taskId = sqeBuffer.tailSqeTaskId - 1;
78 : HCCL_DEBUG("[%s] thread id = [%u] task id = [%u]", __func__, GetStream(thread)->id(), taskId);
79 : return dfx::ProfilingManager::ReportMainStreamTask(*GetStream(thread), taskId, TAIL_TASK);
80 : #else
81 0 : HCCL_INFO("[%s] not support, do nothing", __func__);
82 : #endif
83 0 : return HCCL_SUCCESS;
84 : }
85 :
86 :
87 : // device 侧的op
88 0 : extern HcclResult HcommProfilingReportDeviceHcclOpInfo(HcomProInfo profInfo)
89 : {
90 : #ifdef CCL_KERNEL_AICPU
91 : MsprofAicpuHCCLOPInfo hcclOpInfo{0};
92 : hcclOpInfo.relay = 0; //目前全是false
93 : hcclOpInfo.retry = 0; //目前全是false
94 : hcclOpInfo.dataType = static_cast<HcclDataType>(profInfo.dataType);
95 : hcclOpInfo.count = profInfo.dataCount;
96 : uint64_t groupHashId = dfx::ProfilingManager::GetProfHashId(profInfo.commName, profInfo.commNameLen);
97 : hcclOpInfo.groupName = groupHashId;
98 : hcclOpInfo.ranksize = profInfo.rankSize;
99 : std::string algTypeStr(profInfo.algType);
100 : hcclOpInfo.streamId = 0; // kfc的流, 目前没有默认为0 AicpuGetStreamId()
101 : AlgType algType;
102 : CHK_PRT_RET(TransferStrToAlgType(algTypeStr, algType) == false,
103 : HCCL_ERROR("[%s] Fail to transfer [%s] to AlgType", __func__, algTypeStr.c_str()), HCCL_E_PARA);
104 : algTypeStr = TransferAlgType(algType);
105 : HCCL_INFO("[%s] groupName = [%u], commName = [%s], ranksize = [%u], taskId = [%u], streamId = [%u], dataType = [%u], algTypeStr = [%s]",
106 : __func__, hcclOpInfo.groupName, profInfo.commName, hcclOpInfo.ranksize, hcclOpInfo.taskId, hcclOpInfo.streamId,
107 : hcclOpInfo.dataType, algTypeStr.c_str());
108 : CHK_RET(dfx::ProfilingManager::ReportHcclOpInfo(hcclOpInfo, algTypeStr));
109 : return HCCL_SUCCESS;
110 : #else
111 0 : HCCL_INFO("[%s] not support, do nothing", __func__);
112 : #endif
113 0 : return HCCL_SUCCESS;
114 : }
115 :
116 0 : extern HcclResult HcommProfilingEnd(ThreadHandle *threads, u32 threadNum)
117 : {
118 : #ifdef CCL_KERNEL_AICPU
119 : // 上报task
120 : if (dfx::ProfilingManager::GetProfL1State()) {
121 : for(u32 i = 0; i < threadNum; i++) {
122 : HCCL_DEBUG("[%s] thread id = [%u]",__func__, GetStream(threads[i])->id());
123 : CHK_RET(dfx::ProfilingManager::ReportTaskInfo(GetStream(threads[i])->id(), GetStream(threads[i])->GetSqeContextPtr()));
124 : }
125 : }
126 :
127 : for (u32 i = 0; i < threadNum; i++) {
128 : HCCL_DEBUG("[%s] thread id = [%u]",__func__, GetStream(threads[i])->id());
129 : CHK_RET(GetStream(threads[i])->ClearLocalBuff());
130 : CHK_RET(dfx::ProfilingManager::UpdateStartReportSqeIdx(GetStream(threads[i])->id(), 0));
131 : }
132 : #else
133 0 : HCCL_INFO("[%s] not support, do nothing", __func__);
134 : #endif
135 0 : return HCCL_SUCCESS;
136 : }
|