Migrate Movement 2 (BatchToSpace-2, DepthToSpace-1, Roll-7, ShuffleCha… (#8158)

* Migrate Movement2 (BatchToSpace-2, DepthToSpace-1, Roll-7, ShuffleChannels-1, SpaceToBatch-2, SpaceToDepth-1)

* Fix typos while copying

* Update to opset namespace and add i4, u4, bf16 tests when available

* Remove i4, u4 tests from BatchToSpace and Roll
This commit is contained in:
Steve Yoo 2021-11-16 09:32:29 +09:00 committed by GitHub
parent c5d0dc3e5f
commit f66d9216ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 1148 additions and 878 deletions

View File

@ -0,0 +1,222 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/opsets/opset1.hpp"
#include "openvino/opsets/opset2.hpp"
#include "base_reference_test.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct BatchToSpaceParams {
BatchToSpaceParams(const Tensor& dataTensor, const Tensor& blockShapeTensor,
const Tensor& cropsBeginTensor, const Tensor& cropsEndTensor,
const Tensor& expectedTensor, const std::string& testcaseName = "") :
dataTensor(dataTensor), blockShapeTensor(blockShapeTensor),
cropsBeginTensor(cropsBeginTensor), cropsEndTensor(cropsEndTensor),
expectedTensor(expectedTensor), testcaseName(testcaseName) {}
Tensor dataTensor;
Tensor blockShapeTensor;
Tensor cropsBeginTensor;
Tensor cropsEndTensor;
Tensor expectedTensor;
std::string testcaseName;
};
class ReferenceBatchToSpaceLayerTest : public testing::TestWithParam<BatchToSpaceParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.dataTensor.data};
refOutData = {params.expectedTensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<BatchToSpaceParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "dType=" << param.dataTensor.type;
result << "_dShape=" << param.dataTensor.shape;
result << "_bsType=" << param.blockShapeTensor.type;
result << "_bsShape=" << param.blockShapeTensor.shape;
result << "_cbType=" << param.cropsBeginTensor.type;
result << "_cbShape=" << param.cropsBeginTensor.shape;
result << "_ceType=" << param.cropsEndTensor.type;
result << "_ceShape=" << param.cropsEndTensor.shape;
result << "_eType=" << param.expectedTensor.type;
if (param.testcaseName != "") {
result << "_eShape=" << param.expectedTensor.shape;
result << "_" << param.testcaseName;
} else {
result << "_eShape=" << param.expectedTensor.shape;
}
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const BatchToSpaceParams& params) {
const auto data = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
const auto blockShape = std::make_shared<opset1::Constant>(element::i64, params.blockShapeTensor.shape, params.blockShapeTensor.data.data());
const auto cropsBegin = std::make_shared<opset1::Constant>(element::i64, params.cropsBeginTensor.shape, params.cropsBeginTensor.data.data());
const auto cropsEnd = std::make_shared<opset1::Constant>(element::i64, params.cropsEndTensor.shape, params.cropsEndTensor.data.data());
const auto batchToSpace = std::make_shared<opset2::BatchToSpace>(data, blockShape, cropsBegin, cropsEnd);
return std::make_shared<Function>(NodeVector {batchToSpace}, ParameterVector {data});
}
};
TEST_P(ReferenceBatchToSpaceLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<BatchToSpaceParams> generateBatchToSpaceParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<BatchToSpaceParams> batchToSpaceParams {
// input_with_shape_4x3
BatchToSpaceParams(
Tensor({4, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}),
Tensor({2}, element::i64, std::vector<int64_t>{1, 2}),
Tensor({2}, element::i64, std::vector<int64_t>{0, 0}),
Tensor({2}, element::i64, std::vector<int64_t>{0, 0}),
Tensor({2, 6}, IN_ET, std::vector<T>{1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12}),
"input_with_shape_4x3"),
// input_with_shape_4x1x1x3
BatchToSpaceParams(
Tensor({4, 1, 1, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 1, 2}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({2, 1, 1, 6}, IN_ET, std::vector<T>{1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12}),
"input_with_shape_4x1x1x3"),
// input_with_shape_4x1x1x3_1
BatchToSpaceParams(
Tensor({4, 1, 1, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 2, 1}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({2, 1, 2, 3}, IN_ET, std::vector<T>{1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12}),
"input_with_shape_4x1x1x3_1"),
// input_with_shape_4x1x1x3_2
BatchToSpaceParams(
Tensor({4, 1, 1, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 2, 2}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({2, 1, 1, 6}, IN_ET, std::vector<T>{1, 4, 2, 5, 3, 6, 7, 10, 8, 11, 9, 12}),
"input_with_shape_4x1x1x3_2"),
// input_with_shape_4x1x2x3
BatchToSpaceParams(
Tensor({4, 1, 2, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 1, 2}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({2, 1, 2, 6}, IN_ET, std::vector<T>{1, 13, 2, 14, 3, 15,
4, 16, 5, 17, 6, 18,
7, 19, 8, 20, 9, 21,
10, 22, 11, 23, 12, 24}),
"input_with_shape_4x1x2x3"),
// input_with_shape_4x1x2x3_1
BatchToSpaceParams(
Tensor({4, 1, 2, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 2, 1}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({2, 1, 4, 3}, IN_ET, std::vector<T>{1, 2, 3, 13, 14, 15,
4, 5, 6, 16, 17, 18,
7, 8, 9, 19, 20, 21,
10, 11, 12, 22, 23, 24}),
"input_with_shape_4x1x2x3_1"),
// input_with_shape_4x1x2x3_2
BatchToSpaceParams(
Tensor({4, 1, 2, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 2, 2}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({1, 1, 4, 6}, IN_ET, std::vector<T>{1, 7, 2, 8, 3, 9,
13, 19, 14, 20, 15, 21,
4, 10, 5, 11, 6, 12,
16, 22, 17, 23, 18, 24}),
"input_with_shape_4x1x2x3_2"),
// input_with_shape_with_crop_4x1x2x3
BatchToSpaceParams(
Tensor({4, 1, 2, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 2, 2}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 2}),
Tensor({1, 1, 4, 4}, IN_ET, std::vector<T>{1, 7, 2, 8, 13, 19, 14, 20,
4, 10, 5, 11, 16, 22, 17, 23}),
"input_with_shape_with_crop_4x1x2x3"),
// input_with_shape_with_crop_4x1x2x3_1
BatchToSpaceParams(
Tensor({4, 1, 2, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 2, 2}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 2}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({1, 1, 4, 4}, IN_ET, std::vector<T>{2, 8, 3, 9, 14, 20, 15, 21,
5, 11, 6, 12, 17, 23, 18, 24}),
"input_with_shape_with_crop_4x1x2x3_1"),
// input_with_shape_with_crop_4x1x2x3_2
BatchToSpaceParams(
Tensor({4, 1, 2, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 2, 2}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 1, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 1, 0}),
Tensor({1, 1, 2, 6}, IN_ET, std::vector<T>{13, 19, 14, 20, 15, 21,
4, 10, 5, 11, 6, 12}),
"input_with_shape_with_crop_4x1x2x3_2"),
};
return batchToSpaceParams;
}
std::vector<BatchToSpaceParams> generateBatchToSpaceCombinedParams() {
const std::vector<std::vector<BatchToSpaceParams>> batchToSpaceTypeParams {
generateBatchToSpaceParams<element::Type_t::i8>(),
generateBatchToSpaceParams<element::Type_t::i16>(),
generateBatchToSpaceParams<element::Type_t::i32>(),
generateBatchToSpaceParams<element::Type_t::i64>(),
generateBatchToSpaceParams<element::Type_t::u8>(),
generateBatchToSpaceParams<element::Type_t::u16>(),
generateBatchToSpaceParams<element::Type_t::u32>(),
generateBatchToSpaceParams<element::Type_t::u64>(),
generateBatchToSpaceParams<element::Type_t::bf16>(),
generateBatchToSpaceParams<element::Type_t::f16>(),
generateBatchToSpaceParams<element::Type_t::f32>(),
generateBatchToSpaceParams<element::Type_t::f64>(),
};
std::vector<BatchToSpaceParams> combinedParams;
for (const auto& params : batchToSpaceTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_BatchToSpace_With_Hardcoded_Refs, ReferenceBatchToSpaceLayerTest,
testing::ValuesIn(generateBatchToSpaceCombinedParams()), ReferenceBatchToSpaceLayerTest::getTestCaseName);
} // namespace

View File

@ -0,0 +1,157 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/opsets/opset1.hpp"
#include "base_reference_test.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct DepthToSpaceParams {
DepthToSpaceParams(const Tensor& dataTensor, const std::string mode, const int32_t blockSize,
const Tensor& expectedTensor, const std::string& testcaseName = "") :
dataTensor(dataTensor), mode(mode), blockSize(blockSize), expectedTensor(expectedTensor),
testcaseName(testcaseName) {}
Tensor dataTensor;
std::string mode;
int32_t blockSize;
Tensor expectedTensor;
std::string testcaseName;
};
class ReferenceDepthToSpaceLayerTest : public testing::TestWithParam<DepthToSpaceParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.dataTensor.data};
refOutData = {params.expectedTensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<DepthToSpaceParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "dType=" << param.dataTensor.type;
result << "_dShape=" << param.dataTensor.shape;
result << "_eType=" << param.expectedTensor.type;
if (param.testcaseName != "") {
result << "_eShape=" << param.expectedTensor.shape;
result << "_" << param.testcaseName;
} else {
result << "_eShape=" << param.expectedTensor.shape;
}
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const DepthToSpaceParams& params) {
opset1::DepthToSpace::DepthToSpaceMode mode = params.mode == "DEPTH_FIRST" ?
opset1::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST : opset1::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST;
const auto data = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
const auto depthToSpace = std::make_shared<opset1::DepthToSpace>(data, mode, params.blockSize);
return std::make_shared<Function>(NodeVector {depthToSpace}, ParameterVector {data});
}
};
TEST_P(ReferenceDepthToSpaceLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<DepthToSpaceParams> generateDepthToSpaceParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<DepthToSpaceParams> depthToSpaceParams {
// depth_to_space_block_first_K1_BS2
DepthToSpaceParams(
Tensor({1, 8, 2}, IN_ET, std::vector<T>{0, 2, 8, 10, 16, 18, 24, 26, 1, 3, 9, 11, 17, 19, 25, 27}),
"BLOCKS_FIRST",
2,
Tensor({1, 4, 4}, IN_ET, std::vector<T>{0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27}),
"depth_to_space_block_first_K1_BS2"),
// depth_to_space_block_first_K2_BS2
DepthToSpaceParams(
Tensor({1, 8, 2, 2}, IN_ET, std::vector<T>{0, 2, 8, 10, 16, 18, 24, 26, 1, 3, 9,
11, 17, 19, 25, 27, 4, 6, 12, 14, 20, 22,
28, 30, 5, 7, 13, 15, 21, 23, 29, 31}),
"BLOCKS_FIRST",
2,
Tensor({1, 2, 4, 4}, IN_ET, std::vector<T>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}),
"depth_to_space_block_first_K2_BS2"),
// depth_to_space_block_first_K2_BS4
DepthToSpaceParams(
Tensor({1, 16, 2, 1}, IN_ET, std::vector<T>{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5,
21, 6, 22, 7, 23, 8, 24, 9, 25, 10, 26,
11, 27, 12, 28, 13, 29, 14, 30, 15, 31}),
"BLOCKS_FIRST",
4,
Tensor({1, 1, 8, 4}, IN_ET, std::vector<T>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}),
"depth_to_space_block_first_K2_BS4"),
// depth_to_space_depth_first_1K_BS2
DepthToSpaceParams(
Tensor({1, 8, 2}, IN_ET, std::vector<T>{0, 2, 1, 3, 4, 6, 5, 7, 8, 10, 9, 11, 12, 14, 13, 15}),
"DEPTH_FIRST",
2,
Tensor({1, 4, 4}, IN_ET, std::vector<T>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}),
"depth_to_space_depth_first_1K_BS2"),
// depth_to_space_depth_first_2K_BS2
DepthToSpaceParams(
Tensor({1, 8, 2, 2}, IN_ET, std::vector<T>{0, 2, 8, 10, 16, 18, 24, 26, 1, 3, 9,
11, 17, 19, 25, 27, 4, 6, 12, 14, 20, 22,
28, 30, 5, 7, 13, 15, 21, 23, 29, 31}),
"DEPTH_FIRST",
2,
Tensor({1, 2, 4, 4}, IN_ET, std::vector<T>{0, 16, 2, 18, 1, 17, 3, 19, 8, 24, 10, 26, 9, 25, 11, 27,
4, 20, 6, 22, 5, 21, 7, 23, 12, 28, 14, 30, 13, 29, 15, 31}),
"depth_to_space_depth_first_2K_BS2"),
// depth_to_space_depth_first_2K_BS4
DepthToSpaceParams(
Tensor({1, 16, 2, 1}, IN_ET, std::vector<T>{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5,
21, 6, 22, 7, 23, 8, 24, 9, 25, 10, 26,
11, 27, 12, 28, 13, 29, 14, 30, 15, 31}),
"DEPTH_FIRST",
4,
Tensor({1, 1, 8, 4}, IN_ET, std::vector<T>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}),
"depth_to_space_depth_first_2K_BS4"),
};
return depthToSpaceParams;
}
std::vector<DepthToSpaceParams> generateDepthToSpaceCombinedParams() {
const std::vector<std::vector<DepthToSpaceParams>> depthToSpaceTypeParams {
generateDepthToSpaceParams<element::Type_t::i8>(),
generateDepthToSpaceParams<element::Type_t::i16>(),
generateDepthToSpaceParams<element::Type_t::i32>(),
generateDepthToSpaceParams<element::Type_t::i64>(),
generateDepthToSpaceParams<element::Type_t::u8>(),
generateDepthToSpaceParams<element::Type_t::u16>(),
generateDepthToSpaceParams<element::Type_t::u32>(),
generateDepthToSpaceParams<element::Type_t::u64>(),
generateDepthToSpaceParams<element::Type_t::bf16>(),
generateDepthToSpaceParams<element::Type_t::f16>(),
generateDepthToSpaceParams<element::Type_t::f32>(),
generateDepthToSpaceParams<element::Type_t::f64>(),
};
std::vector<DepthToSpaceParams> combinedParams;
for (const auto& params : depthToSpaceTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_DepthToSpace_With_Hardcoded_Refs, ReferenceDepthToSpaceLayerTest,
testing::ValuesIn(generateDepthToSpaceCombinedParams()), ReferenceDepthToSpaceLayerTest::getTestCaseName);
} // namespace

View File

@ -0,0 +1,212 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/opsets/opset1.hpp"
#include "openvino/opsets/opset7.hpp"
#include "base_reference_test.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct RollParams {
RollParams(const Tensor& dataTensor, const Tensor& shiftTensor, const Tensor& axesTensor,
const Tensor& expectedTensor, const std::string& testcaseName = "") :
dataTensor(dataTensor), shiftTensor(shiftTensor), axesTensor(axesTensor),
expectedTensor(expectedTensor), testcaseName(testcaseName) {}
Tensor dataTensor;
Tensor shiftTensor;
Tensor axesTensor;
Tensor expectedTensor;
std::string testcaseName;
};
class ReferenceRollLayerTest : public testing::TestWithParam<RollParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.dataTensor.data};
refOutData = {params.expectedTensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<RollParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "dType=" << param.dataTensor.type;
result << "_dShape=" << param.dataTensor.shape;
result << "_sType=" << param.shiftTensor.type;
result << "_sShape=" << param.shiftTensor.shape;
result << "_aType=" << param.axesTensor.type;
result << "_aShape=" << param.axesTensor.shape;
result << "_eType=" << param.expectedTensor.type;
if (param.testcaseName != "") {
result << "_eShape=" << param.expectedTensor.shape;
result << "_=" << param.testcaseName;
} else {
result << "_eShape=" << param.expectedTensor.shape;
}
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const RollParams& params) {
const auto data = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
const auto shift = std::make_shared<opset1::Constant>(params.shiftTensor.type,
params.shiftTensor.shape,
params.shiftTensor.data.data());
const auto axes = std::make_shared<opset1::Constant>(params.axesTensor.type,
params.axesTensor.shape,
params.axesTensor.data.data());
const auto roll = std::make_shared<opset7::Roll>(data, shift, axes);
return std::make_shared<Function>(NodeVector {roll}, ParameterVector {data});
}
};
TEST_P(ReferenceRollLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<RollParams> generateRollParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<RollParams> rollParams {
// roll_repeated_axes
RollParams(
Tensor({4, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}),
Tensor({3}, element::i64, std::vector<int64_t>{1, 2, 1}),
Tensor({3}, element::i64, std::vector<int64_t>{0, 1, 0}),
Tensor({4, 3}, IN_ET, std::vector<T>{8, 9, 7, 11, 12, 10, 2, 3, 1, 5, 6, 4}),
"roll_repeated_axes"),
// roll_negative_axes
RollParams(
Tensor({4, 2, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}),
Tensor({3}, element::i64, std::vector<int64_t>{2, -1, -7}),
Tensor({3}, element::i64, std::vector<int64_t>{-1, -1, -2}),
Tensor({4, 2, 3}, IN_ET, std::vector<T>{6, 4, 5, 3, 1, 2, 12, 10, 11, 9, 7, 8, 18, 16, 17, 15, 13, 14, 24, 22, 23, 21, 19, 20}),
"roll_negative_axes"),
};
return rollParams;
}
std::vector<RollParams> generateRollFloatingPointParams() {
std::vector<RollParams> rollParams {
// roll_2d_input
RollParams(
Tensor({4, 3}, element::f32, std::vector<float>{50.2907,
70.8054,
-68.3403,
62.6444,
4.9748,
-18.5551,
40.5383,
-15.3859,
-4.5881,
-43.3479,
94.1676,
-95.7097}),
Tensor({1}, element::i64, std::vector<int64_t>{1}),
Tensor({1}, element::i64, std::vector<int64_t>{0}),
Tensor({4, 3}, element::f32, std::vector<float>{-43.3479,
94.1676,
-95.7097,
50.2907,
70.8054,
-68.3403,
62.6444,
4.9748,
-18.5551,
40.5383,
-15.3859,
-4.5881}),
"roll_2d_input"),
// roll_2d_input_negative_shift
RollParams(
Tensor({4, 3}, element::f32, std::vector<float>{50.2907,
70.8054,
-68.3403,
62.6444,
4.9748,
-18.5551,
40.5383,
-15.3859,
-4.5881,
-43.3479,
94.1676,
-95.7097}),
Tensor({2}, element::i64, std::vector<int64_t>{-1, 2}),
Tensor({2}, element::i64, std::vector<int64_t>{0, 1}),
Tensor({4, 3}, element::f32, std::vector<float>{4.9748,
-18.5551,
62.6444,
-15.3859,
-4.5881,
40.5383,
94.1676,
-95.7097,
-43.3479,
70.8054,
-68.3403,
50.2907}),
"roll_2d_input_negative_shift"),
// roll_3d_input
RollParams(
Tensor({4, 2, 3}, element::f32, std::vector<float>{94.0773, 33.0599, 58.1724, -20.3640, 54.5372, -54.3023, 10.4662, 11.7532,
-11.7692, 56.4223, -95.3774, 8.8978, 1.9305, 13.8025, 12.0827, 81.4669,
19.5321, -8.9553, -75.3226, 20.8033, 20.7660, 62.7361, 14.9372, -33.0825}),
Tensor({3}, element::i64, std::vector<int64_t>{2, 1, 3}),
Tensor({3}, element::i64, std::vector<int64_t>{0, 1, 2}),
Tensor({4, 2, 3}, element::f32, std::vector<float>{81.4669, 19.5321, -8.9553, 1.9305, 13.8025, 12.0827, 62.7361, 14.9372,
-33.0825, -75.3226, 20.8033, 20.7660, -20.3640, 54.5372, -54.3023, 94.0773,
33.0599, 58.1724, 56.4223, -95.3774, 8.8978, 10.4662, 11.7532, -11.7692}),
"roll_3d_input"),
// roll_3d_input_negative_shift
RollParams(
Tensor({4, 2, 3}, element::f32, std::vector<float>{94.0773, 33.0599, 58.1724, -20.3640, 54.5372, -54.3023, 10.4662, 11.7532,
-11.7692, 56.4223, -95.3774, 8.8978, 1.9305, 13.8025, 12.0827, 81.4669,
19.5321, -8.9553, -75.3226, 20.8033, 20.7660, 62.7361, 14.9372, -33.0825}),
Tensor({3}, element::i64, std::vector<int64_t>{-5, 1, 3}),
Tensor({3}, element::i64, std::vector<int64_t>{0, 1, 1}),
Tensor({4, 2, 3}, element::f32, std::vector<float>{10.4662, 11.7532, -11.7692, 56.4223, -95.3774, 8.8978, 1.9305, 13.8025,
12.0827, 81.4669, 19.5321, -8.9553, -75.3226, 20.8033, 20.7660, 62.7361,
14.9372, -33.0825, 94.0773, 33.0599, 58.1724, -20.3640, 54.5372, -54.3023}),
"roll_3d_input_negative_shift"),
};
return rollParams;
}
std::vector<RollParams> generateRollCombinedParams() {
const std::vector<std::vector<RollParams>> rollTypeParams {
generateRollParams<element::Type_t::i8>(),
generateRollParams<element::Type_t::i16>(),
generateRollParams<element::Type_t::i32>(),
generateRollParams<element::Type_t::i64>(),
generateRollParams<element::Type_t::u8>(),
generateRollParams<element::Type_t::u16>(),
generateRollParams<element::Type_t::u32>(),
generateRollParams<element::Type_t::u64>(),
generateRollParams<element::Type_t::bf16>(),
generateRollParams<element::Type_t::f16>(),
generateRollParams<element::Type_t::f32>(),
generateRollParams<element::Type_t::f64>(),
generateRollFloatingPointParams(),
};
std::vector<RollParams> combinedParams;
for (const auto& params : rollTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_Roll_With_Hardcoded_Refs, ReferenceRollLayerTest,
testing::ValuesIn(generateRollCombinedParams()), ReferenceRollLayerTest::getTestCaseName);
} // namespace

View File

@ -0,0 +1,209 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/opsets/opset1.hpp"
#include "base_reference_test.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct ShuffleChannelsParams {
ShuffleChannelsParams(const Tensor& dataTensor, const int32_t axis, const int32_t group,
const Tensor& expectedTensor, const std::string& testcaseName = "") :
dataTensor(dataTensor), axis(axis), group(group),
expectedTensor(expectedTensor), testcaseName(testcaseName) {}
Tensor dataTensor;
int32_t axis;
int32_t group;
Tensor expectedTensor;
std::string testcaseName;
};
class ReferenceShuffleChannelsLayerTest : public testing::TestWithParam<ShuffleChannelsParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.dataTensor.data};
refOutData = {params.expectedTensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<ShuffleChannelsParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "dType=" << param.dataTensor.type;
result << "_dShape=" << param.dataTensor.shape;
result << "_axis=" << param.axis;
result << "_group=" << param.group;
result << "_eType=" << param.expectedTensor.type;
if (param.testcaseName != "") {
result << "_eShape=" << param.expectedTensor.shape;
result << "_=" << param.testcaseName;
} else {
result << "_eShape=" << param.expectedTensor.shape;
}
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const ShuffleChannelsParams& params) {
const auto data = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
const auto function = std::make_shared<opset1::ShuffleChannels>(data, params.axis, params.group);
return std::make_shared<Function>(NodeVector {function}, ParameterVector {data});
}
};
TEST_P(ReferenceShuffleChannelsLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<ShuffleChannelsParams> generateParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<ShuffleChannelsParams> params {
// shuffle_channels_simple
ShuffleChannelsParams(
Tensor({1, 15, 2, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59}),
1,
5,
Tensor({1, 15, 2, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59}),
"shuffle_channels_simple"),
// shuffle_channels_negative_axis
ShuffleChannelsParams(
Tensor({15, 2, 1, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59}),
-4,
5,
Tensor({15, 2, 1, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59}),
"shuffle_channels_negative_axis"),
// shuffle_channels_float
ShuffleChannelsParams(
Tensor({6, 1, 1, 1}, IN_ET, std::vector<T>{0, 1, 2, 3, 4, 5}),
0,
2,
Tensor({6, 1, 1, 1}, IN_ET, std::vector<T>{0, 3, 1, 4, 2, 5}),
"shuffle_channels_float"),
// shuffle_channels_1d
ShuffleChannelsParams(
Tensor({15}, IN_ET, std::vector<T>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}),
0,
5,
Tensor({15}, IN_ET, std::vector<T>{0, 3, 6, 9, 12, 1, 4, 7, 10, 13, 2, 5, 8, 11, 14}),
"shuffle_channels_1d"),
// shuffle_channels_2d
ShuffleChannelsParams(
Tensor({15, 4}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59}),
0,
5,
Tensor({15, 4}, IN_ET, std::vector<T>{
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38,
39, 48, 49, 50, 51, 4, 5, 6, 7, 16, 17, 18, 19, 28, 29,
30, 31, 40, 41, 42, 43, 52, 53, 54, 55, 8, 9, 10, 11, 20,
21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59}),
"shuffle_channels_2d"),
// shuffle_channels_3d
ShuffleChannelsParams(
Tensor({15, 2, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59}),
0,
5,
Tensor({15, 2, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38,
39, 48, 49, 50, 51, 4, 5, 6, 7, 16, 17, 18, 19, 28, 29,
30, 31, 40, 41, 42, 43, 52, 53, 54, 55, 8, 9, 10, 11, 20,
21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59}),
"shuffle_channels_3d"),
// shuffle_channels_5d
ShuffleChannelsParams(
Tensor({2, 2, 15, 2, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59}),
2,
5,
Tensor({2, 2, 15, 2, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59,
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59,
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59,
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59}),
"shuffle_channels_5d"),
};
return params;
}
std::vector<ShuffleChannelsParams> generateShuffleChannelsCombinedParams() {
const std::vector<std::vector<ShuffleChannelsParams>> generatedParams {
generateParams<element::Type_t::i8>(),
generateParams<element::Type_t::i16>(),
generateParams<element::Type_t::i32>(),
generateParams<element::Type_t::i64>(),
generateParams<element::Type_t::u8>(),
generateParams<element::Type_t::u16>(),
generateParams<element::Type_t::u32>(),
generateParams<element::Type_t::u64>(),
generateParams<element::Type_t::bf16>(),
generateParams<element::Type_t::f16>(),
generateParams<element::Type_t::f32>(),
generateParams<element::Type_t::f64>(),
};
std::vector<ShuffleChannelsParams> combinedParams;
for (const auto& params : generatedParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_ShuffleChannels_With_Hardcoded_Refs, ReferenceShuffleChannelsLayerTest,
testing::ValuesIn(generateShuffleChannelsCombinedParams()), ReferenceShuffleChannelsLayerTest::getTestCaseName);
} // namespace

View File

@ -0,0 +1,143 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/opsets/opset1.hpp"
#include "openvino/opsets/opset2.hpp"
#include "openvino/op/constant.hpp"
#include "base_reference_test.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct SpaceToBatchParams {
SpaceToBatchParams(const Tensor& dataTensor, const Tensor& blockShapeTensor,
const Tensor& padsBeginTensor, const Tensor& padsEndTensor,
const Tensor& expectedTensor, const std::string& testcaseName = "") :
dataTensor(dataTensor), blockShapeTensor(blockShapeTensor),
padsBeginTensor(padsBeginTensor), padsEndTensor(padsEndTensor),
expectedTensor(expectedTensor), testcaseName(testcaseName) {}
Tensor dataTensor;
Tensor blockShapeTensor;
Tensor padsBeginTensor;
Tensor padsEndTensor;
Tensor expectedTensor;
std::string testcaseName;
};
class ReferenceSpaceToBatchLayerTest : public testing::TestWithParam<SpaceToBatchParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.dataTensor.data};
refOutData = {params.expectedTensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<SpaceToBatchParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "dType=" << param.dataTensor.type;
result << "_dShape=" << param.dataTensor.shape;
result << "_bsType=" << param.blockShapeTensor.type;
result << "_bsShape=" << param.blockShapeTensor.shape;
result << "_pbType=" << param.padsBeginTensor.type;
result << "_pbShape=" << param.padsBeginTensor.shape;
result << "_peType=" << param.padsEndTensor.type;
result << "_peShape=" << param.padsEndTensor.shape;
result << "_eType=" << param.expectedTensor.type;
if (param.testcaseName != "") {
result << "_eShape=" << param.expectedTensor.shape;
result << "_" << param.testcaseName;
} else {
result << "_eShape=" << param.expectedTensor.shape;
}
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const SpaceToBatchParams& params) {
const auto data = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
const auto blockShape = std::make_shared<opset1::Constant>(element::i64, params.blockShapeTensor.shape, params.blockShapeTensor.data.data());
const auto padsBegin = std::make_shared<opset1::Constant>(element::i64, params.padsBeginTensor.shape, params.padsBeginTensor.data.data());
const auto padsEnd = std::make_shared<opset1::Constant>(element::i64, params.padsEndTensor.shape, params.padsEndTensor.data.data());
const auto batchToSpace = std::make_shared<opset2::SpaceToBatch>(data, blockShape, padsBegin, padsEnd);
return std::make_shared<ov::Function>(NodeVector {batchToSpace}, ParameterVector {data});
}
};
TEST_P(ReferenceSpaceToBatchLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<SpaceToBatchParams> generateParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<SpaceToBatchParams> batchToSpaceParams {
// space_to_batch_4D
SpaceToBatchParams(
Tensor({1, 1, 2, 2}, IN_ET, std::vector<T>{1, 1, 1, 1}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 1, 1}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({1, 1, 2, 2}, IN_ET, std::vector<T>{1, 1, 1, 1}),
"space_to_batch_4D"),
// space_to_batch_5D
SpaceToBatchParams(
Tensor({1, 1, 3, 2, 1}, IN_ET, std::vector<T>{1, 1, 1, 1, 1, 1}),
Tensor({5}, element::i64, std::vector<int64_t>{1, 1, 3, 2, 2}),
Tensor({5}, element::i64, std::vector<int64_t>{0, 0, 1, 0, 3}),
Tensor({5}, element::i64, std::vector<int64_t>{0, 0, 2, 0, 0}),
Tensor({12, 1, 2, 1, 2}, IN_ET, std::vector<T>{
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}),
"space_to_batch_5D"),
// space_to_batch_4x4
SpaceToBatchParams(
Tensor({1, 1, 4, 4}, IN_ET, std::vector<T>{
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}),
Tensor({4}, element::i64, std::vector<int64_t>{1, 1, 1, 1}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 1, 0}),
Tensor({4}, element::i64, std::vector<int64_t>{0, 0, 0, 0}),
Tensor({1, 1, 5, 4}, IN_ET, std::vector<T>{
0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 1, 0, 0, 0, 0, 1}),
"space_to_batch_4x4"),
};
return batchToSpaceParams;
}
std::vector<SpaceToBatchParams> generateCombinedParams() {
const std::vector<std::vector<SpaceToBatchParams>> batchToSpaceTypeParams {
generateParams<element::Type_t::i8>(),
generateParams<element::Type_t::i16>(),
generateParams<element::Type_t::i32>(),
generateParams<element::Type_t::i64>(),
generateParams<element::Type_t::u8>(),
generateParams<element::Type_t::u16>(),
generateParams<element::Type_t::u32>(),
generateParams<element::Type_t::u64>(),
generateParams<element::Type_t::bf16>(),
generateParams<element::Type_t::f16>(),
generateParams<element::Type_t::f32>(),
generateParams<element::Type_t::f64>(),
};
std::vector<SpaceToBatchParams> combinedParams;
for (const auto& params : batchToSpaceTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_SpaceToBatch_With_Hardcoded_Refs, ReferenceSpaceToBatchLayerTest,
testing::ValuesIn(generateCombinedParams()), ReferenceSpaceToBatchLayerTest::getTestCaseName);
} // namespace

View File

@ -0,0 +1,169 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/opsets/opset1.hpp"
#include "base_reference_test.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct SpaceToDepthParams {
SpaceToDepthParams(const Tensor& dataTensor, const std::string mode, const int32_t blockSize,
const Tensor& expectedTensor, const std::string& testcaseName = "") :
dataTensor(dataTensor), mode(mode), blockSize(blockSize), expectedTensor(expectedTensor),
testcaseName(testcaseName) {}
Tensor dataTensor;
std::string mode;
int32_t blockSize;
Tensor expectedTensor;
std::string testcaseName;
};
class ReferenceSpaceToDepthLayerTest : public testing::TestWithParam<SpaceToDepthParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.dataTensor.data};
refOutData = {params.expectedTensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<SpaceToDepthParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "dType=" << param.dataTensor.type;
result << "_dShape=" << param.dataTensor.shape;
result << "_eType=" << param.expectedTensor.type;
if (param.testcaseName != "") {
result << "_eShape=" << param.expectedTensor.shape;
result << "_" << param.testcaseName;
} else {
result << "_eShape=" << param.expectedTensor.shape;
}
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const SpaceToDepthParams& params) {
opset1::SpaceToDepth::SpaceToDepthMode mode = params.mode == "DEPTH_FIRST" ?
opset1::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST : opset1::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
const auto data = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
const auto SpaceToDepth = std::make_shared<opset1::SpaceToDepth>(data, mode, params.blockSize);
return std::make_shared<Function>(NodeVector {SpaceToDepth}, ParameterVector {data});
}
};
TEST_P(ReferenceSpaceToDepthLayerTest, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<SpaceToDepthParams> generateParams() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<SpaceToDepthParams> params {
// space_to_depth_block_first_K2_BS2
SpaceToDepthParams(
Tensor({1, 2, 4, 4}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31}),
"BLOCKS_FIRST",
2,
Tensor({1, 8, 2, 2}, IN_ET, std::vector<T>{
0, 2, 8, 10, 16, 18, 24, 26, 1, 3, 9, 11, 17, 19, 25, 27,
4, 6, 12, 14, 20, 22, 28, 30, 5, 7, 13, 15, 21, 23, 29, 31}),
"space_to_depth_block_first_K2_BS2"),
// space_to_depth_block_first_K2_BS3
SpaceToDepthParams(
Tensor({1, 2, 6, 3}, IN_ET, std::vector<T>{
0, 4, 8, 12, 16, 20, 24, 28, 32, 1, 5, 9,
13, 17, 21, 25, 29, 33, 2, 6, 10, 14, 18, 22,
26, 30, 34, 3, 7, 11, 15, 19, 23, 27, 31, 35}),
"BLOCKS_FIRST",
3,
Tensor({1, 18, 2, 1}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35}),
"space_to_depth_block_first_K2_BS3"),
// space_to_depth_block_first_K1_BS3
SpaceToDepthParams(
Tensor({1, 2, 6}, IN_ET, std::vector<T>{
0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11}),
"BLOCKS_FIRST",
3,
Tensor({1, 6, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}),
"space_to_depth_block_first_K1_BS3"),
// space_to_depth_depth_first_K2_BS2
SpaceToDepthParams(
Tensor({1, 2, 4, 4}, IN_ET, std::vector<T>{
0, 16, 2, 18, 1, 17, 3, 19, 8, 24, 10,
26, 9, 25, 11, 27, 4, 20, 6, 22, 5, 21,
7, 23, 12, 28, 14, 30, 13, 29, 15, 31}),
"DEPTH_FIRST",
2,
Tensor({1, 8, 2, 2}, IN_ET, std::vector<T>{
0, 2, 8, 10, 16, 18, 24, 26, 1, 3, 9, 11, 17, 19, 25, 27,
4, 6, 12, 14, 20, 22, 28, 30, 5, 7, 13, 15, 21, 23, 29, 31}),
"space_to_depth_depth_first_K2_BS2"),
// space_to_depth_depth_first_K2_BS3
SpaceToDepthParams(
Tensor({1, 2, 6, 3}, IN_ET, std::vector<T>{
0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5,
7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 28,
30, 32, 34, 19, 21, 23, 25, 27, 29, 31, 33, 35}),
"DEPTH_FIRST",
3,
Tensor({1, 18, 2, 1}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35}),
"space_to_depth_depth_first_K2_BS3"),
// space_to_depth_depth_first_K1_BS3
SpaceToDepthParams(
Tensor({1, 2, 6}, IN_ET, std::vector<T>{
0, 2, 4, 1, 3, 5, 6, 8, 10, 7, 9, 11}),
"DEPTH_FIRST",
3,
Tensor({1, 6, 2}, IN_ET, std::vector<T>{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}),
"space_to_depth_depth_first_K1_BS3"),
};
return params;
}
std::vector<SpaceToDepthParams> generateCombinedParams() {
const std::vector<std::vector<SpaceToDepthParams>> generatedParams {
generateParams<element::Type_t::i8>(),
generateParams<element::Type_t::i16>(),
generateParams<element::Type_t::i32>(),
generateParams<element::Type_t::i64>(),
generateParams<element::Type_t::u8>(),
generateParams<element::Type_t::u16>(),
generateParams<element::Type_t::u32>(),
generateParams<element::Type_t::u64>(),
generateParams<element::Type_t::bf16>(),
generateParams<element::Type_t::f16>(),
generateParams<element::Type_t::f32>(),
generateParams<element::Type_t::f64>(),
};
std::vector<SpaceToDepthParams> combinedParams;
for (const auto& params : generatedParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_SpaceToDepth_With_Hardcoded_Refs, ReferenceSpaceToDepthLayerTest,
testing::ValuesIn(generateCombinedParams()), ReferenceSpaceToDepthLayerTest::getTestCaseName);
} // namespace

View File

@ -77,6 +77,15 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*ReferencePadTest.*pad_exterior_2d_3x0)", R"(.*ReferencePadTest.*pad_exterior_2d_3x0)",
// CVS-70975 // CVS-70975
R"(.*ReferencePadTestParamsTooLarge.*)", R"(.*ReferencePadTestParamsTooLarge.*)",
// CVS-64006
R"(.*ReferenceBatchToSpaceLayerTest.*dType=i4.*)",
R"(.*ReferenceBatchToSpaceLayerTest.*dType=u4.*)",
// CVS-64113
R"(.*ReferenceRollLayerTest.*dType=i4.*)",
R"(.*ReferenceRollLayerTest.*dType=u4.*)",
// CVS-64050
R"(.*ReferenceSpaceToBatchLayerTest.*dType=i4.*)",
R"(.*ReferenceSpaceToBatchLayerTest.*dType=u4.*)",
}; };
#ifdef _WIN32 #ifdef _WIN32

View File

@ -380,6 +380,7 @@ set(SRC
visitors/op/rnn_cell.cpp visitors/op/rnn_cell.cpp
visitors/op/rnn_sequence.cpp visitors/op/rnn_sequence.cpp
visitors/op/roi_pooling.cpp visitors/op/roi_pooling.cpp
visitors/op/roll.cpp
visitors/op/round.cpp visitors/op/round.cpp
visitors/op/scatter_elements_update.cpp visitors/op/scatter_elements_update.cpp
visitors/op/scatter_update.cpp visitors/op/scatter_update.cpp
@ -478,13 +479,11 @@ set(MULTI_TEST_SRC
backend/aliased_output.in.cpp backend/aliased_output.in.cpp
backend/api.in.cpp backend/api.in.cpp
backend/auto_broadcast.in.cpp backend/auto_broadcast.in.cpp
backend/batch_to_space.in.cpp
backend/broadcast.in.cpp backend/broadcast.in.cpp
backend/builder_reduce_ops_opset1.in.cpp backend/builder_reduce_ops_opset1.in.cpp
backend/concat.in.cpp backend/concat.in.cpp
backend/ctc_greedy_decoder.in.cpp backend/ctc_greedy_decoder.in.cpp
backend/ctc_greedy_decoder_seq_len.in.cpp backend/ctc_greedy_decoder_seq_len.in.cpp
backend/depth_to_space.in.cpp
backend/dyn_reshape.in.cpp backend/dyn_reshape.in.cpp
backend/experimental_detectron_topk_rois.in.cpp backend/experimental_detectron_topk_rois.in.cpp
backend/dynamic.in.cpp backend/dynamic.in.cpp
@ -500,10 +499,6 @@ set(MULTI_TEST_SRC
backend/one_hot.in.cpp backend/one_hot.in.cpp
backend/recurrent_cells.in.cpp backend/recurrent_cells.in.cpp
backend/region_yolo.in.cpp backend/region_yolo.in.cpp
backend/roll.in.cpp
backend/space_to_depth.in.cpp
backend/shuffle_channels.in.cpp
backend/space_to_batch.in.cpp
backend/sqrt.in.cpp backend/sqrt.in.cpp
backend/tile.in.cpp backend/tile.in.cpp
backend/topk.in.cpp backend/topk.in.cpp

View File

@ -1,167 +0,0 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
namespace {
template <typename dataType>
struct BatchToSpaceParams {
using Data = test::NDArrayBase<dataType>;
using BlockShape = test::NDArrayBase<int64_t>;
using Crops = test::NDArrayBase<int64_t>;
BatchToSpaceParams(Data in_data, BlockShape block_shape, Crops crops_begin, Crops crops_end, Data expected_output)
: m_data{std::move(in_data)},
m_block_shape{std::move(block_shape)},
m_crops_begin{std::move(crops_begin)},
m_crops_end{std::move(crops_end)},
m_expected_output{std::move(expected_output)} {}
Data m_data;
BlockShape m_block_shape;
Crops m_crops_begin;
Crops m_crops_end;
Data m_expected_output;
};
template <typename dataType>
static void BatchToSpaceTestExecute(const BatchToSpaceParams<dataType>& params) {
const auto data = make_shared<op::Parameter>(element::from<dataType>(), params.m_data.get_shape());
const auto block_shape =
op::Constant::create(element::i64, params.m_block_shape.get_shape(), params.m_block_shape.get_vector());
const auto crops_begin =
op::Constant::create(element::i64, params.m_crops_begin.get_shape(), params.m_crops_begin.get_vector());
const auto crops_end =
op::Constant::create(element::i64, params.m_crops_end.get_shape(), params.m_crops_end.get_vector());
const auto batch_to_space = make_shared<op::v1::BatchToSpace>(data, block_shape, crops_begin, crops_end);
auto f = make_shared<Function>(batch_to_space, ParameterVector{data});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input(params.m_data.get_vector());
test_case.add_expected_output(params.m_expected_output.get_vector());
test_case.run_with_tolerance_as_fp(1e-4f);
}
class BatchToSpaceTestFloat : public testing::TestWithParam<BatchToSpaceParams<float>> {};
} // namespace
NGRAPH_TEST_P(${BACKEND_NAME}, BatchToSpaceTestFloat, BatchToSpaceTestFloatCases) {
BatchToSpaceTestExecute(GetParam());
}
const test::NDArray<float, 2> input_with_shape_4x3(
{{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}, {7.0f, 8.0f, 9.0f}, {10.0f, 11.0f, 12.0f}});
const test::NDArray<int64_t, 1> zero_crops_2d({0, 0});
NGRAPH_INSTANTIATE_TEST_SUITE_P(${BACKEND_NAME},
batch_to_space_2d_without_crops,
BatchToSpaceTestFloat,
testing::Values(BatchToSpaceParams<float>{
input_with_shape_4x3,
test::NDArray<int64_t, 1>({1, 2}),
zero_crops_2d,
zero_crops_2d,
test::NDArray<float, 2>({{1.0f, 7.0f, 2.0f, 8.0f, 3.0f, 9.0f},
{4.0f, 10.0f, 5.0f, 11.0f, 6.0f, 12.0f}})}));
const test::NDArray<float, 4> input_with_shape_4x1x1x3(
{{{{1.0f, 2.0f, 3.0f}}}, {{{4.0f, 5.0f, 6.0f}}}, {{{7.0f, 8.0f, 9.0f}}}, {{{10.0f, 11.0f, 12.0f}}}});
const test::NDArray<float, 4> input_with_shape_4x1x2x3({{{{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}}},
{{{7.0f, 8.0f, 9.0f}, {10.0f, 11.0f, 12.0f}}},
{{{13.0f, 14.0f, 15.0f}, {16.0f, 17.0f, 18.0f}}},
{{{19.0f, 20.0f, 21.0f}, {22.0f, 23.0f, 24.0f}}}});
const test::NDArray<int64_t, 1> zero_crops_4d({0, 0, 0, 0});
NGRAPH_INSTANTIATE_TEST_SUITE_P(
${BACKEND_NAME},
batch_to_space_4d_without_crops,
BatchToSpaceTestFloat,
testing::Values(
BatchToSpaceParams<float>{input_with_shape_4x1x1x3,
test::NDArray<int64_t, 1>({1, 1, 1, 2}),
zero_crops_4d,
zero_crops_4d,
test::NDArray<float, 4>({{{{1.0f, 7.0f, 2.0f, 8.0f, 3.0f, 9.0f}}},
{{{4.0f, 10.0f, 5.0f, 11.0f, 6.0f, 12.0f}}}})},
BatchToSpaceParams<float>{input_with_shape_4x1x1x3,
test::NDArray<int64_t, 1>({1, 1, 2, 1}),
zero_crops_4d,
zero_crops_4d,
test::NDArray<float, 4>({{{{1.0f, 2.0f, 3.0f}, {7.0f, 8.0f, 9.0f}}},
{{{4.0f, 5.0f, 6.0f}, {10.0f, 11.0f, 12.0f}}}})},
BatchToSpaceParams<float>{input_with_shape_4x1x1x3,
test::NDArray<int64_t, 1>({1, 1, 2, 2}),
zero_crops_4d,
zero_crops_4d,
test::NDArray<float, 4>({{{{1.0f, 4.0f, 2.0f, 5.0f, 3.0f, 6.0f},
{7.0f, 10.0f, 8.0f, 11.0f, 9.0f, 12.0f}}}})},
BatchToSpaceParams<float>{
input_with_shape_4x1x2x3,
test::NDArray<int64_t, 1>({1, 1, 1, 2}),
zero_crops_4d,
zero_crops_4d,
test::NDArray<float, 4>(
{{{{1.0f, 13.0f, 2.0f, 14.0f, 3.0f, 15.0f}, {4.0f, 16.0f, 5.0f, 17.0f, 6.0f, 18.0f}}},
{{{7.0f, 19.0f, 8.0f, 20.0f, 9.0f, 21.0f}, {10.0f, 22.0f, 11.0f, 23.0f, 12.0f, 24.0f}}}})},
BatchToSpaceParams<float>{
input_with_shape_4x1x2x3,
test::NDArray<int64_t, 1>({1, 1, 2, 1}),
zero_crops_4d,
zero_crops_4d,
test::NDArray<float, 4>(
{{{{1.0f, 2.0f, 3.0f}, {13.0f, 14.0f, 15.0f}, {4.0f, 5.0f, 6.0f}, {16.0f, 17.0f, 18.0f}}},
{{{7.0f, 8.0f, 9.0f}, {19.0f, 20.0f, 21.0f}, {10.0f, 11.0f, 12.0f}, {22.0f, 23.0f, 24.0f}}}})},
BatchToSpaceParams<float>{input_with_shape_4x1x2x3,
test::NDArray<int64_t, 1>({1, 1, 2, 2}),
zero_crops_4d,
zero_crops_4d,
test::NDArray<float, 4>({{{{1.0f, 7.0f, 2.0f, 8.0f, 3.0f, 9.0f},
{13.0f, 19.0f, 14.0f, 20.0f, 15.0f, 21.0f},
{4.0f, 10.0f, 5.0f, 11.0f, 6.0f, 12.0f},
{16.0f, 22.0f, 17.0f, 23.0f, 18.0f, 24.0f}}}})}));
NGRAPH_INSTANTIATE_TEST_SUITE_P(
${BACKEND_NAME},
batch_to_space_4d_crops,
BatchToSpaceTestFloat,
testing::Values(BatchToSpaceParams<float>{input_with_shape_4x1x2x3,
test::NDArray<int64_t, 1>({1, 1, 2, 2}),
test::NDArray<int64_t, 1>({0, 0, 0, 0}),
test::NDArray<int64_t, 1>({0, 0, 0, 2}),
test::NDArray<float, 4>({{{{1.0f, 7.0f, 2.0f, 8.0f},
{13.0f, 19.0f, 14.0f, 20.0f},
{4.0f, 10.0f, 5.0f, 11.0f},
{16.0f, 22.0f, 17.0f, 23.0f}}}})},
BatchToSpaceParams<float>{input_with_shape_4x1x2x3,
test::NDArray<int64_t, 1>({1, 1, 2, 2}),
test::NDArray<int64_t, 1>({0, 0, 0, 2}),
test::NDArray<int64_t, 1>({0, 0, 0, 0}),
test::NDArray<float, 4>({{{{2.0f, 8.0f, 3.0f, 9.0f},
{14.0f, 20.0f, 15.0f, 21.0f},
{5.0f, 11.0f, 6.0f, 12.0f},
{17.0f, 23.0f, 18.0f, 24.0f}}}})},
BatchToSpaceParams<float>{input_with_shape_4x1x2x3,
test::NDArray<int64_t, 1>({1, 1, 2, 2}),
test::NDArray<int64_t, 1>({0, 0, 1, 0}),
test::NDArray<int64_t, 1>({0, 0, 1, 0}),
test::NDArray<float, 4>({{{{13.0f, 19.0f, 14.0f, 20.0f, 15.0f, 21.0f},
{4.0f, 10.0f, 5.0f, 11.0f, 6.0f, 12.0f}}}})}));

View File

@ -1,106 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/op/depth_to_space.hpp"
#include "util/test_control.hpp"
using namespace ngraph;
static std::string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, depth_to_space_block_first_K1_BS2) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 8, 2});
auto depth_to_space = std::make_shared<op::DepthToSpace>(A, op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST, 2);
auto function = std::make_shared<Function>(NodeVector{depth_to_space}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>(
{0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f, 1.f, 3.f, 9.f, 11.f, 17.f, 19.f, 25.f, 27.f});
test_case.add_expected_output<float>(
Shape{1, 4, 4},
{0.f, 1.f, 2.f, 3.f, 8.f, 9.f, 10.f, 11.f, 16.f, 17.f, 18.f, 19.f, 24.f, 25.f, 26.f, 27.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, depth_to_space_block_first_K2_BS2) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 8, 2, 2});
auto depth_to_space = std::make_shared<op::DepthToSpace>(A, op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST, 2);
auto function = std::make_shared<Function>(NodeVector{depth_to_space}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f, 1.f, 3.f, 9.f,
11.f, 17.f, 19.f, 25.f, 27.f, 4.f, 6.f, 12.f, 14.f, 20.f, 22.f,
28.f, 30.f, 5.f, 7.f, 13.f, 15.f, 21.f, 23.f, 29.f, 31.f});
test_case.add_expected_output<float>(
Shape{1, 2, 4, 4},
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f,
16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, depth_to_space_block_first_K2_BS4) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 16, 2, 1});
auto depth_to_space = std::make_shared<op::DepthToSpace>(A, op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST, 4);
auto function = std::make_shared<Function>(NodeVector{depth_to_space}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 16.f, 1.f, 17.f, 2.f, 18.f, 3.f, 19.f, 4.f, 20.f, 5.f,
21.f, 6.f, 22.f, 7.f, 23.f, 8.f, 24.f, 9.f, 25.f, 10.f, 26.f,
11.f, 27.f, 12.f, 28.f, 13.f, 29.f, 14.f, 30.f, 15.f, 31.f});
test_case.add_expected_output<float>(
Shape{1, 1, 8, 4},
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f,
16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, depth_to_space_depth_first_1K_BS2) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 8, 2});
auto depth_to_space = std::make_shared<op::DepthToSpace>(A, op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST, 2);
auto function = std::make_shared<Function>(NodeVector{depth_to_space}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 2.f, 1.f, 3.f, 4.f, 6.f, 5.f, 7.f, 8.f, 10.f, 9.f, 11.f, 12.f, 14.f, 13.f, 15.f});
test_case.add_expected_output<float>(
Shape{1, 4, 4},
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, depth_to_space_depth_first_2K_BS2) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 8, 2, 2});
auto depth_to_space = std::make_shared<op::DepthToSpace>(A, op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST, 2);
auto function = std::make_shared<Function>(NodeVector{depth_to_space}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f, 1.f, 3.f, 9.f,
11.f, 17.f, 19.f, 25.f, 27.f, 4.f, 6.f, 12.f, 14.f, 20.f, 22.f,
28.f, 30.f, 5.f, 7.f, 13.f, 15.f, 21.f, 23.f, 29.f, 31.f});
test_case.add_expected_output<float>(
Shape{1, 2, 4, 4},
{0.f, 16.f, 2.f, 18.f, 1.f, 17.f, 3.f, 19.f, 8.f, 24.f, 10.f, 26.f, 9.f, 25.f, 11.f, 27.f,
4.f, 20.f, 6.f, 22.f, 5.f, 21.f, 7.f, 23.f, 12.f, 28.f, 14.f, 30.f, 13.f, 29.f, 15.f, 31.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, depth_to_space_depth_first_2K_BS4) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 16, 2, 1});
auto depth_to_space = std::make_shared<op::DepthToSpace>(A, op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST, 4);
auto function = std::make_shared<Function>(NodeVector{depth_to_space}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 16.f, 1.f, 17.f, 2.f, 18.f, 3.f, 19.f, 4.f, 20.f, 5.f,
21.f, 6.f, 22.f, 7.f, 23.f, 8.f, 24.f, 9.f, 25.f, 10.f, 26.f,
11.f, 27.f, 12.f, 28.f, 13.f, 29.f, 14.f, 30.f, 15.f, 31.f});
test_case.add_expected_output<float>(
Shape{1, 1, 8, 4},
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f,
16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f});
test_case.run();
}

View File

@ -1,197 +0,0 @@
//*****************************************************************************
// Copyright 2017-2021 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.
//*****************************************************************************
#include "engines_util/execute_tools.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/opsets/opset7.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "ngraph/shape.hpp"
#include "runtime/backend.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, roll_2d_input) {
Shape shape{4, 3};
auto x = make_shared<opset7::Parameter>(element::f32, shape);
auto shift = make_shared<opset7::Constant>(element::i64, Shape{1}, vector<int64_t>{1});
auto axes = make_shared<opset7::Constant>(element::i64, Shape{1}, vector<int64_t>{0});
auto f = make_shared<Function>(make_shared<opset7::Roll>(x, shift, axes), ParameterVector{x});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto x_tensor = backend->create_tensor(element::f32, shape);
copy_data(x_tensor,
vector<float>{50.2907,
70.8054,
-68.3403,
62.6444,
4.9748,
-18.5551,
40.5383,
-15.3859,
-4.5881,
-43.3479,
94.1676,
-95.7097});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {x_tensor});
EXPECT_TRUE(test::all_close_f((vector<float>{-43.3479,
94.1676,
-95.7097,
50.2907,
70.8054,
-68.3403,
62.6444,
4.9748,
-18.5551,
40.5383,
-15.3859,
-4.5881}),
read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, roll_2d_input_negative_shift) {
Shape shape{4, 3};
auto x = make_shared<opset7::Parameter>(element::f32, shape);
auto shift = make_shared<opset7::Constant>(element::i32, Shape{2}, vector<int32_t>{-1, 2});
auto axes = make_shared<opset7::Constant>(element::i32, Shape{2}, vector<int32_t>{0, 1});
auto f = make_shared<Function>(make_shared<opset7::Roll>(x, shift, axes), ParameterVector{x});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto x_tensor = backend->create_tensor(element::f32, shape);
copy_data(x_tensor,
vector<float>{50.2907,
70.8054,
-68.3403,
62.6444,
4.9748,
-18.5551,
40.5383,
-15.3859,
-4.5881,
-43.3479,
94.1676,
-95.7097});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {x_tensor});
EXPECT_TRUE(test::all_close_f((vector<float>{4.9748,
-18.5551,
62.6444,
-15.3859,
-4.5881,
40.5383,
94.1676,
-95.7097,
-43.3479,
70.8054,
-68.3403,
50.2907}),
read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, roll_repeated_axes) {
Shape shape{4, 3};
auto x = make_shared<opset7::Parameter>(element::i64, shape);
auto shift = make_shared<opset7::Constant>(element::i64, Shape{3}, vector<int64_t>{1, 2, 1});
auto axes = make_shared<opset7::Constant>(element::i64, Shape{3}, vector<int64_t>{0, 1, 0});
auto f = make_shared<Function>(make_shared<opset7::Roll>(x, shift, axes), ParameterVector{x});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto x_tensor = backend->create_tensor(element::i64, shape);
copy_data(x_tensor, vector<int64_t>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
auto result = backend->create_tensor(element::i64, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {x_tensor});
EXPECT_TRUE(
test::all_close((vector<int64_t>{8, 9, 7, 11, 12, 10, 2, 3, 1, 5, 6, 4}), read_vector<int64_t>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, roll_3d_input) {
Shape shape{4, 2, 3};
auto x = make_shared<opset7::Parameter>(element::f32, shape);
auto shift = make_shared<opset7::Constant>(element::i64, Shape{3}, vector<int64_t>{2, 1, 3});
auto axes = make_shared<opset7::Constant>(element::i64, Shape{3}, vector<int64_t>{0, 1, 2});
auto f = make_shared<Function>(make_shared<opset7::Roll>(x, shift, axes), ParameterVector{x});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto x_tensor = backend->create_tensor(element::f32, shape);
copy_data(x_tensor, vector<float>{94.0773, 33.0599, 58.1724, -20.3640, 54.5372, -54.3023, 10.4662, 11.7532,
-11.7692, 56.4223, -95.3774, 8.8978, 1.9305, 13.8025, 12.0827, 81.4669,
19.5321, -8.9553, -75.3226, 20.8033, 20.7660, 62.7361, 14.9372, -33.0825});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {x_tensor});
EXPECT_TRUE(
test::all_close_f((vector<float>{81.4669, 19.5321, -8.9553, 1.9305, 13.8025, 12.0827, 62.7361, 14.9372,
-33.0825, -75.3226, 20.8033, 20.7660, -20.3640, 54.5372, -54.3023, 94.0773,
33.0599, 58.1724, 56.4223, -95.3774, 8.8978, 10.4662, 11.7532, -11.7692}),
read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, roll_3d_input_negative_shift) {
Shape shape{4, 2, 3};
auto x = make_shared<opset7::Parameter>(element::f32, shape);
auto shift = make_shared<opset7::Constant>(element::i32, Shape{3}, vector<int32_t>{-5, 1, 3});
auto axes = make_shared<opset7::Constant>(element::i64, Shape{3}, vector<int64_t>{0, 1, 1});
auto f = make_shared<Function>(make_shared<opset7::Roll>(x, shift, axes), ParameterVector{x});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto x_tensor = backend->create_tensor(element::f32, shape);
copy_data(x_tensor, vector<float>{94.0773, 33.0599, 58.1724, -20.3640, 54.5372, -54.3023, 10.4662, 11.7532,
-11.7692, 56.4223, -95.3774, 8.8978, 1.9305, 13.8025, 12.0827, 81.4669,
19.5321, -8.9553, -75.3226, 20.8033, 20.7660, 62.7361, 14.9372, -33.0825});
auto result = backend->create_tensor(element::f32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {x_tensor});
EXPECT_TRUE(
test::all_close_f((vector<float>{10.4662, 11.7532, -11.7692, 56.4223, -95.3774, 8.8978, 1.9305, 13.8025,
12.0827, 81.4669, 19.5321, -8.9553, -75.3226, 20.8033, 20.7660, 62.7361,
14.9372, -33.0825, 94.0773, 33.0599, 58.1724, -20.3640, 54.5372, -54.3023}),
read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, roll_negative_axes) {
Shape shape{4, 2, 3};
auto x = make_shared<opset7::Parameter>(element::i32, shape);
auto shift = make_shared<opset7::Constant>(element::i64, Shape{3}, vector<int64_t>{2, -1, -7});
auto axes = make_shared<opset7::Constant>(element::i32, Shape{3}, vector<int32_t>{-1, -1, -2});
auto f = make_shared<Function>(make_shared<opset7::Roll>(x, shift, axes), ParameterVector{x});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
auto x_tensor = backend->create_tensor(element::i32, shape);
copy_data(x_tensor,
vector<int32_t>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24});
auto result = backend->create_tensor(element::i32, shape);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {x_tensor});
EXPECT_TRUE(test::all_close(
(vector<int32_t>{6, 4, 5, 3, 1, 2, 12, 10, 11, 9, 7, 8, 18, 16, 17, 15, 13, 14, 24, 22, 23, 21, 19, 20}),
read_vector<int32_t>(result)));
}

View File

@ -1,174 +0,0 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/execute_tools.hpp"
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "runtime/backend.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, shuffle_channels_simple) {
const auto data = make_shared<op::Parameter>(element::i32, Shape{1, 15, 2, 2});
auto tested_op = make_shared<op::ShuffleChannels>(data, 1, 5);
auto function = make_shared<Function>(tested_op, ParameterVector{data});
auto test_case = test::TestCase<TestEngine>(function);
std::vector<int32_t> input_data(60);
std::iota(std::begin(input_data), std::end(input_data), 0);
test_case.add_input(input_data);
test_case.add_expected_output<int32_t>(
Shape{1, 15, 2, 2},
{0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, shuffle_channels_negative_axis) {
// In this test the output is the same as in shuffle_channels_simple but
// the axis value is negative and the C(channels) value is in a different dimension(0) of the
// shape
const auto data = make_shared<op::Parameter>(element::i32, Shape{15, 2, 1, 2});
auto tested_op = make_shared<op::ShuffleChannels>(data, -4, 5);
auto function = make_shared<Function>(tested_op, ParameterVector{data});
auto test_case = test::TestCase<TestEngine>(function);
std::vector<int32_t> input_data(60);
std::iota(std::begin(input_data), std::end(input_data), 0);
test_case.add_input(input_data);
test_case.add_expected_output<int32_t>(
Shape{15, 2, 1, 2},
{0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, shuffle_channels_float) {
const auto data = make_shared<op::Parameter>(element::f32, Shape{6, 1, 1, 1});
auto tested_op = make_shared<op::ShuffleChannels>(data, 0, 2);
auto function = make_shared<Function>(tested_op, ParameterVector{data});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
test_case.add_expected_output<float>(Shape{6, 1, 1, 1}, {0.0f, 3.0f, 1.0f, 4.0f, 2.0f, 5.0f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, shuffle_channels_1d) {
Shape data_shape{15};
const auto data = make_shared<op::Parameter>(element::i32, data_shape);
auto tested_op = make_shared<op::ShuffleChannels>(data, 0, 5);
auto function = make_shared<Function>(tested_op, ParameterVector{data});
auto test_case = test::TestCase<TestEngine>(function);
std::vector<int32_t> input_data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
test_case.add_input(input_data);
test_case.add_expected_output<int32_t>(data_shape, {0, 3, 6, 9, 12, 1, 4, 7, 10, 13, 2, 5, 8, 11, 14});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, shuffle_channels_2d) {
Shape data_shape{15, 4};
const auto data = make_shared<op::Parameter>(element::i32, data_shape);
auto tested_op = make_shared<op::ShuffleChannels>(data, 0, 5);
auto function = make_shared<Function>(tested_op, ParameterVector{data});
auto test_case = test::TestCase<TestEngine>(function);
std::vector<int32_t> input_data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59};
test_case.add_input(input_data);
test_case.add_expected_output<int32_t>(data_shape, {0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38,
39, 48, 49, 50, 51, 4, 5, 6, 7, 16, 17, 18, 19, 28, 29,
30, 31, 40, 41, 42, 43, 52, 53, 54, 55, 8, 9, 10, 11, 20,
21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, shuffle_channels_3d) {
Shape data_shape{15, 2, 2};
const auto data = make_shared<op::Parameter>(element::i32, data_shape);
auto tested_op = make_shared<op::ShuffleChannels>(data, 0, 5);
auto function = make_shared<Function>(tested_op, ParameterVector{data});
auto test_case = test::TestCase<TestEngine>(function);
std::vector<int32_t> input_data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59};
test_case.add_input(input_data);
test_case.add_expected_output<int32_t>(data_shape, {0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38,
39, 48, 49, 50, 51, 4, 5, 6, 7, 16, 17, 18, 19, 28, 29,
30, 31, 40, 41, 42, 43, 52, 53, 54, 55, 8, 9, 10, 11, 20,
21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, shuffle_channels_5d) {
Shape data_shape{2, 2, 15, 2, 2};
const auto data = make_shared<op::Parameter>(element::i32, data_shape);
auto tested_op = make_shared<op::ShuffleChannels>(data, 2, 5);
auto function = make_shared<Function>(tested_op, ParameterVector{data});
auto test_case = test::TestCase<TestEngine>(function);
std::vector<int32_t> input_data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59};
test_case.add_input(input_data);
test_case.add_expected_output<int32_t>(
data_shape,
{0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59,
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59,
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59,
0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39, 48, 49, 50, 51,
4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43, 52, 53, 54, 55,
8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47, 56, 57, 58, 59});
test_case.run();
}

View File

@ -1,119 +0,0 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
static void SpaceToBatchTest(const std::vector<float>& inputs,
const Shape inputs_shape,
const std::vector<int64_t>& block_shapes,
const Shape blocks_shape,
const std::vector<int64_t>& pads_begins,
const std::vector<int64_t>& pads_ends,
const Shape pads_shape,
const std::vector<float>& outputs,
const Shape outputs_shape) {
auto inputs_param = make_shared<op::Parameter>(element::f32, inputs_shape);
auto block_shapes_param = make_shared<op::Constant>(element::i64, blocks_shape, block_shapes);
auto pads_begins_param = make_shared<op::Constant>(element::i64, pads_shape, pads_begins);
auto pads_ends_param = make_shared<op::Constant>(element::i64, pads_shape, pads_ends);
auto space_to_batch =
make_shared<op::v1::SpaceToBatch>(inputs_param, block_shapes_param, pads_begins_param, pads_ends_param);
auto f = make_shared<Function>(space_to_batch, ParameterVector{inputs_param});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(inputs);
test_case.add_expected_output<float>(outputs_shape, outputs);
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, space_to_batch_4D) {
const Shape inputs_shape{1, 1, 2, 2};
const std::vector<float> inputs{1.0f, 1.0f, 1.0f, 1.0f};
const Shape blocks_shape{4};
const std::vector<int64_t> block_shapes{1, 1, 1, 1};
const Shape pads_shape{4};
const std::vector<int64_t> pads_begins{0, 0, 0, 0};
const std::vector<int64_t> pads_ends{0, 0, 0, 0};
const Shape outputs_shape{1, 1, 2, 2};
const std::vector<float> outputs{1.0f, 1.0f, 1.0f, 1.0f};
SpaceToBatchTest(inputs,
inputs_shape,
block_shapes,
blocks_shape,
pads_begins,
pads_ends,
pads_shape,
outputs,
outputs_shape);
}
NGRAPH_TEST(${BACKEND_NAME}, space_to_batch_5D) {
const Shape inputs_shape{1, 1, 3, 2, 1};
const std::vector<float> inputs{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
const Shape blocks_shape{5};
const std::vector<int64_t> block_shapes{1, 1, 3, 2, 2};
const Shape pads_shape{5};
const std::vector<int64_t> pads_begins{0, 0, 1, 0, 3};
const std::vector<int64_t> pads_ends{0, 0, 2, 0, 0};
const Shape outputs_shape{12, 1, 2, 1, 2};
const std::vector<float> outputs{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
SpaceToBatchTest(inputs,
inputs_shape,
block_shapes,
blocks_shape,
pads_begins,
pads_ends,
pads_shape,
outputs,
outputs_shape);
}
NGRAPH_TEST(${BACKEND_NAME}, space_to_batch_4x4) {
const Shape inputs_shape{1, 1, 4, 4};
const std::vector<float>
inputs{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
const Shape blocks_shape{4};
const std::vector<int64_t> block_shapes{1, 1, 1, 1};
const Shape pads_shape{4};
const std::vector<int64_t> pads_begins{0, 0, 1, 0};
const std::vector<int64_t> pads_ends{0, 0, 0, 0};
const Shape outputs_shape{1, 1, 5, 4};
const std::vector<float> outputs{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
SpaceToBatchTest(inputs,
inputs_shape,
block_shapes,
blocks_shape,
pads_begins,
pads_ends,
pads_shape,
outputs,
outputs_shape);
}

View File

@ -1,109 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/op/space_to_depth.hpp"
#include "util/test_control.hpp"
using namespace ngraph;
static std::string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_block_first_K2_BS2) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 4, 4});
const auto mode = op::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 2);
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f,
11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f, 18.f, 19.f, 20.f, 21.f,
22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f});
test_case.add_expected_output<float>(
Shape{1, 8, 2, 2},
{0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f, 1.f, 3.f, 9.f, 11.f, 17.f, 19.f, 25.f, 27.f,
4.f, 6.f, 12.f, 14.f, 20.f, 22.f, 28.f, 30.f, 5.f, 7.f, 13.f, 15.f, 21.f, 23.f, 29.f, 31.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_block_first_K2_BS3) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 6, 3});
const auto mode = op::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 3);
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 4.f, 8.f, 12.f, 16.f, 20.f, 24.f, 28.f, 32.f, 1.f, 5.f, 9.f,
13.f, 17.f, 21.f, 25.f, 29.f, 33.f, 2.f, 6.f, 10.f, 14.f, 18.f, 22.f,
26.f, 30.f, 34.f, 3.f, 7.f, 11.f, 15.f, 19.f, 23.f, 27.f, 31.f, 35.f});
test_case.add_expected_output<float>(
Shape{1, 18, 2, 1},
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f,
18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f, 32.f, 33.f, 34.f, 35.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_block_first_K1_BS3) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 6});
const auto mode = op::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 3);
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 4.f, 8.f, 1.f, 5.f, 9.f, 2.f, 6.f, 10.f, 3.f, 7.f, 11.f});
test_case.add_expected_output<float>(Shape{1, 6, 2},
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_depth_first_K2_BS2) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 4, 4});
const auto mode = op::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST;
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 2);
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 16.f, 2.f, 18.f, 1.f, 17.f, 3.f, 19.f, 8.f, 24.f, 10.f,
26.f, 9.f, 25.f, 11.f, 27.f, 4.f, 20.f, 6.f, 22.f, 5.f, 21.f,
7.f, 23.f, 12.f, 28.f, 14.f, 30.f, 13.f, 29.f, 15.f, 31.f});
test_case.add_expected_output<float>(
Shape{1, 8, 2, 2},
{0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f, 1.f, 3.f, 9.f, 11.f, 17.f, 19.f, 25.f, 27.f,
4.f, 6.f, 12.f, 14.f, 20.f, 22.f, 28.f, 30.f, 5.f, 7.f, 13.f, 15.f, 21.f, 23.f, 29.f, 31.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_depth_first_K2_BS3) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 6, 3});
const auto mode = op::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST;
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 3);
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 2.f, 4.f, 6.f, 8.f, 10.f, 12.f, 14.f, 16.f, 1.f, 3.f, 5.f,
7.f, 9.f, 11.f, 13.f, 15.f, 17.f, 18.f, 20.f, 22.f, 24.f, 26.f, 28.f,
30.f, 32.f, 34.f, 19.f, 21.f, 23.f, 25.f, 27.f, 29.f, 31.f, 33.f, 35.f});
test_case.add_expected_output<float>(
Shape{1, 18, 2, 1},
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f,
18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f, 32.f, 33.f, 34.f, 35.f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_depth_first_K1_BS3) {
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 6});
const auto mode = op::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST;
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 3);
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>({0.f, 2.f, 4.f, 1.f, 3.f, 5.f, 6.f, 8.f, 10.f, 7.f, 9.f, 11.f});
test_case.add_expected_output<float>(Shape{1, 6, 2},
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f});
test_case.run();
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/opsets/opset7.hpp"
#include "util/visitor.hpp"
using namespace std;
using namespace ngraph;
using ngraph::test::NodeBuilder;
TEST(attributes, roll_op) {
NodeBuilder::get_ops().register_factory<opset7::Roll>();
const auto A = make_shared<op::Parameter>(element::f32, Shape{4, 3});
const auto B = make_shared<op::Constant>(element::i32, Shape{3});
const auto C = make_shared<op::Constant>(element::i32, Shape{3});
const auto roll = make_shared<opset7::Roll>(A, B, C);
NodeBuilder builder(roll);
const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}