Migrate Movement 1 (Broadcast-1, Concat-1, Tile-1) (#8388)
* Migrate Movement 1 (Broadcast-1, Concat-1, Tile-1) * Add Broadcast-3 * Update to namespace opset * Add broadcast_test_helper
This commit is contained in:
1 parent
32052a8f92
commit
808323afa8
8 files changed
+2073
-1250
No files matched your search
@@ -0,0 +1,528 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/opsets/opset1.hpp"
|
||||
#include "openvino/opsets/opset3.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct BroadcastParams {
|
||||
BroadcastParams(
|
||||
const Tensor& dataTensor, const Tensor& targetShapeTensor,
|
||||
const Tensor& expectedTensor, const std::string& testcaseName = "") :
|
||||
dataTensor(dataTensor), targetShapeTensor(targetShapeTensor),
|
||||
expectedTensor(expectedTensor), testcaseName(testcaseName) {}
|
||||
|
||||
Tensor dataTensor;
|
||||
Tensor targetShapeTensor;
|
||||
Tensor expectedTensor;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceBroadcastTest : public testing::TestWithParam<BroadcastParams>, 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<BroadcastParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "dType=" << param.dataTensor.type;
|
||||
result << "_dShape=" << param.dataTensor.shape;
|
||||
result << "_tsType=" << param.targetShapeTensor.type;
|
||||
result << "_tsShape=" << param.targetShapeTensor.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 BroadcastParams& params) {
|
||||
const auto A = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
const auto f = std::make_shared<Function>(
|
||||
std::make_shared<opset1::Broadcast>(A, opset1::Constant::create(params.targetShapeTensor.type,
|
||||
params.targetShapeTensor.shape,
|
||||
params.targetShapeTensor.data.data())),
|
||||
ParameterVector{A});
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceBroadcastTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
class ReferenceBroadcastTestV3 : public ReferenceBroadcastTest {
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const BroadcastParams& params) {
|
||||
const auto A = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
const auto f = std::make_shared<Function>(
|
||||
std::make_shared<opset3::Broadcast>(A, opset1::Constant::create(params.targetShapeTensor.type,
|
||||
params.targetShapeTensor.shape,
|
||||
params.targetShapeTensor.data.data())),
|
||||
ParameterVector{A});
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceBroadcastTestV3, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
struct BroadcastParamsExplicitAxis : BroadcastParams {
|
||||
BroadcastParamsExplicitAxis(
|
||||
const Tensor& dataTensor, const Tensor& targetShapeTensor, const Tensor& axesMappingTensor,
|
||||
const Tensor& expectedTensor, const std::string& testcaseName = "") :
|
||||
BroadcastParams(dataTensor, targetShapeTensor, expectedTensor, testcaseName),
|
||||
axesMappingTensor(axesMappingTensor) {}
|
||||
|
||||
Tensor axesMappingTensor;
|
||||
};
|
||||
|
||||
class ReferenceBroadcastTestExplicitAxis : public testing::TestWithParam<BroadcastParamsExplicitAxis>, 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<BroadcastParamsExplicitAxis>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "dType=" << param.dataTensor.type;
|
||||
result << "_dShape=" << param.dataTensor.shape;
|
||||
result << "_tsType=" << param.targetShapeTensor.type;
|
||||
result << "_tsShape=" << param.targetShapeTensor.shape;
|
||||
result << "_amType=" << param.axesMappingTensor.type;
|
||||
result << "_amShape=" << param.axesMappingTensor.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 BroadcastParamsExplicitAxis& params) {
|
||||
const auto A = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
const auto f = std::make_shared<Function>(
|
||||
std::make_shared<opset1::Broadcast>(A,
|
||||
opset1::Constant::create(params.targetShapeTensor.type,
|
||||
params.targetShapeTensor.shape,
|
||||
params.targetShapeTensor.data.data()),
|
||||
opset1::Constant::create(params.axesMappingTensor.type,
|
||||
params.axesMappingTensor.shape,
|
||||
params.axesMappingTensor.data.data())),
|
||||
ParameterVector{A});
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceBroadcastTestExplicitAxis, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
struct BroadcastParamsTestHelper {
|
||||
BroadcastParamsTestHelper(
|
||||
const Shape& shapeA,
|
||||
const Shape& shapeR,
|
||||
const AxisSet& axes, const std::string& testcaseName = "") :
|
||||
shapeA(shapeA), shapeR(shapeR),
|
||||
axes(axes), testcaseName(testcaseName) {}
|
||||
|
||||
Shape shapeA;
|
||||
Shape shapeR;
|
||||
AxisSet axes;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceBroadcastTestTestHelper : public testing::TestWithParam<BroadcastParamsTestHelper>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
std::vector<float> inpData(shape_size<const Shape>(params.shapeA));
|
||||
iota(inpData.begin(), inpData.end(), 1.f);
|
||||
const auto refA = CreateTensor(params.shapeA, element::f32, inpData);
|
||||
inputData = {refA};
|
||||
}
|
||||
|
||||
void SetUp1() {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
std::vector<float> inpData(shape_size<const Shape>(params.shapeA));
|
||||
iota(inpData.begin(), inpData.end(), 1.f);
|
||||
const auto wrkA = CreateTensor(params.shapeA, element::f32, inpData);
|
||||
inputData = {wrkA};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<BroadcastParamsTestHelper>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "aShape=" << param.shapeA;
|
||||
result << "_rShape=" << param.shapeR;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_axes=" << param.axes;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_axes=" << param.axes;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const BroadcastParamsTestHelper& params) {
|
||||
const auto A = std::make_shared<opset1::Parameter>(element::f32, params.shapeA);
|
||||
const auto shape_const = opset1::Constant::create(element::u64, Shape{params.shapeR.size()}, params.shapeR);
|
||||
std::shared_ptr<Node> broadcast;
|
||||
if (params.axes.size() > 0) {
|
||||
auto axes_const = opset1::Constant::create(element::i64, Shape{params.axes.size()}, params.axes.to_vector());
|
||||
broadcast = std::make_shared<opset1::Broadcast>(A, shape_const, axes_const);
|
||||
} else {
|
||||
broadcast = std::make_shared<opset1::Broadcast>(A, shape_const);
|
||||
}
|
||||
auto f = std::make_shared<Function>(broadcast, ParameterVector{A});
|
||||
return f;
|
||||
}
|
||||
|
||||
protected:
|
||||
void GenerateRefOutData() {
|
||||
actualOutData.clear();
|
||||
for (const auto &output : executableNetwork.outputs()) {
|
||||
actualOutData.emplace_back(inferRequest.get_tensor(output));
|
||||
}
|
||||
refOutData = actualOutData;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceBroadcastTestTestHelper, CompareWithRefs) {
|
||||
LoadNetwork();
|
||||
FillInputs();
|
||||
Infer();
|
||||
GenerateRefOutData();
|
||||
SetUp1();
|
||||
Exec();
|
||||
}
|
||||
|
||||
class ReferenceBroadcastTestExplicitAxisReversed : public ReferenceBroadcastTestExplicitAxis {
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const BroadcastParamsExplicitAxis& params) {
|
||||
const auto A = std::make_shared<opset1::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
auto broadcast = std::make_shared<opset1::Broadcast>(
|
||||
A,
|
||||
opset1::Constant::create(params.targetShapeTensor.type,
|
||||
params.targetShapeTensor.shape,
|
||||
params.targetShapeTensor.data.data()),
|
||||
opset1::Constant::create(params.axesMappingTensor.type,
|
||||
params.axesMappingTensor.shape,
|
||||
params.axesMappingTensor.data.data()));
|
||||
auto reverse = std::make_shared<opset1::Reverse>(broadcast,
|
||||
opset1::Constant::create(element::i64, {1}, {1}),
|
||||
opset1::Reverse::Mode::INDEX);
|
||||
auto f = std::make_shared<Function>(NodeVector{reverse}, ParameterVector{A});
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceBroadcastTestExplicitAxisReversed, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<BroadcastParams> generateParams() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<BroadcastParams> params {
|
||||
BroadcastParams(
|
||||
Tensor(ET, {}, std::vector<T>{6}),
|
||||
Tensor(element::u64, {1}, std::vector<uint64_t>{4}),
|
||||
Tensor(ET, {4}, std::vector<T>{6, 6, 6, 6}),
|
||||
"broadcast_scalar_vector"),
|
||||
BroadcastParams(
|
||||
Tensor(ET, {}, std::vector<T>{6}),
|
||||
Tensor(element::u64, {2}, std::vector<uint64_t>{2, 2}),
|
||||
Tensor(ET, {2, 2}, std::vector<T>{6, 6, 6, 6}),
|
||||
"broadcast_scalar_matrix"),
|
||||
BroadcastParams(
|
||||
Tensor(ET, {}, std::vector<T>{6}),
|
||||
Tensor(element::u64, {3}, std::vector<uint64_t>{2, 2, 2}),
|
||||
Tensor(ET, {2, 2, 2}, std::vector<T>{6, 6, 6, 6, 6, 6, 6, 6}),
|
||||
"broadcast_scalar_tensor"),
|
||||
BroadcastParams(
|
||||
Tensor(ET, {2, 2, 2}, std::vector<T>{2, 4, 6, 8, 16, 32, 64, 127}),
|
||||
Tensor(element::u64, {3}, std::vector<uint64_t>{2, 2, 2}),
|
||||
Tensor(ET, {2, 2, 2}, std::vector<T>{2, 4, 6, 8, 16, 32, 64, 127}),
|
||||
"broadcast_trivial"),
|
||||
BroadcastParams(
|
||||
Tensor(ET, {2, 2}, std::vector<T>{1, 2, 3, 4}),
|
||||
Tensor(element::u64, {3}, std::vector<uint64_t>{2, 2, 2}),
|
||||
Tensor(ET, {2, 2, 2}, std::vector<T>{1, 2, 3, 4, 1, 2, 3, 4}),
|
||||
"broadcast_matrix_0"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<BroadcastParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<BroadcastParams>> 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<BroadcastParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Broadcast_With_Hardcoded_Refs, ReferenceBroadcastTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceBroadcastTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Broadcast_With_Hardcoded_Refs, ReferenceBroadcastTestV3,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceBroadcastTest::getTestCaseName);
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<BroadcastParamsExplicitAxis> generateParamsExplicitAxis() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<BroadcastParamsExplicitAxis> params {
|
||||
BroadcastParamsExplicitAxis(
|
||||
Tensor(ET, {}, std::vector<T>{6}),
|
||||
Tensor(element::u64, {2}, std::vector<uint64_t>{1, 2}),
|
||||
Tensor(element::i64, {1}, std::vector<int64_t>{0}),
|
||||
Tensor(ET, {1, 2}, std::vector<T>{6, 6}),
|
||||
"broadcast_scalar_vector_explicit_axis_0"),
|
||||
BroadcastParamsExplicitAxis(
|
||||
Tensor(ET, {3}, std::vector<T>{1, 2, 3}),
|
||||
Tensor(element::u64, {2}, std::vector<uint64_t>{3, 4}),
|
||||
Tensor(element::i64, {1}, std::vector<int64_t>{0}),
|
||||
Tensor(ET, {3, 4}, std::vector<T>{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}),
|
||||
"broadcast_vector_colwise"),
|
||||
BroadcastParamsExplicitAxis(
|
||||
Tensor(ET, {4}, std::vector<T>{1, 2, 3, 4}),
|
||||
Tensor(element::u64, {2}, std::vector<uint64_t>{3, 4}),
|
||||
Tensor(element::i64, {1}, std::vector<int64_t>{1}),
|
||||
Tensor(ET, {3, 4}, std::vector<T>{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}),
|
||||
"broadcast_vector_rowwise"),
|
||||
BroadcastParamsExplicitAxis(
|
||||
Tensor(ET, {1}, std::vector<T>{4}),
|
||||
Tensor(element::u64, {2}, std::vector<uint64_t>{3, 1}),
|
||||
Tensor(element::i64, {1}, std::vector<int64_t>{1}),
|
||||
Tensor(ET, {3, 1}, std::vector<T>{4, 4, 4}),
|
||||
"broadcast_scalar_to_matrix"),
|
||||
BroadcastParamsExplicitAxis(
|
||||
Tensor(ET, {2, 2}, std::vector<T>{1, 2, 3, 4}),
|
||||
Tensor(element::u64, {3}, std::vector<uint64_t>{2, 2, 2}),
|
||||
Tensor(element::i64, {2}, std::vector<int64_t>{0, 2}),
|
||||
Tensor(ET, {2, 2, 2}, std::vector<T>{1, 2, 1, 2, 3, 4, 3, 4}),
|
||||
"broadcast_matrix_1"),
|
||||
BroadcastParamsExplicitAxis(
|
||||
Tensor(ET, {2, 2}, std::vector<T>{1, 2, 3, 4}),
|
||||
Tensor(element::u64, {3}, std::vector<uint64_t>{2, 2, 2}),
|
||||
Tensor(element::i64, {2}, std::vector<int64_t>{0, 1}),
|
||||
Tensor(ET, {2, 2, 2}, std::vector<T>{1, 1, 2, 2, 3, 3, 4, 4}),
|
||||
"broadcast_matrix_2"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<BroadcastParamsExplicitAxis> generateCombinedParamsExplicitAxis() {
|
||||
const std::vector<std::vector<BroadcastParamsExplicitAxis>> generatedParams {
|
||||
generateParamsExplicitAxis<element::Type_t::i8>(),
|
||||
generateParamsExplicitAxis<element::Type_t::i16>(),
|
||||
generateParamsExplicitAxis<element::Type_t::i32>(),
|
||||
generateParamsExplicitAxis<element::Type_t::i64>(),
|
||||
generateParamsExplicitAxis<element::Type_t::u8>(),
|
||||
generateParamsExplicitAxis<element::Type_t::u16>(),
|
||||
generateParamsExplicitAxis<element::Type_t::u32>(),
|
||||
generateParamsExplicitAxis<element::Type_t::u64>(),
|
||||
generateParamsExplicitAxis<element::Type_t::bf16>(),
|
||||
generateParamsExplicitAxis<element::Type_t::f16>(),
|
||||
generateParamsExplicitAxis<element::Type_t::f32>(),
|
||||
generateParamsExplicitAxis<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<BroadcastParamsExplicitAxis> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Broadcast_With_Hardcoded_Refs, ReferenceBroadcastTestExplicitAxis,
|
||||
testing::ValuesIn(generateCombinedParamsExplicitAxis()), ReferenceBroadcastTestExplicitAxis::getTestCaseName);
|
||||
|
||||
std::vector<BroadcastParamsTestHelper> generateParamsTestHelper() {
|
||||
std::vector<BroadcastParamsTestHelper> params {
|
||||
BroadcastParamsTestHelper(
|
||||
{2},
|
||||
{3, 2, 4},
|
||||
{1},
|
||||
"broadcast_algo_vector_middle"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2},
|
||||
{3, 2},
|
||||
{1},
|
||||
"broadcast_algo_vector_forward_2"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2},
|
||||
{4, 3, 2},
|
||||
{2},
|
||||
"broadcast_algo_vector_forward_3"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2},
|
||||
{5, 4, 3, 2},
|
||||
{3},
|
||||
"broadcast_algo_vector_forward_4"),
|
||||
BroadcastParamsTestHelper(
|
||||
{},
|
||||
{5, 4, 3, 2},
|
||||
{},
|
||||
"broadcast_algo_scalar"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2},
|
||||
{2, 3},
|
||||
{0},
|
||||
"broadcast_algo_vector_backward_2"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2},
|
||||
{2, 3, 4},
|
||||
{0},
|
||||
"broadcast_algo_vector_backward_3"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2},
|
||||
{2, 3, 4, 5},
|
||||
{0},
|
||||
"broadcast_algo_vector_backward_4"),
|
||||
BroadcastParamsTestHelper(
|
||||
{4, 5},
|
||||
{2, 3, 4, 5},
|
||||
{2, 3},
|
||||
"broadcast_algo_matrix_backward_4"),
|
||||
BroadcastParamsTestHelper(
|
||||
{3, 5},
|
||||
{2, 3, 4, 5},
|
||||
{1, 3},
|
||||
"broadcast_algo_matrix_stride_1"),
|
||||
BroadcastParamsTestHelper(
|
||||
{3, 4},
|
||||
{2, 3, 4, 5},
|
||||
{1, 2},
|
||||
"broadcast_algo_matrix_stride_2"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2, 4},
|
||||
{2, 3, 4, 5},
|
||||
{0, 2},
|
||||
"broadcast_algo_matrix_stride_3"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2, 3, 4},
|
||||
{5, 2, 3, 4},
|
||||
{1, 2, 3},
|
||||
"broadcast_algo_3d_backward"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2, 3, 4},
|
||||
{2, 5, 3, 4},
|
||||
{0, 2, 3},
|
||||
"broadcast_algo_3d_stride_1"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2, 3, 4},
|
||||
{2, 3, 5, 4},
|
||||
{0, 1, 3},
|
||||
"broadcast_algo_3d_stride_2"),
|
||||
BroadcastParamsTestHelper(
|
||||
{3, 1},
|
||||
{2, 3, 3},
|
||||
{1, 2},
|
||||
"broadcast_algo_3d_diffrent_rank"),
|
||||
BroadcastParamsTestHelper(
|
||||
{2, 3, 1, 1},
|
||||
{2, 3, 4, 5},
|
||||
{0, 1, 2, 3},
|
||||
"broadcast_algo_4d_same_rank"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<BroadcastParamsTestHelper> generateCombinedParamsTestHelper() {
|
||||
const std::vector<std::vector<BroadcastParamsTestHelper>> generatedParams {
|
||||
generateParamsTestHelper(),
|
||||
};
|
||||
std::vector<BroadcastParamsTestHelper> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Broadcast_With_Hardcoded_Refs, ReferenceBroadcastTestTestHelper,
|
||||
testing::ValuesIn(generateCombinedParamsTestHelper()), ReferenceBroadcastTestTestHelper::getTestCaseName);
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<BroadcastParamsExplicitAxis> generateParamsExplicitAxisReversed() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<BroadcastParamsExplicitAxis> params {
|
||||
BroadcastParamsExplicitAxis(
|
||||
Tensor(ET, {4}, std::vector<T>{1, 2, 3, 4}),
|
||||
Tensor(element::u64, {2}, std::vector<uint64_t>{3, 4}),
|
||||
Tensor(element::i64, {1}, std::vector<int64_t>{1}),
|
||||
Tensor(ET, {3, 4}, std::vector<T>{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}),
|
||||
"broadcast_vector_rowwise_reversed"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<BroadcastParamsExplicitAxis> generateCombinedParamsExplicitAxisReversed() {
|
||||
const std::vector<std::vector<BroadcastParamsExplicitAxis>> generatedParams {
|
||||
generateParamsExplicitAxisReversed<element::Type_t::i8>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::i16>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::i32>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::i64>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::u8>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::u16>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::u32>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::u64>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::bf16>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::f16>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::f32>(),
|
||||
generateParamsExplicitAxisReversed<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<BroadcastParamsExplicitAxis> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Broadcast_With_Hardcoded_Refs, ReferenceBroadcastTestExplicitAxisReversed,
|
||||
testing::ValuesIn(generateCombinedParamsExplicitAxisReversed()), ReferenceBroadcastTestExplicitAxis::getTestCaseName);
|
||||
} // namespace
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,110 @@
|
||||
// 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 TileParams {
|
||||
TileParams(
|
||||
const Tensor& A, const Tensor& repeats,
|
||||
const Tensor& expected, const std::string& testcaseName = "") :
|
||||
A(A), repeats(repeats), expected(expected), testcaseName(testcaseName) {}
|
||||
|
||||
Tensor A;
|
||||
Tensor repeats;
|
||||
Tensor expected;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceTileTest : public testing::TestWithParam<TileParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.A.data};
|
||||
refOutData = {params.expected.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<TileParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "aType=" << param.A.type;
|
||||
result << "_aShape=" << param.A.shape;
|
||||
result << "_rType=" << param.repeats.type;
|
||||
result << "_rShape=" << param.repeats.shape;
|
||||
result << "_eType=" << param.expected.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_eShape=" << param.expected.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_rShape=" << param.expected.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const TileParams& params) {
|
||||
const auto A = std::make_shared<opset1::Parameter>(params.A.type, params.A.shape);
|
||||
const auto repeats = std::make_shared<opset1::Constant>(params.repeats.type, params.repeats.shape,
|
||||
params.repeats.data.data());
|
||||
const auto tile = std::make_shared<opset1::Tile>(A, repeats);
|
||||
const auto f = std::make_shared<Function>(NodeVector{tile}, ParameterVector{A});
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceTileTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<TileParams> generateParams() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<TileParams> params {
|
||||
TileParams(
|
||||
Tensor(ET, {3}, std::vector<T>{1, 2, 3}),
|
||||
Tensor(element::i64, {3}, std::vector<int64_t>{2, 2, 1}),
|
||||
Tensor(ET, {2, 2, 3}, std::vector<T>{1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3}),
|
||||
"tile_3d_small_data_rank"),
|
||||
TileParams(
|
||||
Tensor(ET, {2, 1, 3}, std::vector<T>{1, 2, 3, 4, 5, 6}),
|
||||
Tensor(element::i64, {2}, std::vector<int64_t>{2, 1}),
|
||||
Tensor(ET, {2, 2, 3}, std::vector<T>{1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6}),
|
||||
"tile_3d_few_repeats"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<TileParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<TileParams>> 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<TileParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Tile_With_Hardcoded_Refs, ReferenceTileTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceTileTest::getTestCaseName);
|
||||
} // namespace
|
||||
@@ -98,6 +98,8 @@ std::vector<std::string> disabledTestPatterns() {
|
||||
R"(.*ReferenceTopKTest.*aType=u16.*)",
|
||||
R"(.*ReferenceTopKTest.*aType=bf16.*)",
|
||||
R"(.*ReferenceTopKTest.*aType=f64.*)",
|
||||
// CVS-63947
|
||||
R"(.*ReferenceConcatTest.*concat_zero_.*)",
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -485,9 +485,7 @@ set(MULTI_TEST_SRC
|
||||
backend/aliased_output.in.cpp
|
||||
backend/api.in.cpp
|
||||
backend/auto_broadcast.in.cpp
|
||||
backend/broadcast.in.cpp
|
||||
backend/builder_reduce_ops_opset1.in.cpp
|
||||
backend/concat.in.cpp
|
||||
backend/dyn_reshape.in.cpp
|
||||
backend/dynamic.in.cpp
|
||||
backend/experimental_detectron_prior_grid.in.cpp
|
||||
@@ -501,7 +499,6 @@ set(MULTI_TEST_SRC
|
||||
backend/non_max_suppression.in.cpp
|
||||
backend/region_yolo.in.cpp
|
||||
backend/sqrt.in.cpp
|
||||
backend/tile.in.cpp
|
||||
backend/unhandled_op.in.cpp
|
||||
backend/validate_call.in.cpp
|
||||
backend/zero_sized.in.cpp
|
||||
|
||||
@@ -1,498 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include "engines_util/execute_tools.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/builder/autobroadcast.hpp"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/runtime/tensor.hpp"
|
||||
#include "runtime/backend.hpp"
|
||||
#include "util/all_close.hpp"
|
||||
#include "util/all_close_f.hpp"
|
||||
#include "util/ndarray.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_vector) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{4};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A, op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r)),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{6});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{6, 6, 6, 6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_vector_explicit_axis_0) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{1, 2};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{1}, {0})),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{6});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{6, 6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_matrix) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{2, 2};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v3::Broadcast>(A, op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r)),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{6});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{6, 6, 6, 6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_tensor) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{2, 2, 2};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A, op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r)),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{6});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{6, 6, 6, 6, 6, 6, 6, 6}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_trivial) {
|
||||
Shape shape{2, 2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A, op::Constant::create(element::u64, Shape{shape.size()}, shape)),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{2, 4, 6, 8, 16, 32, 64, 128});
|
||||
auto result = backend->create_tensor(element::f32, shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{2, 4, 6, 8, 16, 32, 64, 128}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_colwise) {
|
||||
Shape shape_a{3};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{3, 4};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{1}, {0})),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_rowwise) {
|
||||
Shape shape_a{4};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{3, 4};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{1}, {1})),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3, 4});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
// Test hybrid mechanism after broadcast
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_rowwise_reversed) {
|
||||
Shape shape_a{4};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{3, 4};
|
||||
auto broadcast = make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{1}, {1}));
|
||||
auto reverse = make_shared<op::v1::Reverse>(broadcast,
|
||||
op::Constant::create(element::i64, {1}, {1}),
|
||||
op::v1::Reverse::Mode::INDEX);
|
||||
auto f = make_shared<Function>(reverse, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3, 4});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_rowwise_int64) {
|
||||
Shape shape_a{4};
|
||||
auto A = make_shared<op::Parameter>(element::i64, shape_a);
|
||||
Shape shape_r{3, 4};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{1}, {1})),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::i64, shape_a);
|
||||
copy_data(a, vector<int64_t>{1, 2, 3, 4});
|
||||
auto result = backend->create_tensor(element::i64, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_EQ((vector<int64_t>{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}), read_vector<int64_t>(result));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_to_matrix_int64) {
|
||||
Shape shape_a{1};
|
||||
auto A = make_shared<op::Parameter>(element::i64, shape_a);
|
||||
Shape shape_r{3, 1};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{1}, {1})),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::i64, shape_a);
|
||||
copy_data(a, vector<int64_t>{4});
|
||||
auto result = backend->create_tensor(element::i64, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_EQ((vector<int64_t>{4, 4, 4}), read_vector<int64_t>(result));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_to_matrix_int32) {
|
||||
Shape shape_a{1};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
Shape shape_r{3, 1};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{1}, {1})),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::i32, shape_a);
|
||||
copy_data(a, vector<int32_t>{4});
|
||||
auto result = backend->create_tensor(element::i32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_EQ((vector<int32_t>{4, 4, 4}), read_vector<int32_t>(result));
|
||||
}
|
||||
|
||||
static void broadcast_test_helper(const Shape& shape_a, const Shape& shape_r, const AxisSet& axes) {
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
|
||||
vector<float> inp_data(shape_size<const Shape>(shape_a));
|
||||
iota(inp_data.begin(), inp_data.end(), 1.f);
|
||||
auto shape_const = op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r);
|
||||
std::shared_ptr<Node> broadcast;
|
||||
if (axes.size() > 0) {
|
||||
auto axes_const = op::Constant::create(element::i64, Shape{axes.size()}, axes.to_vector());
|
||||
broadcast = make_shared<op::v1::Broadcast>(A, shape_const, axes_const);
|
||||
} else {
|
||||
broadcast = make_shared<op::v1::Broadcast>(A, shape_const);
|
||||
}
|
||||
auto f = make_shared<Function>(broadcast, ParameterVector{A});
|
||||
|
||||
auto ref_backend = runtime::Backend::create("INTERPRETER");
|
||||
auto wrk_backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto wrk_a = wrk_backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(wrk_a, inp_data);
|
||||
|
||||
auto ref_a = ref_backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(ref_a, inp_data);
|
||||
|
||||
auto wrk_result = wrk_backend->create_tensor(element::f32, shape_r);
|
||||
auto ref_result = ref_backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto wrk_handle = wrk_backend->compile(f);
|
||||
auto ref_handle = ref_backend->compile(f);
|
||||
wrk_handle->call_with_validate({wrk_result}, {wrk_a});
|
||||
ref_handle->call_with_validate({ref_result}, {ref_a});
|
||||
EXPECT_TRUE(
|
||||
test::all_close_f(read_vector<float>(ref_result), read_vector<float>(wrk_result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_vector_middle) {
|
||||
Shape shape_a{2};
|
||||
Shape shape_r{3, 2, 4};
|
||||
AxisSet axis{1};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_vector_forward_2) {
|
||||
Shape shape_a{2};
|
||||
Shape shape_r{3, 2};
|
||||
AxisSet axis{1};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_vector_forward_3) {
|
||||
Shape shape_a{2};
|
||||
Shape shape_r{4, 3, 2};
|
||||
AxisSet axis{2};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_vector_forward_4) {
|
||||
Shape shape_a{2};
|
||||
Shape shape_r{5, 4, 3, 2};
|
||||
AxisSet axis{3};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_scalar) {
|
||||
Shape shape_a{};
|
||||
Shape shape_r{5, 4, 3, 2};
|
||||
AxisSet axis{};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_vector_backward_2) {
|
||||
Shape shape_a{2};
|
||||
Shape shape_r{2, 3};
|
||||
AxisSet axis{0};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_vector_backward_3) {
|
||||
Shape shape_a{2};
|
||||
Shape shape_r{2, 3, 4};
|
||||
AxisSet axis{0};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_vector_backward_4) {
|
||||
Shape shape_a{2};
|
||||
Shape shape_r{2, 3, 4, 5};
|
||||
AxisSet axis{0};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_matrix_backward_4) {
|
||||
Shape shape_a{4, 5};
|
||||
Shape shape_r{2, 3, 4, 5};
|
||||
AxisSet axis{2, 3};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_matrix_stride_1) {
|
||||
Shape shape_a{3, 5};
|
||||
Shape shape_r{2, 3, 4, 5};
|
||||
AxisSet axis{1, 3};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_matrix_stride_2) {
|
||||
Shape shape_a{3, 4};
|
||||
Shape shape_r{2, 3, 4, 5};
|
||||
AxisSet axis{1, 2};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_matrix_stride_3) {
|
||||
Shape shape_a{2, 4};
|
||||
Shape shape_r{2, 3, 4, 5};
|
||||
AxisSet axis{0, 2};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_3d_backward) {
|
||||
Shape shape_a{2, 3, 4};
|
||||
Shape shape_r{5, 2, 3, 4};
|
||||
AxisSet axis{1, 2, 3};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_3d_stride_1) {
|
||||
Shape shape_a{2, 3, 4};
|
||||
Shape shape_r{2, 5, 3, 4};
|
||||
AxisSet axis{0, 2, 3};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_3d_stride_2) {
|
||||
Shape shape_a{2, 3, 4};
|
||||
Shape shape_r{2, 3, 5, 4};
|
||||
AxisSet axis{0, 1, 3};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_3d_diffrent_rank) {
|
||||
Shape shape_a{3, 1};
|
||||
Shape shape_r{2, 3, 3};
|
||||
AxisSet axis{1, 2};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_4d_same_rank) {
|
||||
Shape shape_a{2, 3, 1, 1};
|
||||
Shape shape_r{2, 3, 4, 5};
|
||||
AxisSet axis{0, 1, 2, 3};
|
||||
broadcast_test_helper(shape_a, shape_r, axis);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_matrix_0) {
|
||||
Shape shape_a{2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{2, 2, 2};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A, op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r)),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3, 4});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 1, 2, 3, 4}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_matrix_1) {
|
||||
Shape shape_a{2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{2, 2, 2};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{2}, {0, 2})),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3, 4});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 1, 2, 3, 4, 3, 4}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, broadcast_matrix_2) {
|
||||
Shape shape_a{2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{2, 2, 2};
|
||||
auto f = make_shared<Function>(
|
||||
make_shared<op::v1::Broadcast>(A,
|
||||
op::Constant::create(element::u64, Shape{shape_r.size()}, shape_r),
|
||||
op::Constant::create(element::i64, Shape{2}, {0, 1})),
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3, 4});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 1, 2, 2, 3, 3, 4, 4}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
@@ -1,672 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "engines_util/execute_tools.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/runtime/tensor.hpp"
|
||||
#include "runtime/backend.hpp"
|
||||
#include "util/all_close.hpp"
|
||||
#include "util/all_close_f.hpp"
|
||||
#include "util/ndarray.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_negative_axis) {
|
||||
auto pshape_a = PartialShape::dynamic();
|
||||
auto A = make_shared<op::Parameter>(element::f32, pshape_a);
|
||||
auto pshape_b = PartialShape::dynamic();
|
||||
auto B = make_shared<op::Parameter>(element::f32, pshape_b);
|
||||
auto pshape_c = PartialShape::dynamic();
|
||||
auto C = make_shared<op::Parameter>(element::f32, pshape_c);
|
||||
auto pshape_r = PartialShape::dynamic();
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(NodeVector{A, B, C}, -1), ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}", true);
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, Shape{2, 2});
|
||||
copy_data(a, vector<float>{2, 4, 8, 16});
|
||||
auto b = backend->create_tensor(element::f32, Shape{2, 3});
|
||||
copy_data(b, vector<float>{1, 2, 4, 8, 16, 32});
|
||||
auto c = backend->create_tensor(element::f32, Shape{2, 3});
|
||||
copy_data(c, vector<float>{2, 3, 5, 7, 11, 13});
|
||||
auto result = backend->create_dynamic_tensor(element::f32, PartialShape::dynamic());
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
ASSERT_EQ(result->get_shape(), (Shape{2, 8}));
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{2, 4, 1, 2, 4, 2, 3, 5, 8, 16, 8, 16, 32, 7, 11, 13}),
|
||||
read_vector<float>(result)));
|
||||
}
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_matrix_colwise) {
|
||||
Shape shape_a{2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_b{2, 3};
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape_b);
|
||||
Shape shape_c{2, 3};
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape_c);
|
||||
Shape shape_r{2, 8};
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(NodeVector{A, B, C}, 1), ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{2, 4, 8, 16});
|
||||
auto b = backend->create_tensor(element::f32, shape_b);
|
||||
copy_data(b, vector<float>{1, 2, 4, 8, 16, 32});
|
||||
auto c = backend->create_tensor(element::f32, shape_c);
|
||||
copy_data(c, vector<float>{2, 3, 5, 7, 11, 13});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{2, 4, 1, 2, 4, 2, 3, 5, 8, 16, 8, 16, 32, 7, 11, 13}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_matrix_rowwise) {
|
||||
Shape shape_a{2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_b{3, 2};
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape_b);
|
||||
Shape shape_c{3, 2};
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape_c);
|
||||
Shape shape_r{8, 2};
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(NodeVector{A, B, C}, 0), ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{2, 4, 8, 16});
|
||||
auto b = backend->create_tensor(element::f32, shape_b);
|
||||
copy_data(b, vector<float>{1, 2, 4, 8, 16, 32});
|
||||
auto c = backend->create_tensor(element::f32, shape_c);
|
||||
copy_data(c, vector<float>{2, 3, 5, 7, 11, 13});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{2, 4, 8, 16, 1, 2, 4, 8, 16, 32, 2, 3, 5, 7, 11, 13}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_matrix_int64) {
|
||||
Shape shape_a{2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::i64, shape_a);
|
||||
Shape shape_b{3, 2};
|
||||
auto B = make_shared<op::Parameter>(element::i64, shape_b);
|
||||
Shape shape_c{3, 2};
|
||||
auto C = make_shared<op::Parameter>(element::i64, shape_c);
|
||||
Shape shape_r{8, 2};
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(NodeVector{A, B, C}, 0), ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::i64, shape_a);
|
||||
copy_data(a, vector<int64_t>{2, 4, 8, 16});
|
||||
auto b = backend->create_tensor(element::i64, shape_b);
|
||||
copy_data(b, vector<int64_t>{1, 2, 4, 8, 16, 32});
|
||||
auto c = backend->create_tensor(element::i64, shape_c);
|
||||
copy_data(c, vector<int64_t>{2, 3, 5, 7, 11, 13});
|
||||
auto result = backend->create_tensor(element::i64, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_EQ((vector<int64_t>{2, 4, 8, 16, 1, 2, 4, 8, 16, 32, 2, 3, 5, 7, 11, 13}), read_vector<int64_t>(result));
|
||||
}
|
||||
|
||||
// Params to drive concat_vector_large testing variations
|
||||
class concat_vector_params : public ::testing::TestWithParam<int> {
|
||||
protected:
|
||||
concat_vector_params() {
|
||||
num_inputs = GetParam();
|
||||
}
|
||||
uint32_t num_inputs;
|
||||
};
|
||||
|
||||
NGRAPH_TEST_P(${BACKEND_NAME}, concat_vector_params, concat_vector_large) {
|
||||
Shape shape_a{1};
|
||||
NodeVector inputs;
|
||||
ParameterVector inputs_param;
|
||||
for (uint32_t i = 0; i < num_inputs; i++) {
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
inputs_param.push_back(A);
|
||||
inputs.push_back(A);
|
||||
}
|
||||
Shape shape_r{num_inputs};
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(inputs, 0), inputs_param);
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
std::vector<std::shared_ptr<runtime::Tensor>> inputs_value;
|
||||
std::vector<float> ref_result;
|
||||
for (uint32_t i = 0; i < num_inputs; i++) {
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{static_cast<float>(i)});
|
||||
ref_result.push_back(static_cast<float>(i));
|
||||
inputs_value.push_back(a);
|
||||
}
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, inputs_value);
|
||||
EXPECT_TRUE(test::all_close_f(ref_result, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
// concat_vector_large case generation
|
||||
// Add thhosw tests to cover paramter space overflow:
|
||||
// cuda kernel parameter space have limit, if there is large number of parameters,
|
||||
// there will be overflow for parameter space.
|
||||
NGRAPH_INSTANTIATE_TEST_SUITE_P(${BACKEND_NAME}, input_sizes, concat_vector_params, testing::Values(100, 128, 999));
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_vector) {
|
||||
Shape shape_a{4};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_b{6};
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape_b);
|
||||
Shape shape_c{2};
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape_c);
|
||||
Shape shape_r{12};
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(NodeVector{A, B, C}, 0), ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{2, 4, 8, 16});
|
||||
auto b = backend->create_tensor(element::f32, shape_b);
|
||||
copy_data(b, vector<float>{1, 2, 4, 8, 16, 32});
|
||||
auto c = backend->create_tensor(element::f32, shape_c);
|
||||
copy_data(c, vector<float>{18, 19});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{2, 4, 8, 16, 1, 2, 4, 8, 16, 32, 18, 19}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_4d_tensor) {
|
||||
Shape shape{1, 1, 1, 1};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape);
|
||||
Shape shape_r{3, 1, 1, 1};
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(NodeVector{A, B, C}, 0), ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{2});
|
||||
auto c = backend->create_tensor(element::f32, shape);
|
||||
copy_data(c, vector<float>{3});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_2d_tensor) {
|
||||
Shape shape{1, 1};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape);
|
||||
Shape shape_r{3, 1};
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(NodeVector{A, B, C}, 0), ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{2});
|
||||
auto c = backend->create_tensor(element::f32, shape);
|
||||
copy_data(c, vector<float>{3});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_in_place_2d_tensor) {
|
||||
Shape shape{1, 1};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto add1 = make_shared<op::v1::Add>(A, B);
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto D = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto add2 = make_shared<op::v1::Add>(C, D);
|
||||
auto subtract = make_shared<op::v1::Subtract>(C, A);
|
||||
Shape shape_r{3, 1};
|
||||
auto f = make_shared<Function>(make_shared<op::Concat>(NodeVector{add1, add2, subtract}, 0),
|
||||
ParameterVector{A, B, C, D});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{2});
|
||||
auto c = backend->create_tensor(element::f32, shape);
|
||||
copy_data(c, vector<float>{3});
|
||||
auto d = backend->create_tensor(element::f32, shape);
|
||||
copy_data(d, vector<float>{4});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c, d});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{3, 7, 2}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_in_place_propagate_2d_tensor) {
|
||||
Shape shape{1, 1};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto add1 = make_shared<op::v1::Add>(A, B);
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto D = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto add2 = make_shared<op::v1::Add>(C, D);
|
||||
auto concat1 = make_shared<op::Concat>(NodeVector{add1, add2}, 0);
|
||||
auto subtract = make_shared<op::v1::Subtract>(C, A);
|
||||
Shape shape_r{3, 1};
|
||||
auto f =
|
||||
make_shared<Function>(make_shared<op::Concat>(NodeVector{concat1, subtract}, 0), ParameterVector{A, B, C, D});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{2});
|
||||
auto c = backend->create_tensor(element::f32, shape);
|
||||
copy_data(c, vector<float>{3});
|
||||
auto d = backend->create_tensor(element::f32, shape);
|
||||
copy_data(d, vector<float>{4});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c, d});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{3, 7, 2}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_in_place_tree_1) {
|
||||
Shape shape{1, 2, 2};
|
||||
Shape shape_r{1, 4, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto add1 = make_shared<op::v1::Add>(A, B);
|
||||
auto add2 = make_shared<op::v1::Add>(A, B);
|
||||
auto concat = make_shared<op::Concat>(NodeVector{add1, add2}, 1);
|
||||
auto f = make_shared<Function>(make_shared<op::v1::Add>(concat, concat), ParameterVector{A, B});
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1, 1, 1, 1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{1, 1, 1, 1});
|
||||
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b});
|
||||
vector<float> expected;
|
||||
expected.resize(8, 4);
|
||||
|
||||
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_in_place_tree_2) {
|
||||
Shape shape{1, 2, 2};
|
||||
Shape shape_r{1, 8, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto add1 = make_shared<op::v1::Add>(A, B);
|
||||
auto add2 = make_shared<op::v1::Add>(A, B);
|
||||
auto concat1 = make_shared<op::Concat>(NodeVector{add1, add2}, 1);
|
||||
auto concat2 = make_shared<op::Concat>(NodeVector{add1, add2}, 1);
|
||||
auto concat12 = make_shared<op::Concat>(NodeVector{concat1, concat2}, 1);
|
||||
auto f = make_shared<Function>(make_shared<op::v1::Add>(concat12, concat12), ParameterVector{A, B});
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1, 1, 1, 1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{1, 1, 1, 1});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b});
|
||||
vector<float> expected;
|
||||
expected.resize(16, 4);
|
||||
|
||||
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_in_place_tree_3) {
|
||||
Shape shape{1, 2, 2};
|
||||
Shape shape_r{1, 16, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto concat1 = make_shared<op::Concat>(NodeVector{A, B}, 1);
|
||||
auto concat2 = make_shared<op::Concat>(NodeVector{A, B}, 1);
|
||||
auto concat3 = make_shared<op::Concat>(NodeVector{A, B}, 1);
|
||||
auto concat4 = make_shared<op::Concat>(NodeVector{A, B}, 1);
|
||||
auto concat12 = make_shared<op::Concat>(NodeVector{concat1, concat2}, 1);
|
||||
auto concat34 = make_shared<op::Concat>(NodeVector{concat3, concat4}, 1);
|
||||
auto concat14 = make_shared<op::Concat>(NodeVector{concat12, concat34}, 1);
|
||||
auto f = make_shared<Function>(make_shared<op::v1::Add>(concat14, concat14), ParameterVector{A, B});
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1, 1, 1, 1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{1, 1, 1, 1});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b});
|
||||
vector<float> expected;
|
||||
expected.resize(32, 2);
|
||||
|
||||
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_in_place_add_concat) {
|
||||
Shape shape{2, 2};
|
||||
Shape shape_r{4, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto add1 = make_shared<op::v1::Add>(A, B);
|
||||
auto add2 = make_shared<op::v1::Add>(add1, add1);
|
||||
auto concat = make_shared<op::Concat>(NodeVector{add1, add2}, 0);
|
||||
auto add3 = make_shared<op::v1::Add>(concat, concat);
|
||||
auto f = make_shared<Function>(add3, ParameterVector{A, B});
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1, 1, 1, 1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{1, 1, 1, 1});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b});
|
||||
vector<float> expected = {4, 4, 4, 4, 8, 8, 8, 8};
|
||||
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_in_place_add_concat_2) {
|
||||
Shape shape{1, 2, 2};
|
||||
Shape shape_r{1, 6, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape);
|
||||
auto add1 = make_shared<op::v1::Add>(A, B);
|
||||
auto add2 = make_shared<op::v1::Add>(A, B);
|
||||
auto add3 = make_shared<op::v1::Add>(A, B);
|
||||
auto add4 = make_shared<op::v1::Add>(A, B);
|
||||
auto add5 = make_shared<op::v1::Add>(A, B);
|
||||
|
||||
auto concat1 = make_shared<op::Concat>(NodeVector{add1, add2, add3}, 1);
|
||||
|
||||
auto concat2 = make_shared<op::Concat>(NodeVector{add4, add2, add5}, 1);
|
||||
|
||||
auto add6 = make_shared<op::v1::Add>(concat1, concat2);
|
||||
auto f = make_shared<Function>(add6, ParameterVector{A, B});
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, shape);
|
||||
copy_data(a, vector<float>{1, 1, 1, 1});
|
||||
auto b = backend->create_tensor(element::f32, shape);
|
||||
copy_data(b, vector<float>{1, 1, 1, 1});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b});
|
||||
vector<float> expected = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
|
||||
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
// from numpy import *
|
||||
// a=linspace(1,2*3*4*3*2,2*3*4*3*2)
|
||||
// b=linspace(1000+1,1000+2*3*3*3*2,2*3*3*3*2)
|
||||
// c=linspace(2000+1,2000+2*3*2*3*2,2*3*2*3*2)
|
||||
// a.shape=(2,3,4,3,2)
|
||||
// b.shape=(2,3,3,3,2)
|
||||
// c.shape=(2,3,2,3,2)
|
||||
// z=concatenate((a,b,c),axis=2)
|
||||
// z.shape=(2*3*(4+3+2)*3*2)
|
||||
// set_printoptions(suppress=True)
|
||||
// print(z)
|
||||
//
|
||||
// [ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
|
||||
// 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.
|
||||
// 21. 22. 23. 24. 1001. 1002. 1003. 1004. 1005. 1006.
|
||||
// 1007. 1008. 1009. 1010. 1011. 1012. 1013. 1014. 1015. 1016.
|
||||
// 1017. 1018. 2001. 2002. 2003. 2004. 2005. 2006. 2007. 2008.
|
||||
// 2009. 2010. 2011. 2012. 25. 26. 27. 28. 29. 30.
|
||||
// 31. 32. 33. 34. 35. 36. 37. 38. 39. 40.
|
||||
// 41. 42. 43. 44. 45. 46. 47. 48. 1019. 1020.
|
||||
// 1021. 1022. 1023. 1024. 1025. 1026. 1027. 1028. 1029. 1030.
|
||||
// 1031. 1032. 1033. 1034. 1035. 1036. 2013. 2014. 2015. 2016.
|
||||
// 2017. 2018. 2019. 2020. 2021. 2022. 2023. 2024. 49. 50.
|
||||
// 51. 52. 53. 54. 55. 56. 57. 58. 59. 60.
|
||||
// 61. 62. 63. 64. 65. 66. 67. 68. 69. 70.
|
||||
// 71. 72. 1037. 1038. 1039. 1040. 1041. 1042. 1043. 1044.
|
||||
// 1045. 1046. 1047. 1048. 1049. 1050. 1051. 1052. 1053. 1054.
|
||||
// 2025. 2026. 2027. 2028. 2029. 2030. 2031. 2032. 2033. 2034.
|
||||
// 2035. 2036. 73. 74. 75. 76. 77. 78. 79. 80.
|
||||
// 81. 82. 83. 84. 85. 86. 87. 88. 89. 90.
|
||||
// 91. 92. 93. 94. 95. 96. 1055. 1056. 1057. 1058.
|
||||
// 1059. 1060. 1061. 1062. 1063. 1064. 1065. 1066. 1067. 1068.
|
||||
// 1069. 1070. 1071. 1072. 2037. 2038. 2039. 2040. 2041. 2042.
|
||||
// 2043. 2044. 2045. 2046. 2047. 2048. 97. 98. 99. 100.
|
||||
// 101. 102. 103. 104. 105. 106. 107. 108. 109. 110.
|
||||
// 111. 112. 113. 114. 115. 116. 117. 118. 119. 120.
|
||||
// 1073. 1074. 1075. 1076. 1077. 1078. 1079. 1080. 1081. 1082.
|
||||
// 1083. 1084. 1085. 1086. 1087. 1088. 1089. 1090. 2049. 2050.
|
||||
// 2051. 2052. 2053. 2054. 2055. 2056. 2057. 2058. 2059. 2060.
|
||||
// 121. 122. 123. 124. 125. 126. 127. 128. 129. 130.
|
||||
// 131. 132. 133. 134. 135. 136. 137. 138. 139. 140.
|
||||
// 141. 142. 143. 144. 1091. 1092. 1093. 1094. 1095. 1096.
|
||||
// 1097. 1098. 1099. 1100. 1101. 1102. 1103. 1104. 1105. 1106.
|
||||
// 1107. 1108. 2061. 2062. 2063. 2064. 2065. 2066. 2067. 2068.
|
||||
// 2069. 2070. 2071. 2072.]
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_5d) {
|
||||
vector<float> a_data(2 * 3 * 4 * 3 * 2);
|
||||
for (int i = 0; i < 2 * 3 * 4 * 3 * 2; i++) {
|
||||
a_data[i] = float(i + 1);
|
||||
}
|
||||
|
||||
vector<float> b_data(2 * 3 * 3 * 3 * 2);
|
||||
for (int i = 0; i < 2 * 3 * 3 * 3 * 2; i++) {
|
||||
b_data[i] = 1000 + float(i + 1);
|
||||
}
|
||||
|
||||
vector<float> c_data(2 * 3 * 2 * 3 * 2);
|
||||
for (int i = 0; i < 2 * 3 * 2 * 3 * 2; i++) {
|
||||
c_data[i] = 2000 + float(i + 1);
|
||||
}
|
||||
|
||||
Shape shape_a{2, 3, 4, 3, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_b{2, 3, 3, 3, 2};
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape_b);
|
||||
Shape shape_c{2, 3, 2, 3, 2};
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape_c);
|
||||
Shape shape_r{2, 3, 9, 3, 2};
|
||||
|
||||
auto r = make_shared<op::Concat>(NodeVector{A, B, C}, 2);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, a_data);
|
||||
auto b = backend->create_tensor(element::f32, shape_b);
|
||||
copy_data(b, b_data);
|
||||
auto c = backend->create_tensor(element::f32, shape_c);
|
||||
copy_data(c, c_data);
|
||||
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_TRUE(test::all_close_f(
|
||||
(vector<float>{
|
||||
1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15.,
|
||||
16., 17., 18., 19., 20., 21., 22., 23., 24., 1001., 1002., 1003., 1004., 1005., 1006.,
|
||||
1007., 1008., 1009., 1010., 1011., 1012., 1013., 1014., 1015., 1016., 1017., 1018., 2001., 2002., 2003.,
|
||||
2004., 2005., 2006., 2007., 2008., 2009., 2010., 2011., 2012., 25., 26., 27., 28., 29., 30.,
|
||||
31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45.,
|
||||
46., 47., 48., 1019., 1020., 1021., 1022., 1023., 1024., 1025., 1026., 1027., 1028., 1029., 1030.,
|
||||
1031., 1032., 1033., 1034., 1035., 1036., 2013., 2014., 2015., 2016., 2017., 2018., 2019., 2020., 2021.,
|
||||
2022., 2023., 2024., 49., 50., 51., 52., 53., 54., 55., 56., 57., 58., 59., 60.,
|
||||
61., 62., 63., 64., 65., 66., 67., 68., 69., 70., 71., 72., 1037., 1038., 1039.,
|
||||
1040., 1041., 1042., 1043., 1044., 1045., 1046., 1047., 1048., 1049., 1050., 1051., 1052., 1053., 1054.,
|
||||
2025., 2026., 2027., 2028., 2029., 2030., 2031., 2032., 2033., 2034., 2035., 2036., 73., 74., 75.,
|
||||
76., 77., 78., 79., 80., 81., 82., 83., 84., 85., 86., 87., 88., 89., 90.,
|
||||
91., 92., 93., 94., 95., 96., 1055., 1056., 1057., 1058., 1059., 1060., 1061., 1062., 1063.,
|
||||
1064., 1065., 1066., 1067., 1068., 1069., 1070., 1071., 1072., 2037., 2038., 2039., 2040., 2041., 2042.,
|
||||
2043., 2044., 2045., 2046., 2047., 2048., 97., 98., 99., 100., 101., 102., 103., 104., 105.,
|
||||
106., 107., 108., 109., 110., 111., 112., 113., 114., 115., 116., 117., 118., 119., 120.,
|
||||
1073., 1074., 1075., 1076., 1077., 1078., 1079., 1080., 1081., 1082., 1083., 1084., 1085., 1086., 1087.,
|
||||
1088., 1089., 1090., 2049., 2050., 2051., 2052., 2053., 2054., 2055., 2056., 2057., 2058., 2059., 2060.,
|
||||
121., 122., 123., 124., 125., 126., 127., 128., 129., 130., 131., 132., 133., 134., 135.,
|
||||
136., 137., 138., 139., 140., 141., 142., 143., 144., 1091., 1092., 1093., 1094., 1095., 1096.,
|
||||
1097., 1098., 1099., 1100., 1101., 1102., 1103., 1104., 1105., 1106., 1107., 1108., 2061., 2062., 2063.,
|
||||
2064., 2065., 2066., 2067., 2068., 2069., 2070., 2071., 2072.}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_zero_length_1d_last) {
|
||||
Shape shape_a{4};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_b{0};
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape_b);
|
||||
Shape shape_r{4};
|
||||
|
||||
auto r = make_shared<op::Concat>(NodeVector{A, B}, 0);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A, B});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
vector<float> a_data{1, 2, 3, 4};
|
||||
vector<float> b_data(0);
|
||||
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, a_data);
|
||||
auto b = backend->create_tensor(element::f32, shape_b);
|
||||
copy_data(b, b_data);
|
||||
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_zero_length_1d_middle) {
|
||||
Shape shape_a{4};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_b{0};
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape_b);
|
||||
Shape shape_c{4};
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape_c);
|
||||
Shape shape_r{8};
|
||||
|
||||
auto r = make_shared<op::Concat>(NodeVector{A, B, C}, 0);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
vector<float> a_data{1, 2, 3, 4};
|
||||
vector<float> b_data(0);
|
||||
vector<float> c_data{5, 6, 7, 8};
|
||||
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, a_data);
|
||||
auto b = backend->create_tensor(element::f32, shape_b);
|
||||
copy_data(b, b_data);
|
||||
auto c = backend->create_tensor(element::f32, shape_c);
|
||||
copy_data(c, c_data);
|
||||
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_zero_zero) {
|
||||
Shape shape{0};
|
||||
auto constant_1 = op::Constant::create(element::f32, shape, {1});
|
||||
auto concat_1 = make_shared<op::Concat>(NodeVector{constant_1, constant_1}, 0);
|
||||
|
||||
auto f = make_shared<Function>(concat_1, ParameterVector{});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
auto result = backend->create_tensor(element::f32, shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {});
|
||||
|
||||
EXPECT_TRUE(test::all_close_f(vector<float>{}, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, concat_zero_length_4d_middle) {
|
||||
Shape shape_a{2, 2, 1, 1};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_b{2, 2, 0, 1};
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape_b);
|
||||
Shape shape_c{2, 2, 1, 1};
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape_c);
|
||||
Shape shape_r{2, 2, 2, 1};
|
||||
|
||||
auto r = make_shared<op::Concat>(NodeVector{A, B, C}, 2);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A, B, C});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
vector<float> a_data{1, 2, 3, 4};
|
||||
vector<float> b_data(0);
|
||||
vector<float> c_data{5, 6, 7, 8};
|
||||
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, a_data);
|
||||
auto b = backend->create_tensor(element::f32, shape_b);
|
||||
copy_data(b, b_data);
|
||||
auto c = backend->create_tensor(element::f32, shape_c);
|
||||
copy_data(c, c_data);
|
||||
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a, b, c});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 5, 2, 6, 3, 7, 4, 8}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include "engines_util/execute_tools.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/runtime/tensor.hpp"
|
||||
#include "runtime/backend.hpp"
|
||||
#include "util/all_close.hpp"
|
||||
#include "util/all_close_f.hpp"
|
||||
#include "util/ndarray.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, tile_3d_small_data_rank) {
|
||||
Shape shape_a{3};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_re{3};
|
||||
auto repeats = make_shared<op::Constant>(element::i64, shape_re, vector<int>{2, 2, 1});
|
||||
Shape shape_r{2, 2, 3};
|
||||
|
||||
auto tile = make_shared<op::v0::Tile>(A, repeats);
|
||||
|
||||
auto f = make_shared<Function>(tile, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3});
|
||||
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f(vector<float>{1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3},
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, tile_3d_few_repeats) {
|
||||
Shape shape_a{2, 1, 3};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_re{2};
|
||||
auto repeats = make_shared<op::Constant>(element::i64, shape_re, vector<int>{2, 1});
|
||||
Shape shape_r{2, 2, 3};
|
||||
|
||||
auto tile = make_shared<op::v0::Tile>(A, repeats);
|
||||
|
||||
auto f = make_shared<Function>(tile, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3, 4, 5, 6});
|
||||
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f(vector<float>{1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6},
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
Reference in new issue
Block a user