Line data Source code
1 : /*
2 : * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
3 : * Description: ccu representation implementation file
4 : * Author: sunzhepeng
5 : * Create: 2024-06-17
6 : */
7 :
8 : #include "ccu_rep_v1.h"
9 : #include "ccu_ins_generator_base.h"
10 : #include "string_util.h"
11 : #include "ccu_kernel.h"
12 :
13 : namespace hcomm{
14 : namespace CcuRep {
15 :
16 372 : CcuRepBlock::CcuRepBlock(CcuInsGeneratorBase* insGenPtr, const std::string &label) :
17 372 : insGeneratorPtr_(insGenPtr), label(label)
18 : {
19 372 : type = CcuRepType::BLOCK;
20 372 : instrCount = 0;
21 372 : }
22 :
23 460 : std::vector<std::shared_ptr<CcuRepBase>> &CcuRepBlock::GetReps()
24 : {
25 460 : return repVec;
26 : }
27 :
28 984 : void CcuRepBlock::Append(std::shared_ptr<CcuRepBase> rep)
29 : {
30 984 : repVec.push_back(rep);
31 984 : }
32 :
33 189 : const std::string &CcuRepBlock::GetLabel() const
34 : {
35 189 : return label;
36 : }
37 :
38 349 : uint16_t CcuRepBlock::InstrCount()
39 : {
40 349 : instrCount = 0;
41 834 : for (const auto &repInBlock : repVec) {
42 485 : instrCount += repInBlock->InstrCount();
43 : }
44 349 : return instrCount;
45 : }
46 :
47 99 : bool CcuRepBlock::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
48 : {
49 99 : this->instrId = instrId;
50 99 : translated = true;
51 :
52 99 : constexpr uint16_t numberTwo = 2; // 暂定repBlock中的rep遍历2次,后续优化
53 297 : for (uint16_t i = 0; i < numberTwo; i++) {
54 452 : for (const auto &repInBlock : GetReps()) {
55 254 : if (!repInBlock->Translated()) {
56 127 : repInBlock->Translate(ccuKernel, instr, instrId, dep);
57 : }
58 : }
59 : }
60 :
61 99 : return translated;
62 : }
63 :
64 1 : std::string CcuRepBlock::Describe()
65 : {
66 1 : return Hccl::StringFormat("RepBlock");
67 : }
68 :
69 2 : std::shared_ptr<CcuRepBase> CcuRepBlock::GetRepByInstrId(uint16_t instrId)
70 : {
71 3 : for (const auto& rep : GetReps()) {
72 2 : const uint16_t repCount = rep->InstrCount();
73 2 : if (repCount == 0) {
74 0 : continue;
75 : }
76 2 : const uint16_t startId = rep->StartInstrId();
77 2 : const uint16_t endId = startId + repCount - 1;
78 2 : if (instrId >= startId && instrId <= endId) {
79 1 : return rep;
80 : }
81 : }
82 1 : return nullptr;
83 : }
84 :
85 : }; // namespace CcuRep
86 : }; // namespace hcomm
|