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 ROCE_MEM_H
12 : #define ROCE_MEM_H
13 :
14 : #include <memory>
15 : #include <vector>
16 : #include <string>
17 : #include "reged_mem_mgr.h"
18 : #include "rma_buffer_mgr.h"
19 : #include "buffer_key.h"
20 : #include "../../../../../legacy/ascend950/unified_platform/resource/buffer/local_rdma_rma_buffer_v2.h"
21 : #include "remote_rma_buffer.h"
22 : #include "exchange_rdma_buffer_dto.h"
23 : #include "local_rdma_rma_buffer.h"
24 :
25 : namespace hcomm {
26 : /**
27 : * @note 职责:用于通信设备EndPoint的注册内存信息管理,支持基于RmaBufferMgr类的重叠内存的检测报错等。
28 : */
29 : class RoceRegedMemMgr : public RegedMemMgr {
30 : public:
31 : using LocalRdmaRmaBufferMgr
32 : = hcomm::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<Hccl::LocalRdmaRmaBuffer>>;
33 : using RemoteRdmaRmaBufferMgr
34 : = hcomm::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<Hccl::RemoteRdmaRmaBuffer>>;
35 :
36 : RoceRegedMemMgr();
37 26 : ~RoceRegedMemMgr() = default;
38 :
39 : HcclResult RegisterMemory(HcommMem mem, const char* memTag, void** memHandle) override;
40 : HcclResult UnregisterMemory(void* memHandle) override;
41 : HcclResult
42 : MemoryExport(const EndpointDesc endpointDesc, void* memHandle, void** memDesc, uint32_t* memDescLen) override;
43 : HcclResult MemoryImport(const void* memDesc, uint32_t descLen, HcommMem* outMem) override;
44 : HcclResult MemoryUnimport(const void* memDesc, uint32_t descLen) override;
45 : HcclResult GetAllMemHandles(void** memHandles, uint32_t* memHandleNum) override;
46 : HcclResult GetMemDesc(const EndpointDesc endpointDesc, Hccl::LocalRdmaRmaBuffer* localRdmaRmaBuffer);
47 : HcclResult GetParamsFromMemDesc(
48 : const void* memDesc, uint32_t descLen, EndpointDesc& endpointDesc, Hccl::ExchangeRdmaBufferDto& dto);
49 :
50 : private:
51 : std::unique_ptr<LocalRdmaRmaBufferMgr> localRdmaRmaBufferMgr_{};
52 : std::vector<RegedBufferEntry<Hccl::LocalRdmaRmaBuffer>> allRegisteredBuffers_;
53 : std::vector<std::shared_ptr<Hccl::LocalRdmaRmaBuffer>> handlesRecords_;
54 : std::unordered_map<EndpointDesc, std::unique_ptr<RemoteRdmaRmaBufferMgr>> remoteRdmaRmaBufferMgrs_;
55 : };
56 : } // namespace hcomm
57 :
58 : #endif // ROCE_MEM_H
|