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