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_TS_URMA_CHANNEL_H
12 : #define AICPU_TS_URMA_CHANNEL_H
13 :
14 : #include <atomic>
15 : #include <cstdint>
16 : #include <memory>
17 : #include <vector>
18 : #include "../channel.h"
19 : #include "aicpu_ts_channel_helper.h"
20 : #include "../../sockets/socket_mgr.h"
21 :
22 : // Orion
23 : #include "../../../../../../src/legacy/ascend950/unified_platform/resource/socket/socket.h"
24 : #include "buffer_key.h"
25 : #include "rma_connection.h"
26 : #include "ub_mem_transport.h"
27 : #include "dev_ub_connection.h"
28 : #include "ub_local_notify.h"
29 : #include "hcomm_adapter_hccp.h"
30 :
31 : namespace hcomm {
32 :
33 : class AicpuTsUrmaChannel : public Channel {
34 : public:
35 : AicpuTsUrmaChannel(EndpointHandle endpointHandle, const HcommChannelDesc& channelDesc);
36 : ~AicpuTsUrmaChannel() override;
37 :
38 : HcclResult Init() override;
39 : HcclResult GetNotifyNum(uint32_t* notifyNum) const override;
40 : HcclResult GetRemoteMems(uint32_t* memNum, CommMem** remoteMem, char*** memInfos) override;
41 : ChannelStatus GetStatus() override;
42 : HcclResult UpdateMemInfo(HcommMemHandle* memHandles, uint32_t memHandleNum) override;
43 :
44 : HcclResult H2DResPack(std::vector<char>& buffer);
45 : HcommChannelKind GetChannelKind() const override;
46 :
47 : virtual HcclResult Clean() override;
48 : virtual HcclResult Resume() override;
49 0 : const HcommChannelDesc& GetChannelDesc() const override { return channelDesc_; }
50 : // 数据面接口
51 : HcclResult NotifyRecord(const uint32_t remoteNotifyIdx) override;
52 : HcclResult NotifyWait(const uint32_t localNotifyIdx, const uint32_t timeout) override;
53 : HcclResult WriteWithNotify(void* dst, const void* src, const uint64_t len, uint32_t remoteNotifyIdx) override;
54 : HcclResult Write(void* dst, const void* src, uint64_t len) override;
55 : HcclResult Read(void* dst, const void* src, uint64_t len) override;
56 : HcclResult ChannelFence() override;
57 :
58 0 : AicpuTsChannelHelper* GetAicpuTsHelper() override { return &aicpuTsHelper_; }
59 :
60 : private:
61 : AicpuTsChannelHelper aicpuTsHelper_;
62 : HcclResult ParseInputParam();
63 : HcclResult StartListen();
64 : HcclResult BuildSocket();
65 : HcclResult BuildAttr();
66 : HcclResult BuildConnection();
67 : HcclResult BuildNotify();
68 : HcclResult BuildUbMemTransport();
69 :
70 : HcclResult PackOpData(std::vector<char>& data);
71 :
72 : private:
73 : std::atomic<bool> isFirstPrintChannelInfo_{true}; // 是否第一次打印通道建链信息,避免重复打印日志刷屏
74 : // --------------------- 入参 ---------------------
75 : EndpointHandle endpointHandle_;
76 : HcommChannelDesc channelDesc_;
77 :
78 : // TODO: 成员变量全部初始化
79 : // --------------------- 转换参数 ---------------------
80 : EndpointDesc localEp_{};
81 : EndpointDesc remoteEp_{};
82 : uint32_t notifyNum_{0};
83 :
84 : // --------------------- 具体成员 ---------------------
85 : Hccl::Socket* socket_{nullptr};
86 : RdmaHandle rdmaHandle_{nullptr};
87 : std::unique_ptr<Hccl::UbMemTransport> memTransport_{nullptr};
88 : Hccl::BaseMemTransport::Attribution attr_{};
89 : Hccl::BaseMemTransport::CommonLocRes commonRes_{};
90 : std::vector<std::unique_ptr<Hccl::DevUbConnection>> connections_{};
91 : std::vector<std::unique_ptr<Hccl::UbLocalNotify>> localNotifies_{};
92 : std::unique_ptr<Hccl::Socket> serverSocket_;
93 : std::unique_ptr<Hccl::SocketConfig> socketConfigHolder_;
94 : const Hccl::SocketConfig* socketConfig_{nullptr};
95 : DevBaseAttr devBaseAttr_{};
96 : uint32_t devicePhyId_{};
97 : };
98 :
99 : } // namespace hcomm
100 :
101 : #endif // AICPU_TS_URMA_CHANNEL_H
|