-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: master
Are you sure you want to change the base?
Conversation
ElementType inputPrecision; | ||
std::tie(searchSortedParams, inputPrecision) = basicParamsSet; | ||
|
||
targetDevice = ov::test::utils::DEVICE_CPU; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override; | ||
}; | ||
|
||
extern const std::vector<SearchSortedSpecificParams> SearchSortedParamsVector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is it used?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) {
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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}, |
There was a problem hiding this comment.
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}, ...}}
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix alignment
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Details:
Tickets: