| 148 | } |
| 149 | |
| 150 | ASTPtrArray 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 |
nothing calls this directly
no test coverage detected