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 : #ifndef AICPU_KFC_RPC_SERVERV2_H
12 : #define AICPU_KFC_RPC_SERVERV2_H
13 :
14 : #include "hccl_tiling_msg.h"
15 : #include "hccl_msg.h"
16 : #include "common/aicpu_hccl_def.h"
17 : #include "common/aicpu_kfc_def.h"
18 : #include "stream_pub.h"
19 :
20 : class AicpuKfcRpcServerV2 {
21 : public:
22 21 : AicpuKfcRpcServerV2() = default;
23 30 : ~AicpuKfcRpcServerV2() = default;
24 : HcclResult Init(const HcclMC2WorkSpace& workspaceInfo, const HcclApi::Mc2InitTilingInner* tilingData = nullptr);
25 : void Reset();
26 : HcclApi::HcclMsgArea* GetHcclMsgArea(void);
27 : HcclApi::HcclMsg (*GetMsgWorkSpace())[HcclApi::HCCL_MSG_CNT];
28 : uint64_t GetFinishAddr(int32_t idx) const;
29 : uint64_t GetCommitareaAddr(int32_t idx) const;
30 : uint64_t GetFinishAddrByHandleId(HcclHandle handleId);
31 : bool GetIsFinalize(u32 queueId = HcclApi::MAX_QUE_NUM);
32 : void SetIsFinalize(u32 queueId, bool finalize);
33 : HcclResult AddCcoreNotify(HcclDispatcher dispatcherPtr, u64 recordAddr, uint32_t turnNum, hccl::Stream* stream);
34 : HcclResult
35 : AddCcoreWait(HcclDispatcher dispatcherPtr, u64 waitAddr, uint32_t turnNum, hccl::Stream* stream, bool isLast);
36 : HcclResult AddFlipTask(HcclDispatcher dispatcherPtr, hccl::Stream* stream);
37 : HcclResult ResetCommitTaskAdd(HcclDispatcher dispatcherPtr, hccl::Stream* stream);
38 : void WriteFinishWhenAllFinalize();
39 : void WriteRestartFlag();
40 40 : uint32_t GetMsgPos(u32 queueId = 0U) const { return msgPos_[queueId]; }
41 15 : void SetMsgPos(u32 queueId, u32 pos) { msgPos_[queueId] = pos; }
42 : bool IsPrintLog() const;
43 : void SetMsgRepeatCnt(u8 repeatCnt);
44 : int32_t GetMsgRepeatCnt(HcclHandle handleId);
45 : int32_t GetMsgHandlePos(HcclHandle handleId);
46 : void PrintAllHcclMsgArea(u32 rankSize);
47 : void PrintAllHcclMsgAreaData();
48 : void PrintMsg(HcclApi::HcclMsg* hcclMsg, uint32_t msgPos, u32 rankSize);
49 6 : void SetMsgPosForKernel(uint32_t msgPos) { msgPosForKernel_ = msgPos; }
50 0 : uint32_t GetMsgPosForKernel(void) const { return msgPosForKernel_; }
51 : void SetMsgHandlePos(uint32_t msgPos, HcclHandle handleId);
52 : void SetNeedRetryFlag(bool needRetryFlag);
53 : bool ReadAddrMsg(HcclApi::HcclMsg* hcclMsg, HcclApi::HcclMsg* msgList, u32 queueIdx, u32 msgPos, u32 rankSize);
54 : bool IsExceedLimit(HcclCMDType commType, u32 rankSize);
55 : HcclApi::HcclMsgExt* GetHcclMsgExtPtr();
56 : HcclResult ProcessExpectPrepareMsg(uint8_t seqNum, uint8_t expectId);
57 :
58 : public:
59 6 : void SetStepSize(u8 stepSize) { curStepSize_ = stepSize; };
60 6 : void SetTotalStep(u16 totalStep) { totalStep_ = totalStep; };
61 0 : u16 GetStepSize() const { return curStepSize_; }
62 0 : u64 GetTurnNumAddr() const { return turnNumAddr_; }
63 13 : u32 GetTotalQueueNum() const { return totalQueueNum_; }
64 28 : BarrierInfo* GetBarrierInfoByGroupIdx(u32 idx) { return barrierFlags_[idx]; }
65 1 : void ClearBarrierStatus(u32 groupIdx, u32 start, u32 cnt)
66 : {
67 1 : (void)memset_s(&(barrierFlags_[groupIdx][start]), cnt * sizeof(BarrierInfo), 0, cnt * sizeof(BarrierInfo));
68 1 : }
69 2 : u32* GetBarrierFinishCnts() { return barrierFinishCnt_; }
70 15 : u64 GetTilingBaseAddr() const { return tilingBaseAddr_; }
71 : void GetLocalQueueRange(u32& start, u32& end);
72 : void DumpBarrierInfo(u32 groupIdx, u32 sqId, u32 devId);
73 :
74 : private:
75 : bool ReadValidMsg(HcclApi::HcclMsg* rMsg, HcclApi::HcclMsg* msg, bool needReProcess, uint32_t msgPos, u32 rankSize);
76 : bool ReadValidMsgExtArea(int32_t idx, u32 rankSize);
77 :
78 : private:
79 : uint64_t workSpace_ = 0;
80 : HcclApi::HcclMsgArea* hcclMsgArea_ = nullptr;
81 : uint32_t repeatCnt_[HcclApi::HCCL_MSG_CNT];
82 : int8_t handleIdMsgPosition_[HcclApi::HCCL_MAX_HANDLE_ID];
83 : uint64_t streamId_;
84 : uint32_t msgPosForKernel_;
85 : uint32_t msgPos_[HcclApi::MAX_QUE_NUM];
86 : bool needReProcess_ = false;
87 : bool isFinalize_[HcclApi::MAX_QUE_NUM];
88 : std::shared_ptr<HcclApi::HcclMsgExt> msgExt_ = std::make_shared<HcclApi::HcclMsgExt>();
89 : u64 prepareTime_[HcclApi::MAX_QUE_NUM]; // 记录 Prepare 消息的时间
90 : u8 eventPrintTurn_; // 记录打印event的turn
91 : bool isPrintLog_ = false;
92 : u8 curStepSize_ = 0U;
93 : u16 totalStep_ = 0U;
94 : u64 turnNumAddr_;
95 : u32 blockNum_ = 1U;
96 : u32 totalQueueNum_ = 0U;
97 : BarrierInfo barrierFlags_[MAX_COMM_CTX_NUM][HcclApi::MAX_QUE_NUM];
98 : u32 barrierFinishCnt_[MAX_AICPU_NUM_BLOCKS];
99 : u64 tilingBaseAddr_;
100 : };
101 :
102 : #endif // __AICPU_RPC_SERVERV2_H__
|