Move memory tests from core to template plugin tests (#16460)
* Move memory tests from core to template plugin tests * Rewrite tests to use template plugin * Don't clone model in INTExecutable * Add reset and modify tests * Delete old test * Fix clang-format * Fix VariableState::set_state * Enable and add var modify tests * Fix INTExecutable * Apply comments
This commit is contained in:
parent
341217de99
commit
66ea57addd
@ -27,13 +27,6 @@ list(APPEND UNIT_TESTS_DEPENDENCIES openvino_template_extension)
|
||||
list(APPEND UNIT_TESTS_DEPENDENCIES template_extension)
|
||||
|
||||
list(APPEND EXCLUDE_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/dnnl.cpp)
|
||||
if (ENABLE_TEMPLATE)
|
||||
list(APPEND UNIT_TESTS_DEPENDENCIES openvino_template_plugin)
|
||||
else()
|
||||
list(APPEND EXCLUDE_TESTS
|
||||
# It should be a part of template plugin
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/op_eval/memory.cpp)
|
||||
endif()
|
||||
|
||||
ov_add_test_target(
|
||||
NAME ${TARGET_NAME}
|
||||
|
@ -1,296 +0,0 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "engines_util/execute_tools.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/op/util/variable.hpp"
|
||||
#include "ngraph/op/util/variable_context.hpp"
|
||||
#include "ngraph/opsets/opset7.hpp"
|
||||
#include "ngraph/util.hpp"
|
||||
#include "ngraph/validation_util.hpp"
|
||||
#include "util/all_close_f.hpp"
|
||||
#include "util/test_tools.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
using namespace ngraph::opset7;
|
||||
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
|
||||
shared_ptr<ngraph::Function> AssignReadGraph() {
|
||||
auto p = make_shared<op::Parameter>(element::f32, Shape{3});
|
||||
auto variable = make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "var_1"});
|
||||
auto read_value = make_shared<ReadValue>(p, variable);
|
||||
auto assign = make_shared<Assign>(read_value, variable);
|
||||
return make_shared<Function>(OutputVector{assign}, ParameterVector{p}, VariableVector{variable});
|
||||
}
|
||||
|
||||
shared_ptr<ngraph::Function> AssignReadAddGraph() {
|
||||
auto p = make_shared<op::Parameter>(element::f32, Shape{3});
|
||||
auto c = std::make_shared<Constant>(element::f32, Shape{3}, std::vector<float>({0, 0, 0}));
|
||||
auto variable = make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "var_1"});
|
||||
auto read_value = make_shared<ReadValue>(c, variable);
|
||||
auto add = make_shared<Add>(p, read_value);
|
||||
auto assign = make_shared<Assign>(add, variable);
|
||||
return make_shared<Function>(OutputVector{assign}, ParameterVector{p}, VariableVector{variable});
|
||||
}
|
||||
|
||||
shared_ptr<ngraph::Function> AssignReadMultiVariableGraph() {
|
||||
auto c = std::make_shared<Constant>(element::f32, Shape{3}, std::vector<float>({0, 0, 0}));
|
||||
|
||||
auto variable = make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "var_1"});
|
||||
auto variable_2 = make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "var_2"});
|
||||
|
||||
auto read_value = make_shared<ReadValue>(c, variable);
|
||||
auto read_value_2 = make_shared<ReadValue>(c, variable_2);
|
||||
|
||||
auto add = make_shared<Add>(read_value_2, read_value);
|
||||
|
||||
auto assign = make_shared<Assign>(add, variable);
|
||||
auto assign_2 = make_shared<Assign>(read_value_2, variable_2);
|
||||
|
||||
return make_shared<Function>(OutputVector{assign}, ParameterVector{}, VariableVector{variable, variable_2});
|
||||
}
|
||||
|
||||
TEST(op_eval, assign_readvalue_without_evaluation_context) {
|
||||
auto fun = AssignReadGraph();
|
||||
auto result = make_shared<HostTensor>();
|
||||
|
||||
const int COUNT_RUNS = 10;
|
||||
std::vector<float> inputs{-5, 0, 5};
|
||||
std::vector<float> expected_result{0, 0, 0};
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor<element::Type_t::f32>(Shape{3}, inputs)}));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(op_eval, assign_readvalue_evaluation_context) {
|
||||
auto fun = AssignReadGraph();
|
||||
auto result = make_shared<HostTensor>();
|
||||
const auto& variables = fun->get_variables();
|
||||
EXPECT_EQ(variables.size(), 1);
|
||||
|
||||
std::vector<float> inputs{-5, 0, 5};
|
||||
std::vector<float> expected_result{0, 0, 0};
|
||||
|
||||
EvaluationContext eval_context;
|
||||
HostTensorPtr h_tensor = make_host_tensor<element::Type_t::f32>(Shape{3}, inputs);
|
||||
VariableContext variable_context;
|
||||
variable_context.set_variable_value(variables[0], std::make_shared<VariableValue>(h_tensor));
|
||||
eval_context.emplace("VariableContext", variable_context);
|
||||
|
||||
const int COUNT_RUNS = 10;
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor<element::Type_t::f32>(Shape{3}, inputs)}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(op_eval, assign_readvalue_add) {
|
||||
auto fun = AssignReadAddGraph();
|
||||
const auto& variables = fun->get_variables();
|
||||
EXPECT_EQ(variables.size(), 1);
|
||||
|
||||
std::vector<float> inputs{-5, 0, 5};
|
||||
|
||||
// creating context
|
||||
EvaluationContext eval_context;
|
||||
auto variable_context = VariableContext();
|
||||
auto variable_value = make_shared<VariableValue>(make_host_tensor<element::Type_t::f32>(Shape{3}, inputs));
|
||||
variable_context.set_variable_value(variables[0], variable_value);
|
||||
eval_context.emplace("VariableContext", variable_context);
|
||||
|
||||
auto result = make_shared<HostTensor>();
|
||||
const int COUNT_RUNS = 10;
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor<element::Type_t::f32>(Shape{3}, inputs)}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
auto result_data = read_vector<float>(result);
|
||||
|
||||
auto cnt = static_cast<float>(i + 1);
|
||||
std::vector<float> expected_result{inputs[0] * cnt, inputs[1] * cnt, inputs[2] * cnt};
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(op_eval, assign_readvalue_reset_before_evaluate) {
|
||||
auto fun = AssignReadAddGraph();
|
||||
const auto& variables = fun->get_variables();
|
||||
EXPECT_EQ(variables.size(), 1);
|
||||
|
||||
std::vector<float> inputs{-5, 0, 5};
|
||||
|
||||
// creating context
|
||||
EvaluationContext eval_context;
|
||||
auto variable_context = VariableContext();
|
||||
auto variable_value = make_shared<VariableValue>(make_host_tensor<element::Type_t::f32>(Shape{3}, inputs));
|
||||
variable_value->set_reset(false);
|
||||
variable_context.set_variable_value(variables[0], variable_value);
|
||||
eval_context.emplace("VariableContext", variable_context);
|
||||
|
||||
auto result = make_shared<HostTensor>();
|
||||
const int COUNT_RUNS = 10;
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor<element::Type_t::f32>(Shape{3}, inputs)}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
auto result_data = read_vector<float>(result);
|
||||
|
||||
auto cnt = static_cast<float>(i + 2);
|
||||
std::vector<float> expected_result{inputs[0] * cnt, inputs[1] * cnt, inputs[2] * cnt};
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(op_eval, assign_readvalue_add_reset) {
|
||||
auto fun = AssignReadAddGraph();
|
||||
std::vector<float> inputs{-5, 0, 5};
|
||||
const auto& variables = fun->get_variables();
|
||||
EXPECT_EQ(variables.size(), 1);
|
||||
|
||||
// creating a Context
|
||||
EvaluationContext eval_context;
|
||||
auto variable_context = VariableContext();
|
||||
auto variable_value = make_shared<VariableValue>(make_host_tensor<element::Type_t::f32>(Shape{3}, inputs));
|
||||
variable_context.set_variable_value(variables[0], variable_value);
|
||||
eval_context.emplace("VariableContext", variable_context);
|
||||
|
||||
auto result = make_shared<HostTensor>();
|
||||
const int COUNT_RUNS = 10;
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor<element::Type_t::f32>(Shape{3}, inputs)}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
auto result_data = read_vector<float>(result);
|
||||
|
||||
auto cnt = static_cast<float>(i + 1);
|
||||
std::vector<float> expected_result{inputs[0] * cnt, inputs[1] * cnt, inputs[2] * cnt};
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
|
||||
const auto& found_context = eval_context.find("VariableContext");
|
||||
EXPECT_NE(found_context, eval_context.end());
|
||||
found_context->second.as<VariableContext>().reset_variable_context();
|
||||
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor<element::Type_t::f32>(Shape{3}, inputs)}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
auto result_data = read_vector<float>(result);
|
||||
|
||||
auto cnt = static_cast<float>(i + 1);
|
||||
std::vector<float> expected_result{inputs[0] * cnt, inputs[1] * cnt, inputs[2] * cnt};
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(op_eval, assign_readvalue_add_modify) {
|
||||
auto fun = AssignReadAddGraph();
|
||||
std::vector<float> inputs{-5, 0, 5};
|
||||
const auto& variables = fun->get_variables();
|
||||
EXPECT_EQ(variables.size(), 1);
|
||||
|
||||
// creating context
|
||||
EvaluationContext eval_context;
|
||||
auto variable_context = VariableContext();
|
||||
auto variable_value = make_shared<VariableValue>(make_host_tensor<element::Type_t::f32>(Shape{3}, inputs));
|
||||
variable_context.set_variable_value(variables[0], variable_value);
|
||||
eval_context.emplace("VariableContext", variable_context);
|
||||
|
||||
auto result = make_shared<HostTensor>();
|
||||
const int COUNT_RUNS = 10;
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor<element::Type_t::f32>(Shape{3}, inputs)}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
|
||||
auto cnt = static_cast<float>(i + 1);
|
||||
std::vector<float> expected_result{inputs[0] * cnt, inputs[1] * cnt, inputs[2] * cnt};
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
|
||||
const auto& found_context = eval_context.find("VariableContext");
|
||||
EXPECT_NE(found_context, eval_context.end());
|
||||
const auto& var_value = found_context->second.as<VariableContext>().get_variable_value(variables[0]);
|
||||
EXPECT_NE(var_value, nullptr);
|
||||
var_value->set_value(make_host_tensor<element::Type_t::f32>(Shape{3}, {1, 2, 3}));
|
||||
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {make_host_tensor<element::Type_t::f32>(Shape{3}, inputs)}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
|
||||
auto cnt = static_cast<float>(i + 1);
|
||||
std::vector<float> expected_result{1 + inputs[0] * cnt, 2 + inputs[1] * cnt, 3 + inputs[2] * cnt};
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(op_eval, assign_readvalue_add_modify_multi_variables) {
|
||||
auto fun = AssignReadMultiVariableGraph();
|
||||
std::vector<float> inputs_1{2, 2, 2};
|
||||
std::vector<float> inputs_2{1, 3, 5};
|
||||
auto var_1 = fun->get_variable_by_id("var_1");
|
||||
auto var_2 = fun->get_variable_by_id("var_2");
|
||||
EXPECT_NE(var_1, nullptr);
|
||||
EXPECT_NE(var_2, nullptr);
|
||||
|
||||
// creating context
|
||||
EvaluationContext eval_context;
|
||||
auto variable_context = VariableContext();
|
||||
auto variable_value_1 = make_shared<VariableValue>(make_host_tensor<element::Type_t::f32>(Shape{3}, inputs_1));
|
||||
auto variable_value_2 = make_shared<VariableValue>(make_host_tensor<element::Type_t::f32>(Shape{3}, inputs_2));
|
||||
variable_value_1->set_reset(false);
|
||||
variable_value_2->set_reset(false);
|
||||
variable_context.set_variable_value(var_1, variable_value_1);
|
||||
variable_context.set_variable_value(var_2, variable_value_2);
|
||||
eval_context.emplace("VariableContext", variable_context);
|
||||
|
||||
auto result = make_shared<HostTensor>();
|
||||
const int COUNT_RUNS = 10;
|
||||
|
||||
std::vector<float> expected_result = inputs_1;
|
||||
for (size_t i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
|
||||
for (size_t j = 0; j < expected_result.size(); ++j) {
|
||||
expected_result[j] += inputs_2[j];
|
||||
}
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
|
||||
const auto& found_context = eval_context.find("VariableContext");
|
||||
EXPECT_NE(found_context, eval_context.end());
|
||||
auto var_context = found_context->second.as<VariableContext>();
|
||||
|
||||
auto var_value = variable_context.get_variable_value(var_1);
|
||||
EXPECT_NE(var_value, nullptr);
|
||||
var_value->set_value(make_host_tensor<element::Type_t::f32>(Shape{3}, {1, 2, 3}));
|
||||
|
||||
auto var_value_2 = variable_context.get_variable_value(var_2);
|
||||
EXPECT_NE(var_value_2, nullptr);
|
||||
var_value_2->set_reset(true);
|
||||
|
||||
expected_result = {1, 2, 3};
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
ASSERT_TRUE(fun->evaluate({result}, {}, eval_context));
|
||||
EXPECT_EQ(result->get_element_type(), element::f32);
|
||||
EXPECT_EQ(result->get_shape(), Shape{3});
|
||||
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(result), expected_result));
|
||||
}
|
||||
}
|
@ -51,6 +51,10 @@ public:
|
||||
/// \returns an ngraph::ResultVector of all input parameters
|
||||
const ov::ResultVector& get_results() const;
|
||||
|
||||
/// \brief Query the internal model
|
||||
/// \returns model which is used inside executable
|
||||
virtual std::shared_ptr<ov::Model> get_model() const = 0;
|
||||
|
||||
/// \brief Create an input Tensor
|
||||
/// \param input_index The index position in the input Parameter vector. This would be the same
|
||||
/// order of Parameters passed into the inputs in the call() method.
|
||||
|
@ -274,3 +274,7 @@ bool ov::runtime::interpreter::INTExecutable::evaluate_node(const std::shared_pt
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::shared_ptr<ov::Model> ov::runtime::interpreter::INTExecutable::get_model() const {
|
||||
return m_model;
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ public:
|
||||
|
||||
std::vector<ov::Tensor> create_output_tensor(size_t output_index, size_t pipeline_depth) override;
|
||||
|
||||
std::shared_ptr<ov::Model> get_model() const override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ov::op::v0::Parameter> get_parameter(size_t index) const;
|
||||
std::shared_ptr<ov::op::v0::Result> get_result(size_t index) const;
|
||||
|
@ -79,8 +79,7 @@ ov::template_plugin::InferRequest::InferRequest(const std::shared_ptr<const ov::
|
||||
|
||||
// Save variable states
|
||||
ov::op::util::VariableContext variable_context;
|
||||
for (const auto& variable : get_template_model()->m_model->get_variables()) {
|
||||
auto value = std::make_shared<ov::op::util::VariableValue>();
|
||||
for (const auto& variable : m_executable->get_model()->get_variables()) {
|
||||
if (!variable_context.get_variable_value(variable)) {
|
||||
auto shape = variable->get_info().data_shape.is_dynamic() ? ov::Shape{0}
|
||||
: variable->get_info().data_shape.to_shape();
|
||||
|
@ -12,8 +12,15 @@ namespace template_plugin {
|
||||
class VariableState : public ov::IVariableState {
|
||||
public:
|
||||
VariableState(const std::string& name, const ov::Tensor& tensor) : ov::IVariableState(name) {
|
||||
set_state(tensor);
|
||||
m_state = tensor;
|
||||
}
|
||||
void set_state(const ov::Tensor& state) override {
|
||||
OPENVINO_ASSERT(state.get_shape() == m_state.get_shape(), "Wrong tensor shape.");
|
||||
OPENVINO_ASSERT(state.get_element_type() == state.get_element_type(), "Wrong tensor type.");
|
||||
OPENVINO_ASSERT(state.get_byte_size() == state.get_byte_size(), "Blob size of tensors are not equal.");
|
||||
std::memcpy(m_state.data(), state.data(), state.get_byte_size());
|
||||
}
|
||||
|
||||
void reset() override {
|
||||
std::memset(m_state.data(), 0, m_state.get_byte_size());
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "base_reference_test.hpp"
|
||||
#include "functional_test_utils/ov_plugin_cache.hpp"
|
||||
#include "openvino/op/add.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/read_value.hpp"
|
||||
#include "openvino/op/util/variable.hpp"
|
||||
@ -107,10 +109,20 @@ private:
|
||||
|
||||
TEST_P(ReferenceReadValueAssignV3LayerTest, ReadValueAssignWithHardcodedRefs) {
|
||||
Exec();
|
||||
const int COUNT_RUNS = 10;
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
Infer();
|
||||
Validate();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ReferenceReadValueAssignV6LayerTest, ReadValueAssignWithHardcodedRefs) {
|
||||
Exec();
|
||||
const int COUNT_RUNS = 10;
|
||||
for (int i = 0; i < COUNT_RUNS; ++i) {
|
||||
Infer();
|
||||
Validate();
|
||||
}
|
||||
}
|
||||
|
||||
template <element::Type_t IN_ET>
|
||||
@ -141,7 +153,13 @@ 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{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,
|
||||
@ -197,3 +215,806 @@ INSTANTIATE_TEST_SUITE_P(smoke_ReadValue_Assign_With_Hardcoded_Refs,
|
||||
ReferenceReadValueAssignV6LayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
struct MemoryTestParams {
|
||||
template <class IT>
|
||||
MemoryTestParams(const ov::Shape& input_shape,
|
||||
const ov::Shape& output_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const ov::element::Type& ouput_type,
|
||||
const std::vector<IT>& input_values,
|
||||
const std::vector<std::vector<IT>>& output_values,
|
||||
const size_t& count_runs,
|
||||
const std::vector<std::string>& variable_id,
|
||||
const size_t& reset_on_run = 0)
|
||||
: m_input_shape(input_shape),
|
||||
m_output_shape(output_shape),
|
||||
m_input_type(input_type),
|
||||
m_output_type(ouput_type),
|
||||
m_input_data(reference_tests::CreateTensor(input_shape, input_type, input_values)),
|
||||
m_expected_data(reference_tests::CreateTensor(output_shape, ouput_type, output_values[0])),
|
||||
m_variable_id(variable_id),
|
||||
m_count_runs(count_runs),
|
||||
m_reset_on_run(reset_on_run) {
|
||||
for (size_t i = 0; i < m_count_runs; i++) {
|
||||
m_expected_data_vector.push_back(reference_tests::CreateTensor(output_shape, ouput_type, output_values[i]));
|
||||
}
|
||||
}
|
||||
ov::Shape m_input_shape;
|
||||
ov::Shape m_output_shape;
|
||||
ov::element::Type m_input_type;
|
||||
ov::element::Type m_output_type;
|
||||
ov::runtime::Tensor m_input_data;
|
||||
ov::runtime::Tensor m_expected_data;
|
||||
std::vector<std::string> m_variable_id;
|
||||
size_t m_count_runs;
|
||||
size_t m_reset_on_run;
|
||||
std::vector<ov::Tensor> m_expected_data_vector;
|
||||
};
|
||||
|
||||
class ReferenceMemoryTest : public testing::TestWithParam<MemoryTestParams> {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<MemoryTestParams>& 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();
|
||||
}
|
||||
|
||||
protected:
|
||||
const std::string targetDevice;
|
||||
std::shared_ptr<ov::Core> core;
|
||||
std::shared_ptr<ov::Model> function;
|
||||
ov::CompiledModel executableNetwork;
|
||||
ov::InferRequest inferRequest;
|
||||
|
||||
ReferenceMemoryTest() : targetDevice("TEMPLATE"), function(), executableNetwork(), inferRequest() {
|
||||
core = ov::test::utils::PluginCache::get().core(targetDevice);
|
||||
};
|
||||
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.m_input_shape, params.m_input_type, params.m_variable_id);
|
||||
executableNetwork = core->compile_model(function, targetDevice);
|
||||
inferRequest = executableNetwork.create_infer_request();
|
||||
}
|
||||
|
||||
void CommonTestSteps(const std::function<void(size_t, ov::InferRequest&)>& custom_step = nullptr) {
|
||||
auto params = GetParam();
|
||||
|
||||
const auto& functionParams = function->get_parameters();
|
||||
inferRequest.set_tensor(executableNetwork.input(0), params.m_input_data);
|
||||
for (size_t i = 0; i < params.m_count_runs; ++i) {
|
||||
if (custom_step) {
|
||||
custom_step(i, inferRequest);
|
||||
}
|
||||
inferRequest.infer();
|
||||
auto actualOutData = inferRequest.get_tensor(executableNetwork.output(0));
|
||||
reference_tests::CommonReferenceTest::ValidateBlobs(params.m_expected_data_vector[i],
|
||||
actualOutData,
|
||||
i,
|
||||
1e-2f,
|
||||
-1.f,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<ov::Model> CreateFunction(const ov::Shape& input_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const std::vector<std::string>& variable_id) = 0;
|
||||
};
|
||||
|
||||
std::shared_ptr<ov::Model> CreateFunction_ReadValueAssingAdd(const ov::Shape& input_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const std::vector<std::string>& variable_id) {
|
||||
auto in = std::make_shared<ov::op::v0::Parameter>(input_type, input_shape);
|
||||
auto c = std::make_shared<ov::op::v0::Constant>(input_type, input_shape, 0);
|
||||
auto variable = std::make_shared<ov::op::util::Variable>(
|
||||
ov::op::util::VariableInfo{ov::PartialShape::dynamic(), ov::element::dynamic, variable_id[0]});
|
||||
auto read_value = std::make_shared<ov::op::v6::ReadValue>(c, variable);
|
||||
auto add = std::make_shared<ov::op::v1::Add>(in, read_value);
|
||||
auto assign = std::make_shared<ov::op::v6::Assign>(add, variable);
|
||||
return std::make_shared<ov::Model>(ov::OutputVector{assign},
|
||||
ov::ParameterVector{in},
|
||||
ov::op::util::VariableVector{variable});
|
||||
}
|
||||
|
||||
std::shared_ptr<ov::Model> CreateFunction_ReadValueAssingAddMultiVariable(const ov::Shape& input_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const std::vector<std::string>& variable_id) {
|
||||
auto in = std::make_shared<ov::op::v0::Parameter>(input_type, input_shape);
|
||||
auto variable1 = std::make_shared<ov::op::util::Variable>(
|
||||
ov::op::util::VariableInfo{ov::PartialShape::dynamic(), ov::element::dynamic, variable_id[0]});
|
||||
auto variable2 = std::make_shared<ov::op::util::Variable>(
|
||||
ov::op::util::VariableInfo{ov::PartialShape::dynamic(), ov::element::dynamic, variable_id[1]});
|
||||
auto read_value1 = std::make_shared<ov::op::v6::ReadValue>(in, variable1);
|
||||
auto read_value2 = std::make_shared<ov::op::v6::ReadValue>(in, variable2);
|
||||
auto add1 = std::make_shared<ov::op::v1::Add>(read_value1, read_value2);
|
||||
auto add2 = std::make_shared<ov::op::v1::Add>(in, add1);
|
||||
auto assign1 = std::make_shared<ov::op::v6::Assign>(add2, variable1);
|
||||
auto assign2 = std::make_shared<ov::op::v6::Assign>(read_value2, variable2);
|
||||
return std::make_shared<ov::Model>(ov::OutputVector{assign1},
|
||||
ov::SinkVector{assign2},
|
||||
ov::ParameterVector{in},
|
||||
ov::op::util::VariableVector{variable1, variable2});
|
||||
}
|
||||
|
||||
class ReferenceReadValueAssignAddLayerTest : public ReferenceMemoryTest {
|
||||
protected:
|
||||
std::shared_ptr<ov::Model> CreateFunction(const ov::Shape& input_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const std::vector<std::string>& variable_id) override {
|
||||
return CreateFunction_ReadValueAssingAdd(input_shape, input_type, variable_id);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceReadValueAssignAddLayerTest, MemoryWithHardcodedRefs) {
|
||||
CommonTestSteps();
|
||||
}
|
||||
|
||||
template <ov::element::Type_t IN_ET>
|
||||
std::vector<MemoryTestParams> generateParamsForReadValueAssignAdd() {
|
||||
using T = typename ov::element_type_traits<IN_ET>::value_type;
|
||||
size_t count_runs = 10;
|
||||
|
||||
std::vector<T> first_result_shape1 = {1};
|
||||
std::vector<T> first_result_shape22 = {1, 2, 3, 4};
|
||||
std::vector<T> first_result_shape123 = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
std::vector<T> new_result_shape1(1, T(0));
|
||||
std::vector<T> new_result_shape22(4, T(0));
|
||||
std::vector<T> new_result_shape123(6, T(0));
|
||||
|
||||
std::vector<std::vector<T>> result_shape1;
|
||||
std::vector<std::vector<T>> result_shape22;
|
||||
std::vector<std::vector<T>> result_shape123;
|
||||
|
||||
for (size_t i = 0; i < count_runs; i++) {
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
result_shape1.push_back(new_result_shape1);
|
||||
result_shape22.push_back(new_result_shape22);
|
||||
result_shape123.push_back(new_result_shape123);
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> params{MemoryTestParams(ov::Shape{1},
|
||||
ov::Shape{1},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1},
|
||||
result_shape1,
|
||||
count_runs,
|
||||
{"v0"}),
|
||||
MemoryTestParams(ov::Shape{2, 2},
|
||||
ov::Shape{2, 2},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4},
|
||||
result_shape22,
|
||||
count_runs,
|
||||
{"v0"}),
|
||||
MemoryTestParams(ov::Shape{1, 2, 3},
|
||||
ov::Shape{1, 2, 3},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6},
|
||||
result_shape123,
|
||||
count_runs,
|
||||
{"v0"})};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> generateCombinedParamsForReadValueAssignAdd() {
|
||||
const std::vector<std::vector<MemoryTestParams>> allTypeParams{
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::f32>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::f16>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::bf16>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::i64>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::i32>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::i16>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::i8>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::u64>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::u32>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::u16>(),
|
||||
generateParamsForReadValueAssignAdd<ov::element::Type_t::u8>()};
|
||||
|
||||
std::vector<MemoryTestParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Memory_With_Hardcoded_Refs,
|
||||
ReferenceReadValueAssignAddLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReadValueAssignAdd()),
|
||||
ReferenceReadValueAssignAddLayerTest::getTestCaseName);
|
||||
|
||||
class ReferenceReadValueAssignAddMultiVariableLayerTest : public ReferenceMemoryTest {
|
||||
protected:
|
||||
std::shared_ptr<ov::Model> CreateFunction(const ov::Shape& input_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const std::vector<std::string>& variable_id) override {
|
||||
return CreateFunction_ReadValueAssingAddMultiVariable(input_shape, input_type, variable_id);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceReadValueAssignAddMultiVariableLayerTest, MemoryWithHardcodedRefs) {
|
||||
CommonTestSteps();
|
||||
}
|
||||
|
||||
template <ov::element::Type_t IN_ET>
|
||||
std::vector<MemoryTestParams> ReadValueAssignAddMultiVariableLayer() {
|
||||
using T = typename ov::element_type_traits<IN_ET>::value_type;
|
||||
size_t count_runs = 10;
|
||||
|
||||
std::vector<T> first_result_shape1 = {1};
|
||||
std::vector<T> first_result_shape22 = {1, 2, 3, 4};
|
||||
std::vector<T> first_result_shape123 = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
std::vector<T> new_result_shape1(1, T(0));
|
||||
std::vector<T> new_result_shape22(4, T(0));
|
||||
std::vector<T> new_result_shape123(6, T(0));
|
||||
|
||||
std::vector<std::vector<T>> result_shape1;
|
||||
std::vector<std::vector<T>> result_shape22;
|
||||
std::vector<std::vector<T>> result_shape123;
|
||||
|
||||
for (size_t i = 0; i < count_runs; i++) {
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
result_shape1.push_back(new_result_shape1);
|
||||
result_shape22.push_back(new_result_shape22);
|
||||
result_shape123.push_back(new_result_shape123);
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> params{MemoryTestParams(ov::Shape{1},
|
||||
ov::Shape{1},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1},
|
||||
result_shape1,
|
||||
count_runs,
|
||||
{"v0", "v1"}),
|
||||
MemoryTestParams(ov::Shape{2, 2},
|
||||
ov::Shape{2, 2},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4},
|
||||
result_shape22,
|
||||
count_runs,
|
||||
{"v0", "v1"}),
|
||||
MemoryTestParams(ov::Shape{1, 2, 3},
|
||||
ov::Shape{1, 2, 3},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6},
|
||||
result_shape123,
|
||||
count_runs,
|
||||
{"v0", "v1"})};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> generateCombinedParamsForReadValueAssignAddMultiVariableLayer() {
|
||||
const std::vector<std::vector<MemoryTestParams>> allTypeParams{
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::f32>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::f16>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::bf16>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::i64>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::i32>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::i16>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::i8>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::u64>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::u32>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::u16>(),
|
||||
ReadValueAssignAddMultiVariableLayer<ov::element::Type_t::u8>()};
|
||||
|
||||
std::vector<MemoryTestParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Memory_With_Hardcoded_Refs,
|
||||
ReferenceReadValueAssignAddMultiVariableLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReadValueAssignAddMultiVariableLayer()),
|
||||
ReferenceReadValueAssignAddMultiVariableLayerTest::getTestCaseName);
|
||||
|
||||
class ReferenceReadValueAssignAddResetLayerTest : public ReferenceMemoryTest {
|
||||
protected:
|
||||
std::shared_ptr<ov::Model> CreateFunction(const ov::Shape& input_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const std::vector<std::string>& variable_id) override {
|
||||
return CreateFunction_ReadValueAssingAdd(input_shape, input_type, variable_id);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceReadValueAssignAddResetLayerTest, MemoryResetWithHardcodedRefs) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto reset_var = [&](size_t iter, ov::InferRequest& inferRequest) {
|
||||
if (params.m_reset_on_run == iter) {
|
||||
auto vars = inferRequest.query_state();
|
||||
for (auto& var : vars) {
|
||||
var.reset();
|
||||
}
|
||||
}
|
||||
};
|
||||
CommonTestSteps(reset_var);
|
||||
}
|
||||
|
||||
template <ov::element::Type_t IN_ET>
|
||||
std::vector<MemoryTestParams> generateParamsForReadValueAssignAddReset() {
|
||||
using T = typename ov::element_type_traits<IN_ET>::value_type;
|
||||
size_t count_runs = 10;
|
||||
size_t reset_on_run = 5;
|
||||
|
||||
std::vector<T> first_result_shape1 = {1};
|
||||
std::vector<T> first_result_shape22 = {1, 2, 3, 4};
|
||||
std::vector<T> first_result_shape123 = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
std::vector<T> new_result_shape1(1, T(0));
|
||||
std::vector<T> new_result_shape22(4, T(0));
|
||||
std::vector<T> new_result_shape123(6, T(0));
|
||||
|
||||
std::vector<std::vector<T>> result_shape1;
|
||||
std::vector<std::vector<T>> result_shape22;
|
||||
std::vector<std::vector<T>> result_shape123;
|
||||
|
||||
for (size_t i = 0; i < count_runs - reset_on_run; i++) {
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
result_shape1.push_back(new_result_shape1);
|
||||
result_shape22.push_back(new_result_shape22);
|
||||
result_shape123.push_back(new_result_shape123);
|
||||
}
|
||||
|
||||
new_result_shape1 = std::vector<T>(1, T(0));
|
||||
new_result_shape22 = std::vector<T>(4, T(0));
|
||||
new_result_shape123 = std::vector<T>(6, T(0));
|
||||
|
||||
for (size_t i = count_runs - reset_on_run; i < count_runs; i++) {
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
result_shape1.push_back(new_result_shape1);
|
||||
result_shape22.push_back(new_result_shape22);
|
||||
result_shape123.push_back(new_result_shape123);
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> params{MemoryTestParams(ov::Shape{1},
|
||||
ov::Shape{1},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1},
|
||||
result_shape1,
|
||||
count_runs,
|
||||
{"v0"},
|
||||
reset_on_run),
|
||||
MemoryTestParams(ov::Shape{2, 2},
|
||||
ov::Shape{2, 2},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4},
|
||||
result_shape22,
|
||||
count_runs,
|
||||
{"v0"},
|
||||
reset_on_run),
|
||||
MemoryTestParams(ov::Shape{1, 2, 3},
|
||||
ov::Shape{1, 2, 3},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6},
|
||||
result_shape123,
|
||||
count_runs,
|
||||
{"v0"},
|
||||
reset_on_run)};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> generateCombinedParamsForReadValueAssignAddReset() {
|
||||
const std::vector<std::vector<MemoryTestParams>> allTypeParams{
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::f32>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::f16>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::bf16>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::i64>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::i32>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::i16>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::i8>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::u64>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::u32>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::u16>(),
|
||||
generateParamsForReadValueAssignAddReset<ov::element::Type_t::u8>()};
|
||||
|
||||
std::vector<MemoryTestParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Memory_With_Hardcoded_Refs,
|
||||
ReferenceReadValueAssignAddResetLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReadValueAssignAddReset()),
|
||||
ReferenceReadValueAssignAddResetLayerTest::getTestCaseName);
|
||||
|
||||
|
||||
class ReferenceReadValueAssignAddModifyLayerTest : public ReferenceMemoryTest {
|
||||
protected:
|
||||
std::shared_ptr<ov::Model> CreateFunction(const ov::Shape& input_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const std::vector<std::string>& variable_id) override {
|
||||
return CreateFunction_ReadValueAssingAdd(input_shape, input_type, variable_id);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceReadValueAssignAddModifyLayerTest, MemoryResetWithHardcodedRefs) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto reset_var = [&](size_t iter, ov::InferRequest& inferRequest) {
|
||||
if (params.m_reset_on_run == iter) {
|
||||
auto vars = inferRequest.query_state();
|
||||
for (auto& var : vars) {
|
||||
var.set_state(params.m_input_data);
|
||||
}
|
||||
}
|
||||
};
|
||||
CommonTestSteps(reset_var);
|
||||
}
|
||||
|
||||
template <ov::element::Type_t IN_ET>
|
||||
std::vector<MemoryTestParams> generateParamsForReadValueAssignAddModify() {
|
||||
using T = typename ov::element_type_traits<IN_ET>::value_type;
|
||||
size_t count_runs = 10;
|
||||
size_t reset_on_run = 5;
|
||||
|
||||
std::vector<T> first_result_shape1 = {1};
|
||||
std::vector<T> first_result_shape22 = {1, 2, 3, 4};
|
||||
std::vector<T> first_result_shape123 = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
std::vector<T> new_result_shape1(1, T(0));
|
||||
std::vector<T> new_result_shape22(4, T(0));
|
||||
std::vector<T> new_result_shape123(6, T(0));
|
||||
|
||||
std::vector<std::vector<T>> result_shape1;
|
||||
std::vector<std::vector<T>> result_shape22;
|
||||
std::vector<std::vector<T>> result_shape123;
|
||||
|
||||
for (size_t i = 0; i < count_runs - reset_on_run; i++) {
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
result_shape1.push_back(new_result_shape1);
|
||||
result_shape22.push_back(new_result_shape22);
|
||||
result_shape123.push_back(new_result_shape123);
|
||||
}
|
||||
|
||||
new_result_shape1 = std::vector<T>(1, T(0));
|
||||
new_result_shape22 = std::vector<T>(4, T(0));
|
||||
new_result_shape123 = std::vector<T>(6, T(0));
|
||||
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
|
||||
for (size_t i = count_runs - reset_on_run; i < count_runs; i++) {
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
result_shape1.push_back(new_result_shape1);
|
||||
result_shape22.push_back(new_result_shape22);
|
||||
result_shape123.push_back(new_result_shape123);
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> params{MemoryTestParams(ov::Shape{1},
|
||||
ov::Shape{1},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1},
|
||||
result_shape1,
|
||||
count_runs,
|
||||
{"v0"},
|
||||
reset_on_run),
|
||||
MemoryTestParams(ov::Shape{2, 2},
|
||||
ov::Shape{2, 2},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4},
|
||||
result_shape22,
|
||||
count_runs,
|
||||
{"v0"},
|
||||
reset_on_run),
|
||||
MemoryTestParams(ov::Shape{1, 2, 3},
|
||||
ov::Shape{1, 2, 3},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6},
|
||||
result_shape123,
|
||||
count_runs,
|
||||
{"v0"},
|
||||
reset_on_run)};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> generateCombinedParamsForReadValueAssignAddModify() {
|
||||
const std::vector<std::vector<MemoryTestParams>> allTypeParams{
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::f32>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::f16>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::bf16>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::i64>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::i32>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::i16>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::i8>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::u64>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::u32>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::u16>(),
|
||||
generateParamsForReadValueAssignAddModify<ov::element::Type_t::u8>()};
|
||||
|
||||
std::vector<MemoryTestParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Memory_With_Hardcoded_Refs,
|
||||
ReferenceReadValueAssignAddModifyLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReadValueAssignAddModify()),
|
||||
ReferenceReadValueAssignAddModifyLayerTest::getTestCaseName);
|
||||
|
||||
|
||||
class ReferenceReadValueAssignAddMultiVariableModifyLayerTest : public ReferenceMemoryTest {
|
||||
protected:
|
||||
std::shared_ptr<ov::Model> CreateFunction(const ov::Shape& input_shape,
|
||||
const ov::element::Type& input_type,
|
||||
const std::vector<std::string>& variable_id) override {
|
||||
return CreateFunction_ReadValueAssingAddMultiVariable(input_shape, input_type, variable_id);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceReadValueAssignAddMultiVariableModifyLayerTest, MemoryResetWithHardcodedRefs) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto reset_var = [&](size_t iter, ov::InferRequest& inferRequest) {
|
||||
if (params.m_reset_on_run == iter) {
|
||||
auto vars = inferRequest.query_state();
|
||||
vars[1].set_state(params.m_input_data);
|
||||
}
|
||||
};
|
||||
CommonTestSteps(reset_var);
|
||||
}
|
||||
|
||||
template <ov::element::Type_t IN_ET>
|
||||
std::vector<MemoryTestParams> generateParamsForReadValueAssignAddMultiVariableModify() {
|
||||
using T = typename ov::element_type_traits<IN_ET>::value_type;
|
||||
size_t count_runs = 10;
|
||||
size_t reset_on_run = 5;
|
||||
|
||||
std::vector<T> first_result_shape1 = {1};
|
||||
std::vector<T> first_result_shape22 = {1, 2, 3, 4};
|
||||
std::vector<T> first_result_shape123 = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
std::vector<T> new_result_shape1(1, T(0));
|
||||
std::vector<T> new_result_shape22(4, T(0));
|
||||
std::vector<T> new_result_shape123(6, T(0));
|
||||
|
||||
std::vector<std::vector<T>> result_shape1;
|
||||
std::vector<std::vector<T>> result_shape22;
|
||||
std::vector<std::vector<T>> result_shape123;
|
||||
|
||||
for (size_t i = 0; i < count_runs - reset_on_run; i++) {
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
result_shape1.push_back(new_result_shape1);
|
||||
result_shape22.push_back(new_result_shape22);
|
||||
result_shape123.push_back(new_result_shape123);
|
||||
}
|
||||
|
||||
std::transform(first_result_shape1.begin(),
|
||||
first_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
first_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(first_result_shape22.begin(),
|
||||
first_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
first_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(first_result_shape123.begin(),
|
||||
first_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
first_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
|
||||
for (size_t i = count_runs - reset_on_run; i < count_runs; i++) {
|
||||
std::transform(new_result_shape1.begin(),
|
||||
new_result_shape1.end(),
|
||||
first_result_shape1.begin(),
|
||||
new_result_shape1.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape22.begin(),
|
||||
new_result_shape22.end(),
|
||||
first_result_shape22.begin(),
|
||||
new_result_shape22.begin(),
|
||||
std::plus<T>());
|
||||
std::transform(new_result_shape123.begin(),
|
||||
new_result_shape123.end(),
|
||||
first_result_shape123.begin(),
|
||||
new_result_shape123.begin(),
|
||||
std::plus<T>());
|
||||
result_shape1.push_back(new_result_shape1);
|
||||
result_shape22.push_back(new_result_shape22);
|
||||
result_shape123.push_back(new_result_shape123);
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> params{MemoryTestParams(ov::Shape{1},
|
||||
ov::Shape{1},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1},
|
||||
result_shape1,
|
||||
count_runs,
|
||||
{"v0", "v1"},
|
||||
reset_on_run),
|
||||
MemoryTestParams(ov::Shape{2, 2},
|
||||
ov::Shape{2, 2},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4},
|
||||
result_shape22,
|
||||
count_runs,
|
||||
{"v0", "v1"},
|
||||
reset_on_run),
|
||||
MemoryTestParams(ov::Shape{1, 2, 3},
|
||||
ov::Shape{1, 2, 3},
|
||||
IN_ET,
|
||||
IN_ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6},
|
||||
result_shape123,
|
||||
count_runs,
|
||||
{"v0", "v1"},
|
||||
reset_on_run)};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<MemoryTestParams> generateCombinedParamsForReadValueAssignAddMultiVariableModify() {
|
||||
const std::vector<std::vector<MemoryTestParams>> allTypeParams{
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::f32>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::f16>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::bf16>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::i64>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::i32>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::i16>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::i8>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::u64>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::u32>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::u16>(),
|
||||
generateParamsForReadValueAssignAddMultiVariableModify<ov::element::Type_t::u8>()};
|
||||
|
||||
std::vector<MemoryTestParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Memory_With_Hardcoded_Refs,
|
||||
ReferenceReadValueAssignAddMultiVariableModifyLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReadValueAssignAddMultiVariableModify()),
|
||||
ReferenceReadValueAssignAddMultiVariableModifyLayerTest::getTestCaseName);
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user