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

Function test_serializer_priority

src/serialization/test/serializer_oss.cpp:603–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

601}
602
603void test_serializer_priority(GraphDumpFormat format) {
604 auto fname = GET_OUTPUT_FILE(format);
605 TensorShape shape{2, 3};
606
607 auto dump = [&](bool keep_pri) {
608 auto cn = CompNode::load("xpu0");
609 auto host_x = std::make_shared<HostTensorND>(cn, shape),
610 host_y = std::make_shared<HostTensorND>(cn, shape);
611 auto graph = ComputingGraph::make();
612 auto x = opr::Host2DeviceCopy::make(*graph, host_x, {"x"}) + 1,
613 y = opr::Host2DeviceCopy::make(*graph, host_y, {"y"}) + 1;
614
615 set_priority(x, 1);
616 set_priority(y, 2);
617
618 auto dumper = GraphDumper::make(OutputFile::make_fs(fname.c_str()), format);
619 GraphDumper::DumpConfig config;
620 if (keep_pri) {
621 config.keep_opr_priority = true;
622 }
623 dumper->dump({x * y}, config);
624 };
625
626 auto load = [&](bool has_pri) {
627 auto loader = GraphLoader::make(InputFile::make_fs(fname.c_str()), format);
628 auto rst = loader->load();
629 VarNode *x, *y;
630 unpack_vector(rst.output_var_list.front().node()->owner_opr()->input(), x, y);
631 auto get_pri = [](VarNode* var) {
632 return var->owner_opr()->node_prop().attribute().priority;
633 };
634 int xpri = get_pri(x), ypri = get_pri(y);
635 if (has_pri) {
636 ASSERT_EQ(1, xpri);
637 ASSERT_EQ(2, ypri);
638 } else {
639 ASSERT_EQ(0, xpri);
640 ASSERT_EQ(0, ypri);
641 }
642 };
643
644 dump(false);
645 load(false);
646
647 dump(true);
648 load(true);
649}
650
651void test_serializer_multiple_params(GraphDumpFormat format) {
652 auto fname = GET_OUTPUT_FILE(format);

Callers 1

TESTFunction · 0.85

Calls 11

set_priorityFunction · 0.85
unpack_vectorFunction · 0.85
frontMethod · 0.80
loadFunction · 0.50
makeFunction · 0.50
dumpMethod · 0.45
loadMethod · 0.45
inputMethod · 0.45
owner_oprMethod · 0.45
nodeMethod · 0.45
attributeMethod · 0.45

Tested by

no test coverage detected