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 : #ifndef HCCLV2_PLT_NET_DEVICE_H
11 : #define HCCLV2_PLT_NET_DEVICE_H
12 :
13 : #include "orion_adapter_hccp.h"
14 : #include "inner_net_dev.h"
15 : #include "buffer_key.h"
16 : #include "hccl_net_dev_defs.h"
17 :
18 : namespace Hccl {
19 :
20 : class HcclNetDevice {
21 : public:
22 :
23 4 : static HcclProtoType ConvertHcclProtoToLinkProto(Hccl::LinkProtoType type)
24 : {
25 4 : switch (type) {
26 0 : case Hccl::LinkProtoType::HCCS_PCIE:
27 0 : return HCCL_PROTO_TYPE_RESERVED;
28 0 : case Hccl::LinkProtoType::TCP:
29 0 : return HCCL_PROTO_TYPE_TCP;
30 0 : case Hccl::LinkProtoType::RDMA:
31 0 : return HCCL_PROTO_TYPE_ROCE;
32 4 : case Hccl::LinkProtoType::UB:
33 4 : return HCCL_PROTO_TYPE_UBC_TP;
34 0 : default:
35 0 : return HCCL_PROTO_TYPE_RESERVED;
36 : }
37 : }
38 :
39 4 : static HcclNetDevDeployment ConvertDeploymentType(Hccl::PortDeploymentType type) {
40 4 : if(type == Hccl::PortDeploymentType::DEV_NET) {
41 3 : return HCCL_NETDEV_DEPLOYMENT_DEVICE;
42 1 : } else if(type == Hccl::PortDeploymentType::HOST_NET) {
43 0 : return HCCL_NETDEV_DEPLOYMENT_HOST;
44 : } else {
45 1 : return HCCL_NETDEV_DEPLOYMENT_RESERVED;
46 : }
47 : }
48 : HcclNetDevice(const NetDevInfo &info);
49 : ~HcclNetDevice();
50 :
51 : // NetDevInfo 读写函数
52 : NetDevInfo GetNetDevInfo() const;
53 :
54 : // Getter 方法:返回 ndev_ 的当前值
55 : InnerNetDev *GetInnerNetDev() const;
56 :
57 : // Setter 方法:允许外部修改 ndev_ 的值
58 : void SetInnerNetDev(InnerNetDev *value);
59 :
60 : RdmaHandle GetRdmaHandle() const;
61 :
62 : std::pair<TokenIdHandle, uint32_t> GetTokenIdInfo(const BufferKey<uintptr_t, u64> &bufKey) const;
63 : void PutTokenIdInfo(const BufferKey<uintptr_t, u64> &bufKey, TokenIdHandle tokenIdHandle) const;
64 : bool IsUB();
65 :
66 : private:
67 : NetDevInfo netDevInfo_;
68 : InnerNetDev *ndev_;
69 : };
70 :
71 : } // namespace Hccl
72 :
73 : #endif // HCCLV2_PLT_NET_DEVICE_H
|