Add input transposing for MatMul (#1462)
authorLiubov Batanina <liubov.batanina@intel.com>
Fri, 24 Jul 2020 12:15:20 +0000 (15:15 +0300)
committerGitHub <noreply@github.com>
Fri, 24 Jul 2020 12:15:20 +0000 (15:15 +0300)
inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/mat_mul.cpp
inference-engine/tests/functional/plugin/shared/include/single_layer_tests/mat_mul.hpp
inference-engine/tests/functional/plugin/shared/src/single_layer_tests/mat_mul.cpp
inference-engine/tests/ngraph_functions/include/ngraph_functions/builders.hpp
inference-engine/tests/ngraph_functions/src/mat_mul.cpp

index 7e173ff..0e3546f 100644 (file)
@@ -32,6 +32,8 @@ INSTANTIATE_TEST_CASE_P(MatMul, MatMulTest,
                 ::testing::ValuesIn(inputPrecisions),
                 ::testing::ValuesIn(shapesA),
                 ::testing::ValuesIn(shapesB),
+                ::testing::Values(false),
+                ::testing::Values(false),
                 ::testing::ValuesIn(secondaryInputTypes),
                 ::testing::Values(CommonTestUtils::DEVICE_CPU)),
         MatMulTest::getTestCaseName);
index 7333295..32c378e 100644 (file)
@@ -15,6 +15,8 @@ typedef std::tuple<
         InferenceEngine::Precision,
         InferenceEngine::SizeVector,
         InferenceEngine::SizeVector,
+        bool,
+        bool,
         ngraph::helpers::InputLayerType,
         LayerTestsUtils::TargetDevice
 > MatMulLayerTestParamsSet;
index 9505f20..7ac3507 100644 (file)
@@ -17,13 +17,17 @@ std::string MatMulTest::getTestCaseName(const testing::TestParamInfo<MatMulLayer
     InferenceEngine::Precision netPrecision;
     InferenceEngine::SizeVector inputShape0;
     InferenceEngine::SizeVector inputShape1;
+    bool transpose_a;
+    bool transpose_b;
     ngraph::helpers::InputLayerType secondaryInputType;
     std::string targetDevice;
-    std::tie(netPrecision, inputShape0, inputShape1, secondaryInputType, targetDevice) = obj.param;
+    std::tie(netPrecision, inputShape0, inputShape1, transpose_a, transpose_b, secondaryInputType, targetDevice) = obj.param;
 
     std::ostringstream result;
     result << "IS0=" << CommonTestUtils::vec2str(inputShape0) << "_";
     result << "IS1=" << CommonTestUtils::vec2str(inputShape1) << "_";
+    result << "transpose_a=" << transpose_a << "_";
+    result << "transpose_b=" << transpose_b << "_";
     result << "secondaryInputType=" << secondaryInputType << "_";
     result << "netPRC=" << netPrecision.name() << "_";
     result << "targetDevice=" << targetDevice;
@@ -33,9 +37,11 @@ std::string MatMulTest::getTestCaseName(const testing::TestParamInfo<MatMulLayer
 void MatMulTest::SetUp() {
     InferenceEngine::SizeVector inputShape0;
     InferenceEngine::SizeVector inputShape1;
+    bool transpose_a;
+    bool transpose_b;
     ngraph::helpers::InputLayerType secondaryInputType;
     auto netPrecision = InferenceEngine::Precision::UNSPECIFIED;
-    std::tie(netPrecision, inputShape0, inputShape1, secondaryInputType, targetDevice) = this->GetParam();
+    std::tie(netPrecision, inputShape0, inputShape1, transpose_a, transpose_b, secondaryInputType, targetDevice) = this->GetParam();
     auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
     auto params = ngraph::builder::makeParams(ngPrc, {inputShape0});
 
@@ -46,7 +52,7 @@ void MatMulTest::SetUp() {
     auto paramOuts = ngraph::helpers::convert2OutputVector(
             ngraph::helpers::castOps2Nodes<ngraph::op::Parameter>(params));
     auto MatMul = std::dynamic_pointer_cast<ngraph::opset3::MatMul>(
-            ngraph::builder::makeMatMul(paramOuts[0], secondaryInput));
+            ngraph::builder::makeMatMul(paramOuts[0], secondaryInput, transpose_a, transpose_b));
     ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(MatMul)};
     function = std::make_shared<ngraph::Function>(results, params, "MatMul");
 }
index b0f18e5..08a40b7 100644 (file)
@@ -258,7 +258,9 @@ std::shared_ptr<Node> makeShuffleChannels(const ngraph::Output<Node> &in,
                                           int group);
 
 std::shared_ptr<Node> makeMatMul(const Output<Node> &A,
-                                 const Output<Node> &B);
+                                 const Output<Node> &B,
+                                 bool transpose_a = false,
+                                 bool transpose_b = false);
 
 std::shared_ptr<ngraph::Node> makeReduce(std::vector<ngraph::Output<Node>> &in,
                                          const std::vector<int> &reductionAxes,
index df16175..62f6dcd 100644 (file)
@@ -8,8 +8,10 @@ namespace ngraph {
 namespace builder {
 
 std::shared_ptr<Node> makeMatMul(const Output<Node>& A,
-                                 const Output<Node>& B) {
-    return std::make_shared<ngraph::opset3::MatMul>(A, B);
+                                 const Output<Node>& B,
+                                 bool transpose_a,
+                                 bool transpose_b) {
+    return std::make_shared<ngraph::opset3::MatMul>(A, B, transpose_a, transpose_b);
 }
 
 }  // namespace builder