Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise equal #6605

Merged
merged 48 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3695668
update spec, init backend file for equal op
bszmelcz Jul 6, 2021
3aa834a
add backend, visitors, serialize SLT tests
bszmelcz Jul 12, 2021
65b80b5
add backend test to manifest cause of mismatch of output type with cp…
bszmelcz Jul 12, 2021
fbf6f25
add equal to list of trusted ops and to cmakelist file
bszmelcz Jul 12, 2021
34ba342
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 12, 2021
fbadb6c
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 13, 2021
efc4ff7
refactor backend tests to the new template
bszmelcz Jul 13, 2021
3faca3d
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 13, 2021
793bdd5
refactor spec
bszmelcz Jul 13, 2021
b1bc99e
remove external link in numpy broadcast and update example
bszmelcz Jul 14, 2021
2ecc7bb
remove comparison.in.cpp file and related tests from manifest
bszmelcz Jul 14, 2021
b00deae
fix example
bszmelcz Jul 14, 2021
5a507aa
remove redundant arguments
bszmelcz Jul 15, 2021
272bfd3
refactor backend tests
bszmelcz Jul 16, 2021
46b7b8c
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 16, 2021
0500e47
add pdpd broadcast to the spec, and different precison to SLT test
bszmelcz Jul 19, 2021
8b5b8fe
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 19, 2021
733f163
add precisions to SLT cpu
bszmelcz Jul 19, 2021
22cf028
remove unsupported type from SLT
bszmelcz Jul 20, 2021
efbea92
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 20, 2021
9a4066f
revert the deletion of comparison.in.cpp file
bszmelcz Jul 21, 2021
f6bf464
remove visitors test, since it will be added in the other PR
bszmelcz Jul 21, 2021
42de433
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 21, 2021
3d3dc1e
remove equal from CMakeLists.txt
bszmelcz Jul 21, 2021
1ff8382
Merge branch 'master' into revise_equal
bszmelcz Jul 21, 2021
742a6b7
refactor links in the spec
bszmelcz Jul 21, 2021
8aae5da
Merge branch 'revise_equal' of https://github.com/bszmelcz/openvino i…
bszmelcz Jul 21, 2021
6618750
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 21, 2021
aca2b14
revert unwanted changes
bszmelcz Jul 21, 2021
86f0571
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 21, 2021
de87c8e
remove equal from unit test manifest
bszmelcz Jul 21, 2021
79a1296
revert links modification in spec
bszmelcz Jul 22, 2021
ed1a22b
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 22, 2021
f86e183
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 23, 2021
eb60224
add namespace
bszmelcz Jul 26, 2021
194bf7d
merge upstream/master
bszmelcz Jul 26, 2021
db837a5
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Jul 27, 2021
c1eb17f
split SSLTs for comaprison ops into seperate files
bszmelcz Aug 3, 2021
cd4b5d0
merge upstream/master
bszmelcz Aug 3, 2021
d8facf8
fix SSLTs names
bszmelcz Aug 4, 2021
41d5f47
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Aug 4, 2021
87fd32b
add missing new lines
bszmelcz Aug 5, 2021
bd26cc7
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Aug 5, 2021
0d2274c
udpate output type in spec
bszmelcz Aug 5, 2021
8299f02
rafactor numeric backend test to template
bszmelcz Aug 7, 2021
0f41ff0
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Aug 7, 2021
d672d32
Merge remote-tracking branch 'upstream/master' into revise_equal
bszmelcz Aug 9, 2021
54d6f57
merge numeric template tests into equal
bszmelcz Aug 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions docs/ops/comparison/Equal_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,50 @@

**Category**: Comparison binary operation

**Short description**: *Equal* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules.
**Short description**: *Equal* performs element-wise comparison operation with two given input tensors applying multi-directional broadcast rules specified in the *auto_broadcast* attribute.

**Detailed description**
Before performing arithmetic operation, input tensors *a* and *b* are broadcasted if their shapes are different and *auto_broadcast* attributes is not *none*. Broadcasting is performed according to *auto_broadcast* value.

After broadcasting *Equal* does the following with the input tensors *a* and *b*:

\f[
o_{i} = a_{i} == b_{i}
\f]

**Attributes**:
bszmelcz marked this conversation as resolved.
Show resolved Hide resolved

* *auto_broadcast*

* **Description**: specifies rules used for auto-broadcasting of input tensors.
* **Range of values**:
* *none* - no auto-broadcasting is allowed, all input shapes should match
* *numpy* - numpy broadcasting rules, aligned with ONNX Broadcasting. Description is available in <a href="https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md">ONNX docs</a>.
* *none* - no auto-broadcasting is allowed, all input shapes should match,
* *numpy* - numpy broadcasting rules, description is available in [Broadcast Rules For Elementwise Operations](../broadcast_rules.md),
bszmelcz marked this conversation as resolved.
Show resolved Hide resolved
* *pdpd* - PaddlePaddle-style implicit broadcasting, description is available in [Broadcast Rules For Elementwise Operations](../broadcast_rules.md).
* **Type**: string
* **Default value**: "numpy"
* **Required**: *no*

**Inputs**

* **1**: A tensor of type *T*. **Required.**
* **2**: A tensor of type *T*. **Required.**
* **1**: A tensor of type *T* and arbitrary shape. **Required.**
* **2**: A tensor of type *T* and arbitrary shape. **Required.**

**Outputs**

* **1**: The result of element-wise comparison operation. A tensor of type boolean.
* **1**: The result of element-wise **comparison** operation applied to the input tensors. A tensor of type **boolean** and the same shape equal to broadcasted shape of two inputs.
bszmelcz marked this conversation as resolved.
Show resolved Hide resolved

**Types**

* *T*: arbitrary supported type.

**Detailed description**
Before performing arithmetic operation, input tensors *a* and *b* are broadcasted if their shapes are different and `auto_broadcast` attributes is not `none`. Broadcasting is performed according to `auto_broadcast` value.

After broadcasting *Equal* does the following with the input tensors *a* and *b*:

\f[
o_{i} = a_{i} == b_{i}
\f]

bszmelcz marked this conversation as resolved.
Show resolved Hide resolved
**Examples**

*Example 1*
*Example 1: no broadcast*

```xml
<layer ... type="Equal">
<data auto_broadcast="none"/>
<input>
<port id="0">
<dim>256</dim>
Expand All @@ -65,9 +67,10 @@ o_{i} = a_{i} == b_{i}
</layer>
```

*Example 2: broadcast*
*Example 2: numpy broadcast*
```xml
<layer ... type="Equal">
<data auto_broadcast="numpy"/>
<input>
<port id="0">
<dim>8</dim>
Expand Down
114 changes: 114 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/equal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (C) 2018-2021 Intel Corporation
bszmelcz marked this conversation as resolved.
Show resolved Hide resolved
// 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;

namespace {
struct EqualParams {
template <class IT, class OT>
EqualParams(const ngraph::PartialShape& input_shape1, const ngraph::PartialShape& input_shape2 , const ngraph::element::Type& iType,
const ngraph::element::Type& oType, const std::vector<IT>& iValues1, const std::vector<IT>& iValues2, const std::vector<OT>& oValues)
: pshape1(input_shape1), pshape2(input_shape2), inType(iType), outType(oType), inputData1(CreateBlob(iType, iValues1)),
inputData2(CreateBlob(iType, iValues2)), refData(CreateBlob(oType, oValues)) {}
ngraph::PartialShape pshape1;
ngraph::PartialShape pshape2;
ngraph::element::Type inType;
ngraph::element::Type outType;
InferenceEngine::Blob::Ptr inputData1;
InferenceEngine::Blob::Ptr inputData2;
InferenceEngine::Blob::Ptr refData;
};

class ReferenceEqualLayerTest : public testing::TestWithParam<EqualParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.pshape1, params.pshape2, params.inType, params.outType);
inputData = {params.inputData1, params.inputData2};
refOutData = {params.refData};
}
static std::string getTestCaseName(const testing::TestParamInfo<EqualParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "inpt_shape1=" << param.pshape1 << "_";
result << "inpt_shape2=" << param.pshape2 << "_";
result << "iType=" << param.inType << "_";
result << "oType=" << param.outType;
return result.str();
}

private:
static std::shared_ptr<Function> CreateFunction(const PartialShape& input_shape1, const PartialShape& input_shape2, const element::Type& input_type,
const element::Type& expected_output_type) {
const auto in = std::make_shared<op::Parameter>(input_type, input_shape1);
const auto in2 = std::make_shared<op::Parameter>(input_type, input_shape2);
const auto equal = std::make_shared<op::v1::Equal>(in, in2);
return std::make_shared<Function>(NodeVector {equal}, ParameterVector {in, in2});
}
};

TEST_P(ReferenceEqualLayerTest, CompareWithHardcodedRefs) {
Exec();
}

template <element::Type_t IN_ET>
std::vector<EqualParams> generateEqualParams(const ngraph::element::Type& type) {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<EqualParams> equalParams {
// 1D // 2D // 3D // 4D
EqualParams(ngraph::PartialShape {2, 2}, ngraph::PartialShape {2, 2}, type, ngraph::element::boolean,
std::vector<T> {0, 12, 23, 0},
std::vector<T> {0, 12, 23, 0},
std::vector<char> {1, 1, 1, 1}),
EqualParams(ngraph::PartialShape {2, 3}, ngraph::PartialShape {2, 3}, type, ngraph::element::boolean,
std::vector<T> {0, 6, 45, 1, 21, 21},
std::vector<T> {1, 18, 23, 1, 19, 21},
std::vector<char> {0, 0, 0, 1, 0, 1}),
EqualParams(ngraph::PartialShape {1}, ngraph::PartialShape {1}, type, ngraph::element::boolean,
std::vector<T> {53},
std::vector<T> {53},
std::vector<char> {1}),
EqualParams(ngraph::PartialShape {2, 4}, ngraph::PartialShape {2, 4}, type, ngraph::element::boolean,
std::vector<T> {0, 12, 23, 0, 1, 5, 11, 8},
std::vector<T> {0, 12, 23, 0, 10, 5, 11, 8},
std::vector<char> {1, 1, 1, 1, 0, 1, 1, 1}),
EqualParams(ngraph::PartialShape {3, 1, 2}, ngraph::PartialShape {1, 2, 1}, type, ngraph::element::boolean,
std::vector<T> {2, 1, 4, 1, 3, 1},
std::vector<T> {1, 1},
std::vector<char> {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}),
EqualParams(ngraph::PartialShape {2, 1, 2, 1}, ngraph::PartialShape {1, 2, 1}, type, ngraph::element::boolean,
std::vector<T> {2, 1, 4, 1},
std::vector<T> {1, 1},
std::vector<char> {0, 1, 0, 1})};
return equalParams;
}

std::vector<EqualParams> generateEqualCombinedParams() {
const std::vector<std::vector<EqualParams>> equalTypeParams {generateEqualParams<element::Type_t::f32>(ngraph::element::f32),
generateEqualParams<element::Type_t::f16>(ngraph::element::f16),
generateEqualParams<element::Type_t::i32>(ngraph::element::i32),
generateEqualParams<element::Type_t::u32>(ngraph::element::u32),
generateEqualParams<element::Type_t::u8>(ngraph::element::boolean)};
std::vector<EqualParams> combinedParams;
std::for_each(equalTypeParams.begin(), equalTypeParams.end(), [&](std::vector<EqualParams> params) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
});
return combinedParams;
}

INSTANTIATE_TEST_SUITE_P(smoke_Equal_With_Hardcoded_Refs, ReferenceEqualLayerTest, ::testing::ValuesIn(generateEqualCombinedParams()),
ReferenceEqualLayerTest::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <vector>
#include "shared_test_classes/single_layer/comparison.hpp"
#include "common_test_utils/test_constants.hpp"

using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::ComparisonParams;

namespace {
TEST_P(ComparisonLayerTest, Serialize) {
Serialize();
}

std::map<std::vector<size_t>, std::vector<std::vector<size_t>>> inputShapes = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to have a separate file for each operation. We can use parametrized test, but initialization of parametrized test should be in the separate file.

Copy link
Contributor Author

@bszmelcz bszmelcz Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilyachur should I add this change in this PR, or create a new PR solely for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this PR is already pretty messy, I would suggest to create a separate PR for this task, but it is up to you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to do it in this PR in order to don't return to revising.

{{1}, {{1}, {17}, {1, 1}, {2, 18}, {1, 1, 2}, {2, 2, 3}, {1, 1, 2, 3}}},
{{5}, {{1}, {1, 1}, {2, 5}, {1, 1, 1}, {2, 2, 5}}},
{{2, 200}, {{1}, {200}, {1, 200}, {2, 200}, {2, 2, 200}}},
{{1, 3, 20}, {{20}, {2, 1, 1}}},
{{2, 17, 3, 4}, {{4}, {1, 3, 4}, {2, 1, 3, 4}}},
{{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}},
};

std::vector<InferenceEngine::Precision> inputsPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::U32,
InferenceEngine::Precision::BOOL,
};

std::vector<ngraph::helpers::ComparisonTypes> comparisonOpTypes = {
ngraph::helpers::ComparisonTypes::EQUAL,
ngraph::helpers::ComparisonTypes::NOT_EQUAL,
ngraph::helpers::ComparisonTypes::GREATER,
ngraph::helpers::ComparisonTypes::GREATER_EQUAL,
ngraph::helpers::ComparisonTypes::LESS,
ngraph::helpers::ComparisonTypes::LESS_EQUAL,
};

std::vector<ngraph::helpers::InputLayerType> secondInputTypes = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER,
};

std::map<std::string, std::string> additional_config = {};

const auto ComparisonTestParams = ::testing::Combine(
::testing::ValuesIn(CommonTestUtils::combineParams(inputShapes)),
::testing::ValuesIn(inputsPrecisions),
::testing::ValuesIn(comparisonOpTypes),
::testing::ValuesIn(secondInputTypes),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::Values(additional_config));

INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, ComparisonTestParams, ComparisonLayerTest::getTestCaseName);

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ std::map<std::vector<size_t>, std::vector<std::vector<size_t>>> inputShapes = {

std::vector<InferenceEngine::Precision> inputsPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::BOOL,
};

std::vector<ngraph::helpers::ComparisonTypes> comparisonOpTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'DepthToSpace-1',
'DetectionOutput-1',
'Divide-1',
'Equal-1',
'Erf-1',
'ExperimentalDetectronDetectionOutput-6',
'ExperimentalDetectronGenerateProposalsSingleImage-6',
Expand Down
21 changes: 0 additions & 21 deletions ngraph/test/backend/comparison.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@ using namespace ngraph;

static string s_manifest = "${MANIFEST}";

NGRAPH_TEST(${BACKEND_NAME}, equal)
{
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::Equal>(A, B), ParameterVector{A, B});

auto backend = runtime::Backend::create("${BACKEND_NAME}");

// Create some tensors for input/output
auto a = backend->create_tensor(element::f32, shape);
copy_data(a, vector<float>{1, 8, -8, 17, -0.5, 0, 1, 1});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{1, 8, 4, 8, 0, 0, 1, 1.5});
auto result = backend->create_tensor(element::boolean, shape);

auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<char>{1, 1, 0, 0, 0, 1, 1, 0}), read_vector<char>(result));
}

NGRAPH_TEST(${BACKEND_NAME}, notequal)
{
Shape shape{2, 2, 2};
Expand Down
1 change: 0 additions & 1 deletion ngraph/test/runtime/ie/unit_test.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ max_pool_2d_1channel_1image_overpadded
grn_2d_with_bias
erf
divide_adjoint_stability
equal
notequal
greater
greatereq
Expand Down