MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / opr2AST

Method opr2AST

src/jit/impl/ast_c.cpp:150–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150ASTPtrArray ast_c::opr2AST(
151 cg::OperatorNodeBase* opr, const ASTPtrArray& inputs,
152 CompNode::DeviceType device_type) {
153 using namespace opr;
154 if (auto elem = gopt::try_cast_as_op<Elemwise>(opr)) {
155 if (check_elem_mode(elem->param().mode, device_type)) {
156 return elem_opr_generator(device_type)
157 .find(elem->param().mode)
158 ->second(inputs, false);
159 }
160 }
161
162 if (auto powc = gopt::try_cast_as_op<PowC>(opr)) {
163
164 mgb_assert(inputs.size() == 1);
165 return {gen_powc(inputs[0], powc->param().exp)};
166 }
167
168 auto imm = SymbolVar{opr->output(0)}.as_immutable_scalar();
169 if (imm.valid()) {
170 auto dtype = imm->dtype();
171 if (dtype == dtype::Int32{}) {
172
173 return {ASTPtr::make<IntAST>(imm->get<int>())};
174 }
175 float scalar_value;
176 if (dtype == dtype::Float32()) {
177 scalar_value = imm->get<float>();
178 } else if (dtype == dtype::Float16()) {
179 scalar_value = imm->get<dt_float16>();
180 } else {
181 mgb_throw(
182 InternalError, "dtype(%s) is not any of [Float16, Float32, Int32]",
183 dtype.name());
184 }
185
186 return {ASTPtr::make<FloatAST>(scalar_value, device_type, false)};
187 }
188
189 if (opr->same_type<opr::TypeCvt>()) {
190
191 // simply ignore TypeCvt oprs.
192 mgb_assert(inputs.size() == 1);
193 return inputs;
194 }
195
196 mgb_throw(
197 InternalError, "unknown opr %s{%s}", opr->cname(),
198 opr->dyn_typeinfo()->name);
199}
200
201#endif // MGB_JIT
202

Callers

nothing calls this directly

Calls 11

check_elem_modeFunction · 0.85
gen_powcFunction · 0.85
as_immutable_scalarMethod · 0.80
paramMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45
outputMethod · 0.45
validMethod · 0.45
dtypeMethod · 0.45
nameMethod · 0.45
cnameMethod · 0.45

Tested by

no test coverage detected