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 : #include "remote_ipc_rma_buffer_impl.h"
12 : #include "hccl_network.h"
13 :
14 : namespace hccl {
15 4 : RemoteIpcRmaBufferImpl::RemoteIpcRmaBufferImpl(const HcclNetDevCtx netDevCtx)
16 4 : : RmaBuffer(netDevCtx, nullptr, 0, RmaMemType::TYPE_NUM, RmaType::IPC_RMA), netDevCtx(netDevCtx)
17 : {
18 4 : }
19 :
20 8 : RemoteIpcRmaBufferImpl::~RemoteIpcRmaBufferImpl()
21 : {
22 8 : }
23 :
24 4 : HcclResult RemoteIpcRmaBufferImpl::Deserialize(const std::string& msg)
25 : {
26 4 : std::istringstream iss(msg);
27 4 : iss.read(reinterpret_cast<char_t *>(&memName.ipcName), sizeof(memName.ipcName));
28 4 : iss.read(reinterpret_cast<char_t *>(&memOffset), sizeof(memOffset));
29 4 : HCCL_DEBUG("[RemoteIpcRmaBufferImpl][Deserialize]ipcName[%s], memOffset[%lu]", memName.ipcName, memOffset);
30 4 : return HCCL_SUCCESS;
31 4 : }
32 :
33 1 : HcclResult RemoteIpcRmaBufferImpl::Open()
34 : {
35 1 : if (memType == RmaMemType::HOST) {
36 0 : HCCL_ERROR("[RemoteIpcRmaBufferImpl][Open]remote memType[%d] not support.", memType);
37 0 : return HCCL_E_PARA;
38 : }
39 :
40 1 : s32 deviceLogicId = 0;
41 1 : if (netDevCtx != nullptr) {
42 1 : deviceLogicId = (static_cast<NetDevContext *>(netDevCtx))->GetLogicId();
43 : } else {
44 0 : CHK_RET(hrtGetDevice(&deviceLogicId));
45 : }
46 1 : bool firstOpened = false;
47 : HcclResult ret = MemNameRepository::GetInstance(deviceLogicId)
48 1 : ->OpenIpcMem(&devAddr, size, memName.ipcName, HCCL_IPC_MEM_NAME_LEN, memOffset, firstOpened);
49 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
50 : HCCL_ERROR("[RemoteIpcRmaBufferImpl][Open]errNo[0x%016llx] Open ipc mem failed. memName[%s], offset[%llu]",
51 : HCCL_ERROR_CODE(ret), memName.ipcName, memOffset), ret);
52 1 : return HCCL_SUCCESS;
53 : }
54 :
55 1 : HcclResult RemoteIpcRmaBufferImpl::Close()
56 : {
57 1 : s32 deviceLogicId = 0;
58 1 : if (netDevCtx != nullptr) {
59 1 : deviceLogicId = (static_cast<NetDevContext *>(netDevCtx))->GetLogicId();
60 : } else {
61 0 : CHK_RET(hrtGetDevice(&deviceLogicId));
62 : }
63 : MemNameRepository::GetInstance(deviceLogicId)
64 1 : ->CloseIpcMem(static_cast<const u8 *>(memName.ipcName));
65 1 : HCCL_DEBUG("[RemoteIpcRmaBufferImpl][Close]memName[%s]", memName.ipcName);
66 1 : return HCCL_SUCCESS;
67 : }
68 : }
|