| 48 | } |
| 49 | |
| 50 | TEST(OptimizerTest, Optimizer) { |
| 51 | std::vector<std::vector<std::string>> fusion_output_map; |
| 52 | // 0 inner_node's 1 ouput -> fusion_node's 0 output |
| 53 | fusion_output_map.push_back({"2", "0", "1", "0"}); |
| 54 | // 1 inner_node's 0 ouput -> fusion_node's 1 output |
| 55 | fusion_output_map.push_back({"3", "1", "0", "1"}); |
| 56 | OptimizeRule optmz_rule1({"2:0 3:1", "3:1"}, "NEW", fusion_output_map); |
| 57 | Optimizer optimizer(local); |
| 58 | optimizer.AddRule(optmz_rule1); |
| 59 | |
| 60 | /* |
| 61 | 0 1 |
| 62 | |/ |
| 63 | 2 |
| 64 | |\ |
| 65 | 3 4 |
| 66 | |/ |
| 67 | 5 |
| 68 | * */ |
| 69 | OptimizeRule optmz_rule( |
| 70 | {"0:0 2:2", "1:1 2:2", "2:2 3:3 4:4", "3:3 5:5", "4:4 5:5", "5:5"}, |
| 71 | "", {}); |
| 72 | DAGDef dag(optmz_rule.adj_info_); |
| 73 | std::shared_ptr<NodeDef> node0 = dag.GetNodeById(0); |
| 74 | std::shared_ptr<NodeDef> node1 = dag.GetNodeById(1); |
| 75 | std::shared_ptr<NodeDef> node2 = dag.GetNodeById(2); |
| 76 | std::shared_ptr<NodeDef> node3 = dag.GetNodeById(3); |
| 77 | std::shared_ptr<NodeDef> node4 = dag.GetNodeById(4); |
| 78 | std::shared_ptr<NodeDef> node5 = dag.GetNodeById(5); |
| 79 | node2->input_edges_.push_back({"0", 0, 0}); |
| 80 | node2->input_edges_.push_back({"1", 1, 0}); |
| 81 | node3->input_edges_.push_back({"2", 2, 0}); |
| 82 | node4->input_edges_.push_back({"2", 2, 1}); |
| 83 | node5->input_edges_.push_back({"3", 3, 0}); |
| 84 | node5->input_edges_.push_back({"4", 4, 0}); |
| 85 | optimizer.Optimize(&dag); |
| 86 | int32_t fusion_id = 6; |
| 87 | bool result = true; |
| 88 | result = result && CheckStrct(node0, {}, {fusion_id}); |
| 89 | result = result && CheckStrct(node1, {}, {fusion_id}); |
| 90 | result = result && CheckStrct(dag.GetNodeById(fusion_id), {0, 1}, {4, 5}); |
| 91 | result = result && CheckStrct(node4, {fusion_id}, {5}); |
| 92 | result = result && CheckStrct(node5, {fusion_id, 4}, {}); |
| 93 | ASSERT_EQ(result, true); |
| 94 | |
| 95 | std::shared_ptr<NodeDef> fusion_node = dag.GetNodeById(fusion_id); |
| 96 | for (EdgeDef ed : fusion_node->input_edges_) { |
| 97 | std::cout << ed.src_name_ |
| 98 | << "," << ed.src_id_ |
| 99 | << "," << ed.src_slot_ << std::endl; |
| 100 | } |
| 101 | |
| 102 | for (EdgeDef ed : node4->input_edges_) { |
| 103 | std::cout << ed.src_name_ |
| 104 | << "," << ed.src_id_ |
| 105 | << "," << ed.src_slot_ << std::endl; |
| 106 | } |
| 107 |
nothing calls this directly
no test coverage detected