[IE TEST] Added constant input to MatMul tests (#1119)
* Added constant input to MatMul tests * Added InputLayerType to ngraph_helpers.hpp
This commit is contained in:
parent
f596432268
commit
fce9d9def0
@ -29,9 +29,9 @@ std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||
InferenceEngine::Precision::FP16,
|
||||
};
|
||||
|
||||
std::vector<InputLayerType> secondaryInputTypes = {
|
||||
InputLayerType::CONSTANT,
|
||||
InputLayerType::PARAMETER,
|
||||
std::vector<ngraph::helpers::InputLayerType> secondaryInputTypes = {
|
||||
ngraph::helpers::InputLayerType::CONSTANT,
|
||||
ngraph::helpers::InputLayerType::PARAMETER,
|
||||
};
|
||||
|
||||
std::vector<OpType> opTypes = {
|
||||
|
@ -22,11 +22,17 @@ const std::vector<std::vector<size_t>> shapesB = {
|
||||
{1, 4, 6, 4}
|
||||
};
|
||||
|
||||
std::vector<ngraph::helpers::InputLayerType> secondaryInputTypes = {
|
||||
ngraph::helpers::InputLayerType::CONSTANT,
|
||||
ngraph::helpers::InputLayerType::PARAMETER,
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MatMul, MatMulTest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(inputPrecisions),
|
||||
::testing::ValuesIn(shapesA),
|
||||
::testing::ValuesIn(shapesB),
|
||||
::testing::ValuesIn(secondaryInputTypes),
|
||||
::testing::Values(CommonTestUtils::DEVICE_CPU)),
|
||||
MatMulTest::getTestCaseName);
|
||||
|
||||
|
@ -26,9 +26,9 @@ std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||
InferenceEngine::Precision::FP16,
|
||||
};
|
||||
|
||||
std::vector<InputLayerType> secondaryInputTypes = {
|
||||
InputLayerType::CONSTANT,
|
||||
InputLayerType::PARAMETER,
|
||||
std::vector<ngraph::helpers::InputLayerType> secondaryInputTypes = {
|
||||
ngraph::helpers::InputLayerType::CONSTANT,
|
||||
ngraph::helpers::InputLayerType::PARAMETER,
|
||||
};
|
||||
|
||||
std::vector<OpType> opTypes = {
|
||||
|
@ -30,9 +30,9 @@ std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||
InferenceEngine::Precision::I64,
|
||||
};
|
||||
|
||||
std::vector<InputLayerType> secondaryInputTypes = {
|
||||
InputLayerType::CONSTANT,
|
||||
InputLayerType::PARAMETER,
|
||||
std::vector<ngraph::helpers::InputLayerType> secondaryInputTypes = {
|
||||
ngraph::helpers::InputLayerType::CONSTANT,
|
||||
ngraph::helpers::InputLayerType::PARAMETER,
|
||||
};
|
||||
|
||||
std::vector<OpType> opTypes = {
|
||||
|
@ -31,9 +31,9 @@ std::vector<InferenceEngine::Precision> netPrecisions = {
|
||||
InferenceEngine::Precision::FP16,
|
||||
};
|
||||
|
||||
std::vector<InputLayerType> secondaryInputTypes = {
|
||||
InputLayerType::CONSTANT,
|
||||
InputLayerType::PARAMETER,
|
||||
std::vector<ngraph::helpers::InputLayerType> secondaryInputTypes = {
|
||||
ngraph::helpers::InputLayerType::CONSTANT,
|
||||
ngraph::helpers::InputLayerType::PARAMETER,
|
||||
};
|
||||
|
||||
std::vector<OpType> opTypes = {
|
||||
|
@ -17,11 +17,6 @@
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
namespace EltwiseParams {
|
||||
enum class InputLayerType {
|
||||
CONSTANT,
|
||||
PARAMETER,
|
||||
};
|
||||
|
||||
enum class OpType {
|
||||
SCALAR,
|
||||
VECTOR
|
||||
@ -31,7 +26,7 @@ enum class OpType {
|
||||
typedef std::tuple<
|
||||
std::vector<std::vector<size_t>>, // input shapes
|
||||
ngraph::helpers::EltwiseTypes, // eltwise op type
|
||||
EltwiseParams::InputLayerType, // secondary input type
|
||||
ngraph::helpers::InputLayerType, // secondary input type
|
||||
EltwiseParams::OpType, // op type
|
||||
InferenceEngine::Precision, // Net precision
|
||||
std::string, // Device name
|
||||
|
@ -15,6 +15,7 @@ typedef std::tuple<
|
||||
InferenceEngine::Precision,
|
||||
InferenceEngine::SizeVector,
|
||||
InferenceEngine::SizeVector,
|
||||
ngraph::helpers::InputLayerType,
|
||||
LayerTestsUtils::TargetDevice
|
||||
> MatMulLayerTestParamsSet;
|
||||
|
||||
|
@ -14,20 +14,6 @@
|
||||
#include "single_layer_tests/eltwise.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
std::ostream& operator<<(std::ostream & os, EltwiseParams::InputLayerType type) {
|
||||
switch (type) {
|
||||
case EltwiseParams::InputLayerType::CONSTANT:
|
||||
os << "CONSTANT";
|
||||
break;
|
||||
case EltwiseParams::InputLayerType::PARAMETER:
|
||||
os << "PARAMETER";
|
||||
break;
|
||||
default:
|
||||
THROW_IE_EXCEPTION << "NOT_SUPPORTED_INPUT_LAYER_TYPE";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream & os, EltwiseParams::OpType type) {
|
||||
switch (type) {
|
||||
case EltwiseParams::OpType::SCALAR:
|
||||
@ -45,7 +31,7 @@ std::ostream& operator<<(std::ostream & os, EltwiseParams::OpType type) {
|
||||
std::string EltwiseLayerTest::getTestCaseName(testing::TestParamInfo<EltwiseTestParams> obj) {
|
||||
std::vector<std::vector<size_t>> inputShapes;
|
||||
InferenceEngine::Precision netPrecision;
|
||||
EltwiseParams::InputLayerType secondaryInputType;
|
||||
ngraph::helpers::InputLayerType secondaryInputType;
|
||||
EltwiseParams::OpType opType;
|
||||
ngraph::helpers::EltwiseTypes eltwiseOpType;
|
||||
std::string targetName;
|
||||
@ -65,7 +51,7 @@ std::string EltwiseLayerTest::getTestCaseName(testing::TestParamInfo<EltwiseTest
|
||||
void EltwiseLayerTest::SetUp() {
|
||||
std::vector<std::vector<size_t>> inputShapes;
|
||||
InferenceEngine::Precision netPrecision;
|
||||
EltwiseParams::InputLayerType secondaryInputType;
|
||||
ngraph::helpers::InputLayerType secondaryInputType;
|
||||
EltwiseParams::OpType opType;
|
||||
ngraph::helpers::EltwiseTypes eltwiseType;
|
||||
std::map<std::string, std::string> additional_config;
|
||||
@ -98,24 +84,11 @@ void EltwiseLayerTest::SetUp() {
|
||||
FAIL() << "Unsupported Secondary operation type";
|
||||
}
|
||||
|
||||
std::shared_ptr<ngraph::Node> secondary_input;
|
||||
switch (secondaryInputType) {
|
||||
case EltwiseParams::InputLayerType::CONSTANT: {
|
||||
std::vector<float> data;
|
||||
data.resize(ngraph::shape_size(inputShape2));
|
||||
CommonTestUtils::fill_data_sine(data.data(), data.size(), 0, 10, 1);
|
||||
secondary_input = ngraph::builder::makeConstant(ngPrc, inputShape2, data);
|
||||
break;
|
||||
}
|
||||
case EltwiseParams::InputLayerType::PARAMETER:
|
||||
input.push_back(ngraph::builder::makeParams(ngPrc, {shape_input_secondary})[0]);
|
||||
secondary_input = input[1];
|
||||
break;
|
||||
default:
|
||||
FAIL() << "Unsupported secondaryInputType";
|
||||
auto secondaryInput = ngraph::builder::makeInputLayer(ngPrc, secondaryInputType, shape_input_secondary);
|
||||
if (secondaryInputType == ngraph::helpers::InputLayerType::PARAMETER) {
|
||||
input.push_back(std::dynamic_pointer_cast<ngraph::opset3::Parameter>(secondaryInput));
|
||||
}
|
||||
|
||||
auto eltwise = ngraph::builder::makeEltwise(input[0], secondary_input, eltwiseType);
|
||||
auto eltwise = ngraph::builder::makeEltwise(input[0], secondaryInput, eltwiseType);
|
||||
function = std::make_shared<ngraph::Function>(eltwise, input, "Eltwise");
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,14 @@ std::string MatMulTest::getTestCaseName(const testing::TestParamInfo<MatMulLayer
|
||||
InferenceEngine::Precision netPrecision;
|
||||
InferenceEngine::SizeVector inputShape0;
|
||||
InferenceEngine::SizeVector inputShape1;
|
||||
ngraph::helpers::InputLayerType secondaryInputType;
|
||||
std::string targetDevice;
|
||||
std::tie(netPrecision, inputShape0, inputShape1, targetDevice) = obj.param;
|
||||
std::tie(netPrecision, inputShape0, inputShape1, secondaryInputType, targetDevice) = obj.param;
|
||||
|
||||
std::ostringstream result;
|
||||
result << "IS0=" << CommonTestUtils::vec2str(inputShape0) << "_";
|
||||
result << "IS1=" << CommonTestUtils::vec2str(inputShape1) << "_";
|
||||
result << "secondaryInputType=" << secondaryInputType << "_";
|
||||
result << "netPRC=" << netPrecision.name() << "_";
|
||||
result << "targetDevice=" << targetDevice;
|
||||
return result.str();
|
||||
@ -31,14 +33,20 @@ std::string MatMulTest::getTestCaseName(const testing::TestParamInfo<MatMulLayer
|
||||
void MatMulTest::SetUp() {
|
||||
InferenceEngine::SizeVector inputShape0;
|
||||
InferenceEngine::SizeVector inputShape1;
|
||||
ngraph::helpers::InputLayerType secondaryInputType;
|
||||
auto netPrecision = InferenceEngine::Precision::UNSPECIFIED;
|
||||
std::tie(netPrecision, inputShape0, inputShape1, targetDevice) = this->GetParam();
|
||||
std::tie(netPrecision, inputShape0, inputShape1, secondaryInputType, targetDevice) = this->GetParam();
|
||||
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
|
||||
auto params = ngraph::builder::makeParams(ngPrc, {inputShape0, inputShape1});
|
||||
auto params = ngraph::builder::makeParams(ngPrc, {inputShape0});
|
||||
|
||||
auto secondaryInput = ngraph::builder::makeInputLayer(ngPrc, secondaryInputType, inputShape1);
|
||||
if (secondaryInputType == ngraph::helpers::InputLayerType::PARAMETER) {
|
||||
params.push_back(std::dynamic_pointer_cast<ngraph::opset3::Parameter>(secondaryInput));
|
||||
}
|
||||
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], paramOuts[1]));
|
||||
ngraph::builder::makeMatMul(paramOuts[0], secondaryInput));
|
||||
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(MatMul)};
|
||||
function = std::make_shared<ngraph::Function>(results, params, "MatMul");
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ makeParams(const element::Type &type, const std::vector<std::pair<std::string, s
|
||||
std::shared_ptr<ngraph::Node> makeConstant(const element::Type &type, const std::vector<size_t> &shape,
|
||||
const std::vector<float> &data, bool random = false);
|
||||
|
||||
std::shared_ptr<ngraph::Node> makeInputLayer(const element::Type& type, ngraph::helpers::InputLayerType inputType,
|
||||
const std::vector<size_t>& shape);
|
||||
|
||||
std::shared_ptr<ngraph::Node> makeConvolution(const ngraph::Output<Node> &in,
|
||||
const element::Type &type,
|
||||
const std::vector<size_t> &filterSize,
|
||||
|
@ -119,6 +119,11 @@ enum ReductionType {
|
||||
LogicalXor
|
||||
};
|
||||
|
||||
enum class InputLayerType {
|
||||
CONSTANT,
|
||||
PARAMETER,
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const ReductionType &m);
|
||||
|
||||
inline std::string quantizationGranularityToString(const QuantizationGranularity &granularity) {
|
||||
@ -180,5 +185,7 @@ std::ostream& operator<<(std::ostream & os, ngraph::helpers::EltwiseTypes type);
|
||||
|
||||
std::ostream& operator<<(std::ostream & os, ngraph::helpers::SqueezeOpType type);
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, ngraph::helpers::InputLayerType type);
|
||||
|
||||
} // namespace helpers
|
||||
} // namespace ngraph
|
||||
|
33
inference-engine/tests/ngraph_functions/src/input_layer.cpp
Normal file
33
inference-engine/tests/ngraph_functions/src/input_layer.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "ngraph_functions/builders.hpp"
|
||||
#include "ngraph_functions/utils/ngraph_helpers.hpp"
|
||||
|
||||
|
||||
namespace ngraph {
|
||||
namespace builder {
|
||||
|
||||
std::shared_ptr<ngraph::Node> makeInputLayer(const element::Type &type, ngraph::helpers::InputLayerType inputType,
|
||||
const std::vector<size_t> &shape) {
|
||||
std::shared_ptr<ngraph::Node> input;
|
||||
switch (inputType) {
|
||||
case ngraph::helpers::InputLayerType::CONSTANT: {
|
||||
std::vector<float> data(ngraph::shape_size(shape));
|
||||
input = ngraph::builder::makeConstant(type, shape, data);
|
||||
break;
|
||||
}
|
||||
case ngraph::helpers::InputLayerType::PARAMETER:
|
||||
input = ngraph::builder::makeParams(type, {shape})[0];
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported inputType");
|
||||
}
|
||||
return input;
|
||||
}
|
||||
} // namespace builder
|
||||
} // namespace ngraph
|
@ -546,5 +546,19 @@ std::ostream& operator<<(std::ostream & os, ngraph::helpers::SqueezeOpType type)
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, ngraph::helpers::InputLayerType type) {
|
||||
switch (type) {
|
||||
case ngraph::helpers::InputLayerType::CONSTANT:
|
||||
os << "CONSTANT";
|
||||
break;
|
||||
case ngraph::helpers::InputLayerType::PARAMETER:
|
||||
os << "PARAMETER";
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("NOT_SUPPORTED_INPUT_LAYER_TYPE");
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
} // namespace helpers
|
||||
} // namespace ngraph
|
||||
|
Loading…
Reference in New Issue
Block a user