Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 "hcomm_c_adpt.h"
12 : #include "hcomm_c_adpt_common.h"
13 : #include "hcomm_result_defs.h"
14 : #include "log.h"
15 : #include "endpoint.h"
16 : #include "param_check_pub.h"
17 : #include "exception_handler.h"
18 : #include "hcomm_res_defs.h"
19 : #include "hcomm_res.h"
20 : #include "hcomm_mem_alloc.h"
21 :
22 : using namespace hcomm;
23 :
24 : HcommResult
25 55 : HcommMemReg(EndpointHandle endpointHandle, const char* memTag, const CommMem* mem, HcommMemHandle* memHandle)
26 : {
27 55 : auto endpoint = GetEndpointMap().GetEndpoint(endpointHandle);
28 55 : CHK_PRT_RET(
29 : endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[%p]", __func__, endpointHandle),
30 : HCCL_E_NOT_FOUND);
31 : return static_cast<HcclResult>(
32 54 : endpoint->GetNicOps()->registerMemory(endpoint->GetNicCtx(), mem, memTag, reinterpret_cast<void**>(memHandle)));
33 : }
34 :
35 63 : HcommResult HcommMemUnreg(EndpointHandle endpointHandle, HcommMemHandle memHandle)
36 : {
37 63 : auto endpoint = GetEndpointMap().GetEndpoint(endpointHandle);
38 63 : CHK_PRT_RET(
39 : endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[%p]", __func__, endpointHandle),
40 : HCCL_E_NOT_FOUND);
41 49 : return static_cast<HcclResult>(endpoint->GetNicOps()->unregisterMemory(endpoint->GetNicCtx(), memHandle));
42 : }
43 :
44 : HcommResult
45 8 : HcommMemExport(EndpointHandle endpointHandle, HcommMemHandle memHandle, void** memDesc, uint32_t* memDescLen)
46 : {
47 8 : auto endpoint = GetEndpointMap().GetEndpoint(endpointHandle);
48 8 : CHK_PRT_RET(
49 : endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[%p]", __func__, endpointHandle),
50 : HCCL_E_NOT_FOUND);
51 : return static_cast<HcclResult>(
52 7 : endpoint->GetNicOps()->memoryExport(endpoint->GetNicCtx(), memHandle, memDesc, memDescLen));
53 : }
54 :
55 7 : HcommResult HcommMemImport(EndpointHandle endpointHandle, const void* memDesc, uint32_t descLen, CommMem* outMem)
56 : {
57 7 : auto endpoint = GetEndpointMap().GetEndpoint(endpointHandle);
58 7 : CHK_PRT_RET(
59 : endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[%p]", __func__, endpointHandle),
60 : HCCL_E_NOT_FOUND);
61 : return static_cast<HcclResult>(
62 7 : endpoint->GetNicOps()->memoryImport(endpoint->GetNicCtx(), memDesc, descLen, outMem));
63 : }
64 :
65 6 : HcommResult HcommMemUnimport(EndpointHandle endpointHandle, const void* memDesc, uint32_t descLen)
66 : {
67 6 : auto endpoint = GetEndpointMap().GetEndpoint(endpointHandle);
68 6 : CHK_PRT_RET(
69 : endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[%p]", __func__, endpointHandle),
70 : HCCL_E_NOT_FOUND);
71 6 : return static_cast<HcclResult>(endpoint->GetNicOps()->memoryUnimport(endpoint->GetNicCtx(), memDesc, descLen));
72 : }
73 :
74 : /* 暂未实现 */
75 0 : HcommResult HcommMemGrant(EndpointHandle endpointHandle, const HcommMemGrantInfo* remoteGrantInfo)
76 : {
77 0 : CHK_PTR_NULL(remoteGrantInfo);
78 0 : HCCL_INFO("[%s] START. endpointHandle[0x%llx].", __func__, endpointHandle);
79 :
80 0 : auto endpoint = GetEndpointMap().GetEndpoint(endpointHandle);
81 0 : CHK_PRT_RET(
82 : endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[0x%llx]", __func__, endpointHandle),
83 : HCCL_E_NOT_FOUND);
84 0 : CHK_RET(endpoint->MemoryGrant(remoteGrantInfo));
85 0 : return HCCL_SUCCESS;
86 : }
87 :
88 : /* 暂未实现 */
89 0 : HcommResult HcommMemRemap(
90 : [[maybe_unused]] const EndpointHandle endpointHandle, [[maybe_unused]] const CommMem* memArray,
91 : [[maybe_unused]] uint64_t arraySize)
92 : {
93 0 : return HCCL_E_NOT_SUPPORT;
94 : }
95 :
96 1 : HcommResult HcommMemGetAllMemHandles(EndpointHandle endpointHandle, void** memHandles, uint32_t* memHandleNum)
97 : {
98 1 : CHK_PTR_NULL(memHandles);
99 0 : CHK_PTR_NULL(memHandleNum);
100 :
101 0 : auto endpoint = GetEndpointMap().GetEndpoint(endpointHandle);
102 0 : CHK_PRT_RET(
103 : endpoint == nullptr, HCCL_ERROR("[%s] endpoint not found, endpointHandle[0x%llx]", __func__, endpointHandle),
104 : HCCL_E_NOT_FOUND);
105 0 : CHK_RET(endpoint->GetAllMemHandles(memHandles, memHandleNum));
106 0 : return HCCL_SUCCESS;
107 : }
108 :
109 8 : HcommResult HcommMemAlloc(void** ptr, size_t size) { return hcomm::MemAlloc(ptr, size); }
110 :
111 7 : HcommResult HcommMemFree(void* ptr) { return hcomm::MemFree(ptr); }
|