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

Function TEST

src/gopt/test/inference.cpp:124–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122} // namespace
123
124TEST(TestGoptInference, ParamFuseConstEndPoint) {
125 constexpr size_t SIZE = 23;
126 HostTensorGenerator<> gen;
127 auto host_x = gen({SIZE}), host_y = gen({1}), host_p = gen({1});
128
129 auto graph = ComputingGraph::make();
130 graph->options().graph_opt_level = 0;
131 auto x = opr::SharedDeviceTensor::make(*graph, *host_x),
132 y = opr::SharedDeviceTensor::make(*graph, *host_y),
133 p = opr::Host2DeviceCopy::make(*graph, host_p), q = p + x, a = y + 3,
134 z0 = a + q, z1 = a + 4;
135
136 HostTensorND host_z0, host_z1;
137
138 SymbolVar z0_1, z1_1;
139 unpack_vector(
140 gopt::GraphOptimizer{}
141 .add_pass<gopt::ParamFusePass>()
142 .apply({{z1, z0}})
143 .endpoint_vars(),
144 z1_1, z0_1);
145
146 auto func = graph->compile(
147 {make_callback_copy(z0_1, host_z0), make_callback_copy(z1_1, host_z1)});
148 func->to_json()->writeto_fpath(
149 output_file("TestGoptInference.ParamFuseEndPoint.json"));
150 func->execute();
151
152 int nr_opr = 0;
153 func->iter_opr_seq([&](cg::OperatorNodeBase*) {
154 ++nr_opr;
155 return true;
156 });
157 ASSERT_EQ(8, nr_opr);
158
159 auto px = host_x->ptr<float>(), pz0 = host_z0.ptr<float>();
160
161 auto yv = host_y->ptr<float>()[0], pv = host_p->ptr<float>()[0],
162 pz1 = host_z1.ptr<float>()[0];
163
164 for (size_t i = 0; i < SIZE; ++i) {
165 MGB_ASSERT_FLOAT_EQ(px[i] + yv + 3 + pv, pz0[i]);
166 }
167 MGB_ASSERT_FLOAT_EQ(yv + 7, pz1);
168}
169
170TEST(TestGoptInference, ParamFuse) {
171 constexpr size_t SIZE = 23;

Callers

nothing calls this directly

Calls 15

unpack_vectorFunction · 0.85
make_callback_copyFunction · 0.85
output_fileFunction · 0.85
powfFunction · 0.85
as_elem_oprFunction · 0.85
subFunction · 0.85
var_from_tensor_shapeFunction · 0.85
maxFunction · 0.85
make_deconvFunction · 0.85
OperatorNodeConfigClass · 0.85
dt_quint8Class · 0.85

Tested by

no test coverage detected