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 : #ifndef AICPU_TS_HCCS_CHANNEL_H
11 : #define AICPU_TS_HCCS_CHANNEL_H
12 : #include <memory>
13 : #include <vector>
14 : #include "hccl_mem_defs.h"
15 : #include "transport_mem.h"
16 : #include "hccl_res.h"
17 : #include "hccl_socket.h"
18 : #include "channel.h"
19 : #include "aicpu_ts_channel_helper.h"
20 : #include "channel_param.h"
21 : #include "buffer.h"
22 : #include "hccl_dispatcher_ctx.h"
23 : #include "rma_buffer.h"
24 : #include "hcomm_c_adpt.h"
25 : #include "../../../endpoints/aicputs_hccs_endpoint.h"
26 :
27 : namespace hcomm {
28 : /**
29 : * @note 职责:Channel的AicpuTs通信引擎、HCCS协议的类派生
30 : */
31 : class AicpuTsHccsChannel : public Channel {
32 : public:
33 : struct HccsExchangeInfo {
34 : s32 memNum = 0;
35 : };
36 : AicpuTsHccsChannel(EndpointHandle endpointHandle, const HcommChannelDesc &channelDesc);
37 : virtual ~AicpuTsHccsChannel();
38 :
39 : HcclResult Init() override;
40 : HcclResult GetNotifyNum(uint32_t *notifyNum) const override;
41 : HcclResult GetRemoteMems(uint32_t *memNum, CommMem **remoteMem, char ***memInfos) override;
42 : ChannelStatus GetStatus() override;
43 :
44 : std::shared_ptr<hccl::Transport> GetTransport() {return transport_;}
45 : HcclResult Clean() override;
46 : HcclResult Resume() override;
47 0 : const HcommChannelDesc& GetChannelDesc() const override { return channelDesc_; }
48 :
49 : // for launch channel kernel data
50 : HcclResult Serialize(std::shared_ptr<hccl::DeviceMem> &out) override;
51 : HcommChannelKind GetChannelKind() const override;
52 :
53 : // 数据面接口
54 : HcclResult NotifyRecord(const uint32_t remoteNotifyIdx) override;
55 : HcclResult NotifyWait(const uint32_t localNotifyIdx, const uint32_t timeout) override;
56 : HcclResult WriteWithNotify(void *dst, const void *src, const uint64_t len, uint32_t remoteNotifyIdx) override;
57 : HcclResult Write(void *dst, const void *src, uint64_t len) override;
58 : HcclResult Read(void *dst, const void *src, uint64_t len) override;
59 : HcclResult ChannelFence() override;
60 :
61 2 : AicpuTsChannelHelper *GetAicpuTsHelper() override { return &aicpuTsHelper_; }
62 :
63 : private:
64 : AicpuTsChannelHelper aicpuTsHelper_;
65 : HcclResult ParseInputParam();
66 : HcclResult EnableP2P();
67 : void DisableP2P();
68 : HcclResult BuildConnection();
69 : void DestroyConnection();
70 : HcclResult EnableMemAccess();
71 : void DisableMemAccess();
72 : HcclResult GetFirstIpByPhyId(u32 devicePhyId, u32 superDevId, hccl::HcclIpAddress &ip);
73 : HcclResult SetMachinePara(hccl::MachinePara &machinePara);
74 : void SetTransportParam(hccl::TransportPara ¶);
75 : HcclResult TransportInit();
76 : void TransportDeInit();
77 : HcclResult BuildHcclChannelHccsRes(HcclChannelHccsRes &channelHccsRes);
78 :
79 : private:
80 : // --------------------- 入参 ---------------------
81 : EndpointHandle endpointHandle_{nullptr};
82 : HcommChannelDesc channelDesc_;
83 :
84 : // --------------------- 转换参数 ---------------------
85 : EndpointDesc localEp_{};
86 : EndpointDesc remoteEp_{};
87 : hccl::HcclIpAddress localIp_;
88 : hccl::HcclIpAddress remoteIp_;
89 : uint32_t notifyNum_{0};
90 : AicpuTsHccsEndpoint *localEpPtr_{nullptr};
91 : uint32_t serverPort_{AICPU_CHANNEL_DEFAULT_PORT};
92 : bool serverInited_{false};
93 : // --------------------- 具体成员 ---------------------
94 : std::shared_ptr<hccl::HcclSocket> socket_{nullptr};
95 : std::string socketTag_{};
96 : bool isSocketServer_{false};
97 : // for create TransportMem
98 : HcclDispatcher dispatcher_{nullptr}; // dispatcher放到最后析构
99 : DispatcherCtxPtr dispatcherCtx_{nullptr};
100 : std::unique_ptr<hccl::NotifyPool> notifyPool_;
101 : std::shared_ptr<hccl::Transport> transport_{nullptr};
102 :
103 : // for get mem temp
104 : std::vector<CommMem> remoteIpcRmaBufferVec_;
105 : std::vector<HcclMemEx> localIpcRmaBufferVecEx_;
106 : std::vector<HcclMemEx> remoteIpcRmaBufferVecEx_;
107 : };
108 : }
109 :
110 : #endif // AICPU_TS_HCCS_CHANNEL_H
|