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

[ref]: Added SearchSorted ref impl #26958

Merged
merged 69 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
187f1c4
[Spec]: Added initial specification of Searchsorted op
pkowalc1 Oct 2, 2024
ccb2134
[op]: S[SearchSorted]: Added new op definition with tests.
pkowalc1 Oct 3, 2024
ef5d369
Merge branch 'master' into search_sorted_op_def
mlukasze Oct 4, 2024
c87ed2f
[unittest]:[SearchSorted]: Fix Windows warnings.
pkowalc1 Oct 4, 2024
5987b73
Update src/core/include/openvino/op/search_sorted.hpp
pkowalc1 Oct 7, 2024
ddee155
Update src/core/shape_inference/include/search_sorted_shape_inference…
pkowalc1 Oct 7, 2024
58cfcdd
Update src/core/shape_inference/include/search_sorted_shape_inference…
pkowalc1 Oct 7, 2024
7663026
Update src/core/include/openvino/op/search_sorted.hpp
pkowalc1 Oct 7, 2024
60984a6
[SortedSearch]: Fixed validation due to review and added more unittests.
pkowalc1 Oct 8, 2024
420b709
[attributes_test]: Added test for SearchSorted op.
pkowalc1 Oct 8, 2024
60eff69
[SearchSorted]: Fixed code style.
pkowalc1 Oct 8, 2024
a33b7f9
Removed search_sorted.rst in order to not block PR contiaining the de…
pkowalc1 Oct 8, 2024
cd3873d
Removed search_sorted.rst in order to not block PR contiaining the de…
pkowalc1 Oct 8, 2024
6b80399
Merge branch 'master' into search_sorted_op_def
pkowalc1 Oct 8, 2024
f7b82e0
[ref]: Added SearchSorted ref impl.
pkowalc1 Oct 8, 2024
cb6531a
[Spec]: Added initial specification of Searchsorted op
pkowalc1 Oct 2, 2024
80b6c25
[op]: S[SearchSorted]: Added new op definition with tests.
pkowalc1 Oct 3, 2024
cf87e7a
Revert "[NPUW] Add initial unpack and partitioning unit tests on NPUW…
ababushk Oct 2, 2024
4778d91
[coverity, core] Fix unchecked return value in bound evaluate (#26768)
praasz Oct 2, 2024
669d921
[OV JS] Add TS definition for AnyMap (#26711)
almilosz Oct 2, 2024
ae194d1
[NPU] Add documentation for batching on NPU plugin (#26865)
pereanub Oct 2, 2024
0b05df1
NPUW: Fix nullptr reference parameter in rearrange_to_proto (#26869)
AsyaPronina Oct 2, 2024
738a52b
single-image-test: added accuracy workaround for computing CPU refere…
beleiuandrei Oct 2, 2024
1939b8f
[GPU] Support large N FC optimization for dynamic quantization case (…
andrew-k-park Oct 3, 2024
07ad6db
[PT FE][GHA] Run PT FE layer tests on Ubuntu 24.04 with Python 3.12 a…
rkazants Oct 3, 2024
94aff1e
[GPU] Fix double jit constants (#26893)
p-durandin Oct 3, 2024
ea85a2f
NPUW: Bring back unpack and partitioning unit tests for NPUW (#26885)
AsyaPronina Oct 3, 2024
ad0b980
[TF FE]: Support complex tensors for ExpandDims operation (#26892)
hub-bla Oct 3, 2024
f6ba78f
[GPU] Extract debug code from network::execute() (#26888)
vladimir-paramuzov Oct 3, 2024
0ac600b
[GPU] Fix unit tests ph4 (#26879)
p-durandin Oct 3, 2024
ca60a93
[GPU] Adjust usm_host memory usage for InferRequest tensors (#26896)
sshlyapn Oct 3, 2024
d3fc978
[GPU] Fix empty oneDnn users (#26900)
p-durandin Oct 3, 2024
1d98baa
[unittest]:[SearchSorted]: Fix Windows warnings.
pkowalc1 Oct 4, 2024
be1c9b4
Update src/core/include/openvino/op/search_sorted.hpp
pkowalc1 Oct 7, 2024
6f9bec3
Update src/core/shape_inference/include/search_sorted_shape_inference…
pkowalc1 Oct 7, 2024
c041426
Update src/core/shape_inference/include/search_sorted_shape_inference…
pkowalc1 Oct 7, 2024
32e9285
Update src/core/include/openvino/op/search_sorted.hpp
pkowalc1 Oct 7, 2024
25aa185
[SortedSearch]: Fixed validation due to review and added more unittests.
pkowalc1 Oct 8, 2024
5990ba9
[attributes_test]: Added test for SearchSorted op.
pkowalc1 Oct 8, 2024
39cdc36
[SearchSorted]: Fixed code style.
pkowalc1 Oct 8, 2024
954f211
Removed search_sorted.rst in order to not block PR contiaining the de…
pkowalc1 Oct 8, 2024
580c4ab
Removed search_sorted.rst in order to not block PR contiaining the de…
pkowalc1 Oct 8, 2024
6bb89b2
[TF FE][Keras] Use latest Keras for TF FE validation and adopt tests …
rkazants Oct 7, 2024
1dd4c67
[core] Convert reference use intrinsic implementation for ChromeOS (…
praasz Oct 7, 2024
f3d747b
Fix ov RTTI (#26895)
itikhono Oct 7, 2024
70be606
[PT FE] Fix torchaudio dependency for MacOS x86 (#26913)
rkazants Oct 7, 2024
83ec200
Docs Add Category to Coveo search engine (#26932)
akopytko Oct 7, 2024
5aa918c
[DOCS] Fixing references to Node.js methods (#26933)
sgolebiewski-intel Oct 7, 2024
f3f6c3f
[GHA] Don't update latest available artifacts link when copy failed (…
akladiev Oct 7, 2024
08db8b6
[GPU] network code cleanup (#26908)
vladimir-paramuzov Oct 7, 2024
8843e65
[DOCS] technical adjustments for the build mstr (#26883)
kblaszczak-intel Oct 7, 2024
d3ac6e0
[NPUW] Better utilize threads on compilation (#26864)
smirnov-alexey Oct 7, 2024
4ae2598
Eliminate nop Convert at the beginning of the MOC pipeline (#26872)
itikhono Oct 7, 2024
f173059
[PT FE] Fix Bitwise translators with 3 inputs (#26930)
rkazants Oct 7, 2024
d6c3a8f
List decompositions for torch.export (#26878)
mvafin Oct 7, 2024
53d8c6d
[DOCS] release notes one more adjustment (#26876)
kblaszczak-intel Oct 8, 2024
7b9c698
[PT FE] Remove explicit optimum deps from validation (#26948)
rkazants Oct 8, 2024
b8f9ee5
Update h5py requirement from <3.12.0,>=3.1.0 to >=3.1.0,<3.13.0 in /s…
dependabot[bot] Oct 8, 2024
46ed119
[ref]: Added SearchSorted ref impl.
pkowalc1 Oct 8, 2024
17b6e6f
Merge branch 'search_sorted_ref_impl' of https://github.com/pkowalc1/…
pkowalc1 Oct 9, 2024
394e474
Merge branch 'master' into search_sorted_ref_impl
pkowalc1 Oct 9, 2024
ae6a83d
[SearchSorted]: Fixed codestyle.
pkowalc1 Oct 9, 2024
f138792
Fixed code style.
pkowalc1 Oct 9, 2024
ed5d4d8
[SearchSorted]: Fixed Windows error.
pkowalc1 Oct 9, 2024
c9bb4b1
Update src/plugins/template/tests/functional/op_reference/search_sort…
pkowalc1 Oct 10, 2024
5c20b4c
[SearchSorted]: Added to opset15_tbl.hpp
pkowalc1 Oct 10, 2024
5a9d440
[tests]: Fixed opset test fail.
pkowalc1 Oct 10, 2024
106c5c3
[ConformanceTests]: Added test for SearchSorted.
pkowalc1 Oct 10, 2024
df1a322
[ConformanceTests]: Fixed compilation error.
pkowalc1 Oct 10, 2024
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
1 change: 1 addition & 0 deletions src/core/include/openvino/opsets/opset15_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ _OPENVINO_OP_REG(StringTensorPack, ov::op::v15)
_OPENVINO_OP_REG(BitwiseLeftShift, ov::op::v15)
_OPENVINO_OP_REG(BitwiseRightShift, ov::op::v15)
_OPENVINO_OP_REG(SliceScatter, ov::op::v15)
_OPENVINO_OP_REG(SearchSorted, ov::op::v15)
55 changes: 55 additions & 0 deletions src/core/reference/include/openvino/reference/search_sorted.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "openvino/core/shape.hpp"
#include "openvino/reference/utils/coordinate_index.hpp"
#include "openvino/reference/utils/coordinate_transform.hpp"

namespace ov {
namespace reference {
template <typename T, typename TOut = int64_t>
void search_sorted(const T* sorted,
const T* values,
TOut* out,
const Shape& sorted_shape,
const Shape& values_shape,
bool right_mode) {
const CoordinateTransformBasic values_transform{values_shape};

std::function<const T*(const T*, const T*, T)> compare_func = nullptr;
if (right_mode) {
compare_func = [](const T* begin, const T* end, T value) {
return std::lower_bound(begin, end, value, std::less_equal<T>());
};
} else {
compare_func = [](const T* begin, const T* end, T value) {
return std::lower_bound(begin, end, value, std::less<T>());
};
}

for (const Coordinate& values_coord : values_transform) {
const auto values_index = coordinate_index(values_coord, values_shape);
const T value = values[values_index];

Coordinate sorted_coord_begin = values_coord;
sorted_coord_begin.back() = 0;

Coordinate sorted_coord_last = values_coord;
sorted_coord_last.back() = sorted_shape.back();

const auto sorted_index_begin = coordinate_index(sorted_coord_begin, sorted_shape);
const auto sorted_index_last = coordinate_index(sorted_coord_last, sorted_shape);

const T* idx_ptr = compare_func(sorted + sorted_index_begin, sorted + sorted_index_last, value);

const ptrdiff_t sorted_index = (idx_ptr - sorted) - sorted_index_begin;

out[values_index] = static_cast<TOut>(sorted_index);
}
}

} // namespace reference
} // namespace ov
2 changes: 1 addition & 1 deletion src/core/tests/opset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ INSTANTIATE_TEST_SUITE_P(opset,
OpsetTestParams{ov::get_opset12, 178},
OpsetTestParams{ov::get_opset13, 186},
OpsetTestParams{ov::get_opset14, 188},
OpsetTestParams{ov::get_opset15, 14}),
OpsetTestParams{ov::get_opset15, 15}),
OpsetTestNameGenerator{});

class MyOpOld : public ov::op::Op {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/template/backend/ops/ops_evaluates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,7 @@ extern template bool evaluate_node<ov::op::v15::StringTensorUnpack>(std::shared_
extern template bool evaluate_node<ov::op::v15::StringTensorPack>(std::shared_ptr<ov::Node> node,
ov::TensorVector& outputs,
const ov::TensorVector& inputs);

extern template bool evaluate_node<ov::op::v15::SearchSorted>(std::shared_ptr<ov::Node> node,
ov::TensorVector& outputs,
const ov::TensorVector& inputs);
50 changes: 50 additions & 0 deletions src/plugins/template/backend/ops/search_sorted.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/reference/search_sorted.hpp"

#include "evaluate_node.hpp"

template <ov::element::Type_t ET>
bool evaluate(const std::shared_ptr<ov::op::v15::SearchSorted>& op,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
using T = typename ov::element_type_traits<ET>::value_type;
ov::reference::search_sorted<T>(inputs[0].data<const T>(),
inputs[1].data<const T>(),
outputs[0].data<int64_t>(),
op->get_input_shape(0),
op->get_input_shape(1),
op->get_right_mode());
return true;
}

template <>
bool evaluate_node<ov::op::v15::SearchSorted>(std::shared_ptr<ov::Node> node,
ov::TensorVector& outputs,
const ov::TensorVector& inputs) {
const auto& element_type = node->get_input_element_type(0);

#define CASE(type) \
case ov::element::type: \
return evaluate<ov::element::type>(ov::as_type_ptr<ov::op::v15::SearchSorted>(node), outputs, inputs);

switch (element_type) {
CASE(bf16);
CASE(f16);
CASE(f32);
CASE(f64);
CASE(i8);
CASE(i16);
CASE(i32);
CASE(i64);
CASE(u8);
CASE(u16);
CASE(u32);
CASE(u64);
default:
OPENVINO_THROW("Unhandled data type ", element_type, " in evaluate_node()");
}
#undef CASE
}
1 change: 1 addition & 0 deletions src/plugins/template/backend/opset_int_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ _OPENVINO_OP_REG(StringTensorPack, ov::op::v15)
_OPENVINO_OP_REG(BitwiseLeftShift, ov::op::v15)
_OPENVINO_OP_REG(BitwiseRightShift, ov::op::v15)
_OPENVINO_OP_REG(SliceScatter, ov::op::v15)
_OPENVINO_OP_REG(SearchSorted, ov::op::v15)

_OPENVINO_OP_REG(AUGRUCell, ov::op::internal)
_OPENVINO_OP_REG(AUGRUSequence, ov::op::internal)
Expand Down
123 changes: 123 additions & 0 deletions src/plugins/template/tests/functional/op_reference/search_sorted.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/op/search_sorted.hpp"

#include <gtest/gtest.h>

#include "base_reference_test.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/parameter.hpp"

using namespace reference_tests;
using namespace ov;

namespace {

struct SearchSortedParams {
PartialShape sortedShape;
PartialShape valuesShape;
bool rightMode;
std::string testcaseName;
reference_tests::Tensor sorted;
reference_tests::Tensor values;
reference_tests::Tensor expectedOutput;
};

template <typename T>
SearchSortedParams PrepareTestCaseParams(const PartialShape& sortedShape,
const PartialShape& valuesShape,
bool rightMode,
const std::vector<T>& sortedData,
const std::vector<T>& valuesData,
const std::vector<int64_t>& expectedData,
const std::string& testcaseName) {
SearchSortedParams ret;
const auto elementType = element::from<T>();

ret.sortedShape = sortedShape;
ret.valuesShape = valuesShape;
ret.rightMode = rightMode;
ret.testcaseName = testcaseName;
ret.sorted = reference_tests::Tensor(elementType, sortedShape.to_shape(), sortedData);
ret.values = reference_tests::Tensor(elementType, valuesShape.to_shape(), valuesData);
ret.expectedOutput = reference_tests::Tensor(element::Type_t::i64, valuesShape.to_shape(), expectedData);

return ret;
}

class ReferenceSearchSortedTest : public testing::TestWithParam<SearchSortedParams>, public CommonReferenceTest {
public:
void SetUp() override {
const auto& params = GetParam();
function = CreateFunction(params);
inputData = {params.sorted.data, params.values.data};
refOutData = {params.expectedOutput.data};
}

static std::string getTestCaseName(const testing::TestParamInfo<SearchSortedParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "type=" << param.sorted.data.get_element_type();
result << "_sortedShape=" << param.sortedShape;
result << "_valuesShape=" << param.valuesShape;
result << "_rightMode=" << param.rightMode;
result << "_=" << param.testcaseName;

return result.str();
}

private:
static std::shared_ptr<Model> CreateFunction(const SearchSortedParams& params) {
const auto sorted =
std::make_shared<op::v0::Parameter>(params.sorted.data.get_element_type(), params.sortedShape);
const auto values =
std::make_shared<op::v0::Parameter>(params.values.data.get_element_type(), params.valuesShape);

const auto op = std::make_shared<op::v15::SearchSorted>(sorted, values, params.rightMode);

return std::make_shared<Model>(NodeVector{op}, ParameterVector{sorted, values});
}
};

TEST_P(ReferenceSearchSortedTest, CompareWithRefs) {
Exec();
}

template <element::Type_t ET>
std::vector<SearchSortedParams> generateParams() {
using T = typename element_type_traits<ET>::value_type;
std::vector<SearchSortedParams> params;

#define TEST_DATA(sorted_shape, values_shape, right_mode, sorted_data, values_data, expected_output_data, description) \
params.push_back(PrepareTestCaseParams<T>(sorted_shape, \
values_shape, \
right_mode, \
sorted_data, \
values_data, \
expected_output_data, \
description));

#include "unit_test_utils/tests_data/search_sorted_data.h"
#undef TEST_DATA

return params;
}

std::vector<SearchSortedParams> generateCombinedParams() {
const std::vector<std::vector<SearchSortedParams>> generatedParams{generateParams<element::Type_t::i32>(),
generateParams<element::Type_t::f32>()};
std::vector<SearchSortedParams> combinedParams;

for (const auto& params : generatedParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}

INSTANTIATE_TEST_SUITE_P(smoke_SearchSorted_With_Hardcoded_Refs,
ReferenceSearchSortedTest,
testing::ValuesIn(generateCombinedParams()),
ReferenceSearchSortedTest::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,15 @@ std::shared_ptr<ov::Model> generateRNNCellBase(const std::shared_ptr<ov::op::Op>
}
}

std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v15::SearchSorted>& node) {
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{16})};
const auto values =
std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{2, 3}, std::vector<float>(6, 0));
auto new_node = std::make_shared<ov::op::v15::SearchSorted>(params.at(0), values);
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(new_node)};
return std::make_shared<ov::Model>(results, params, "SearchSortedGraph");
}

std::shared_ptr<ov::Model> generateSubGraphOp(const std::shared_ptr<ov::op::Op> &node) {
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{{2, 2}}),
std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{{2, 2}}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once

#define LIST(...) \
{ __VA_ARGS__ }

// TEST_DATA(sorted_shape,
// values_shape,
// right_mode,
// sorted_data,
// values_data,
// expected_output_data,
// description)

// NOTE: expected output were generated using pyTorch.searchsorted implementation.

TEST_DATA(LIST(5),
LIST(2, 3),
false,
LIST(1, 3, 5, 7, 9),
LIST(3, 6, 9, 3, 6, 9),
LIST(1, 3, 4, 1, 3, 4),
"1d_tensor_1");

TEST_DATA(LIST(5),
LIST(4, 3),
false,
LIST(1, 3, 5, 7, 9),
LIST(0, 6, 20, 1, 6, 9, 1, 0, 0, 9, 10, 20),
LIST(0, 3, 5, 0, 3, 4, 0, 0, 0, 4, 5, 5),
"1d_tensor_2");

TEST_DATA(LIST(5),
LIST(4, 3),
true,
LIST(1, 3, 5, 7, 9),
LIST(0, 6, 20, 1, 6, 9, 1, 0, 0, 9, 10, 20),
LIST(0, 3, 5, 1, 3, 5, 1, 0, 0, 5, 5, 5),
"1d_tensor_2_right_mode");

TEST_DATA(LIST(5),
LIST(2, 2, 3),
false,
LIST(1, 3, 5, 7, 9),
LIST(0, 6, 20, 1, 6, 9, 1, 0, 0, 9, 10, 20),
LIST(0, 3, 5, 0, 3, 4, 0, 0, 0, 4, 5, 5),
"1d_tensor_3");

TEST_DATA(LIST(5),
LIST(2, 2, 3),
true,
LIST(1, 3, 5, 7, 9),
LIST(0, 6, 20, 1, 6, 9, 1, 0, 0, 9, 10, 20),
LIST(0, 3, 5, 1, 3, 5, 1, 0, 0, 5, 5, 5),
"1d_tensor_3_right_mode");

TEST_DATA(LIST(2, 5),
LIST(2, 3),
false,
LIST(1, 3, 5, 7, 9, 2, 4, 6, 8, 10),
LIST(3, 6, 9, 3, 6, 9),
LIST(1, 3, 4, 1, 2, 4),
"nd_tensor_1");

TEST_DATA(LIST(2, 5),
LIST(2, 3),
true,
LIST(1, 3, 5, 7, 9, 2, 4, 6, 8, 10),
LIST(3, 6, 9, 3, 6, 9),
LIST(2, 3, 5, 1, 3, 4),
"nd_tensor_1_right_mode");

TEST_DATA(LIST(2, 2, 5),
LIST(2, 2, 3),
false,
LIST(1, 3, 5, 7, 9, 0, 2, 4, 6, 8, -20, 5, 10, 23, 41, 100, 125, 130, 132, 139),
LIST(0, 6, 20, 1, 6, 9, 1, 0, 0, 9, 10, 20),
LIST(0, 3, 5, 1, 3, 5, 1, 1, 1, 0, 0, 0),
"nd_tensor_2");

TEST_DATA(LIST(2, 2, 5),
LIST(2, 2, 3),
true,
LIST(1, 3, 5, 7, 9, 0, 2, 4, 6, 8, -20, 5, 10, 23, 41, 100, 125, 130, 132, 139),
LIST(0, 6, 20, 1, 6, 9, 1, 0, 0, 9, 10, 20),
LIST(0, 3, 5, 1, 4, 5, 1, 1, 1, 0, 0, 0),
"nd_tensor_2");
Loading