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