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

[CPU]: Added impl of SearchSorted op #27036

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

pkowalc1
Copy link
Contributor

@pkowalc1 pkowalc1 commented Oct 14, 2024

Details:

  • Added support for SearchSorted op with tests.

Tickets:

@pkowalc1 pkowalc1 added the WIP work in progress label Oct 14, 2024
@pkowalc1 pkowalc1 requested review from a team as code owners October 14, 2024 14:39
@github-actions github-actions bot added the category: CPU OpenVINO CPU plugin label Oct 14, 2024
@pkowalc1 pkowalc1 requested review from a team as code owners October 16, 2024 12:44
@github-actions github-actions bot added the category: IE Tests OpenVINO Test: plugins and common label Oct 16, 2024
@pkowalc1 pkowalc1 removed the WIP work in progress label Oct 16, 2024
@pkowalc1 pkowalc1 changed the title [WIP]: [CPU]: SearchSorted added impl. [CPU]: SearchSorted added impl. Oct 16, 2024
@pkowalc1 pkowalc1 changed the title [CPU]: SearchSorted added impl. [CPU]: Added impl of SearchSorted op Oct 16, 2024
ElementType inputPrecision;
std::tie(searchSortedParams, inputPrecision) = basicParamsSet;

targetDevice = ov::test::utils::DEVICE_CPU;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it is shared test targetDevice should be test parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


SearchSortedContext ctx = {*this};

#define CASE(OV_TYPE) OV_CASE2(OV_TYPE, ov::element::i64, ov::element_type_traits<OV_TYPE>::value_type, int64_t)
Copy link
Contributor

Choose a reason for hiding this comment

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

OV CPU Plugin doesn't support i64 data_type for internal tensor. So current tests work only because SearchSorted op is last op in the graph: SearchSorted [i64] -> Result.
In case there is other op after SearchSorted than precision will be: SearchSorted [i32] -> Op -> [i32] -> Convert [i64] -> Result.
So if we still need to support i64 for the first case lets handle i32 in switch below as well. Otherwise lets leave i32 only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i64 is needed as some models use it, so fixed by adding i32.

@dmitry-gorokhov dmitry-gorokhov added this to the 2024.5 milestone Oct 17, 2024
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;
};

extern const std::vector<SearchSortedSpecificParams> SearchSortedParamsVector;
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is it used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


static const int SEED = 7877;

std::string SearchSortedLayerTest::getTestCaseName(testing::TestParamInfo<SearchSortedLayerTestParams> obj) {
Copy link
Contributor

Choose a reason for hiding this comment

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

std::string SearchSortedLayerTest::getTestCaseName(const testing::TestParamInfo<SearchSortedLayerTestParams>& obj) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


ElementType inputPrecision;
std::string targetDevice;
std::tie(searchSortedParams, inputPrecision, targetDevice) = basicParamsSet;
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to use reference to avoid extra copy const auto& p = std::get<n>(basicParamsSet)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Every single test on CPU side I have checked is doing it this way - so will keep it to be that way to be consistent.

inputs.insert({funcInputs[0].get_node_shared_ptr(), sortedTensor});

auto valuesTensor =
ov::test::utils::create_and_fill_tensor_unique_sequence(dataPrecision, targetInputStaticShapes[1], 0, 8, SEED);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no statement in specification that the second input should be sorted and unique.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point - fixed.

INSTANTIATE_TEST_SUITE_P(smoke_SearchSortedTest,
SearchSortedLayerTest,
::testing::Combine(::testing::ValuesIn(SearchSortedLayerTest::GenerateParams()),
testing::Values(ElementType::f32, ElementType::f16),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add i8 at least

Copy link
Contributor Author

@pkowalc1 pkowalc1 Oct 18, 2024

Choose a reason for hiding this comment

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

I have added tests for i64 and u32 - since they are used in the model that needs SearchSorted.

I cannot add currently test for i8 due to a bug in data_utils.hpp:317, which causes generate_input to loop infinitively. After fixing it, it will work, but fixing that bug is orthogonal to this PR and should be done in separate PR.


const std::vector<SearchSortedSpecificParams> SearchSortedLayerTest::GenerateParams() {
const std::vector<SearchSortedSpecificParams> params = {
SearchSortedSpecificParams{InputShape{{}, {{1, 18, 104}}}, InputShape{{}, {{1, 18, 104}}}, true},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add more shapes instances to check dynamic case. Like {{}, {{1, 18, 104}, {3, 50, 70}, ...}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more tests cases.


#define CASE(OV_TYPE) \
OV_CASE2(OV_TYPE, ov::element::i64, ov::element_type_traits<OV_TYPE>::value_type, int64_t), \
OV_CASE2(OV_TYPE, ov::element::i32, ov::element_type_traits<OV_TYPE>::value_type, int32_t)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix alignment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

CASE(ov::element::f16),
CASE(ov::element::bf16),
CASE(ov::element::i32),
CASE(ov::element::u32),
Copy link
Contributor

Choose a reason for hiding this comment

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

U32 is not needed since plugin converts it to i32

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

OV_CASE2(OV_TYPE, ov::element::i64, ov::element_type_traits<OV_TYPE>::value_type, int64_t), \
OV_CASE2(OV_TYPE, ov::element::i32, ov::element_type_traits<OV_TYPE>::value_type, int32_t)

OV_SWITCH(intel_cpu,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since OV_SWITCH doesn't check if any condition is satisfied, we need to guarantee inputPrecision and outputPrecision are in supported range. In order to do that lets adjust precision which we use in initSupportedPrimitiveDescriptors. See as as example https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_cpu/src/nodes/scatter_update.cpp#L273-L283.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - as discussed in separate channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: CPU OpenVINO CPU plugin category: IE Tests OpenVINO Test: plugins and common
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants