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