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 URMA_MEMORY_H
12 : #define URMA_MEMORY_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 "local_ub_rma_buffer.h"
21 : #include "remote_rma_buffer.h"
22 : #include "exchange_ub_buffer_dto.h"
23 :
24 : namespace hcomm {
25 : /**
26 : * @note 职责:用于通信设备EndPoint的注册内存信息管理,支持基于RmaBufferMgr类的重叠内存的检测报错等。
27 : */
28 : class UbRegedMemMgr : public RegedMemMgr {
29 : public:
30 : using LocalUbRmaBufferMgr
31 : = hcomm::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<Hccl::LocalUbRmaBuffer>>;
32 : using RemoteUbRmaBufferMgr
33 : = hcomm::RmaBufferMgr<hccl::BufferKey<uintptr_t, u64>, std::shared_ptr<Hccl::RemoteUbRmaBuffer>>;
34 :
35 : UbRegedMemMgr();
36 49 : ~UbRegedMemMgr() = 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::LocalUbRmaBuffer* localUbRmaBuffer);
46 : HcclResult GetParamsFromMemDesc(
47 : const void* memDesc, uint32_t descLen, EndpointDesc& endpointDesc, Hccl::ExchangeUbBufferDto& dto);
48 :
49 : private:
50 : std::unique_ptr<LocalUbRmaBufferMgr> localUbRmaBufferMgr_{};
51 : std::vector<RegedBufferEntry<Hccl::LocalUbRmaBuffer>> allRegisteredBuffers_;
52 : std::vector<std::shared_ptr<Hccl::LocalUbRmaBuffer>> handlesRecords_;
53 : std::unordered_map<EndpointDesc, std::unique_ptr<RemoteUbRmaBufferMgr>> remoteUbRmaBufferMgrs_;
54 : };
55 : } // namespace hcomm
56 :
57 : #endif // URMA_ENDPOINT_H
|