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

Method CondExecPred

src/opr/impl/cond.cpp:316–353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314}
315
316CondExecPred::CondExecPred(
317 VarNode* pred, const VarNodeArrayView& keys, const Param& param,
318 const OperatorNodeConfig& config)
319 : Super(pred->owner_graph(), config, "cond_pred", {pred}), m_param{param} {
320 m_masks.reserve(keys.size() + 1);
321 auto add_out = [this](const std::string& name) {
322 auto var = add_output(name);
323 var->add_flag(VarNode::Flag::NO_SYS_MEM_ALLOC).dtype(dtype::Int32{});
324 m_masks.emplace_back(std::make_shared<ExecutionMask>(var));
325 };
326 for (size_t i = 0; i < keys.size(); ++i) {
327 mgb_throw_if(
328 keys[i]->dtype() != pred->dtype(), GraphError,
329 "dtype mismatch: pred=%s input[%zu]=%s", pred->dtype().name(), i,
330 keys[i]->dtype().name());
331 add_input({keys[i]});
332 if (param.mode == Param::Mode::PIECEWISE) {
333 if (!i) {
334 add_out("[-inf,k0]");
335 }
336 if (i != keys.size() - 1) {
337 add_out(ssprintf("[k%zu,k%zu]", i, i + 1));
338 } else {
339 add_out(ssprintf("[k%zu,inf]", i));
340 }
341 } else {
342 add_out(ssprintf("branch%zu", i));
343 }
344 }
345 if (param.mode == Param::Mode::CASE_FALLBACK) {
346 add_out("fallback");
347 }
348 add_input({pred});
349 add_equivalence_component<PODHash<Param>>(&m_param);
350
351 // ensure listener is registered
352 GlobalRegistry::get(*owner_graph());
353}
354
355cg::OperatorNodeBase* CondExecPred::make_opr(
356 SymbolVar pred, const VarNodeArrayView& keys, const Param& param,

Callers

nothing calls this directly

Calls 7

getFunction · 0.85
emplace_backMethod · 0.80
owner_graphMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
dtypeMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected