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

Function test_serializer_APlusB

src/serialization/test/serializer_oss.cpp:120–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120void test_serializer_APlusB(GraphDumpFormat format) {
121 auto fname = GET_OUTPUT_FILE(format);
122 TensorShape shape{2, 3};
123
124 auto dump = [&]() {
125 auto cn = CompNode::load("xpu0");
126 auto host_x = std::make_shared<HostTensorND>(cn, shape),
127 host_y = std::make_shared<HostTensorND>(cn, shape);
128 auto graph = ComputingGraph::make();
129 auto x = opr::Host2DeviceCopy::make(*graph, host_x, {"x"}),
130 y = opr::Host2DeviceCopy::make(*graph, host_y, {"y"});
131
132 auto dumper = GraphDumper::make(OutputFile::make_fs(fname.c_str()), format);
133 // test dump duplicated
134 auto rst = dumper->dump({(x + y).rename("z"), x + y});
135 ASSERT_EQ(2u, rst.outputs.size());
136 };
137
138 auto load = [&]() {
139 HostTensorGenerator<> gen;
140 auto loader = GraphLoader::make(InputFile::make_fs(fname.c_str()), format);
141 auto rst = loader->load();
142 auto xv = rst.tensor_map.at("x");
143 auto yv = rst.tensor_map.at("y");
144 ASSERT_EQ(shape, xv->shape());
145 ASSERT_EQ(shape, yv->shape());
146 *xv = *gen(shape);
147 *yv = *gen(shape);
148 HostTensorND host_z, host_z_expect;
149 host_z_expect.copy_from(*xv);
150 for (size_t i = 0, it = shape.total_nr_elems(); i < it; ++i)
151 host_z_expect.ptr<float>()[i] += yv->ptr<float>()[i];
152 auto func = rst.graph_compile(
153 {make_callback_copy(rst.output_var_map.at("z"), host_z)});
154 func->execute();
155 MGB_ASSERT_TENSOR_EQ(host_z_expect, host_z);
156 };
157
158 dump();
159 load();
160}
161
162void test_serializer_APlusB_param(GraphDumpFormat format) {
163 auto cns = load_multiple_xpus(2);

Callers 1

TESTFunction · 0.85

Calls 14

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

Tested by

no test coverage detected