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 "aicpu_share_data_manager.h"
12 : namespace hccl {
13 11 : HcclResult AicpuShareDataManager::Init(u64 addr, u64 size)
14 : {
15 : // 初始化公共数据
16 11 : aicpuCustomParam_ = reinterpret_cast<AicpuCustomParam*>(addr);
17 11 : if (aicpuCustomParam_ == nullptr || size != sizeof(AicpuCustomParam)) {
18 0 : HCCL_ERROR(
19 : "%s fail, addr[%p] is null or size[%llu] is not equal to the size[%llu] of AicpuCustomParam", __func__,
20 : aicpuCustomParam_, size, sizeof(AicpuCustomParam));
21 0 : return HCCL_E_PARA;
22 : }
23 11 : HCCL_INFO("%s success, aicpuCustomParam:%p, size:%llu", __func__, aicpuCustomParam_, size);
24 11 : return HCCL_SUCCESS;
25 : }
26 :
27 0 : u32 AicpuShareDataManager::GetOpRingBufferIdx()
28 : {
29 0 : CHK_PRT_RET(aicpuCustomParam_ == nullptr, HCCL_ERROR("%s fail, aicpuCustomParam is nullptr", __func__), 0);
30 0 : return aicpuCustomParam_->taskExceptionParam.opRingBufferIdx;
31 : }
32 :
33 0 : HcclResult AicpuShareDataManager::RecordOpInfo(
34 : const std::string& newTag, OpParam& opParam, u32 opExecIndex, u32 userRank, bool isCustom)
35 : {
36 0 : CHK_PRT_RET(aicpuCustomParam_ == nullptr, HCCL_ERROR("%s fail, aicpuCustomParam is nullptr", __func__), HCCL_E_PTR);
37 0 : auto& aicpuOpInfo = aicpuCustomParam_->taskExceptionParam.opInfo;
38 : // opRingBufferIdx是算子信息在aicpuOpInfo数组中的索引,记录的sqe信息也会记录这个值,实现sqe和算子信息的匹配
39 0 : u32& opRingBufferIdx = aicpuCustomParam_->taskExceptionParam.opRingBufferIdx;
40 :
41 0 : CHK_SAFETY_FUNC_RET(strcpy_s(aicpuOpInfo[opRingBufferIdx].tagBuff, HCCL_TAG_SIZE, newTag.c_str()));
42 0 : aicpuOpInfo[opRingBufferIdx].opIndex = opParam.index;
43 0 : aicpuOpInfo[opRingBufferIdx].opExecIndex = opExecIndex;
44 0 : HCCL_DEBUG(
45 : "%s tag[%s] opRingBufferIdx[%u] opIndex[%u] rootId[%u] opType[%u] srcAddr[0x%x] dstAddr[0x%x]", __func__,
46 : aicpuOpInfo[opRingBufferIdx].tagBuff, opRingBufferIdx, aicpuOpInfo[opRingBufferIdx].opIndex, opParam.root,
47 : opParam.opType, opParam.inputPtr, opParam.outputPtr);
48 0 : if (opParam.opType == HcclCMDType::HCCL_CMD_INVALID) {
49 0 : return HCCL_E_PARA;
50 0 : } else if (opParam.opType == HcclCMDType::HCCL_CMD_BATCH_SEND_RECV) {
51 0 : aicpuOpInfo[opRingBufferIdx].count = SYS_MAX_COUNT;
52 0 : aicpuOpInfo[opRingBufferIdx].dataType = HCCL_DATA_TYPE_RESERVED;
53 0 : } else if (
54 0 : opParam.opType == HcclCMDType::HCCL_CMD_ALLTOALLV || opParam.opType == HcclCMDType::HCCL_CMD_ALLTOALLVC
55 0 : || opParam.opType == HcclCMDType::HCCL_CMD_ALLTOALL) {
56 0 : aicpuOpInfo[opRingBufferIdx].count = opParam.All2AllDataDes.sendCount;
57 0 : aicpuOpInfo[opRingBufferIdx].dataType = opParam.All2AllDataDes.sendType;
58 0 : } else if (
59 0 : opParam.opType == HcclCMDType::HCCL_CMD_ALLGATHER_V
60 0 : || opParam.opType == HcclCMDType::HCCL_CMD_REDUCE_SCATTER_V) {
61 0 : aicpuOpInfo[opRingBufferIdx].count = static_cast<u64*>(opParam.VDataDes.counts)[userRank];
62 0 : aicpuOpInfo[opRingBufferIdx].dataType = opParam.VDataDes.dataType;
63 : } else {
64 0 : aicpuOpInfo[opRingBufferIdx].count = opParam.DataDes.count;
65 0 : aicpuOpInfo[opRingBufferIdx].dataType = opParam.DataDes.dataType;
66 : }
67 0 : HCCL_DEBUG(
68 : "[HcclCommAicpu][RecordOpInfo] count[%llu] dataType[%u]", aicpuOpInfo[opRingBufferIdx].count,
69 : aicpuOpInfo[opRingBufferIdx].dataType);
70 :
71 0 : aicpuOpInfo[opRingBufferIdx].opType = static_cast<uint8_t>(opParam.opType);
72 0 : aicpuOpInfo[opRingBufferIdx].rootId = opParam.root;
73 0 : aicpuOpInfo[opRingBufferIdx].dstAddr = reinterpret_cast<uint64_t>(opParam.outputPtr);
74 0 : aicpuOpInfo[opRingBufferIdx].srcAddr = reinterpret_cast<uint64_t>(opParam.inputPtr);
75 0 : aicpuOpInfo[opRingBufferIdx].reduceType = opParam.reduceType;
76 0 : aicpuOpInfo[opRingBufferIdx].isCustom = isCustom;
77 0 : opRingBufferIdx++; // +1后为下一个算子的index
78 0 : opRingBufferIdx = opRingBufferIdx % OPINFO_RING_BUFFER_MAX;
79 0 : return HCCL_SUCCESS;
80 : }
81 :
82 0 : const AicpuOpInfo* AicpuShareDataManager::GetAicpuOpInfo(u32 opRingBufferIdx)
83 : {
84 0 : CHK_PRT_RET(aicpuCustomParam_ == nullptr, HCCL_ERROR("%s fail, aicpuCustomParam is nullptr", __func__), nullptr);
85 0 : CHK_PRT_RET(
86 : opRingBufferIdx >= OPINFO_RING_BUFFER_MAX,
87 : HCCL_ERROR(
88 : "%s fail, opRingBufferIdx[%u] should be smaller than %u", __func__, opRingBufferIdx,
89 : OPINFO_RING_BUFFER_MAX),
90 : nullptr);
91 :
92 0 : return &(aicpuCustomParam_->taskExceptionParam.opInfo[opRingBufferIdx]);
93 : }
94 : } // namespace hccl
|