Fixed Minimum op if u8/16/32/64 data type is used (#6665)
This commit is contained in:
parent
0d76993429
commit
bdaa44d0be
112
docs/template_plugin/tests/functional/op_reference/minimum.cpp
Normal file
112
docs/template_plugin/tests/functional/op_reference/minimum.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#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 <tuple>
|
||||
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace ngraph;
|
||||
using namespace InferenceEngine;
|
||||
using namespace reference_tests;
|
||||
|
||||
struct MinimumParams {
|
||||
template <class IT, class OT>
|
||||
MinimumParams(const PartialShape& s,
|
||||
const element::Type& iType, const element::Type& oType,
|
||||
const std::vector<IT>& iValues1, const std::vector<IT>& iValues2,
|
||||
const std::vector<OT>& oValues)
|
||||
: pshape(s),
|
||||
inType(iType),
|
||||
outType(oType),
|
||||
inputData1(CreateBlob(iType, iValues1)),
|
||||
inputData2(CreateBlob(iType, iValues2)),
|
||||
refData(CreateBlob(oType, oValues)) {}
|
||||
PartialShape pshape;
|
||||
element::Type inType;
|
||||
element::Type outType;
|
||||
Blob::Ptr inputData1;
|
||||
Blob::Ptr inputData2;
|
||||
Blob::Ptr refData;
|
||||
};
|
||||
|
||||
class ReferenceMinimumLayerTest : public testing::TestWithParam<MinimumParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.pshape, params.inType);
|
||||
inputData = {params.inputData1, params.inputData2};
|
||||
refOutData = {params.refData};
|
||||
}
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<MinimumParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "shape=" << param.pshape << "_";
|
||||
result << "iType=" << param.inType << "_";
|
||||
result << "oType=" << param.outType;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const PartialShape& shape, const element::Type& data_type) {
|
||||
auto A = std::make_shared<op::Parameter>(data_type, shape);
|
||||
auto B = std::make_shared<op::Parameter>(data_type, shape);
|
||||
return std::make_shared<Function>(std::make_shared<op::v1::Minimum>(A, B), ParameterVector{A, B});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceMinimumLayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_Minimum, ReferenceMinimumLayerTest, ::testing::Values(
|
||||
MinimumParams(PartialShape {8},
|
||||
element::u8,
|
||||
element::u8,
|
||||
std::vector<uint8_t> {1, 8, 8, 17, 5, 5, 2, 3},
|
||||
std::vector<uint8_t> {1, 2, 4, 8, 0, 2, 1, 200},
|
||||
std::vector<uint8_t> {1, 2, 4, 8, 0, 2, 1, 3}),
|
||||
MinimumParams(PartialShape {8},
|
||||
element::u16,
|
||||
element::u16,
|
||||
std::vector<uint16_t> {1, 8, 8, 17, 5, 7, 123, 3},
|
||||
std::vector<uint16_t> {1, 2, 4, 8, 0, 2, 1, 1037},
|
||||
std::vector<uint16_t> {1, 2, 4, 8, 0, 2, 1, 3}),
|
||||
MinimumParams(PartialShape {8},
|
||||
element::u32,
|
||||
element::u32,
|
||||
std::vector<uint32_t> {1, 8, 8, 17, 5, 5, 2, 1},
|
||||
std::vector<uint32_t> {1, 2, 4, 8, 0, 2, 1, 222},
|
||||
std::vector<uint32_t> {1, 2, 4, 8, 0, 2, 1, 1}),
|
||||
MinimumParams(PartialShape {8},
|
||||
element::u64,
|
||||
element::u64,
|
||||
std::vector<uint64_t> {1, 8, 8, 17, 5, 5, 2, 13},
|
||||
std::vector<uint64_t> {1, 2, 4, 8, 0, 2, 1, 2222},
|
||||
std::vector<uint64_t> {1, 2, 4, 8, 0, 2, 1, 13}),
|
||||
MinimumParams(PartialShape {8},
|
||||
element::f32,
|
||||
element::f32,
|
||||
std::vector<float> {1, 8, -8, 17, -0.5, 0.5, 2, 1},
|
||||
std::vector<float> {1, 2, 4, 8, 0, 0, 1, 1.5},
|
||||
std::vector<float> {1, 2, -8, 8, -.5, 0, 1, 1}),
|
||||
MinimumParams(PartialShape {8},
|
||||
element::i32,
|
||||
element::i32,
|
||||
std::vector<int32_t> {1, 8, -8, 17, -5, 67635216, 2, 1},
|
||||
std::vector<int32_t> {1, 2, 4, 8, 0, 18448, 1, 6},
|
||||
std::vector<int32_t> {1, 2, -8, 8, -5, 18448, 1, 1}),
|
||||
MinimumParams(PartialShape {8},
|
||||
element::i64,
|
||||
element::i64,
|
||||
std::vector<int64_t> {1, 8, -8, 17, -5, 67635216, 2, 17179887632},
|
||||
std::vector<int64_t> {1, 2, 4, 8, 0, 18448, 1, 280592},
|
||||
std::vector<int64_t> {1, 2, -8, 8, -5, 18448, 1, 280592})),
|
||||
ReferenceMinimumLayerTest::getTestCaseName);
|
@ -62,6 +62,7 @@
|
||||
#include <transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.hpp>
|
||||
#include <transformations/op_conversions/convert_deformable_conv_v8_to_v1.hpp>
|
||||
#include <transformations/smart_reshape/matmul_sr.hpp>
|
||||
#include <transformations/op_conversions/convert_minimum_to_power_and_max.hpp>
|
||||
#include <transformations/convert_precision.hpp>
|
||||
#include <transformations/init_node_info.hpp>
|
||||
#include <transformations/rt_info/fused_names_attribute.hpp>
|
||||
@ -321,6 +322,7 @@ static void TransformationUpToCPUSpecificOpSet(std::shared_ptr<ngraph::Function>
|
||||
pass_config->disable<ngraph::pass::WeightsDequantizeToFakeQuantize>();
|
||||
pass_config->disable<ngraph::pass::SimplifyCTCGreedyDecoderSeqLen>();
|
||||
pass_config->disable<ngraph::pass::ConvertGather7ToGather1>();
|
||||
pass_config->disable<ngraph::pass::ConvertMinimum>();
|
||||
|
||||
pass_config->enable<ngraph::pass::NormalizeL2Decomposition>();
|
||||
pass_config->enable<ngraph::pass::ConvertInterpolate1ToInterpolate4>();
|
||||
|
@ -20,7 +20,7 @@ ngraph::pass::ConvertMinimum::ConvertMinimum() {
|
||||
|
||||
ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) {
|
||||
auto minimum = std::dynamic_pointer_cast<ngraph::opset1::Minimum> (m.get_match_root());
|
||||
if (!minimum || transformation_callback(minimum)) {
|
||||
if (!minimum || transformation_callback(minimum) || !minimum->get_output_element_type(0).is_signed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,8 @@ bool evaluate_minimum(const HostTensorPtr& arg0,
|
||||
switch (arg0->get_element_type()) {
|
||||
NGRAPH_TYPE_CASE(evaluate_minimum, i32, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_minimum, i64, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_minimum, u8, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_minimum, u16, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_minimum, u32, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_minimum, u64, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_minimum, f16, arg0, arg1, out, broadcast_spec);
|
||||
|
@ -468,7 +468,6 @@ set(MULTI_TEST_SRC
|
||||
backend/matrix_nms.in.cpp
|
||||
backend/maximum.in.cpp
|
||||
backend/max_pool.in.cpp
|
||||
backend/minimum.in.cpp
|
||||
backend/mish.in.cpp
|
||||
backend/mod.in.cpp
|
||||
backend/multiclass_nms.in.cpp
|
||||
|
@ -1,99 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
// clang-format off
|
||||
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
|
||||
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
|
||||
#endif
|
||||
|
||||
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
|
||||
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "util/engine/test_engines.hpp"
|
||||
#include "util/test_case.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, minimum) {
|
||||
Shape shape{2, 2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto f = make_shared<Function>(make_shared<op::v1::Minimum>(A, B), ParameterVector{A, B});
|
||||
|
||||
std::vector<float> a{1, 8, -8, 17, -0.5, 0.5, 2, 1};
|
||||
std::vector<float> b{1, 2, 4, 8, 0, 0, 1, 1.5};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_multiple_inputs<float>({a, b});
|
||||
test_case.add_expected_output<float>(shape, {1, 2, -8, 8, -.5, 0, 1, 1});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, minimum_int32) {
|
||||
Shape shape{2, 2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::i32, shape);
|
||||
auto f = make_shared<Function>(make_shared<op::v1::Minimum>(A, B), ParameterVector{A, B});
|
||||
|
||||
std::vector<int32_t> a{1, 8, -8, 17, -5, 67635216, 2, 1};
|
||||
std::vector<int32_t> b{1, 2, 4, 8, 0, 18448, 1, 6};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_multiple_inputs<int32_t>({a, b});
|
||||
test_case.add_expected_output<int32_t>(shape, {1, 2, -8, 8, -5, 18448, 1, 1});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, minimum_int64) {
|
||||
Shape shape{2, 2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::i64, shape);
|
||||
auto B = make_shared<op::Parameter>(element::i64, shape);
|
||||
auto f = make_shared<Function>(make_shared<op::v1::Minimum>(A, B), ParameterVector{A, B});
|
||||
|
||||
std::vector<int64_t> a{1, 8, -8, 17, -5, 67635216, 2, 17179887632};
|
||||
std::vector<int64_t> b{1, 2, 4, 8, 0, 18448, 1, 280592};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_multiple_inputs<int64_t>({a, b});
|
||||
test_case.add_expected_output<int64_t>(shape, {1, 2, -8, 8, -5, 18448, 1, 280592});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
// TODO Refactor to use TestCase if u16 will be handled correctly
|
||||
NGRAPH_TEST(${BACKEND_NAME}, minimum_u16) {
|
||||
const Shape shape{3};
|
||||
const auto A = make_shared<op::Parameter>(element::u16, shape);
|
||||
const auto B = make_shared<op::Parameter>(element::u16, shape);
|
||||
auto f = make_shared<Function>(make_shared<op::v1::Minimum>(A, B), ParameterVector{A, B});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::u16, shape);
|
||||
copy_data(a, std::vector<uint16_t>{3, 2, 1});
|
||||
auto b = backend->create_tensor(element::u16, shape);
|
||||
copy_data(b, std::vector<uint16_t>{1, 4, 4});
|
||||
auto result = backend->create_tensor(element::u16, shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b});
|
||||
|
||||
EXPECT_TRUE(test::all_close((std::vector<uint16_t>{1, 2, 1}), read_vector<uint16_t>(result)));
|
||||
}
|
@ -1493,8 +1493,6 @@ IE_GPU.onnx_model_gather_elements_float_3D_axis_2
|
||||
# not supported fp16 blob input
|
||||
IE_CPU.evaluate_ctc_greedy_decoder_seq_len_f16
|
||||
|
||||
# incorrect result for Minimum if u16 type is used
|
||||
minimum_u16
|
||||
IE_CPU/ElemTypesTests/1.onnx_test_add_abc_set_precission
|
||||
|
||||
# not yet implemented on CPU/GPU Gather 7
|
||||
|
@ -24,14 +24,97 @@ namespace
|
||||
const auto expected_data = expected->rmap();
|
||||
|
||||
const auto* computed_data_buffer = computed_data.template as<const T*>();
|
||||
const auto* expected_data_buffer = expected_data.template as<const T*>();
|
||||
|
||||
std::vector<T> computed_values(computed_data_buffer,
|
||||
computed_data_buffer + computed->size());
|
||||
|
||||
switch (static_cast<InferenceEngine::Precision::ePrecision>(expected->getTensorDesc().getPrecision()))
|
||||
{
|
||||
case InferenceEngine::Precision::FP32: {
|
||||
const auto* expected_data_buffer = expected_data.template as<const float *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::FP64: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const double *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::I8: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const int8_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::I16: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const int16_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::I32: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const int32_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::I64: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const int64_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::U8: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const uint8_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::U16: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const uint16_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::U32: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const uint32_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::U64: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const uint64_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::BOOL: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const uint8_t *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
case InferenceEngine::Precision::BF16: {
|
||||
const auto *expected_data_buffer = expected_data.template as<const bfloat16 *>();
|
||||
std::vector<T> expected_values(expected_data_buffer,
|
||||
expected_data_buffer + computed->size());
|
||||
return std::make_pair(std::move(computed_values), std::move(expected_values));
|
||||
break;
|
||||
}
|
||||
default: THROW_IE_EXCEPTION << "Not implemented yet";
|
||||
}
|
||||
}
|
||||
|
||||
/// Compares two blobs containing floating point elements.
|
||||
@ -87,12 +170,6 @@ namespace
|
||||
const size_t tolerance_bits)
|
||||
{
|
||||
const auto& computed_precision = computed->getTensorDesc().getPrecision();
|
||||
const auto& expected_precision = expected->getTensorDesc().getPrecision();
|
||||
|
||||
if (computed_precision != expected_precision)
|
||||
{
|
||||
return testing::AssertionFailure() << "Blob precisions mismatch";
|
||||
}
|
||||
|
||||
switch (static_cast<InferenceEngine::Precision::ePrecision>(computed_precision))
|
||||
{
|
||||
|
@ -96,7 +96,6 @@ xfail_issue_44957 = xfail_test(reason="Expected: Unsupported dynamic op: NonZero
|
||||
xfail_issue_44958 = xfail_test(reason="Expected: Unsupported dynamic op: Interpolate")
|
||||
xfail_issue_44965 = xfail_test(reason="Expected: RuntimeError: value info has no element")
|
||||
xfail_issue_44968 = xfail_test(reason="Expected: Unsupported dynamic op: Squeeze")
|
||||
xfail_issue_46762 = xfail_test(reason="Incorrect result of Minimum op if uint data type is used")
|
||||
xfail_issue_47323 = xfail_test(reason="RuntimeError: The plugin does not support FP64")
|
||||
xfail_issue_47337 = xfail_test(reason="RuntimeError: Unsupported dynamic ops: v1::OneHot")
|
||||
xfail_issue_33593 = xfail_test(reason="Current implementation of MaxPool doesn't support indices output")
|
||||
|
@ -45,7 +45,6 @@ from tests import (
|
||||
xfail_issue_44968,
|
||||
xfail_issue_45180,
|
||||
xfail_issue_45344,
|
||||
xfail_issue_46762,
|
||||
xfail_issue_47323,
|
||||
xfail_issue_47337,
|
||||
xfail_issue_48052,
|
||||
@ -183,13 +182,6 @@ tests_expected_to_fail = [
|
||||
"OnnxBackendNodeModelTest.test_top_k_smallest_cpu",
|
||||
),
|
||||
(xfail_issue_33633, "OnnxBackendNodeModelTest.test_maxpool_2d_dilations_cpu"),
|
||||
(
|
||||
xfail_issue_46762,
|
||||
"OnnxBackendNodeModelTest.test_min_uint8_cpu",
|
||||
"OnnxBackendNodeModelTest.test_min_uint16_cpu",
|
||||
"OnnxBackendNodeModelTest.test_min_uint32_cpu",
|
||||
"OnnxBackendNodeModelTest.test_min_uint64_cpu",
|
||||
),
|
||||
(
|
||||
xfail_issue_55760,
|
||||
"OnnxBackendNodeModelTest.test_argmax_negative_axis_keepdims_example_select_last_index_cpu",
|
||||
|
Loading…
Reference in New Issue
Block a user