-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Develop Bucketize Reference Implementation (#3693)
* Bucketize: Revise op class and add type_prop unit tests * Bucketize: Develop reference implementation * Bucketize: Add unit tests * Bucketize: Add single layer test and cpu instantiation * Bucketize: Add unit test with empty buckets for INTERPRETER * Bucketize: Typo in buckets element type check * Bucketize: Add custom generated inputs in single layer test class * Bucketize: Use random_device to generate seed for data blob * Bucketize: Remove unsupported f64 precision * Bucketize: Add function description * Bucketize: Remove randomness of inputs generation by using static seed * Bucketize: Support different precisions for data and bucket inputs * Bucketize: Refactor type_prop tests and improve backend unit test coverage
- Loading branch information
Showing
14 changed files
with
625 additions
and
21 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...ngine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/bucketize.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2020 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <vector> | ||
|
||
#include "single_layer_tests/bucketize.hpp" | ||
#include "common_test_utils/test_constants.hpp" | ||
|
||
using namespace LayerTestsDefinitions; | ||
|
||
const std::vector<std::vector<size_t>> dataShapes = { | ||
{1, 20, 20}, | ||
{2, 3, 50, 50} | ||
}; | ||
|
||
const std::vector<std::vector<size_t>> bucketsShapes = { | ||
{5}, | ||
{20}, | ||
{100} | ||
}; | ||
|
||
const std::vector<InferenceEngine::Precision> inPrc = { | ||
InferenceEngine::Precision::FP32, | ||
InferenceEngine::Precision::FP16, | ||
InferenceEngine::Precision::I64, | ||
InferenceEngine::Precision::I32 | ||
}; | ||
|
||
const std::vector<InferenceEngine::Precision> netPrc = { | ||
InferenceEngine::Precision::I64, | ||
InferenceEngine::Precision::I32 | ||
}; | ||
|
||
const auto test_Bucketize_right_edge = ::testing::Combine( | ||
::testing::ValuesIn(dataShapes), | ||
::testing::ValuesIn(bucketsShapes), | ||
::testing::Values(true), | ||
::testing::ValuesIn(inPrc), | ||
::testing::ValuesIn(inPrc), | ||
::testing::ValuesIn(netPrc), | ||
::testing::Values(CommonTestUtils::DEVICE_CPU) | ||
); | ||
|
||
const auto test_Bucketize_left_edge = ::testing::Combine( | ||
::testing::ValuesIn(dataShapes), | ||
::testing::ValuesIn(bucketsShapes), | ||
::testing::Values(false), | ||
::testing::ValuesIn(inPrc), | ||
::testing::ValuesIn(inPrc), | ||
::testing::ValuesIn(netPrc), | ||
::testing::Values(CommonTestUtils::DEVICE_CPU) | ||
); | ||
|
||
INSTANTIATE_TEST_CASE_P(smoke_TestsBucketize_right, BucketizeLayerTest, test_Bucketize_right_edge, BucketizeLayerTest::getTestCaseName); | ||
INSTANTIATE_TEST_CASE_P(smoke_TestsBucketize_left, BucketizeLayerTest, test_Bucketize_left_edge, BucketizeLayerTest::getTestCaseName); |
14 changes: 14 additions & 0 deletions
14
inference-engine/tests/functional/plugin/shared/include/single_layer_tests/bucketize.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2020 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "shared_test_classes/single_layer/bucketize.hpp" | ||
|
||
namespace LayerTestsDefinitions { | ||
|
||
TEST_P(BucketizeLayerTest, CompareWithRefs) { | ||
Run(); | ||
} | ||
} // namespace LayerTestsDefinitions |
35 changes: 35 additions & 0 deletions
35
...sts/functional/shared_test_classes/include/shared_test_classes/single_layer/bucketize.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2020 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include <tuple> | ||
#include <string> | ||
|
||
#include "ngraph_functions/builders.hpp" | ||
#include "ngraph_functions/utils/ngraph_helpers.hpp" | ||
|
||
#include "shared_test_classes/base/layer_test_utils.hpp" | ||
|
||
namespace LayerTestsDefinitions { | ||
|
||
using bucketizeParamsTuple = std::tuple< | ||
InferenceEngine::SizeVector, // Data shape | ||
InferenceEngine::SizeVector, // Buckets shape | ||
bool, // Right edge of interval | ||
InferenceEngine::Precision, // Data input precision | ||
InferenceEngine::Precision, // Buckets input precision | ||
InferenceEngine::Precision, // Output precision | ||
std::string>; // Device name | ||
|
||
class BucketizeLayerTest : public testing::WithParamInterface<bucketizeParamsTuple>, | ||
virtual public LayerTestsUtils::LayerTestsCommon { | ||
public: | ||
static std::string getTestCaseName(testing::TestParamInfo<bucketizeParamsTuple> obj); | ||
InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override; | ||
protected: | ||
void SetUp() override; | ||
}; | ||
|
||
} // namespace LayerTestsDefinitions |
68 changes: 68 additions & 0 deletions
68
inference-engine/tests/functional/shared_test_classes/src/single_layer/bucketize.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (C) 2020 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "shared_test_classes/single_layer/bucketize.hpp" | ||
|
||
namespace LayerTestsDefinitions { | ||
|
||
std::string BucketizeLayerTest::getTestCaseName(testing::TestParamInfo<bucketizeParamsTuple> obj) { | ||
InferenceEngine::SizeVector dataShape; | ||
InferenceEngine::SizeVector bucketsShape; | ||
bool with_right_bound; | ||
InferenceEngine::Precision inDataPrc; | ||
InferenceEngine::Precision inBucketsPrc; | ||
InferenceEngine::Precision netPrc; | ||
std::string targetDevice; | ||
|
||
std::tie(dataShape, bucketsShape, with_right_bound, inDataPrc, inBucketsPrc, netPrc, targetDevice) = obj.param; | ||
|
||
std::ostringstream result; | ||
result << "DS=" << CommonTestUtils::vec2str(dataShape) << "_"; | ||
result << "BS=" << CommonTestUtils::vec2str(bucketsShape) << "_"; | ||
if (with_right_bound) | ||
result << "rightIntervalEdge_"; | ||
else | ||
result << "leftIntervalEdge_"; | ||
result << "inDataPrc=" << inDataPrc.name() << "_"; | ||
result << "inBucketsPrc=" << inBucketsPrc.name() << "_"; | ||
result << "netPrc=" << netPrc.name() << "_"; | ||
result << "trgDev=" << targetDevice; | ||
return result.str(); | ||
} | ||
|
||
InferenceEngine::Blob::Ptr BucketizeLayerTest::GenerateInput(const InferenceEngine::InputInfo &info) const { | ||
InferenceEngine::Blob::Ptr blobPtr; | ||
const std::string name = info.name(); | ||
if (name == "a_data") { | ||
auto data_shape = info.getTensorDesc().getDims(); | ||
auto data_size = std::accumulate(begin(data_shape), end(data_shape), 1, std::multiplies<uint64_t>()); | ||
blobPtr = FuncTestUtils::createAndFillBlob(info.getTensorDesc(), data_size * 5, 0, 10, 7235346); | ||
} else if (name == "b_buckets") { | ||
blobPtr = FuncTestUtils::createAndFillBlobUniqueSequence(info.getTensorDesc(), 0, 10, 8234231); | ||
} | ||
return blobPtr; | ||
} | ||
|
||
void BucketizeLayerTest::SetUp() { | ||
InferenceEngine::SizeVector dataShape; | ||
InferenceEngine::SizeVector bucketsShape; | ||
bool with_right_bound; | ||
InferenceEngine::Precision inDataPrc; | ||
InferenceEngine::Precision inBucketsPrc; | ||
InferenceEngine::Precision netPrc; | ||
|
||
std::tie(dataShape, bucketsShape, with_right_bound, inDataPrc, inBucketsPrc, netPrc, targetDevice) = this->GetParam(); | ||
|
||
auto ngInDataPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inDataPrc); | ||
auto ngInBucketsPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inBucketsPrc); | ||
auto ngNetPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrc); | ||
auto data = std::make_shared<ngraph::op::Parameter>(ngInDataPrc, ngraph::Shape(dataShape)); | ||
data->set_friendly_name("a_data"); | ||
auto buckets = std::make_shared<ngraph::op::Parameter>(ngInBucketsPrc, ngraph::Shape(bucketsShape)); | ||
buckets->set_friendly_name("b_buckets"); | ||
auto bucketize = std::make_shared<ngraph::op::v3::Bucketize>(data, buckets, ngNetPrc, with_right_bound); | ||
function = std::make_shared<ngraph::Function>(std::make_shared<ngraph::opset1::Result>(bucketize), ngraph::ParameterVector{data, buckets}, "Bucketize"); | ||
} | ||
} // namespace LayerTestsDefinitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
ngraph/core/reference/include/ngraph/runtime/reference/bucketize.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//***************************************************************************** | ||
// Copyright 2017-2020 Intel Corporation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
//***************************************************************************** | ||
|
||
#pragma once | ||
|
||
#include <algorithm> | ||
|
||
#include "ngraph/shape.hpp" | ||
|
||
namespace ngraph | ||
{ | ||
namespace runtime | ||
{ | ||
namespace reference | ||
{ | ||
template <typename T, typename B, typename P> | ||
void bucketize(const T* data, | ||
const B* buckets, | ||
P* out, | ||
const Shape& data_shape, | ||
const Shape& buckets_shape, | ||
bool with_right_bound) | ||
{ | ||
size_t data_size = shape_size(data_shape); | ||
size_t buckets_size = shape_size(buckets_shape); | ||
|
||
// if buckets is empty, bucket index for all elements | ||
// in output is equal to 0 | ||
if (buckets_size == 0) | ||
{ | ||
std::fill_n(out, data_size, static_cast<P>(0)); | ||
return; | ||
} | ||
|
||
for (size_t i = 0; i < data_size; i++) | ||
{ | ||
const T val = data[i]; | ||
const B* bound = nullptr; | ||
|
||
bound = with_right_bound | ||
? std::lower_bound(buckets, buckets + buckets_size, val) | ||
: std::upper_bound(buckets, buckets + buckets_size, val); | ||
|
||
out[i] = static_cast<P>(bound - buckets); | ||
} | ||
} | ||
|
||
} // namespace reference | ||
|
||
} // namespace runtime | ||
|
||
} // namespace ngraph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.