| 210 | } |
| 211 | |
| 212 | void 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 | |
| 246 | void test_serializer_custom_loader(GraphDumpFormat format) { |
| 247 | auto fname = GET_OUTPUT_FILE(format); |
no test coverage detected