| 62 | MGB_DYN_TYPE_OBJ_FINAL_IMPL(SharedDeviceTensorDirect); |
| 63 | |
| 64 | TEST(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 | |
| 94 | TEST(TestMemReuse, PureMLP1) { |
| 95 | auto graph = ComputingGraph::make(); |
nothing calls this directly
no test coverage detected