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

Function run_level2

src/core/test/comp_node_helper.cpp:163–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163void run_level2(CompNode cn, bool use_multi_holder) {
164 HostTensorGenerator<> gen;
165 auto host_x = gen({4, 3, 6, 7}, cn), host_w = gen({2, 3, 2, 3}, cn),
166 host_y = gen({1, 25}, cn), host_z = gen({8, 1}, cn),
167 host_large = gen({8, 25}, cn);
168 auto make_func = [&](bool enable) -> thin_function<const HostTensorND&()> {
169 auto graph = ComputingGraph::make();
170 graph->options().graph_opt_level = 0;
171 if (enable) {
172 graph->options().var_sanity_check_first_run = false;
173 graph->options().comp_node_seq_record_level = 2;
174 }
175 auto repeat2 = [](SymbolVar x) { return opr::Concat::make({x, x}, 0); };
176 SymbolVar w;
177 auto dev_w = std::make_shared<DeviceTensorND>();
178 // test shared dev tensor with 1 refcnt
179 if (use_multi_holder) {
180 dev_w->copy_from(*host_w).sync();
181 w = opr::MultipleDeviceTensorHolder::make(*graph, {dev_w})[0];
182 } else {
183 w = opr::SharedDeviceTensor::make(*graph, *host_w);
184 }
185
186 auto x = opr::Host2DeviceCopy::make(*graph, host_x),
187 // test shared dev tensor with 1 refcnt
188 c = opr::Convolution::make(x, w).reshape({8, 25}),
189 y = opr::Host2DeviceCopy::make(*graph, host_y),
190 large = opr::ImmutableTensor::make(*graph, *host_large),
191 z = opr::Host2DeviceCopy::make(*graph, host_z),
192 // elemwise with larger tmp storage
193 t0 = opr::Elemwise::make(
194 {c, y, z}, opr::Elemwise::Mode::FUSE_MUL_ADD3) +
195 large,
196 // t1 shape is {8, 1}
197 t1 = opr::reduce_sum(t0, z.symshape()),
198 t2 = opr::Elemwise::make(
199 {repeat2(c), y, repeat2(t1)}, opr::Elemwise::Mode::FUSE_MUL_ADD3),
200 large1 = opr::ImmutableTensor::make(*graph, *host_large);
201 t2 * 2; // unused opr
202
203 // used large static infer
204 graph->static_infer_manager().infer_value(large.node());
205
206 // unused large static infer
207 graph->static_infer_manager().infer_value(large1.node());
208
209 // static infer value
210 graph->static_infer_manager().infer_value((t1.symshape() + 1).node());
211
212 auto result = std::make_shared<HostTensorND>();
213 auto func = graph->compile({make_callback_copy(t2, *result)});
214 std::shared_ptr<cg::AsyncExecutable> sh_func(func.release());
215 if (enable) {
216 ComputingGraph::assert_destroy(graph);
217 }
218 auto exec = [result, sh_func]() -> const HostTensorND& {
219 sh_func->execute();
220 return *result;

Callers 2

run<level2>Function · 0.85
run<level2_multi_holder>Function · 0.85

Calls 15

make_callback_copyFunction · 0.85
make_funcFunction · 0.85
symshapeMethod · 0.80
infer_valueMethod · 0.80
resizeMethod · 0.80
makeFunction · 0.70
genFunction · 0.50
reduce_sumFunction · 0.50
syncMethod · 0.45
copy_fromMethod · 0.45
reshapeMethod · 0.45
nodeMethod · 0.45

Tested by

no test coverage detected