Line data Source code
1 : /**
2 : * Copyright (c) 2026 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_ROCE_MEM_H
11 : #define AICPU_TS_ROCE_MEM_H
12 :
13 : #include <cstring>
14 : #include <map>
15 : #include <memory>
16 : #include <string>
17 : #include <unordered_map>
18 : #include <vector>
19 : #include "reged_mem_mgr.h"
20 : #include "hccl_mem_defs.h"
21 : #include "hccl_network.h"
22 : #include "transport_pub.h"
23 : #include "local_rdma_rma_buffer.h"
24 : #include "remote_rdma_rma_buffer.h"
25 :
26 : namespace hcomm {
27 : class AicpuTsRoceRegedMemMgr : public RegedMemMgr {
28 : public:
29 : AicpuTsRoceRegedMemMgr(HcclNetDev netDev, RdmaHandle rdmaHandle);
30 23 : ~AicpuTsRoceRegedMemMgr() override = default;
31 :
32 : HcclResult RegisterMemory(HcommMem mem, const char *memTag, void **memHandle) override;
33 : HcclResult UnregisterMemory(void *memHandle) override;
34 : HcclResult MemoryExport(const EndpointDesc endpointDesc, void *memHandle, void **memDesc, uint32_t *memDescLen) override;
35 : HcclResult MemoryImport(const void *memDesc, uint32_t descLen, HcommMem *outMem) override;
36 : HcclResult MemoryUnimport(const void *memDesc, uint32_t descLen) override;
37 : HcclResult GetAllMemHandles(void **memHandles, uint32_t *memHandleNum) override;
38 :
39 : HcclResult GetAllMemDetails(std::vector<RoceMemDetails> &localOut, std::vector<RoceMemDetails> &remoteOut) const;
40 :
41 : private:
42 : using RemoteRdmaRmaBufferMgr =
43 : hccl::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<hccl::RemoteRdmaRmaBuffer>>;
44 :
45 : struct EndpointDescLess {
46 0 : bool operator()(const EndpointDesc &a, const EndpointDesc &b) const noexcept
47 : {
48 0 : return std::memcmp(&a, &b, sizeof(EndpointDesc)) < 0;
49 : }
50 : };
51 :
52 : HcclResult GetParamsFromMemDesc(const void *memDesc, uint32_t descLen, EndpointDesc &endpointDesc, std::string &rdmaBlob);
53 : void TrackRegisteredBuffer(const std::shared_ptr<hccl::LocalRdmaRmaBuffer> &localBuffer);
54 :
55 : HcclResult GatherLocalMemDetails(std::vector<RoceMemDetails> &localOut) const;
56 : HcclResult AppendLocalNotifyMemDetails(std::vector<RoceMemDetails> &localOut) const;
57 : void GatherRemoteMemDetails(std::vector<RoceMemDetails> &remoteOut) const;
58 :
59 : HcclNetDev netDev_{nullptr};
60 : std::shared_ptr<hccl::NetDevContext::LocalRdmaRmaBufferMgr> localRdmaRmaBufferMgr_{nullptr};
61 : std::vector<RegedBufferEntry<hccl::LocalRdmaRmaBuffer>> allRegisteredBuffers_;
62 : std::vector<HcclBuf> hcclBufRecords_;
63 : std::unordered_map<hccl::LocalRdmaRmaBuffer *, std::vector<char>> exportDescByBuffer_;
64 : std::map<EndpointDesc, std::unique_ptr<RemoteRdmaRmaBufferMgr>, EndpointDescLess> remoteRdmaRmaBufferMgrs_;
65 : };
66 :
67 : } // namespace hcomm
68 : #endif // AICPU_TS_ROCE_MEM_H
|