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_rep_reference_manager_v1.h"
10 :
11 : #include "string_util.h"
12 : #include "exception_util.h"
13 : #include "ccu_api_exception.h"
14 :
15 : #include "ccu_ins_generator_base.h"
16 : #include "ccu_kernel.h"
17 :
18 : namespace hcomm {
19 : namespace CcuRep {
20 :
21 : using namespace Hccl;
22 :
23 16 : CcuRepFuncCall::CcuRepFuncCall(CcuInsGeneratorBase* insGenPtr, const std::string &label) :
24 16 : insGeneratorPtr_(insGenPtr), label(label)
25 : {
26 16 : type = CcuRepType::FUNC_CALL;
27 16 : instrCount = 0;
28 16 : }
29 :
30 2 : CcuRepFuncCall::CcuRepFuncCall(CcuInsGeneratorBase* insGenPtr, const Variable &funcAddrVar) :
31 6 : insGeneratorPtr_(insGenPtr), label(""), funcAddrVar(funcAddrVar)
32 : {
33 2 : type = CcuRepType::FUNC_CALL;
34 2 : }
35 :
36 6 : const std::string &CcuRepFuncCall::GetLabel() const
37 : {
38 6 : return label;
39 : }
40 :
41 6 : void CcuRepFuncCall::Reference(std::shared_ptr<CcuRepFuncBlock> refRep)
42 : {
43 6 : funcBlock = refRep;
44 6 : }
45 :
46 6 : void CcuRepFuncCall::SetFuncManager(CcuRepReferenceManager *funcManager)
47 : {
48 6 : this->funcManager = funcManager;
49 6 : }
50 :
51 9 : void CcuRepFuncCall::SetInArg(const Variable &var)
52 : {
53 9 : inArgCount++;
54 9 : inArgs.push_back(CcuRepArg(var));
55 9 : }
56 :
57 2 : void CcuRepFuncCall::SetOutArg(const Variable &var)
58 : {
59 2 : outArgCount++;
60 2 : if (outArgCount > FUNC_ARG_MAX) {
61 0 : Hccl::THROW<Hccl::CcuApiException>("CcuFunc Max ArgCount = %u", FUNC_ARG_MAX);
62 : }
63 2 : outArgs.push_back(CcuRepArg(var));
64 2 : }
65 :
66 1 : void CcuRepFuncCall::SetInArg(const std::vector<Variable> &varList)
67 : {
68 1 : inArgCount += varList.size();
69 1 : inArgs.push_back(CcuRepArg(varList));
70 1 : }
71 :
72 1 : void CcuRepFuncCall::SetOutArg(const std::vector<Variable> &varList)
73 : {
74 1 : outArgCount += varList.size();
75 1 : if (outArgCount > FUNC_ARG_MAX) {
76 0 : Hccl::THROW<Hccl::CcuApiException>("CcuFunc Max ArgCount = %u", FUNC_ARG_MAX);
77 : }
78 1 : outArgs.push_back(CcuRepArg(varList));
79 1 : }
80 :
81 26 : uint16_t CcuRepFuncCall::InstrCount()
82 : {
83 26 : instrCount = inArgCount + outArgCount + insGeneratorPtr_->GetInstrCount(type); // funcCall除去入参和出参的处理外,需要额外4条指令
84 26 : return instrCount;
85 : }
86 :
87 5 : bool CcuRepFuncCall::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
88 : {
89 5 : if (funcManager == nullptr) {
90 0 : Hccl::THROW<Hccl::CcuApiException>("funcManager is nullptr");
91 : }
92 : // 未实现, FuncCall和FuncBlock中的args个数校验
93 :
94 5 : if (this->instr == nullptr) {
95 5 : this->instrId = instrId;
96 5 : this->instr = instr;
97 5 : instr += InstrCount();
98 5 : instrId += InstrCount();
99 : }
100 :
101 5 : if (funcBlock != nullptr && !funcBlock->Translated()) {
102 0 : return translated;
103 : }
104 :
105 5 : translated = true;
106 :
107 5 : CHK_RET_THROW(CcuApiException,
108 : Hccl::StringFormat("[CcuRepFuncCall][%s] failed to translate functionCall for instrId[%u] ", __func__, instrId),
109 : insGeneratorPtr_->CcuRepFuncCallTranslate(ccuKernel, instr, instrId, this, dep));
110 :
111 5 : return translated;
112 : }
113 :
114 6 : std::string CcuRepFuncCall::Describe()
115 : {
116 6 : return Hccl::StringFormat("FuncCall[%s]", label.c_str());
117 : }
118 :
119 5 : int32_t CcuRepFuncCall::GetCallLayer()
120 : {
121 5 : return funcBlock == nullptr ? FUNC_NEST_MAX : funcBlock->GetCallLayer();
122 : }
123 :
124 : }; // namespace CcuRep
125 : }; // namespace hcomm
|