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

Method init

src/plugin/impl/num_range_checker.cpp:12–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10using namespace mgb;
11
12void NumRangeChecker::Checker::init(VarNode* var, float range) {
13 if (m_func)
14 return;
15
16 m_inp = std::make_shared<DeviceTensorND>(var->comp_node(), var->dtype());
17 m_out = std::make_unique<HostTensorND>();
18 auto cg = ComputingGraph::make();
19 cg->options().log_level = 0;
20 auto vi = opr::VolatileSharedDeviceTensor::make(*cg, m_inp),
21 chk = opr::abs(vi) < range, good = opr::reduce_min(chk, chk.make_scalar(1));
22 auto cb = [d = m_out.get()](DeviceTensorND& dv) { d->copy_from(dv).sync(); };
23 m_func = cg->compile({{good, cb}});
24}
25
26bool NumRangeChecker::Checker::check(VarNode* var) {
27 auto&& val = var->dev_tensor();

Callers 1

on_var_computedMethod · 0.45

Calls 9

makeFunction · 0.50
absFunction · 0.50
comp_nodeMethod · 0.45
dtypeMethod · 0.45
make_scalarMethod · 0.45
getMethod · 0.45
syncMethod · 0.45
copy_fromMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected