| 57 | } // namespace |
| 58 | |
| 59 | TEST(TestSubGraphExtractor, MultipleOutputs) { |
| 60 | HostTensorGenerator<> gen; |
| 61 | auto graph = ComputingGraph::make(); |
| 62 | |
| 63 | auto mkvar = [&](const char* name, const TensorShape& shp) { |
| 64 | return opr::Host2DeviceCopy::make(*graph, gen(shp)).rename(name); |
| 65 | }; |
| 66 | |
| 67 | auto mkcvar = [&](const char* name, const TensorShape& shp) { |
| 68 | return opr::SharedDeviceTensor::make(*graph, *gen(shp)).rename(name); |
| 69 | }; |
| 70 | |
| 71 | graph->options().graph_opt_level = 0; |
| 72 | auto x = mkvar("x", {8, 8, 8, 8}), w1 = mkcvar("w1", {4, 8, 3, 3}); |
| 73 | auto y = mkvar("y", {1, 8, 1, 1}); |
| 74 | auto add = x + y; |
| 75 | |
| 76 | opr::Convolution::Param param; |
| 77 | param.pad_h = param.pad_w = 1; |
| 78 | auto c1 = opr::Convolution::make(add, w1, param); |
| 79 | auto w2 = mkcvar("w2", {8, 4, 3, 3}); |
| 80 | auto c2 = opr::ConvolutionBackwardData::make(w2, add, param, {}, {}); |
| 81 | auto sym_var_arr = MultipleInputOutput::make({c1, c2}); |
| 82 | auto z = sym_var_arr[1]; |
| 83 | z = z + (-128); |
| 84 | |
| 85 | using OprList = SubGraphExtractor::OprList; |
| 86 | static const OprList opr_list = { |
| 87 | opr::ConvolutionForward::typeinfo(), |
| 88 | opr::Elemwise::typeinfo(), |
| 89 | opr::TypeCvt::typeinfo(), |
| 90 | MultipleInputOutput::typeinfo(), |
| 91 | }; |
| 92 | SubGraphExtractor extractor(opr_list); |
| 93 | auto partitions = extractor.extract({z}); |
| 94 | ASSERT_EQ(partitions.size(), 1u); |
| 95 | // outputs: sym_var_arr[0], z, add |
| 96 | ASSERT_EQ(partitions[0].output().size(), 3u); |
| 97 | ASSERT_TRUE(partitions[0].output().count(add.node()) > 0); |
| 98 | ASSERT_TRUE(partitions[0].output().count(z.node()) > 0); |
| 99 | ASSERT_TRUE(partitions[0].output().count(sym_var_arr[0].node()) > 0); |
| 100 | ASSERT_TRUE(partitions[0].output().count(sym_var_arr[1].node()) == 0); |
| 101 | // inputs: x, y, w1, c2, (-128) |
| 102 | ASSERT_EQ(partitions[0].input().size(), 5u); |
| 103 | ASSERT_TRUE(partitions[0].input().count(x.node()) > 0); |
| 104 | ASSERT_TRUE(partitions[0].input().count(c2.node()) > 0); |
| 105 | // opr: (x + y) conv1 multi_io, (z - 128) |
| 106 | ASSERT_EQ(partitions[0].opr_set().size(), 4u); |
| 107 | ASSERT_TRUE(partitions[0].opr_set().count(add.node()->owner_opr()) > 0); |
| 108 | ASSERT_TRUE(partitions[0].opr_set().count(c1.node()->owner_opr()) > 0); |
| 109 | ASSERT_TRUE(partitions[0].opr_set().count(sym_var_arr[0].node()->owner_opr()) > 0); |
| 110 | ASSERT_TRUE(partitions[0].opr_set().count(z.node()->owner_opr()) > 0); |
| 111 | } |
| 112 | |
| 113 | TEST(TestSubGraphExtractor, MultipleReaders) { |
| 114 | HostTensorGenerator<> gen; |
nothing calls this directly
no test coverage detected