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 :
12 : #ifndef __COLL_COMM_AICPU_H__
13 : #define __COLL_COMM_AICPU_H__
14 :
15 : #include "common.h"
16 : #include "aicpu_init_param.h"
17 : #include "topo_matcher.h"
18 : #include "hcomm_primitives.h"
19 : #include "transport_pub.h"
20 : #include "thread.h"
21 : #include "local_notify.h"
22 : #include "ub_transport_lite_impl.h"
23 : #include "p2p_transport_lite_impl.h"
24 : #include "task_exception.h"
25 : #include "aicpu_launch_manager.h"
26 : #include "channel_param.h"
27 : #include "hdc_pub.h"
28 : #include "ns_recovery/aicpu/ns_recovery_lite.h"
29 : #include <atomic>
30 : #include "hcclCommDfxLite.h"
31 : #include "error_message_v2.h"
32 : #include "kfc.h"
33 : #include "aicpu_hdc.h"
34 : #include "roce_transport_lite_impl.h"
35 : #include "hccl/hccl_types.h"
36 :
37 : using namespace hccl;
38 :
39 : class CollCommAicpu {
40 : public:
41 : ~CollCommAicpu();
42 : HcclResult InitAicpuIndOp(CommAicpuParam *commAicpuParam);
43 : HcclResult InitThreads(ThreadMgrAicpuParam *param);
44 : HcclResult AllocChannelResource(HcclChannelUrmaRes *commParam);
45 : HcclResult NotifyFree(NotifyMgrAicpuParam *param);
46 : HcclResult NotifyAlloc(NotifyMgrAicpuParam *param);
47 2 : const std::vector<std::shared_ptr<Thread>>& GetAllThread() { return threads_; };
48 2 : const HcclTopoInfo& GetTopoInfo() { return topoInfo_; }
49 13 : const std::string& GetIdentifier() { return identifier_; }
50 :
51 : // taskException
52 0 : bool IsErrorReported() { return isErrorReported_; }
53 1 : void SetErrorReported(bool isErrorReported) { isErrorReported_ = isErrorReported; }
54 : HcclResult SendErrorMessageReportToHost(Hccl::ErrorMessageReport& errMsgInfo);
55 : HcclResult RegisterProfCallBack();
56 14 : HcclCommDfxLite* GetHcclCommDfxLite() { return &dfx_; };
57 2 : std::shared_mutex& GetThreadMutex() { return threadMutex_; }
58 4 : u32 GetDevId() { return devId_; }
59 :
60 : // h2d - d2h通道信息交互
61 : HcclResult BackGroundGetCmd(Hccl::KfcCommand &cmd);
62 : HcclResult BackGroundSetStatus(Hccl::KfcStatus state);
63 : u32 UpdateIndex();
64 :
65 6 : HcclCommStatus GetCommmStatus() { return commStatus_; }
66 : void SetCommmStatus(HcclCommStatus status);
67 :
68 : // N秒快恢
69 : hccl::NsRecoveryLitePtr GetNsRecoveryLitePtr();
70 : HcclResult Clean();
71 : HcclResult Resume(HcclChannelUrmaRes *commParam);
72 :
73 : HcclResult CheckIndOpExecStatus(bool timeout);
74 :
75 : private:
76 : // 初始化
77 : void InitIndopEnv(CommAicpuParam *commAicpuParam);
78 : HcclResult InitHDCommunicate(CommAicpuParam *commAicpuParam);
79 :
80 : HcclResult InitUrmaChannel(HcclChannelUrmaRes *commParam);
81 : HcclResult ParsePackData(std::vector<char> &data, ChannelHandle &handle);
82 : HcclResult RegisterChannelAddDfxTaskInfo(ChannelHandle channel);
83 : HcclResult RegisterThreadAddDfxTaskInfo(ThreadHandle thread);
84 : void InitBackGroundThread();
85 : HcclResult ResumePackData(std::vector<char> &data, ChannelHandle &handle);
86 : HcclResult ProcessUrmaRes(HcclChannelUrmaRes *commParam, bool isInit);
87 :
88 : u32 devId_{0};
89 : //通用的通道
90 : std::shared_ptr<hccl::HDCommunicate> kfcControlTransferH2D_{nullptr};
91 : std::shared_ptr<hccl::HDCommunicate> kfcStatusTransferD2H_{nullptr};
92 :
93 : std::string identifier_;
94 : HcclCommStatus commStatus_{HcclCommStatus::HCCL_COMM_STATUS_INVALID};
95 : HcclTopoInfo topoInfo_;
96 : std::shared_mutex threadMutex_;
97 : std::vector<std::shared_ptr<Thread>> threads_;
98 : std::vector<std::unique_ptr<LocalNotify>> notifys_;
99 : // A5 独立算子
100 : std::unordered_map<ChannelHandle, std::unique_ptr<Hccl::UbTransportLiteImpl>> ubTransportMap_;
101 : std::unordered_map<ChannelHandle, std::unique_ptr<Hccl::P2PTransportLiteImpl>> p2pTransportMap_;
102 : std::unordered_map<ChannelHandle, std::unique_ptr<Hccl::RoceTransportLiteImpl>> roceTransportMap_;
103 :
104 : // N秒快恢相关
105 : hccl::NsRecoveryLitePtr nsRecoveryLitePtr_{nullptr};
106 :
107 : // dfx
108 : bool isErrorReported_{false}; // 是否上报了taskException信息
109 : HcclCommDfxLite dfx_;
110 : u32 index_{0};
111 : };
112 :
113 : #endif // __COLL_COMM_AICPU_H__
|