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

Function run_forward

src/opr/test/dnn/instance_norm.cpp:19–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17using Param = opr::InstanceNormForward::Param;
18
19void run_forward(bool is_affine) {
20 using Checker = AutoOprChecker<3, 3>;
21
22 Param param;
23 param.eps = 1e-5;
24 param.affine = is_affine;
25
26 auto make_graph = [&](const Checker::SymInpArray& inputs) -> Checker::SymOutArray {
27 auto out =
28 opr::InstanceNormForward::make(inputs[0], inputs[1], inputs[2], param);
29 return {out[0], out[1], out[2]};
30 };
31
32 auto fwd = [&](Checker::NumOutArray& dest, Checker::NumInpArray inp) {
33 auto opr =
34 MegDNNHandle::get(CompNodeEnv::from_comp_node(CompNode::default_cpu()))
35 ->create_operator<megdnn::GroupNormForward>();
36 auto inp_shape = inp[0]->shape();
37 auto n_slices = inp_shape[0];
38 auto C = inp_shape[1];
39 param.group = C;
40 opr->param() = param;
41
42 dest[0].dtype(dtype::Float32())
43 .comp_node(inp[0]->comp_node())
44 .resize(inp_shape);
45 dest[1].dtype(dtype::Float32())
46 .comp_node(inp[0]->comp_node())
47 .resize({n_slices, C});
48 dest[2].dtype(dtype::Float32())
49 .comp_node(inp[0]->comp_node())
50 .resize({n_slices, C});
51 std::vector<dt_byte> workspace(opr->get_workspace_in_bytes(
52 inp[0]->layout(), inp[1]->layout(), inp[2]->layout(), dest[0].layout(),
53 dest[1].layout(), dest[2].layout()));
54 opr->exec(
55 inp[0]->as_megdnn(), inp[1]->as_megdnn(), inp[2]->as_megdnn(),
56 dest[0].as_megdnn(), dest[1].as_megdnn(), dest[2].as_megdnn(),
57 {workspace.data(), workspace.size()});
58 };
59
60 auto gen = [&](HostTensorND& src) {
61 HostTensorGenerator<dtype::Float32, RandomDistribution::GAUSSIAN> src_gen(0.f);
62 src = *src_gen(src.shape(), src.comp_node());
63 };
64
65 Checker::RunOptions option;
66 option.numdiff_max_err = 1e-4;
67 Checker checker{make_graph, fwd};
68
69 checker.set_input_generator(0, gen);
70 checker.set_input_generator(1, gen);
71 checker.set_input_generator(2, gen);
72 checker.set_input_allow_grad(0, false);
73 checker.set_input_allow_grad(1, false);
74 checker.set_input_allow_grad(2, false);
75 checker.set_output_allow_grad(0, false);
76 checker.set_output_allow_grad(1, false);

Callers 1

TESTFunction · 0.70

Calls 14

getFunction · 0.85
resizeMethod · 0.80
as_megdnnMethod · 0.80
makeFunction · 0.50
shapeMethod · 0.45
paramMethod · 0.45
comp_nodeMethod · 0.45
dtypeMethod · 0.45
layoutMethod · 0.45
execMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected