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