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_v2.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
31 : = hcomm::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<Hccl::LocalRdmaRmaBuffer>>;
32 : using RemoteRdmaRmaBufferMgr
33 : = hcomm::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<Hccl::RemoteRdmaRmaBuffer>>;
34 :
35 : RoceRegedMemMgr();
36 26 : ~RoceRegedMemMgr() = default;
37 :
38 : HcclResult RegisterMemory(HcommMem mem, const char* memTag, void** memHandle) override;
39 : HcclResult UnregisterMemory(void* memHandle) override;
40 : HcclResult
41 : MemoryExport(const EndpointDesc endpointDesc, void* memHandle, void** memDesc, uint32_t* memDescLen) override;
42 : HcclResult MemoryImport(const void* memDesc, uint32_t descLen, HcommMem* outMem) override;
43 : HcclResult MemoryUnimport(const void* memDesc, uint32_t descLen) override;
44 : HcclResult GetAllMemHandles(void** memHandles, uint32_t* memHandleNum) override;
45 : HcclResult GetMemDesc(const EndpointDesc endpointDesc, Hccl::LocalRdmaRmaBuffer* localRdmaRmaBuffer);
46 : HcclResult GetParamsFromMemDesc(
47 : const void* memDesc, uint32_t descLen, EndpointDesc& endpointDesc, Hccl::ExchangeRdmaBufferDto& dto);
48 :
49 : private:
50 : std::unique_ptr<LocalRdmaRmaBufferMgr> localRdmaRmaBufferMgr_{};
51 : std::vector<RegedBufferEntry<Hccl::LocalRdmaRmaBuffer>> allRegisteredBuffers_;
52 : std::vector<std::shared_ptr<Hccl::LocalRdmaRmaBuffer>> handlesRecords_;
53 : std::unordered_map<EndpointDesc, std::unique_ptr<RemoteRdmaRmaBufferMgr>> remoteRdmaRmaBufferMgrs_;
54 : };
55 : } // namespace hcomm
56 :
57 : #endif // ROCE_MEM_H
|