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

Function test_serializer_immutable

src/serialization/test/serializer_oss.cpp:212–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210}
211
212void test_serializer_immutable(GraphDumpFormat format) {
213 auto fname = GET_OUTPUT_FILE(format);
214 TensorShape shape{2, 3};
215
216 auto dump = [&]() {
217 auto cn = CompNode::load("xpu0");
218 auto host_x = std::make_shared<HostTensorND>(cn, shape);
219 auto graph = ComputingGraph::make();
220 auto x = opr::Host2DeviceCopy::make(*graph, host_x, {"x"});
221 auto dumper = GraphDumper::make(OutputFile::make_fs(fname.c_str()), format);
222 dumper->dump({(x + 1.f).rename("y")});
223 };
224
225 auto load = [&]() {
226 HostTensorGenerator<> gen;
227 auto loader = GraphLoader::make(InputFile::make_fs(fname.c_str()), format);
228 auto rst = loader->load();
229 auto xv = rst.tensor_map.at("x");
230 ASSERT_EQ(shape, xv->shape());
231 *xv = *gen(shape);
232 HostTensorND host_y, host_y_expect;
233 host_y_expect.copy_from(*xv);
234 for (size_t i = 0, it = shape.total_nr_elems(); i < it; ++i)
235 host_y_expect.ptr<float>()[i] += 1;
236 auto func = rst.graph_compile(
237 {make_callback_copy(rst.output_var_map.at("y"), host_y)});
238 func->execute();
239 MGB_ASSERT_TENSOR_EQ(host_y_expect, host_y);
240 };
241
242 dump();
243 load();
244}
245
246void test_serializer_custom_loader(GraphDumpFormat format) {
247 auto fname = GET_OUTPUT_FILE(format);

Callers 1

TESTFunction · 0.85

Calls 13

make_callback_copyFunction · 0.85
renameMethod · 0.80
graph_compileMethod · 0.80
loadFunction · 0.50
makeFunction · 0.50
genFunction · 0.50
dumpMethod · 0.45
loadMethod · 0.45
atMethod · 0.45
shapeMethod · 0.45
copy_fromMethod · 0.45
total_nr_elemsMethod · 0.45

Tested by

no test coverage detected