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 : #ifndef CCU_CHANNEL_CTX_MGR_H
12 : #define CCU_CHANNEL_CTX_MGR_H
13 :
14 : #include <vector>
15 : #include <mutex>
16 :
17 : #include "hccl_types.h"
18 : #include "ccu_dev_mgr_imp.h"
19 :
20 : namespace hcomm {
21 :
22 : constexpr uint32_t MASK_VTP = 0xFFFF0000;
23 : constexpr uint32_t MASK_VTP_LOW = 0x0000FFFF;
24 : constexpr uint32_t MASK_VTP_HIGH = 0x000000FF;
25 :
26 : struct ChannelResInfo {
27 : bool allocated{false};
28 : uint32_t feId{0};
29 : ChannelInfo channelInfo{};
30 : };
31 :
32 : void DumpChannelResInfo(const uint32_t feId, const ChannelInfo& info);
33 : bool IsEidEmpty(const uint8_t (&eidRaw)[URMA_EID_LEN]);
34 :
35 : class CcuChannelCtxMgr {
36 : public:
37 211 : CcuChannelCtxMgr(const int32_t devLogicId, const uint8_t dieId, const uint32_t devPhyId)
38 422 : : devLogicId_(devLogicId),
39 211 : dieId_(dieId),
40 211 : devPhyId_(devPhyId) {};
41 : CcuChannelCtxMgr() = default;
42 211 : virtual ~CcuChannelCtxMgr() = default;
43 :
44 : virtual HcclResult Init() = 0;
45 :
46 : virtual HcclResult Alloc(const ChannelPara& channelPara, std::vector<ChannelInfo>& channelInfos) = 0;
47 : virtual HcclResult Config(const ChannelCfg& channelCfg) = 0;
48 : virtual HcclResult Release(const uint32_t channelId) = 0;
49 :
50 : protected:
51 : bool CheckIfChannelAllocated(const uint32_t channelId) const;
52 :
53 : protected:
54 : std::mutex innerMutex_{};
55 : int32_t devLogicId_{0};
56 : uint8_t dieId_{0};
57 : uint32_t devPhyId_{0};
58 :
59 : std::vector<ChannelResInfo> channelResInfos_;
60 : };
61 :
62 : } // namespace hcomm
63 :
64 : #endif // CCU_CHANNEL_CTX_MGR_H
|