3
3
//
4
4
#include < gtest/gtest.h>
5
5
6
+ #include < common_test_utils/test_common.hpp>
7
+
6
8
#include " dummy_node.hpp"
7
- #include " nodes/reorder.h"
8
9
#include " nodes/input.h"
10
+ #include " nodes/reorder.h"
9
11
#include " nodes/transpose.h"
10
-
11
12
#include " ov_models/builders.hpp"
12
13
13
14
using namespace ov ::intel_cpu;
15
+ using LOOK = Edge::LOOK;
16
+ struct MergeTransposeReorderTestParams {
17
+ enum Result {IS_OPTIMIZED, NOT_OPTIMIZED};
18
+ MergeTransposeReorderTestParams (const ov::Shape& testShape,
19
+ ov::element::Type_t testPrec,
20
+ LayoutType firstNodeLayout,
21
+ LOOK firstNodeInplaceDirection,
22
+ LayoutType secondNodeLayout,
23
+ LOOK secondNodeInplaceDirection,
24
+ Result test_result)
25
+ : testShape(testShape),
26
+ testPrec (testPrec),
27
+ firstNodeLayout(firstNodeLayout),
28
+ firstNodeInplaceDirection(firstNodeInplaceDirection),
29
+ secondNodeLayout(secondNodeLayout),
30
+ secondNodeInplaceDirection(secondNodeInplaceDirection),
31
+ test_result(test_result) {}
32
+
33
+ ov::Shape testShape;
34
+ ov::element::Type_t testPrec;
35
+ LayoutType firstNodeLayout;
36
+ LOOK firstNodeInplaceDirection;
37
+ LayoutType secondNodeLayout;
38
+ LOOK secondNodeInplaceDirection;
39
+ Result test_result;
40
+ };
41
+ using Result = MergeTransposeReorderTestParams::Result;
14
42
15
43
/*
16
44
* MergeTransposeReorderIsOptimizedCPUTest to test the CPU plugin-in MergeTransposeReorder graph optimizer
17
45
* under the circumstance that the upstream node or downstream node is inPlaced thereby the inserted Reorder
18
46
* cannot be optimized.
19
47
*/
20
- class MergeTransposeReorderIsOptimizedCPUTest : public ::testing::Test {
48
+ class MergeTransposeReorderIsOptimizedCPUTest : public testing ::WithParamInterface<MergeTransposeReorderTestParams>,
49
+ public ov::test::TestsCommon {
21
50
public:
22
51
void Validate () const {
23
52
CheckTransposeCount (0 );
24
- CheckReorderOptimized (std::string (" _fake" ), false ); // the fused node is of name "reshape_abcd_acdb_fake"
53
+ const bool is_optimized = GetParam ().test_result == MergeTransposeReorderTestParams::Result::IS_OPTIMIZED;
54
+ CheckReorderOptimized (std::string (" _fake" ), is_optimized); // the fused reorder has always postfix "fake"
25
55
}
26
56
57
+ protected:
27
58
void SetUp () override {
28
- CreateGraph ();
59
+ MergeTransposeReorderTestParams params = GetParam ();
60
+ CreateGraph (params.testShape ,
61
+ params.testPrec ,
62
+ params.firstNodeLayout ,
63
+ params.firstNodeInplaceDirection ,
64
+ params.secondNodeLayout ,
65
+ params.secondNodeInplaceDirection );
29
66
}
30
67
31
- protected:
32
- /* graph typology
33
- ---------
34
- |Input |
35
- ---------
36
- |
37
- ----------
38
- | Dummy | <*NOTE: fake node with laytout NCSP, and inplace from upstream*>
39
- ----------
40
- |
41
- |---------------|
42
- | ---------- |
43
- | |Transpose| |
44
- | --------- |
45
- | | |
46
- | --------- |
47
- | |Reorder | | <*NOTE: Reorder is inheristically inserted since Multiply is asking NSPC input.*>
48
- | --------- |
49
- |---------------|
50
- |
51
- -----------
52
- | Dummy | <*NOTE: fake node with laytout NSPC, and inplace from downstream*>
53
- -----------
54
- |
55
- ---------
56
- |Output |
57
- ---------
68
+ /* graph topology
69
+ ┌───────┐
70
+ │ Input │
71
+ └───┬───┘
72
+ │
73
+ ┌───┴───┐
74
+ │ Dummy │ <*NOTE: fake node with firstNodeLayout, and firstNodeInplaceDirection*>
75
+ └───┬───┘
76
+ │
77
+ ┌────┴────┐
78
+ │Transpose│ <*NOTE: Reorder is inserted before/after Transpose depending on first/second node layouts.*>
79
+ └────┬────┘
80
+ │
81
+ ┌───┴───┐
82
+ │ Dummy │ <*NOTE: fake node with secondNodeLayout, and secondNodeInplaceDirection*>
83
+ └───┬───┘
84
+ │
85
+ ┌────┴───┐
86
+ │ Output │
87
+ └────────┘
58
88
*/
59
- void CreateGraph () {
60
- //
89
+ void CreateGraph (const ov::Shape& testShape,
90
+ const ov::element::Type_t& testPrec,
91
+ LayoutType firstNodeLayout,
92
+ LOOK firstNodeInplaceDirection,
93
+ LayoutType secondNodeLayout,
94
+ LOOK secondNodeInplaceDirection) {
61
95
Config conf;
62
96
conf.rtCacheCapacity = 100 ;
63
97
auto context = std::make_shared<GraphContext>(conf, nullptr , nullptr , false );
64
98
const dnnl::engine cpuEngine = context->getEngine ();
65
99
66
100
m_graph = std::unique_ptr<Graph>(new Graph ());
67
101
102
+ OPENVINO_ASSERT (testShape.size () == 4 || testShape.size () == 3 , " Only 4D and 3D shapes are supported" );
68
103
// ov::Model with only a transpose node
69
- ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(testPrec, ov::Shape ( testShape) )};
70
- auto order = std::vector<int32_t >{0 , 3 , 1 , 2 };
104
+ ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(testPrec, testShape)};
105
+ auto order = testShape. size () == 4 ? std::vector<int32_t >{0 , 3 , 1 , 2 } : std::vector< int32_t >{ 0 , 2 , 1 };
71
106
auto constOrder = ngraph::builder::makeConstant (ov::element::i32, {order.size ()}, order);
72
107
auto transpose = std::make_shared<ov::op::v1::Transpose>(params[0 ], constOrder);
73
108
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(transpose)};
@@ -86,18 +121,16 @@ class MergeTransposeReorderIsOptimizedCPUTest : public ::testing::Test {
86
121
87
122
auto inputNode = std::make_shared<node::Input>(params[0 ], context);
88
123
89
- // dummy ncsp + inPlace LOOK_UP
90
124
auto dummyNode1 = std::make_shared<cpu_unit_test::DummyNode>(
91
- testShape, testPrec, " reshape" , " DummyNode" , context, LayoutType::ncsp, Edge::LOOK::LOOK_UP );
125
+ testShape, testPrec, " reshape" , " DummyNode" , context, firstNodeLayout, firstNodeInplaceDirection );
92
126
93
127
auto orderNode = std::make_shared<node::Input>(constOrder, context); // const order
94
128
auto transposeNode = std::make_shared<node::Transpose>(transpose, context);
95
129
transposeNode->filterSupportedPrimitiveDescriptors ();
96
130
97
- // dummy nspc + inPlace LOOK_DOWN
98
- const ov::Shape shape_tranpose{testShape[0 ], testShape[3 ], testShape[1 ], testShape[2 ]}; // shape after transpose
131
+ const auto & transpose_shape = transpose->get_output_shape (0 );
99
132
auto dummyNode2 = std::make_shared<cpu_unit_test::DummyNode>(
100
- shape_tranpose , testPrec, " multiply" , " DummyNode" , context, LayoutType::nspc, Edge::LOOK::LOOK_DOWN );
133
+ transpose_shape , testPrec, " multiply" , " DummyNode" , context, secondNodeLayout, secondNodeInplaceDirection );
101
134
102
135
auto outputNode = std::make_shared<node::Input>(results[0 ], context);
103
136
@@ -146,12 +179,20 @@ class MergeTransposeReorderIsOptimizedCPUTest : public ::testing::Test {
146
179
}
147
180
148
181
private:
149
- const ov::element::Type_t testPrec = ov::element::Type_t::f32;
150
- const ov::Shape testShape{1 , 3 , 8 , 16 };
151
-
152
182
std::unique_ptr<Graph> m_graph;
153
- }; // class MergeTransposeReorderIsOptimizedCPUTest
183
+ }; // class MergeTransposeReorderIsOptimizedCPUTest
154
184
155
- TEST_F (MergeTransposeReorderIsOptimizedCPUTest, smoke_Run_MergeTransposeReorder_isOptimized) {
185
+ TEST_P (MergeTransposeReorderIsOptimizedCPUTest, smoke_Run_MergeTransposeReorder_isOptimized) {
156
186
Validate ();
157
- }
187
+ }
188
+
189
+ const std::vector<MergeTransposeReorderTestParams> params = {
190
+ {{1 , 3 , 8 , 16 }, ov::element::f32, LayoutType::ncsp, LOOK::LOOK_UP, LayoutType::nspc, LOOK::LOOK_DOWN, Result::NOT_OPTIMIZED},
191
+ {{1 , 3 , 8 , 16 }, ov::element::f32, LayoutType::ncsp, LOOK::LOOK_DOWN, LayoutType::nspc, LOOK::LOOK_UP, Result::IS_OPTIMIZED},
192
+ {{3 , 8 , 16 }, ov::element::f32, LayoutType::nspc, LOOK::LOOK_UP, LayoutType::ncsp, LOOK::LOOK_DOWN, Result::NOT_OPTIMIZED},
193
+ {{3 , 8 , 16 }, ov::element::f32, LayoutType::nspc, LOOK::LOOK_DOWN, LayoutType::ncsp, LOOK::LOOK_UP, Result::IS_OPTIMIZED},
194
+ };
195
+
196
+ INSTANTIATE_TEST_SUITE_P (smoke_Run_MergeTransposeReorder_isOptimized,
197
+ MergeTransposeReorderIsOptimizedCPUTest,
198
+ ::testing::ValuesIn (params));
0 commit comments