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_JETTY_CTX_MGR_V1_H
12 : #define CCU_JETTY_CTX_MGR_V1_H
13 :
14 : #include <memory>
15 : #include <vector>
16 : #include <unordered_map>
17 :
18 : #include "ccu_jetty_ctx_mgr.h"
19 : #include "ccu_res_allocator.h"
20 :
21 : namespace hcomm {
22 :
23 : class CcuJettyCtxMgrV1 : public CcuJettyCtxMgr {
24 : public:
25 60 : CcuJettyCtxMgrV1(const int32_t devLogicId, const uint8_t dieId, const uint32_t devPhyId)
26 60 : : CcuJettyCtxMgr(devLogicId, dieId, devPhyId) {};
27 :
28 : CcuJettyCtxMgrV1() = default;
29 60 : ~CcuJettyCtxMgrV1() override final = default;
30 :
31 : HcclResult Init() override final;
32 :
33 : HcclResult Alloc(const uint32_t feId, const uint32_t jettyNum, const uint32_t sqSize,
34 : std::vector<JettyInfo>& jettyInfos) override final;
35 : HcclResult Config(const uint32_t feId, const std::vector<JettyInfo> &jettyInfos,
36 : const std::vector<JettyCfg>& jettyCfgs) override final;
37 : HcclResult Release(const uint32_t feId, const std::vector<JettyInfo> &jettyInfos) override final;
38 :
39 : private:
40 : struct JettyAllocator {
41 : PfeJettyStrategy strategy{};
42 : std::unique_ptr<CcuResIdAllocator> idAllocator{nullptr};
43 :
44 60 : explicit JettyAllocator(PfeJettyStrategy pfeJettyStrategy): strategy(pfeJettyStrategy)
45 : {
46 : // 外部对空指针进行校验
47 60 : idAllocator.reset(new (std::nothrow) CcuResIdAllocator(strategy.size));
48 60 : }
49 : };
50 :
51 : HcclResult GetJettyAllocator(uint32_t feId, JettyAllocator* &allocatorHandle);
52 :
53 : private:
54 : std::unique_ptr<JettyAllocator> allocator_; // 所有FE的Jetty统一打平分配
55 : };
56 :
57 : }; // namespace hcomm
58 :
59 : #endif
|