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

Function TEST

src/core/test/mem_reuse.cpp:64–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62MGB_DYN_TYPE_OBJ_FINAL_IMPL(SharedDeviceTensorDirect);
63
64TEST(TestMemReuse, PureMLP0) {
65 auto graph = ComputingGraph::make();
66 HostTensorGenerator<> gen;
67 CompNode cn = CompNode::load("cpu0");
68 //! FIXME currently recursive chooser does not support workspace_limit in
69 //! heuristic
70 auto host_inp = gen({256, 1, 64, 64}, cn), host_kern0 = gen({32, 1, 1, 1}, cn),
71 host_kern1 = gen({32, 32, 1, 1}, cn);
72 auto inp = opr::SharedDeviceTensor::make(*graph, *host_inp, {"inp"}),
73 kern0 = opr::SharedDeviceTensor::make(*graph, *host_kern0, {"kern0"}),
74 kern1 = opr::SharedDeviceTensor::make(*graph, *host_kern1, {"kern1"});
75 constexpr size_t NR_LAYER = 7;
76 SymbolVar layers[NR_LAYER];
77 layers[0] = make_conv(inp, kern0).rename("l0");
78 for (size_t i = 1; i < NR_LAYER; i++)
79 layers[i] = make_conv(layers[i - 1], kern1).rename(ssprintf("l%zu", i));
80 size_t alloc_size = 0;
81 auto hdl = graph->event().register_receiver<cg::event::StaticMemAlloc>(
82 [&](const cg::event::StaticMemAlloc& s) {
83 if (s.comp_node.valid()) {
84 alloc_size = s.alloc_size;
85 }
86 });
87
88 graph->options().allocate_static_mem_after_graph_compile = true;
89 graph->compile({{layers[NR_LAYER - 1], [](DeviceTensorND&) {}}});
90
91 EXPECT_EQ(host_inp->layout().span().dist_byte() * 32 * 2, alloc_size);
92}
93
94TEST(TestMemReuse, PureMLP1) {
95 auto graph = ComputingGraph::make();

Callers

nothing calls this directly

Calls 15

make_convFunction · 0.85
make_callback_copyFunction · 0.85
dev_ptrFunction · 0.85
make_no_fwdFunction · 0.85
subFunction · 0.85
is_static_var_storageFunction · 0.85
prev_dev_ptrFunction · 0.85
renameMethod · 0.80
dist_byteMethod · 0.80
spanMethod · 0.80
prev_dev_ptrMethod · 0.80
makeFunction · 0.70

Tested by

no test coverage detected