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 "shared_jetty_connection_adapter.h"
12 : #include "dev_ub_connection.h"
13 : #include "log.h"
14 : #include "adapter_rts_common.h"
15 :
16 : namespace hcomm {
17 :
18 : // 适配层当前实现:转发到 Hccl::DevUbConnection 的新增共享 jetty 方法。
19 : // TODO(architecture): DevUbConnection 自 legacy/ 迁入 base_comm 后,本文件可直接操作 connection,
20 : // 届时移除对 dev_ub_connection.h 的 #include,base_comm 完全不依赖 legacy 实现细节。
21 11 : HcclResult InjectSharedJettyToConn(
22 : void* rawConnection, const Endpoint::SharedJettyCtx& ctx, void* endpointTag, std::function<void(void*)> releaseCb)
23 : {
24 11 : if (rawConnection == nullptr) {
25 1 : return HCCL_E_PARA;
26 : }
27 10 : auto* conn = static_cast<Hccl::DevUbConnection*>(rawConnection);
28 20 : return conn->InjectSharedJetty(
29 10 : ctx.handle, ctx.handlePtr, ctx.jettyId, ctx.sqBuffVa, ctx.dbAddr, ctx.localQpKey, ctx.keySize, ctx.sqDepth,
30 20 : ctx.tpHandle, endpointTag, std::move(releaseCb));
31 : }
32 :
33 9 : HcclResult ExtractJettyInfoFromConn(void* rawConnection, Endpoint::SharedJettyCtx& ctx)
34 : {
35 9 : if (rawConnection == nullptr) {
36 1 : return HCCL_E_PARA;
37 : }
38 8 : auto* conn = static_cast<Hccl::DevUbConnection*>(rawConnection);
39 8 : Hccl::DevUbConnection::JettyInfo info;
40 8 : CHK_RET(conn->GetJettyInfo(info));
41 8 : ctx.handle = info.handle;
42 8 : ctx.handlePtr = info.handlePtr;
43 8 : ctx.jettyId = info.jettyId;
44 8 : ctx.sqBuffVa = info.sqBuffVa;
45 8 : ctx.dbAddr = info.dbAddr;
46 8 : ctx.keySize = info.keySize;
47 8 : ctx.sqDepth = info.sqDepth;
48 8 : ctx.tpHandle = info.tpHandle;
49 8 : ctx.rdmaHandle = info.rdmaHandle;
50 8 : ctx.jfcHandle = info.jfcHandle;
51 : // 严格按实际 keySize 拷贝,避免拷贝超出实际 keySize 的无效尾部
52 8 : if (info.keySize > Hccl::HRT_UB_QP_KEY_MAX_LEN) {
53 0 : HCCL_ERROR("[%s] invalid keySize[%u], max[%u].", __func__, info.keySize, Hccl::HRT_UB_QP_KEY_MAX_LEN);
54 0 : return HCCL_E_PARA;
55 : }
56 8 : CHK_SAFETY_FUNC_RET(memcpy_s(ctx.localQpKey, Hccl::HRT_UB_QP_KEY_MAX_LEN, info.localQpKey, info.keySize));
57 8 : return HCCL_SUCCESS;
58 : }
59 :
60 8 : HcclResult TransferConnJettyOwnership(void* rawConnection)
61 : {
62 8 : if (rawConnection == nullptr) {
63 1 : return HCCL_E_PARA;
64 : }
65 7 : auto* conn = static_cast<Hccl::DevUbConnection*>(rawConnection);
66 7 : conn->TransferJettyOwnership();
67 7 : return HCCL_SUCCESS;
68 : }
69 :
70 : } // namespace hcomm
|