Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 HCOMM_CCU_INSTANCE_H
12 : #define HCOMM_CCU_INSTANCE_H
13 :
14 : #include <array>
15 : #include <memory>
16 : #include <vector>
17 :
18 : #include "ccu_types.h"
19 : #include "ccu_res_pack.h"
20 : #include "ccu_drv_handle.h"
21 : #include "ccu_device_res.h"
22 : #include "ccu_res_desc.h"
23 : #include "ccu_res_desc_mgr.h"
24 :
25 : namespace hcomm {
26 :
27 : /**
28 : * @note 职责:管理通信域持有的CCU资源
29 : */
30 : class CcuInstance {
31 : public:
32 158 : explicit CcuInstance() {};
33 : ~CcuInstance();
34 : CcuResult InitByInsType(const CcuInstanceType insType);
35 : // 基于资源描述符数组初始化(新接口路径,资源数量由 resDesc 驱动)
36 : CcuResult InitByResDescs(const CcuResDesc* descs[], uint32_t descNum);
37 : // 使用当前 Device 上所有已使能 ioDie 的全部资源初始化
38 : CcuResult InitByAllRes();
39 : CcuResult Reset();
40 : CcuResPack* GetResPack();
41 : // 获取 ccuIns 在指定 die 上持有的资源描述符,用于查询接口
42 : const CcuResDesc& GetTotalResDescs(uint8_t dieId) const;
43 : CcuResult SaveKernel(const CcuKernelHandle kernelHandle);
44 : const std::vector<CcuKernelHandle>& GetUntranslatedKernels();
45 : void SetHandle(CcuInsHandle insHandle);
46 :
47 : // 是否使用固定资源数量创建(InitByInsType 路径置 true,其余路径保持 false)
48 47 : bool IsFixedResNum() const { return isFixedResNum_; }
49 :
50 : CcuResult BeginRegister();
51 : CcuResult CheckRegistering() const;
52 : CcuResult EndRegister();
53 : void AbortRegister();
54 :
55 : private:
56 : // 从 resPack_ 取 CcuResRepository,把各 die 各资源类型的占用数量写入 totalResDescs_
57 : CcuResult FillTotalResDescs();
58 :
59 : enum class RegisterState { IDLE, REGISTERING, REGISTER_ABORTED };
60 : RegisterState registerState_{RegisterState::IDLE};
61 : int32_t devLogicId_{INT32_MAX};
62 : CcuInsHandle insHandle_{0};
63 : std::shared_ptr<hcomm::CcuDrvHandle> ccuDrvHandle_{};
64 : std::unique_ptr<CcuResPack> resPack_{};
65 : std::vector<CcuKernelHandle> kernelHandles_{};
66 : std::vector<CcuKernelHandle> untranslatedKernelHandles_{};
67 : std::array<CcuResDesc, CCU_MAX_IODIE_NUM> totalResDescs_{}; // ccuIns持有的全部资源描述符
68 : bool isFixedResNum_{false}; // InitByInsType 路径置 true(使用固定资源数量创建),其余保持 false
69 : };
70 :
71 : } // namespace hcomm
72 : #endif // HCOMM_CCU_INSTANCE_H
|