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

Function TEST

src/plugin/test/var_sanity_check.cpp:10–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8using namespace mgb;
9
10TEST(TestVarSanityCheck, Simple) {
11 HostTensorGenerator<> gen;
12 auto host_x = gen({1024}), host_y = gen({1024});
13 auto graph = ComputingGraph::make();
14 SymbolVar x = opr::Host2DeviceCopy::make(*graph, host_x),
15 y = opr::Host2DeviceCopy::make(*graph, host_y), y1 = y.reshape({1024, 1}),
16 z = x + y1.reshape({1024});
17
18 bool should_change = false;
19 ComputingGraph::OutputSpec out_spec = {
20 {y1,
21 [&](DeviceTensorND& v) {
22 if (should_change) {
23 HostTensorND hv;
24 hv.copy_from(v).sync().ptr<float>()[123]++;
25 v.copy_from(hv);
26 }
27 }},
28 {z, [&](DeviceTensorND& v) {
29 HostTensorND hv;
30 hv.copy_from(v).sync();
31 for (int i = 0; i < 1024; i++) {
32 ASSERT_EQ(
33 host_x->ptr<float>()[i] + host_y->ptr<float>()[i],
34 hv.ptr<float>()[i])
35 << "failed at " << i;
36 ;
37 }
38 }}};
39 auto func = graph->compile(out_spec);
40 func->execute().wait();
41 func = graph->compile(out_spec);
42 func->execute().wait();
43
44 should_change = true;
45 func = graph->compile(out_spec);
46 ASSERT_THROW(func->execute().wait(), VarSanityCheck::Error);
47}
48
49TEST(TestVarSanityCheck, InputModify) {
50 HostTensorGenerator<> gen;

Callers

nothing calls this directly

Calls 15

copy_from_fixlayoutMethod · 0.80
genFunction · 0.50
makeFunction · 0.50
loadFunction · 0.50
reshapeMethod · 0.45
syncMethod · 0.45
copy_fromMethod · 0.45
compileMethod · 0.45
waitMethod · 0.45
executeMethod · 0.45
dev_tensorMethod · 0.45
inputMethod · 0.45

Tested by

no test coverage detected