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