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

Method add_opr

src/jit/impl/internal_graph.cpp:176–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176void InternalGraphGenerator::add_opr(cg::OperatorNodeBase* opr) {
177 if (m_opr_set.count(opr)) {
178 // ignore duplicated oprs (which occur in tests)
179 return;
180 }
181
182 if (opr->input().empty()) {
183 mgb_assert(
184 opr->same_type<opr::ImmutableTensor>(),
185 "should not add net source opr %s{%s}", opr->cname(),
186 opr->dyn_typeinfo()->name);
187 }
188
189 // currently only single-output opr is supported; ensure it here
190 for (size_t i = 1; i < opr->output().size(); ++i) {
191 mgb_assert(opr->output()[i]->contain_flag(VarNode::Flag::VOLATILE_CONTENT));
192 }
193
194 if (!m_opr_set.empty()) {
195 auto nr_remove = m_graph_input_set.erase(opr->output(0));
196 mgb_assert(nr_remove == 1, "opr output not added");
197 } else {
198 // opr_set is empty, so this is the endpoint opr
199 m_var_dep_type[opr->output(0)] = DepType::DEV_VALUE;
200 }
201
202 m_opr_set.insert(opr);
203 for (auto inp : opr->input()) {
204 m_graph_input_set.insert(inp);
205 }
206
207 for (auto&& i : opr->node_prop().dep_map()) {
208 DepType dt = i.second & ~DepType::VALUE_ALLOW_EMPTY;
209 mgb_assert(
210 dt == DepType::DEV_VALUE || dt == DepType::HOST_VALUE,
211 "unsupported dep type: opr %s{%s} on input %s dt=%d", opr->cname(),
212 opr->dyn_typeinfo()->name, i.first->cname(), static_cast<int>(dt));
213 m_var_dep_type[i.first] |= i.second;
214 }
215
216 if (opr->same_type<opr::Reduce>()) {
217 if (!has_reduce()) {
218 m_before_reduce_shape = opr->input(0)->shape();
219 m_feature_bits |= JITFeatureBits::REDUCE;
220 }
221 mgb_assert(opr->input(0)->shape().eq_shape(m_before_reduce_shape));
222 find_reduce_opr_deps(opr);
223 }
224 if (opr->same_type<opr::Dimshuffle>()) {
225 m_feature_bits |= JITFeatureBits::DIMSHUFFLE;
226 find_oprs_depended_by_dimshuffle(opr);
227 }
228 if (opr->same_type<mgb::jit::JITExecutor>()) {
229 auto jit = &opr->cast_final<mgb::jit::JITExecutor>();
230 if (jit->has_reduce()) {
231 if (!has_reduce()) {
232 m_before_reduce_shape = jit->broadcasted_input_shape();
233 m_feature_bits |= JITFeatureBits::REDUCE;

Callers 13

run<expand_jit_executor>Function · 0.45
TESTFunction · 0.45
ensure_init_graphMethod · 0.45
run<simple>Function · 0.45
run<grad>Function · 0.45
run_mlirFunction · 0.45
run_mlir_broadcastFunction · 0.45
run_mlir_different_shapeFunction · 0.45
run_mlir_modeFunction · 0.45
run_typecvtFunction · 0.45
run_dimshuffleFunction · 0.45
TESTFunction · 0.45

Calls 15

has_reduceFunction · 0.85
has_reduceMethod · 0.80
has_dimshuffleMethod · 0.80
countMethod · 0.45
emptyMethod · 0.45
inputMethod · 0.45
cnameMethod · 0.45
sizeMethod · 0.45
outputMethod · 0.45
contain_flagMethod · 0.45
eraseMethod · 0.45

Tested by 12

run<expand_jit_executor>Function · 0.36
TESTFunction · 0.36
ensure_init_graphMethod · 0.36
run<simple>Function · 0.36
run<grad>Function · 0.36
run_mlirFunction · 0.36
run_mlir_broadcastFunction · 0.36
run_mlir_different_shapeFunction · 0.36
run_mlir_modeFunction · 0.36
run_typecvtFunction · 0.36
run_dimshuffleFunction · 0.36
TESTFunction · 0.36