| 6 | using namespace mgb; |
| 7 | |
| 8 | TEST(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}}} |