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 CCU_URMA_CHANNEL_H
12 : #define CCU_URMA_CHANNEL_H
13 :
14 : #include <memory>
15 : #include <vector>
16 : #include <atomic>
17 : #include <mutex>
18 : #include <optional>
19 :
20 : #include "../channel.h"
21 :
22 : #include "urma_endpoint.h"
23 : #include "ccu_transport_.h"
24 :
25 : namespace hcomm {
26 :
27 : class CcuUrmaChannel : public Channel {
28 : public:
29 : // 当前仅支持交换hccl buffer
30 : CcuUrmaChannel(const EndpointHandle locEndpointHandle, const HcommChannelDesc& channelDesc);
31 : ~CcuUrmaChannel() override;
32 :
33 : HcclResult Init() override;
34 : ChannelStatus GetStatus() override;
35 :
36 : HcclResult GetNotifyNum(uint32_t* notifyNum) const override;
37 : HcclResult GetRemoteMems(uint32_t* memNum, CommMem** remoteMem, char*** memInfos) override;
38 : HcclResult UpdateMemInfo(HcommMemHandle* memHandles, uint32_t memHandleNum) override;
39 :
40 : HcclResult Clean() override;
41 : HcclResult Resume() override;
42 :
43 : HcclResult ChannelFence() override;
44 : HcclResult NotifyRecord(const uint32_t remoteNotifyIdx) override;
45 : HcclResult NotifyWait(const uint32_t localNotifyIdx, const uint32_t timeout) override;
46 : HcclResult WriteWithNotify(void* dst, const void* src, const uint64_t len, uint32_t remoteNotifyIdx) override;
47 : HcclResult Write(void* dst, const void* src, uint64_t len) override;
48 : HcclResult Read(void* dst, const void* src, uint64_t len) override;
49 :
50 : public:
51 : uint32_t GetDieId() const;
52 : uint32_t GetChannelId() const;
53 : HcclResult GetRmtSignalAddrByIndex(uint32_t index, uint64_t& rmtCkeAddr) const;
54 : HcclResult GetRmtCcuBufferTokenInfo(uint32_t& rmtTokenId, uint32_t& rmtTokenValue) const;
55 : HcclResult GetRmtVarAddrByIndex(uint32_t index, uint64_t& rmtXnAddr) const;
56 : HcclResult GetLocCkeByIndex(const uint32_t index, uint32_t& locCkeId) const;
57 : HcclResult GetLocXnByIndex(const uint32_t index, uint32_t& locXnId) const;
58 :
59 : HcclResult GetRmtCkeByIndex(const uint32_t index, uint32_t& rmtCkeId) const;
60 : HcclResult GetRmtXnByIndex(const uint32_t index, uint32_t& rmtXnId) const;
61 :
62 : HcclResult GetRmtWishCntXnAddr(const std::string& resGroupTag, uint64_t& wishCntXnAddr) const;
63 :
64 : HcclResult GetRmtBuffer(uint64_t& addr, uint32_t& size, uint32_t& tokenId, uint32_t& tokenValue) const;
65 :
66 0 : EndpointHandle GetlocEndPointHandle() { return locEndpointHandle_; }
67 15 : const HcommChannelDesc& GetChannelDesc() const override { return channelDesc_; }
68 :
69 : private:
70 : ChannelStatus TryPrepareAndConstruct();
71 :
72 : std::atomic<bool> isFirstPrintChannelInfo_{true}; // 是否第一次打印通道建链信息,避免重复打印日志刷屏
73 : std::unique_ptr<CcuTransport> impl_{nullptr};
74 : ChannelStatus channelStatus_{ChannelStatus::INIT};
75 : // 保护 GetStatus 懒建链与状态读写:并发轮询同一 channel 时避免 impl_/channelStatus_ 竞态
76 : std::mutex statusMtx_{};
77 : EndpointHandle locEndpointHandle_{nullptr};
78 : HcommChannelDesc channelDesc_{};
79 : UrmaEndpoint* ccuEndpoint_{nullptr};
80 : std::optional<Hccl::LinkData> linkData_;
81 : Hccl::Socket* socket_{nullptr};
82 : std::vector<HcommMemHandle> memHandles_{};
83 : };
84 :
85 : } // namespace hcomm
86 : #endif // CCU_URMA_CHANNEL_H
|