Add ReadValue and Assign to template plugin tests (#9132)
* Add readvalue, assign to templte plugin test * Fix clang error * Fix clang error * Remove unnecessary comment * Fix type-casting error * Fix ci issue regarding const value * Change Function to Model * Fix op scope * Change way to get variable * Fix type-casting error * Set variable id to const * Fix side-effect in ieFuncTests * Implement Assign-3, ReadValue-3 in evaluates_map * Correct setting attribute * Correct setting attribute * Remove unnecessarily added method * Roll back v6 * Use member variable for variable_id in assign-3, read_value-3 * Get data pointer from host tensor * Remove visitor API test for ReadValue-6, Assign-6 * Implement visitor api test for read_value-6, assign-6 * Fix clang error * Split read_value and assign into each file for visitor test Co-authored-by: Ilya Churaev <ilya.churaev@intel.com>
This commit is contained in:
parent
c4f5bce3b0
commit
000723acd0
|
|
@ -3529,6 +3529,24 @@ bool evaluate(const shared_ptr<op::v8::Gather>& op, const HostTensorVector& outp
|
|||
return true;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const shared_ptr<op::v3::Assign>& op, const HostTensorVector& outputs, const HostTensorVector& inputs) {
|
||||
outputs[0]->set_unary(inputs[0]);
|
||||
void* input = inputs[0]->get_data_ptr();
|
||||
outputs[0]->write(input, outputs[0]->get_size_in_bytes());
|
||||
return true;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const shared_ptr<op::v3::ReadValue>& op,
|
||||
const HostTensorVector& outputs,
|
||||
const HostTensorVector& inputs) {
|
||||
outputs[0]->set_unary(inputs[0]);
|
||||
void* input = inputs[0]->get_data_ptr();
|
||||
outputs[0]->write(input, outputs[0]->get_size_in_bytes());
|
||||
return true;
|
||||
}
|
||||
|
||||
template <ov::element::Type_t ET>
|
||||
inline bool evaluate(const shared_ptr<op::v8::NV12toRGB>& op,
|
||||
const HostTensorVector& outputs,
|
||||
|
|
|
|||
|
|
@ -154,8 +154,7 @@ bool runtime::interpreter::INTExecutable::call(const vector<shared_ptr<runtime::
|
|||
if (!variable_context.get_variable_value(variable)) {
|
||||
auto h_tensor = std::make_shared<ngraph::HostTensor>(cloned_node->get_input_element_type(0),
|
||||
cloned_node->get_input_shape(0));
|
||||
std::vector<float> data(ov::shape_size(cloned_node->get_input_shape(0)), 0);
|
||||
h_tensor->write(data.data(), data.size() * sizeof(float));
|
||||
h_tensor->write(h_tensor->get_data_ptr(), h_tensor->get_size_in_bytes());
|
||||
variable_context.set_variable_value(variable, std::make_shared<VariableValue>(h_tensor));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ NGRAPH_OP(Reshape, op::v1)
|
|||
NGRAPH_OP(Select, op::v1)
|
||||
NGRAPH_OP(GatherTree, op::v1)
|
||||
|
||||
NGRAPH_OP(Assign, op::v3)
|
||||
NGRAPH_OP(Bucketize, op::v3)
|
||||
NGRAPH_OP(EmbeddingBagOffsetsSum, ngraph::op::v3)
|
||||
NGRAPH_OP(EmbeddingBagPackedSum, ngraph::op::v3)
|
||||
|
|
@ -73,6 +74,7 @@ NGRAPH_OP(EmbeddingSegmentsSum, ngraph::op::v3)
|
|||
NGRAPH_OP(GRUCell, ngraph::op::v3)
|
||||
NGRAPH_OP(NonMaxSuppression, op::v3)
|
||||
NGRAPH_OP(NonZero, op::v3)
|
||||
NGRAPH_OP(ReadValue, op::v3)
|
||||
NGRAPH_OP(ScatterNDUpdate, op::v3)
|
||||
NGRAPH_OP(ShapeOf, op::v3)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,199 @@
|
|||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "base_reference_test.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/read_value.hpp"
|
||||
#include "openvino/op/util/variable.hpp"
|
||||
|
||||
using namespace ov;
|
||||
using namespace reference_tests;
|
||||
|
||||
namespace {
|
||||
|
||||
struct ReadValueAssignParams {
|
||||
template <class IT>
|
||||
ReadValueAssignParams(const Shape& input_shape,
|
||||
const Shape& output_shape,
|
||||
const element::Type& input_type,
|
||||
const element::Type& ouput_type,
|
||||
const std::vector<IT>& input_values,
|
||||
const std::vector<IT>& output_values,
|
||||
const std::string& variable_id)
|
||||
: m_input_shape(input_shape),
|
||||
m_output_shape(output_shape),
|
||||
m_input_type(input_type),
|
||||
m_output_type(ouput_type),
|
||||
m_input_data(CreateTensor(input_type, input_values)),
|
||||
m_expected_data(CreateTensor(ouput_type, output_values)),
|
||||
m_variable_id(variable_id) {}
|
||||
Shape m_input_shape;
|
||||
Shape m_output_shape;
|
||||
element::Type m_input_type;
|
||||
element::Type m_output_type;
|
||||
runtime::Tensor m_input_data;
|
||||
runtime::Tensor m_expected_data;
|
||||
std::string m_variable_id;
|
||||
};
|
||||
|
||||
class ReferenceReadValueAssignV3LayerTest : public testing::TestWithParam<ReadValueAssignParams>,
|
||||
public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.m_input_shape, params.m_input_type, params.m_variable_id);
|
||||
inputData = {params.m_input_data};
|
||||
refOutData = {params.m_expected_data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<ReadValueAssignParams>& obj) {
|
||||
auto params = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "shape=" << params.m_input_shape << "_";
|
||||
result << "iType=" << params.m_input_type << "_";
|
||||
result << "shape=" << params.m_output_shape << "_";
|
||||
result << "oType=" << params.m_output_type;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Model> CreateFunction(const Shape& input_shape,
|
||||
const element::Type& input_type,
|
||||
const std::string variable_id) {
|
||||
auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
auto read_value = std::make_shared<op::v3::ReadValue>(in, variable_id);
|
||||
auto assign = std::make_shared<op::v3::Assign>(read_value, variable_id);
|
||||
return std::make_shared<Model>(OutputVector{assign}, ParameterVector{in});
|
||||
}
|
||||
};
|
||||
|
||||
class ReferenceReadValueAssignV6LayerTest : public testing::TestWithParam<ReadValueAssignParams>,
|
||||
public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.m_input_shape, params.m_input_type, params.m_variable_id);
|
||||
inputData = {params.m_input_data};
|
||||
refOutData = {params.m_expected_data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<ReadValueAssignParams>& obj) {
|
||||
auto params = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "shape=" << params.m_input_shape << "_";
|
||||
result << "iType=" << params.m_input_type << "_";
|
||||
result << "shape=" << params.m_output_shape << "_";
|
||||
result << "oType=" << params.m_output_type;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Model> CreateFunction(const Shape& input_shape,
|
||||
const element::Type& input_type,
|
||||
const std::string variable_id) {
|
||||
auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
auto variable = std::make_shared<op::util::Variable>(
|
||||
op::util::VariableInfo{PartialShape::dynamic(), element::dynamic, variable_id});
|
||||
auto assign = std::make_shared<op::v6::Assign>(in, variable);
|
||||
auto read_value = std::make_shared<op::v6::ReadValue>(assign, variable);
|
||||
return std::make_shared<Model>(OutputVector{read_value},
|
||||
ParameterVector{in},
|
||||
op::util::VariableVector{variable});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceReadValueAssignV3LayerTest, ReadValueAssignWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceReadValueAssignV6LayerTest, ReadValueAssignWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t IN_ET>
|
||||
std::vector<ReadValueAssignParams> generateParamsForReadValueAssign() {
|
||||
using T = typename element_type_traits<IN_ET>::value_type;
|
||||
|
||||
std::vector<ReadValueAssignParams> params{
|
||||
ReadValueAssignParams(ov::Shape{1}, ov::Shape{1}, IN_ET, IN_ET, std::vector<T>{1}, std::vector<T>{1}, "v0"),
|
||||
ReadValueAssignParams(ov::Shape{2, 2},
|
||||
ov::Shape{2, 2},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4},
|
||||
std::vector<T>{1, 2, 3, 4},
|
||||
"v0"),
|
||||
ReadValueAssignParams(ov::Shape{1, 2, 3},
|
||||
ov::Shape{1, 2, 3},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6},
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6},
|
||||
"v0")};
|
||||
return params;
|
||||
}
|
||||
|
||||
template <element::Type_t IN_ET>
|
||||
std::vector<ReadValueAssignParams> generateParamsForReadValueAssignBoolean() {
|
||||
using T = typename element_type_traits<IN_ET>::value_type;
|
||||
|
||||
std::vector<ReadValueAssignParams> params{
|
||||
ReadValueAssignParams(ov::Shape{1}, ov::Shape{1}, IN_ET, IN_ET, std::vector<T>{true}, std::vector<T>{true}, "v0"),
|
||||
ReadValueAssignParams(ov::Shape{2, 2},
|
||||
ov::Shape{2, 2},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{true, true, false, false},
|
||||
std::vector<T>{true, true, false, false},
|
||||
"v0"),
|
||||
ReadValueAssignParams(ov::Shape{1, 2, 3},
|
||||
ov::Shape{1, 2, 3},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{true, false, true, false, true, false},
|
||||
std::vector<T>{true, false, true, false, true, false},
|
||||
"v0")};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<ReadValueAssignParams> generateCombinedParamsForReadValueAssign() {
|
||||
const std::vector<std::vector<ReadValueAssignParams>> allTypeParams{
|
||||
generateParamsForReadValueAssign<element::Type_t::f64>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::f32>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::f16>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::bf16>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::i64>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::i32>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::i16>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::i8>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::i4>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::u64>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::u32>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::u16>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::u8>(),
|
||||
generateParamsForReadValueAssign<element::Type_t::u4>(),
|
||||
generateParamsForReadValueAssignBoolean<element::Type_t::boolean>()};
|
||||
|
||||
std::vector<ReadValueAssignParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_ReadValue_Assign_With_Hardcoded_Refs,
|
||||
ReferenceReadValueAssignV3LayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReadValueAssign()),
|
||||
ReferenceReadValueAssignV3LayerTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_ReadValue_Assign_With_Hardcoded_Refs,
|
||||
ReferenceReadValueAssignV6LayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReadValueAssign()),
|
||||
ReferenceReadValueAssignV6LayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
|
|
@ -265,6 +265,7 @@ set(SRC
|
|||
visitors/op/add.cpp
|
||||
visitors/op/asin.cpp
|
||||
visitors/op/asinh.cpp
|
||||
visitors/op/assign.cpp
|
||||
visitors/op/atan.cpp
|
||||
visitors/op/atanh.cpp
|
||||
visitors/op/avg_pool.cpp
|
||||
|
|
@ -364,6 +365,7 @@ set(SRC
|
|||
visitors/op/psroi_pooling.cpp
|
||||
visitors/op/random_uniform.cpp
|
||||
visitors/op/rdft.cpp
|
||||
visitors/op/read_value.cpp
|
||||
visitors/op/reduce_l1.cpp
|
||||
visitors/op/reduce_l2.cpp
|
||||
visitors/op/reduce_logical_and.cpp
|
||||
|
|
|
|||
|
|
@ -117,6 +117,9 @@ public:
|
|||
virtual operator ov::Dimension&() {
|
||||
NGRAPH_CHECK(false, "Invalid type access");
|
||||
}
|
||||
virtual operator std::shared_ptr<Variable>&() {
|
||||
NGRAPH_CHECK(false, "Invalid type access");
|
||||
}
|
||||
uint64_t get_index() {
|
||||
return m_index;
|
||||
}
|
||||
|
|
@ -219,6 +222,8 @@ public:
|
|||
a->set(m_values.get<ov::PartialShape>(name));
|
||||
} else if (auto a = ngraph::as_type<ngraph::AttributeAdapter<ov::Dimension>>(&adapter)) {
|
||||
a->set(m_values.get<ov::Dimension>(name));
|
||||
} else if (auto a = ngraph::as_type<ngraph::AttributeAdapter<std::shared_ptr<Variable>>>(&adapter)) {
|
||||
a->set(m_values.get<std::shared_ptr<Variable>>(name));
|
||||
} else {
|
||||
NGRAPH_CHECK(false, "Attribute \"", name, "\" cannot be unmarshalled");
|
||||
}
|
||||
|
|
@ -303,6 +308,8 @@ public:
|
|||
m_values.insert_vector(name, a->get());
|
||||
} else if (auto a = ngraph::as_type<ngraph::AttributeAdapter<ov::Dimension>>(&adapter)) {
|
||||
m_values.insert(name, a->get());
|
||||
} else if (auto a = ngraph::as_type<ngraph::AttributeAdapter<std::shared_ptr<Variable>>>(&adapter)) {
|
||||
m_values.insert(name, a->get());
|
||||
} else {
|
||||
NGRAPH_CHECK(false, "Attribute \"", name, "\" cannot be marshalled");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/opsets/opset3.hpp"
|
||||
#include "ngraph/opsets/opset6.hpp"
|
||||
#include "util/visitor.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
using ngraph::test::NodeBuilder;
|
||||
using ngraph::test::ValueMap;
|
||||
|
||||
TEST(attributes, assign_v3_op) {
|
||||
NodeBuilder::get_ops().register_factory<opset3::Assign>();
|
||||
const auto in = make_shared<op::Parameter>(element::f32, Shape{1});
|
||||
const string variable_id = "v0";
|
||||
const auto read_value = make_shared<opset3::ReadValue>(in, variable_id);
|
||||
const auto assign = make_shared<opset3::Assign>(read_value, variable_id);
|
||||
NodeBuilder builder(assign);
|
||||
|
||||
// attribute count
|
||||
const auto expected_attr_count = 1;
|
||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||
}
|
||||
|
||||
TEST(attributes, assign_v6_op) {
|
||||
NodeBuilder::get_ops().register_factory<opset6::Assign>();
|
||||
const auto in = make_shared<op::Parameter>(element::f32, Shape{1});
|
||||
const auto variable = std::make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "v0"});
|
||||
const auto read_value = make_shared<opset6::ReadValue>(in, variable);
|
||||
const auto assign = make_shared<opset6::Assign>(read_value, variable);
|
||||
NodeBuilder builder(assign);
|
||||
|
||||
// attribute count
|
||||
const auto expected_attr_count = 1;
|
||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/opsets/opset3.hpp"
|
||||
#include "ngraph/opsets/opset6.hpp"
|
||||
#include "util/visitor.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
using ngraph::test::NodeBuilder;
|
||||
using ngraph::test::ValueMap;
|
||||
|
||||
TEST(attributes, readvalue_v3_op) {
|
||||
NodeBuilder::get_ops().register_factory<opset3::ReadValue>();
|
||||
const auto in = make_shared<op::Parameter>(element::f32, Shape{1});
|
||||
const string variable_id = "v0";
|
||||
const auto read_value = make_shared<opset3::ReadValue>(in, variable_id);
|
||||
NodeBuilder builder(read_value);
|
||||
|
||||
// attribute count
|
||||
const auto expected_attr_count = 1;
|
||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||
}
|
||||
|
||||
TEST(attributes, readvalue_v6_op) {
|
||||
NodeBuilder::get_ops().register_factory<opset6::ReadValue>();
|
||||
const auto in = make_shared<op::Parameter>(element::f32, Shape{1});
|
||||
const auto variable = std::make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "v0"});
|
||||
const auto read_value = make_shared<opset6::ReadValue>(in, variable);
|
||||
NodeBuilder builder(read_value);
|
||||
|
||||
// attribute count
|
||||
const auto expected_attr_count = 1;
|
||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||
}
|
||||
Loading…
Reference in New Issue