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_REP_TRANSLATOR_H
12 : #define HCOMM_CCU_REP_TRANSLATOR_H
13 :
14 : #include <memory>
15 : #include <vector>
16 : #include <functional>
17 :
18 : #include "ccu_instr_info_v1.h"
19 : #include "ccu_rep_block_v1.h"
20 : #include "ccu_rep_reference_manager_v1.h"
21 : #include "ccu_kernel_resource.h"
22 : #include "ccu_rep_base_v1.h"
23 : #include "ccu_kernel.h"
24 : #include "ccu_dev_mgr_imp.h"
25 :
26 : namespace hcomm {
27 : namespace CcuRep {
28 :
29 : class CcuRepTranslator {
30 : public:
31 : CcuRepTranslator(
32 : int32_t deviceLogicId, uint8_t dieId, std::shared_ptr<CcuRepReferenceManager> refManager,
33 : std::array<uint16_t, CCU_MAX_IODIE_NUM>& reserverChannalId, std::pair<uint64_t, uint64_t>& ccuTokenInfo,
34 : uint64_t hbmTokenInfo);
35 :
36 : CcuRepTranslator(std::shared_ptr<CcuRepReferenceManager> refManager, const TransDep& transDep);
37 : static uint32_t GetInstrNum(const int32_t devLogicId);
38 : static CcuResReq GetResReq(const int32_t devLogicId, uint8_t dieId);
39 : void GetRes(CcuRepResource& res);
40 : CcuInstrInfo Translate(
41 : CcuKernel* ccuKernel, const std::vector<std::shared_ptr<CcuRepBase>>& repVec, uint16_t startInstrId,
42 : bool isFuncBlock = false);
43 : void Translate(
44 : CcuKernel* ccuKernel, const std::vector<std::shared_ptr<CcuRepBase>>& repVec, CcuInstr*& instr,
45 : uint16_t& instrId, std::function<bool(std::shared_ptr<CcuRepBase>)> filter);
46 : void DumpInstruction(const CcuInstrInfo& instrInfo) const;
47 : void SetTransDep(TransDep transDepIn) { transDep = transDepIn; }
48 54 : TransDep& GetTransDep() { return transDep; }
49 :
50 : private:
51 : template <typename T1, typename T2>
52 : void BuildReference(const std::shared_ptr<CcuRepBase>& rep);
53 : void PreProcess(std::shared_ptr<CcuRepBase> rep);
54 : void CommonProcess(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId);
55 : void FinishMainBlock(CcuInstr*& instr, uint16_t& instrId);
56 : void DumpRep(const std::vector<std::shared_ptr<CcuRepBase>>& repVec, const CcuInstrInfo& instrInfo) const;
57 : void BindResource(bool isFuncBlock);
58 :
59 : private:
60 : static const int XN_NUM = 4; // 4: Xn资源个数
61 : static const int GSA_NUM = 3; // 3: GSA资源个数
62 : static const int CKE_NUM = 2; // 2: CKE资源个数
63 : static const int V2_RELJMP_INSTR_NUM = 9; // V2: RelJmp生成的指令数
64 : static const int V2_FINISH_BLOCK_INSTR_NUM = 10; // V2: FinishMainBlock占用的指令数(RelJmp+Jump或10xNop)
65 : std::shared_ptr<CcuRepReferenceManager> refManager{nullptr};
66 : Variable var[XN_NUM];
67 : Address addr[GSA_NUM];
68 : CompletedEvent signal[CKE_NUM]; // 声明为CompletedEvent,使用离散cke
69 : TransDep transDep{};
70 : CcuVersion ccuVersion{CcuVersion::CCU_INVALID};
71 : };
72 : }; // namespace CcuRep
73 : }; // namespace hcomm
74 :
75 : #endif // HCCL_CCU_REP_TRANSLATOR_H
|