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 : #include "ub_mem.h"
11 : #include <algorithm>
12 : #include "log.h"
13 :
14 : namespace hcomm {
15 :
16 13 : UbMemRegedMemMgr::UbMemRegedMemMgr() { localIpcRmaBufferMgr_ = std::make_unique<LocalIpcRmaBufferMgr>(); }
17 :
18 27 : HcclResult UbMemRegedMemMgr::RegisterMemory(HcommMem mem, const char* memTag, void** memHandle)
19 : {
20 27 : HCCL_INFO("[%s] Begin", __func__);
21 27 : CHK_PTR_NULL(localIpcRmaBufferMgr_);
22 27 : std::lock_guard<std::mutex> lock(memMtx_);
23 54 : return RegisterMemoryImpl(
24 27 : mem, memTag, memHandle, localIpcRmaBufferMgr_, allRegisteredBuffers_,
25 : static_cast<std::vector<std::shared_ptr<Hccl::LocalIpcRmaBuffer>>*>(nullptr), "UbMemRegedMemMgr",
26 0 : [&](auto& bufPtr, auto& parent) {
27 5 : return std::make_shared<Hccl::LocalIpcRmaBuffer>(bufPtr, *parent);
28 : },
29 0 : [&](auto& bufPtr) {
30 16 : return std::make_shared<Hccl::LocalIpcRmaBuffer>(bufPtr);
31 27 : });
32 27 : }
33 :
34 25 : HcclResult UbMemRegedMemMgr::UnregisterMemory(void* memHandle)
35 : {
36 25 : HCCL_INFO("[%s] Begin", __func__);
37 25 : CHK_PTR_NULL(localIpcRmaBufferMgr_);
38 25 : std::lock_guard<std::mutex> lock(memMtx_);
39 50 : return UnregisterMemoryImpl(
40 25 : memHandle, localIpcRmaBufferMgr_, allRegisteredBuffers_,
41 : static_cast<std::vector<std::shared_ptr<Hccl::LocalIpcRmaBuffer>>*>(nullptr),
42 0 : [](auto* b) {
43 12 : return b->GetIpcPtr();
44 : },
45 0 : [](auto a, auto b) {
46 6 : return a == b;
47 25 : });
48 25 : }
49 :
50 : HcclResult
51 0 : UbMemRegedMemMgr::MemoryExport(const EndpointDesc endpointDesc, void* memHandle, void** memDesc, uint32_t* memDescLen)
52 : {
53 0 : HCCL_INFO("UbMemRegedMemMgr MemoryExport is not supported.");
54 0 : return HCCL_SUCCESS;
55 : }
56 :
57 0 : HcclResult UbMemRegedMemMgr::MemoryImport(const void* memDesc, uint32_t descLen, HcommMem* outMem)
58 : {
59 0 : HCCL_INFO("UbMemRegedMemMgr MemoryImport is not supported.");
60 0 : return HCCL_SUCCESS;
61 : }
62 :
63 0 : HcclResult UbMemRegedMemMgr::MemoryUnimport(const void* memDesc, uint32_t descLen)
64 : {
65 0 : HCCL_INFO("UbMemRegedMemMgr MemoryUnimport is not supported.");
66 0 : return HCCL_SUCCESS;
67 : }
68 :
69 0 : HcclResult UbMemRegedMemMgr::GetAllMemHandles(void** memHandles, uint32_t* memHandleNum)
70 : {
71 0 : HCCL_INFO("UbMemRegedMemMgr GetAllMemHandles is not supported.");
72 0 : return HCCL_SUCCESS;
73 : }
74 : } // namespace hcomm
|