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

Function TEST

src/plugin/test/var_value_checker.cpp:8–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6using namespace mgb;
7
8TEST(TestVarValueChecker, Simple) {
9 HostTensorGenerator<> gen;
10 auto graph = ComputingGraph::make();
11 VarValueChecker checker(graph.get(), 2);
12 bool should_fail = false;
13 auto cb = [&should_fail](DeviceTensorND& dv) {
14 if (!should_fail)
15 return;
16 HostTensorND hv;
17 hv.copy_from(dv).sync();
18 hv.ptr<float>()[0] += 1;
19 dv.copy_from(hv).sync();
20 };
21
22 auto host_x = gen({3});
23 auto x = opr::Host2DeviceCopy::make(*graph, host_x), y = x + 1,
24 z = opr::CallbackInjector::make(y, cb);
25 auto func = graph->compile({{z, {}}});
26 func->execute();
27 should_fail = true;
28 for (int i = 0; i < 6; ++i) {
29 // run 6 times becore x, ADD, IMM(1) are not modified
30 func->execute();
31 }
32 ASSERT_THROW(func->execute(), MegBrainError);
33}
34
35// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

Callers

nothing calls this directly

Calls 7

makeFunction · 0.50
genFunction · 0.50
getMethod · 0.45
syncMethod · 0.45
copy_fromMethod · 0.45
compileMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected