LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/device/aicpu_kfc/framework - aicpu_kfc_rpc_server.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 1 1
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 1 1

            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_SERVER_H
      12              : #define AICPU_KFC_RPC_SERVER_H
      13              : 
      14              : #include "hccl_msg.h"
      15              : #include "common/aicpu_hccl_def.h"
      16              : #include "common/aicpu_kfc_def.h"
      17              : 
      18              : constexpr uint32_t AC_MAX_AIV = 64U;  // 最多有64个AIV
      19              : 
      20              : enum RANK_MSG_TYPE {
      21              :     RANK_ADDR = 1,
      22              :     RANK_WORK = 2,
      23              :     RANK_ADD_AND_WORK = 3,
      24              :     RANK_TAIL_TIME = 6,
      25              :     RANK_MSG_END
      26              : };
      27              : 
      28              : class AicpuKfcRpcServer {
      29              : public:
      30           10 :     AicpuKfcRpcServer() = default;
      31              :     ~AicpuKfcRpcServer() = default;
      32              : 
      33              :     void Init(u64 workSpaceAddr, uint32_t notifyOff, uint16_t notifyBeginCnt, KFCTask *taskParam);
      34              :     void Init(u64 workSpaceAddr);
      35              :     bool RcvMsg(AivAicpuOpParam *rMsg, uint32_t aivID, uint8_t msgType);
      36              :     bool CheckRcvAddrMsg(AivAicpuOpParam *rMsg, uint32_t aivID);
      37              :     bool CheckRcvAddrMsg(HcclApi::HcclMsg *hcclMsg, uint32_t msgPos);
      38              :     bool CheckRcvWorkMsg(AivAicpuOpParam *rMsg, uint32_t aivID, uint32_t curTurnCnt);
      39              :     bool PostMsg(AivAicpuOpParam *rMsg, uint32_t aivID);
      40              :     bool ReadWorkMsg(AivAicpuOpParam *rMsg, uint32_t aivID, uint32_t curTurnCnt);
      41              :     bool ReadAddrMsg(AivAicpuOpParam *rMsg, uint32_t aivID);
      42              :     bool ReadAddrMsg(HcclApi::HcclMsg *hcclMsg, uint32_t msgPos);
      43              :     bool ReadApiValidMsg(HcclApi::HcclMsg *rMsg, HcclApi::HcclMsg *msg, bool reset);
      44              :     bool PostMsg(uint32_t curTurnCnt) const;
      45              :     bool CheckAivIsEnd(uint32_t aivId);
      46              :     bool NeedAutoGenMsg();
      47              :     uint8_t GetWaitPolicy();
      48              :     uint8_t GetTaskType() const;
      49              :     uint8_t GetRspPolicy();
      50              :     uint8_t GetGenTaskNum();
      51              :     TASK_PREPARE_POSITION GetPreparePosition() const;
      52              :     void ClearWorkMsg() const;
      53              :     void WriteFinishWhenAllFinalize(uint32_t msgPos);
      54              :     void HcclMsg2AicAicpuOpParam(CommonHcclMsg *hcclMsg, AivAicpuOpParam *opMsg);
      55              :     void WriteTurnCnt(uint32_t msgPos);
      56              :     void PrintAllHcclMsgArea();
      57              :     void PrintAllHcclMsgAreaData();
      58              :     void PrintMsg(HcclApi::HcclMsg *hcclMsg, uint32_t msgPos);
      59              : 
      60              : private:
      61              :     template <typename T>
      62              :     bool ReadValidMsg(T *rMsg, T *msg, uint8_t msgType, bool reset);
      63              :     bool GenMsgIsLastMsg();
      64              :     std::string GetMsgTypeString(uint8_t msgType);
      65              :     void GenMsgByTaskParam(AivAicpuOpParam *outMsg);
      66              :     u64 GetSendOff() const;
      67              :     u64 GetRecvOff() const;
      68              :     void CalcAllgatherBuffer(AivAicpuOpParam *outMsg) const;
      69              :     void CalcAllreduceBuffer(AivAicpuOpParam *outMsg) const;
      70              :     void CalcReduceScatterBuffer(AivAicpuOpParam *outMsg) const;
      71              :     bool CheckDebugMode(HcclApi::HcclMsg *rMsg);
      72              : 
      73              : private:
      74              :     struct RpcMsgBody {
      75              :         // Rank* aiv * MsgSize * sizeof(消息)
      76              :         AivAicpuOpParam msgRcvArea[AC_MAX_AIV][HcclApi::HCCL_MSG_CNT];
      77              :         AivAicpuOpParam msgSndArea[AC_MAX_AIV][HcclApi::HCCL_MSG_CNT];
      78              :     };
      79              :     RpcMsgBody *msgBody_ = nullptr;
      80              : 
      81              :     HcclApi::HcclMsgArea *hcclMsgArea_ = nullptr;
      82              : 
      83              :     AivAicpuOpParam *msgSndWorkArea_ = nullptr;
      84              :     AivAicpuOpParam *msgRcvRspArea_ = nullptr;
      85              :     // 记录每个消息队列的位置
      86              :     uint32_t rcvMsgPos_[AC_MAX_AIV] = {0};  // 接收队列的初始化位置
      87              :     uint32_t sndMsgPos_[AC_MAX_AIV] = {0};
      88              :     uint32_t aivState_[AC_MAX_AIV] = {0};
      89              : 
      90              :     uint64_t genTaskNum_;
      91              :     KFCTask *genTaskParam_;
      92              :     HcclKFCTilingData *tilingData_;
      93              : };
      94              : 
      95              : #endif  // __AICPU_RPC_SERVER_HPP__
        

Generated by: LCOV version 2.0-1