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 : // device 侧的op
87 0 : extern HcclResult HcommProfilingReportDeviceHcclOpInfo(HcomProInfo profInfo)
88 : {
89 : #ifdef CCL_KERNEL_AICPU
90 : MsprofAicpuHCCLOPInfo hcclOpInfo{0};
91 : hcclOpInfo.relay = 0; // 目前全是false
92 : hcclOpInfo.retry = 0; // 目前全是false
93 : hcclOpInfo.dataType = static_cast<HcclDataType>(profInfo.dataType);
94 : hcclOpInfo.count = profInfo.dataCount;
95 : uint64_t groupHashId = dfx::ProfilingManager::GetProfHashId(profInfo.commName, profInfo.commNameLen);
96 : hcclOpInfo.groupName = groupHashId;
97 : hcclOpInfo.ranksize = profInfo.rankSize;
98 : std::string algTypeStr(profInfo.algType);
99 : hcclOpInfo.streamId = 0; // kfc的流, 目前没有默认为0 AicpuGetStreamId()
100 : AlgType algType;
101 : CHK_PRT_RET(
102 : 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(
106 : "[%s] groupName = [%u], commName = [%s], ranksize = [%u], taskId = [%u], streamId = [%u], dataType = [%u], "
107 : "algTypeStr = [%s]",
108 : __func__, hcclOpInfo.groupName, profInfo.commName, hcclOpInfo.ranksize, hcclOpInfo.taskId, hcclOpInfo.streamId,
109 : hcclOpInfo.dataType, algTypeStr.c_str());
110 : CHK_RET(dfx::ProfilingManager::ReportHcclOpInfo(hcclOpInfo, algTypeStr));
111 : return HCCL_SUCCESS;
112 : #else
113 0 : HCCL_INFO("[%s] not support, do nothing", __func__);
114 : #endif
115 0 : return HCCL_SUCCESS;
116 : }
117 :
118 0 : extern HcclResult HcommProfilingEnd(ThreadHandle* threads, u32 threadNum)
119 : {
120 : #ifdef CCL_KERNEL_AICPU
121 : // 上报task
122 : if (dfx::ProfilingManager::GetProfL1State()) {
123 : for (u32 i = 0; i < threadNum; i++) {
124 : HCCL_DEBUG("[%s] thread id = [%u]", __func__, GetStream(threads[i])->id());
125 : CHK_RET(dfx::ProfilingManager::ReportTaskInfo(
126 : GetStream(threads[i])->id(), GetStream(threads[i])->GetSqeContextPtr()));
127 : }
128 : }
129 :
130 : for (u32 i = 0; i < threadNum; i++) {
131 : HCCL_DEBUG("[%s] thread id = [%u]", __func__, GetStream(threads[i])->id());
132 : CHK_RET(GetStream(threads[i])->ClearLocalBuff());
133 : CHK_RET(dfx::ProfilingManager::UpdateStartReportSqeIdx(GetStream(threads[i])->id(), 0));
134 : }
135 : #else
136 0 : HCCL_INFO("[%s] not support, do nothing", __func__);
137 : #endif
138 0 : return HCCL_SUCCESS;
139 : }
|