Skip to content

Commit

Permalink
Reference tests use OpenVINO 2.0 headers and namespaces (openvinotool…
Browse files Browse the repository at this point in the history
…kit#7700)

* Reference tests via OpenVINO 2.0

* Migrated to new API acos test

* Fixed other tests compilation

* Fixed tests

* Reference tests use ov::

* Fixed compilation
  • Loading branch information
ilya-lavrenov authored Sep 28, 2021
1 parent eee864a commit 65dcffe
Show file tree
Hide file tree
Showing 54 changed files with 727 additions and 991 deletions.
13 changes: 4 additions & 9 deletions docs/template_plugin/tests/functional/op_reference/acos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>
#include <vector>

#include "openvino/op/acos.hpp"
#include "base_reference_test.hpp"

using namespace ngraph;
using namespace ov;

namespace reference_tests {
namespace {
Expand Down Expand Up @@ -45,8 +40,8 @@ class ReferenceAcosLayerTest : public testing::TestWithParam<AcosParams>, public

private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto acos = std::make_shared<op::Acos>(in);
const auto in = std::make_shared<op::v0::Parameter>(type, shape);
const auto acos = std::make_shared<op::v0::Acos>(in);
return std::make_shared<Function>(NodeVector {acos}, ParameterVector {in});
}
};
Expand Down
12 changes: 5 additions & 7 deletions docs/template_plugin/tests/functional/op_reference/acosh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

#include <gtest/gtest.h>

#include <shared_test_classes/base/layer_test_utils.hpp>
#include <vector>

#include "openvino/op/acosh.hpp"
#include "base_reference_test.hpp"

using namespace ngraph;
using namespace ov;

namespace reference_tests {
namespace {
Expand Down Expand Up @@ -42,9 +40,9 @@ class ReferenceAcoshLayerTest : public testing::TestWithParam<AcoshParams>, publ

private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto acosh = std::make_shared<op::Acosh>(in);
return std::make_shared<Function>(NodeVector {acosh}, ParameterVector {in});
const auto in = std::make_shared<op::v0::Parameter>(type, shape);
const auto acosh = std::make_shared<op::v3::Acosh>(in);
return std::make_shared<ov::Function>(NodeVector {acosh}, ParameterVector {in});
}
};

Expand Down
16 changes: 6 additions & 10 deletions docs/template_plugin/tests/functional/op_reference/asin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>
#include <vector>

#include "openvino/op/asin.hpp"
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "base_reference_test.hpp"

using namespace ngraph;
using namespace ov;

namespace reference_tests {
namespace {
Expand Down Expand Up @@ -45,9 +41,9 @@ class ReferenceAsinLayerTest : public testing::TestWithParam<AsinParams>, public

private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Asin = std::make_shared<op::Asin>(in);
return std::make_shared<Function>(NodeVector {Asin}, ParameterVector {in});
const auto in = std::make_shared<op::v0::Parameter>(type, shape);
const auto Asin = std::make_shared<op::v0::Asin>(in);
return std::make_shared<ov::Function>(NodeVector {Asin}, ParameterVector {in});
}
};

Expand Down
16 changes: 6 additions & 10 deletions docs/template_plugin/tests/functional/op_reference/asinh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>
#include <vector>

#include "openvino/op/asinh.hpp"
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "base_reference_test.hpp"

using namespace ngraph;
using namespace ov;

namespace reference_tests {
namespace {
Expand Down Expand Up @@ -45,9 +41,9 @@ class ReferenceAsinhLayerTest : public testing::TestWithParam<AsinhParams>, publ

private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto Asinh = std::make_shared<op::Asinh>(in);
return std::make_shared<Function>(NodeVector {Asinh}, ParameterVector {in});
const auto in = std::make_shared<op::v0::Parameter>(type, shape);
const auto Asinh = std::make_shared<op::v3::Asinh>(in);
return std::make_shared<ov::Function>(NodeVector {Asinh}, ParameterVector {in});
}
};

Expand Down
15 changes: 5 additions & 10 deletions docs/template_plugin/tests/functional/op_reference/atan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>
#include <vector>

#include "openvino/op/atan.hpp"
#include "base_reference_test.hpp"

using namespace ngraph;
using namespace ov;

namespace reference_tests {
namespace {
Expand Down Expand Up @@ -45,9 +40,9 @@ class ReferenceAtanLayerTest : public testing::TestWithParam<AtanParams>, public

private:
static std::shared_ptr<Function> CreateFunction(const Shape& shape, const element::Type& type) {
const auto in = std::make_shared<op::Parameter>(type, shape);
const auto atan = std::make_shared<op::Atan>(in);
return std::make_shared<Function>(NodeVector{atan}, ParameterVector{in});
const auto in = std::make_shared<op::v0::Parameter>(type, shape);
const auto atan = std::make_shared<op::v0::Atan>(in);
return std::make_shared<ov::Function>(NodeVector{atan}, ParameterVector{in});
}
};

Expand Down
40 changes: 17 additions & 23 deletions docs/template_plugin/tests/functional/op_reference/atanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@
//

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <limits>
#include <algorithm>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>

#include "openvino/op/atanh.hpp"
#include "base_reference_test.hpp"
#include "openvino/runtime/allocator.hpp"

using namespace reference_tests;
using namespace ngraph;
using namespace InferenceEngine;
using namespace ov;

struct AtanhParams {
template <class IT>
AtanhParams(const ngraph::PartialShape& shape, const ngraph::element::Type& iType, const std::vector<IT>& iValues)
: pshape(shape), inType(iType), outType(iType), inputData(CreateBlob(iType, iValues)) {
AtanhParams(const ov::PartialShape& shape, const ov::element::Type& iType, const std::vector<IT>& iValues)
: pshape(shape), inType(iType), outType(iType), inputData(CreateTensor(iType, iValues)) {
std::vector<IT> oValues;
std::vector<double> output;
for (auto element : iValues)
Expand All @@ -39,11 +33,11 @@ struct AtanhParams {

for (auto element : output)
oValues.push_back(static_cast<IT>(element));
refData = CreateBlob(outType, oValues);
refData = CreateTensor(outType, oValues);
}
ngraph::PartialShape pshape;
ngraph::element::Type inType;
ngraph::element::Type outType;
ov::PartialShape pshape;
ov::element::Type inType;
ov::element::Type outType;
ov::runtime::Tensor inputData;
ov::runtime::Tensor refData;
};
Expand All @@ -68,9 +62,9 @@ class ReferenceAtanhLayerTest : public testing::TestWithParam<AtanhParams>, publ
private:
static std::shared_ptr<Function> CreateFunction(const PartialShape& input_shape, const element::Type& input_type,
const element::Type& expected_output_type) {
const auto in = std::make_shared<op::Parameter>(input_type, input_shape);
const auto atanh = std::make_shared<op::Atanh>(in);
return std::make_shared<Function>(NodeVector {atanh}, ParameterVector {in});
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
const auto atanh = std::make_shared<op::v3::Atanh>(in);
return std::make_shared<ov::Function>(NodeVector {atanh}, ParameterVector {in});
}
};

Expand All @@ -80,16 +74,16 @@ TEST_P(ReferenceAtanhLayerTest, CompareWithRefs) {

INSTANTIATE_TEST_SUITE_P(
smoke_Atanh_With_Hardcoded_Refs, ReferenceAtanhLayerTest,
::testing::Values(AtanhParams(ngraph::PartialShape {2, 4}, ngraph::element::f32,
::testing::Values(AtanhParams(ov::PartialShape {2, 4}, ov::element::f32,
std::vector<float> {-INFINITY, -2.0f, -1.0f, -0.5f, 0.0f, 0.8f, 1.0f, INFINITY}),
AtanhParams(ngraph::PartialShape {2, 4}, ngraph::element::f16,
AtanhParams(ov::PartialShape {2, 4}, ov::element::f16,
std::vector<float16> {-INFINITY, -2.0f, -1.0f, -0.5f, -0.0f, 0.8f, 1.0f, INFINITY}),
AtanhParams(ngraph::PartialShape {2, 3}, ngraph::element::i32,
AtanhParams(ov::PartialShape {2, 3}, ov::element::i32,
std::vector<int32_t> {std::numeric_limits<int32_t>::min(), -2, -1, 1, 2, std::numeric_limits<int32_t>::max()}),
AtanhParams(ngraph::PartialShape {2, 3}, ngraph::element::u32,
AtanhParams(ov::PartialShape {2, 3}, ov::element::u32,
std::vector<uint32_t> {std::numeric_limits<uint32_t>::min(), 0, 1, 2, 3, std::numeric_limits<uint32_t>::max()}),
AtanhParams(ngraph::PartialShape {2, 3}, ngraph::element::i64,
AtanhParams(ov::PartialShape {2, 3}, ov::element::i64,
std::vector<int64_t> {std::numeric_limits<int64_t>::min(), -2, -1, 1, 2, std::numeric_limits<int64_t>::max()}),
AtanhParams(ngraph::PartialShape {2, 3}, ngraph::element::u64,
AtanhParams(ov::PartialShape {2, 3}, ov::element::u64,
std::vector<uint64_t> {std::numeric_limits<uint64_t>::min(), 0, 1, 2, 3, std::numeric_limits<uint64_t>::max()})),
ReferenceAtanhLayerTest::getTestCaseName);
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
#include "base_reference_test.hpp"
#include "functional_test_utils/ov_plugin_cache.hpp"
#include "shared_test_classes/base/layer_test_utils.hpp"

#include <gtest/gtest.h>

Expand All @@ -11,7 +12,7 @@
#include "openvino/runtime/tensor.hpp"
#include "transformations/utils/utils.hpp"

using namespace InferenceEngine;
using namespace ov;

namespace reference_tests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <ngraph/ngraph.hpp>
#include "openvino/core/shape.hpp"
#include "openvino/runtime/allocator.hpp"
#include "openvino/runtime/tensor.hpp"
#include "openvino/runtime/core.hpp"
#include "openvino/core/type/element_type.hpp"

#include <shared_test_classes/base/layer_test_utils.hpp>

namespace reference_tests {

class CommonReferenceTest {
public:
CommonReferenceTest();

void Exec();

void LoadNetwork();

void FillInputs();

void Infer();

void Validate();

private:
Expand All @@ -43,7 +36,7 @@ class CommonReferenceTest {
};

template <class T>
ov::runtime::Tensor CreateBlob(const ov::element::Type& element_type, const std::vector<T>& values, size_t size = 0) {
ov::runtime::Tensor CreateTensor(const ov::element::Type& element_type, const std::vector<T>& values, size_t size = 0) {
size_t real_size = size ? size : values.size() * sizeof(T) / element_type.size();
ov::runtime::Tensor tensor { element_type, {real_size} };
std::memcpy(tensor.data(), values.data(), std::min(real_size * element_type.size(), sizeof(T) * values.size()));
Expand All @@ -61,7 +54,7 @@ struct Tensor {

template <typename T>
Tensor(const ov::Shape& shape, ov::element::Type type, const std::vector<T>& data_elements)
: Tensor {shape, type, CreateBlob(type, data_elements)} {}
: Tensor {shape, type, CreateTensor(type, data_elements)} {}

ov::Shape shape;
ov::element::Type type;
Expand Down
20 changes: 8 additions & 12 deletions docs/template_plugin/tests/functional/op_reference/comparison.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>
#include <vector>

#include "base_reference_test.hpp"
#include "ngraph_functions/builders.hpp"

using namespace ov;

namespace reference_tests {
namespace ComparisonOpsRefTestDefinitions {

Expand Down Expand Up @@ -50,13 +46,13 @@ class ReferenceComparisonLayerTest : public testing::TestWithParam<RefComparison
}

private:
static std::shared_ptr<ngraph::Function> CreateFunction(ngraph::helpers::ComparisonTypes comp_op_type, const ngraph::PartialShape& input_shape1,
const ngraph::PartialShape& input_shape2, const ngraph::element::Type& input_type,
const ngraph::element::Type& expected_output_type) {
const auto in = std::make_shared<ngraph::op::Parameter>(input_type, input_shape1);
const auto in2 = std::make_shared<ngraph::op::Parameter>(input_type, input_shape2);
static std::shared_ptr<ov::Function> CreateFunction(ngraph::helpers::ComparisonTypes comp_op_type, const ov::PartialShape& input_shape1,
const ov::PartialShape& input_shape2, const ov::element::Type& input_type,
const ov::element::Type& expected_output_type) {
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape1);
const auto in2 = std::make_shared<op::v0::Parameter>(input_type, input_shape2);
const auto comp = ngraph::builder::makeComparison(in, in2, comp_op_type);
return std::make_shared<ngraph::Function>(ngraph::NodeVector {comp}, ngraph::ParameterVector {in, in2});
return std::make_shared<ov::Function>(ov::NodeVector {comp}, ov::ParameterVector {in, in2});
}
};
} // namespace ComparisonOpsRefTestDefinitions
Expand Down
32 changes: 14 additions & 18 deletions docs/template_plugin/tests/functional/op_reference/conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>
#include <vector>

#include "base_reference_test.hpp"
#include "ngraph_functions/builders.hpp"

using namespace ov;

namespace reference_tests {
namespace ConversionOpsRefTestDefinitions {

Expand All @@ -23,14 +19,14 @@ static std::map<ngraph::helpers::ConversionTypes, std::string> conversionNames =

struct ConvertParams {
template <class IT, class OT>
ConvertParams(ngraph::helpers::ConversionTypes convType, const ngraph::PartialShape& shape, const ngraph::element::Type& iType,
const ngraph::element::Type& oType, const std::vector<IT>& iValues, const std::vector<OT>& oValues, size_t iSize = 0, size_t oSize = 0)
: conversionType(convType), pshape(shape), inType(iType), outType(oType), inputData(CreateBlob(iType, iValues, iSize)),
refData(CreateBlob(oType, oValues, oSize)) {}
ConvertParams(ngraph::helpers::ConversionTypes convType, const ov::PartialShape& shape, const ov::element::Type& iType,
const ov::element::Type& oType, const std::vector<IT>& iValues, const std::vector<OT>& oValues, size_t iSize = 0, size_t oSize = 0)
: conversionType(convType), pshape(shape), inType(iType), outType(oType), inputData(CreateTensor(iType, iValues, iSize)),
refData(CreateTensor(oType, oValues, oSize)) {}
ngraph::helpers::ConversionTypes conversionType;
ngraph::PartialShape pshape;
ngraph::element::Type inType;
ngraph::element::Type outType;
ov::PartialShape pshape;
ov::element::Type inType;
ov::element::Type outType;
ov::runtime::Tensor inputData;
ov::runtime::Tensor refData;
};
Expand All @@ -55,12 +51,12 @@ class ReferenceConversionLayerTest : public testing::TestWithParam<ConvertParams
}

private:
static std::shared_ptr<ngraph::Function> CreateFunction(const ngraph::PartialShape& input_shape, const ngraph::element::Type& input_type,
const ngraph::element::Type& expected_output_type,
const ngraph::helpers::ConversionTypes& conversion_type) {
const auto in = std::make_shared<ngraph::op::Parameter>(input_type, input_shape);
static std::shared_ptr<ov::Function> CreateFunction(const ov::PartialShape& input_shape, const ov::element::Type& input_type,
const ov::element::Type& expected_output_type,
const ngraph::helpers::ConversionTypes& conversion_type) {
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
const auto convert = ngraph::builder::makeConversion(in, expected_output_type, conversion_type);
return std::make_shared<ngraph::Function>(ngraph::NodeVector {convert}, ngraph::ParameterVector {in});
return std::make_shared<ov::Function>(ov::NodeVector {convert}, ov::ParameterVector {in});
}
};
} // namespace ConversionOpsRefTestDefinitions
Expand Down
Loading

0 comments on commit 65dcffe

Please sign in to comment.