From 704c0b9bf98d6f3116bc60f6c0d09f4e6273c424 Mon Sep 17 00:00:00 2001 From: sunsuodong Date: Fri, 14 Aug 2020 15:08:20 +0800 Subject: [PATCH] fix bug and add testcase --- mindspore/lite/src/model_impl.cc | 4 + mindspore/lite/src/populate_parameter.cc | 4 +- .../lite/src/runtime/kernel/arm/fp32/tile.h | 2 +- .../lite/src/runtime/kernel/arm/fp32/unique.h | 2 +- .../src/runtime/kernel/arm/int8/add_int8.h | 2 +- .../runtime/kernel/arm/int8/bias_add_int8.h | 2 +- .../kernel/arm/nnacl/{ => fp32}/tile.c | 4 +- .../kernel/arm/nnacl/{ => fp32}/tile.h | 0 .../kernel/arm/nnacl/{ => fp32}/unique.c | 2 +- .../kernel/arm/nnacl/{ => fp32}/unique.h | 0 .../kernel/arm/nnacl/{ => int8}/add_int8.c | 2 +- .../kernel/arm/nnacl/{ => int8}/add_int8.h | 0 .../arm/nnacl/int8/arithmetic_self_int8.c | 2 +- .../runtime/kernel/arm/nnacl/int8/mul_int8.c | 2 +- .../runtime/kernel/arm/nnacl/int8/sub_int8.c | 2 +- .../arm/fp32/reverse_sequence_fp32_tests.cc | 157 ++++++++++++++++++ .../kernel/arm/fp32/tile_fp32_tests.cc | 70 ++++++++ .../kernel/arm/fp32/unique_fp32_tests.cc | 70 ++++++++ .../kernel/arm/fp32/unstack_fp32_tests.cc | 122 ++++++++++++++ .../kernel/arm/int8/bias_add_int8_tests.cc | 75 +++++++++ 20 files changed, 511 insertions(+), 13 deletions(-) rename mindspore/lite/src/runtime/kernel/arm/nnacl/{ => fp32}/tile.c (93%) rename mindspore/lite/src/runtime/kernel/arm/nnacl/{ => fp32}/tile.h (100%) rename mindspore/lite/src/runtime/kernel/arm/nnacl/{ => fp32}/unique.c (97%) rename mindspore/lite/src/runtime/kernel/arm/nnacl/{ => fp32}/unique.h (100%) rename mindspore/lite/src/runtime/kernel/arm/nnacl/{ => int8}/add_int8.c (99%) rename mindspore/lite/src/runtime/kernel/arm/nnacl/{ => int8}/add_int8.h (100%) create mode 100644 mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/reverse_sequence_fp32_tests.cc create mode 100644 mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/tile_fp32_tests.cc create mode 100644 mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/unique_fp32_tests.cc create mode 100644 mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/unstack_fp32_tests.cc create mode 100644 mindspore/lite/test/ut/src/runtime/kernel/arm/int8/bias_add_int8_tests.cc diff --git a/mindspore/lite/src/model_impl.cc b/mindspore/lite/src/model_impl.cc index e030cbb875..25273b928f 100644 --- a/mindspore/lite/src/model_impl.cc +++ b/mindspore/lite/src/model_impl.cc @@ -221,6 +221,10 @@ lite::Primitive *ModelImpl::CopyPrimitive(const schema::Primitive *src_prim) { return new lite::Split(const_cast(src_prim)); case schema::PrimitiveType_OneHot: return new lite::OneHot(const_cast(src_prim)); + case schema::PrimitiveType_SpaceToDepth: + return new lite::SpaceToDepth(const_cast(src_prim)); + case schema::PrimitiveType_Tile: + return new lite::Tile(const_cast(src_prim)); case schema::PrimitiveType_Resize: return new lite::Resize(const_cast(src_prim)); case schema::PrimitiveType_MatMul: diff --git a/mindspore/lite/src/populate_parameter.cc b/mindspore/lite/src/populate_parameter.cc index 80a00476cf..207a78877f 100644 --- a/mindspore/lite/src/populate_parameter.cc +++ b/mindspore/lite/src/populate_parameter.cc @@ -36,7 +36,7 @@ #include "src/runtime/kernel/arm/nnacl/matmul_parameter.h" #include "src/runtime/kernel/arm/nnacl/fp32/roi_pooling.h" #include "src/runtime/kernel/arm/nnacl/softmax_parameter.h" -#include "src/runtime/kernel/arm/nnacl/tile.h" +#include "src/runtime/kernel/arm/nnacl/fp32/tile.h" #include "src/runtime/kernel/arm/nnacl/fp32/topk.h" #include "src/runtime/kernel/arm/nnacl/fp32/reduce.h" #include "src/runtime/kernel/arm/nnacl/fp32/activation.h" @@ -55,7 +55,7 @@ #include "src/runtime/kernel/arm/nnacl/fp32/gather.h" #include "src/runtime/kernel/arm/nnacl/fp32/reverse.h" #include "src/runtime/kernel/arm/nnacl/reverse_sequence.h" -#include "src/runtime/kernel/arm/nnacl/unique.h" +#include "src/runtime/kernel/arm/nnacl/fp32/unique.h" #include "src/runtime/kernel/arm/nnacl/scale.h" #include "src/runtime/kernel/arm/nnacl/fp32/gatherNd.h" #include "src/runtime/kernel/arm/nnacl/resize_parameter.h" diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/tile.h b/mindspore/lite/src/runtime/kernel/arm/fp32/tile.h index 3b1bb74ead..879e77d604 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/tile.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/tile.h @@ -18,7 +18,7 @@ #include #include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/nnacl/tile.h" +#include "src/runtime/kernel/arm/nnacl/fp32/tile.h" namespace mindspore::kernel { class TileCPUKernel : public LiteKernel { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unique.h b/mindspore/lite/src/runtime/kernel/arm/fp32/unique.h index 6d5dbe672c..72f0ceb458 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unique.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unique.h @@ -18,7 +18,7 @@ #include #include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/nnacl/unique.h" +#include "src/runtime/kernel/arm/nnacl/fp32/unique.h" namespace mindspore::kernel { class UniqueCPUKernel : public LiteKernel { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h index 5a1da51340..79692449f7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h @@ -18,7 +18,7 @@ #include #include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/nnacl/add_int8.h" +#include "src/runtime/kernel/arm/nnacl/int8/add_int8.h" #include "src/runtime/runtime_api.h" namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h index c8c7717be4..d442bab0f3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h @@ -18,7 +18,7 @@ #include #include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/nnacl/unique.h" +#include "src/runtime/kernel/arm/nnacl/fp32/unique.h" #include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" namespace mindspore::kernel { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.c b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/tile.c similarity index 93% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/tile.c rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/tile.c index 53fd3929e1..70a4c0c264 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.c +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/tile.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "nnacl/tile.h" +#include "nnacl/fp32/tile.h" #include void DoCopyData(float *input_data, float *output_data, size_t size, size_t multiple) { @@ -35,7 +35,7 @@ int DoTileOneDimension(float *input_data, float *output_data, size_t dim, TilePa for (size_t j = 0; j < parameter->multiples_[dim]; ++j) { size_t in_pos = parameter->in_strides_[dim] * i; size_t out_pos = parameter->out_strides_[dim] * (i + j * src_dim_size); - TileOneDimension(input_data + in_pos, output_data + out_pos, dim + 1, parameter); + DoTileOneDimension(input_data + in_pos, output_data + out_pos, dim + 1, parameter); } } return 0; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/tile.h similarity index 100% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/tile.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/tile.h diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.c b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unique.c similarity index 97% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/unique.c rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unique.c index ec7a66987a..26d186fd79 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.c +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unique.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "nnacl/unique.h" +#include "nnacl/fp32/unique.h" int Find(float *array, int len, float target) { for (int i = 0; i < len; ++i) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unique.h similarity index 100% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/unique.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unique.h diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.c b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/add_int8.c similarity index 99% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.c rename to mindspore/lite/src/runtime/kernel/arm/nnacl/int8/add_int8.c index 5aaa98c037..30599bed98 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.c +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/add_int8.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "nnacl/add_int8.h" +#include "nnacl/int8/add_int8.h" #ifdef ENABLE_NEON #include #endif diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/add_int8.h similarity index 100% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/int8/add_int8.h diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.c b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.c index 46b27cc54f..2ff0c7202f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.c +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.c @@ -18,7 +18,7 @@ #include "nnacl/int8/arithmetic_self_int8.h" #ifdef ENABLE_NEON #include -#include "nnacl/add_int8.h" +#include "nnacl/int8/add_int8.h" #endif #include "nnacl/quantization/fixed_point.h" diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.c b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.c index 811433e9ad..36a7244a81 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.c +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.c @@ -18,7 +18,7 @@ #include "nnacl/mul_parameter.h" #ifdef ENABLE_NEON #include -#include "nnacl/add_int8.h" +#include "nnacl/int8/add_int8.h" #endif #include "nnacl/quantization/fixed_point.h" diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sub_int8.c b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sub_int8.c index 756ee9ecf2..3a822ac1de 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sub_int8.c +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sub_int8.c @@ -17,7 +17,7 @@ #include "nnacl/int8/sub_int8.h" #ifdef ENABLE_NEON #include -#include "nnacl/add_int8.h" +#include "nnacl/int8/add_int8.h" #endif #include "nnacl/quantization/fixed_point.h" diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/reverse_sequence_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/reverse_sequence_fp32_tests.cc new file mode 100644 index 0000000000..9c8c9c30f8 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/reverse_sequence_fp32_tests.cc @@ -0,0 +1,157 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 +#include +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.h" +#include "mindspore/lite/src/kernel_registry.h" + +namespace mindspore { +class TestReverseSequenceFp32 : public mindspore::CommonTest { + public: + TestReverseSequenceFp32() {} +}; + +TEST_F(TestReverseSequenceFp32, BatchLessSeq) { + lite::tensor::Tensor in_tensor0(kNumberTypeFloat32, {2, 3, 4, 2}); + lite::tensor::Tensor in_tensor1(kNumberTypeInt32, {3}); + lite::tensor::Tensor out_tensor(kNumberTypeFloat32, {2, 3, 4, 2}); + float input_data0[] = {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}; + int input_data1[] = {2, 3, 4}; + float output_data[2 * 3 * 4 * 2] = {0}; + in_tensor0.SetData(input_data0); + in_tensor1.SetData(input_data1); + out_tensor.SetData(output_data); + std::vector inputs = {&in_tensor0, &in_tensor1}; + std::vector outputs = {&out_tensor}; + + ReverseSequenceParameter parameter = {0}; + parameter.batch_axis_ = 1; + parameter.seq_axis_ = 2; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_ReverseSequence}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + EXPECT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + EXPECT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + float expect[] = {2, 3, 0, 1, 4, 5, 6, 7, 12, 13, 10, 11, 8, 9, 14, 15, 22, 23, 20, 21, 18, 19, 16, 17, + 26, 27, 24, 25, 28, 29, 30, 31, 36, 37, 34, 35, 32, 33, 38, 39, 46, 47, 44, 45, 42, 43, 40, 41}; + EXPECT_EQ(out_tensor.ElementsNum(), 2 * 3 * 4 * 2); + + for (int i = 0; i < 2 * 3 * 4 * 2; i++) { + EXPECT_EQ(output_data[i], expect[i]); + } + + in_tensor0.SetData(nullptr); + in_tensor1.SetData(nullptr); + out_tensor.SetData(nullptr); +} + +TEST_F(TestReverseSequenceFp32, BatchGreaterSeq) { + lite::tensor::Tensor in_tensor0(kNumberTypeFloat32, {2, 3, 4, 2}); + lite::tensor::Tensor in_tensor1(kNumberTypeInt32, {4}); + lite::tensor::Tensor out_tensor(kNumberTypeFloat32, {2, 3, 4, 2}); + float input_data0[] = {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}; + int input_data1[] = {2, 3, 3, 2}; + float output_data[2 * 3 * 4 * 2] = {0}; + in_tensor0.SetData(input_data0); + in_tensor1.SetData(input_data1); + out_tensor.SetData(output_data); + std::vector inputs = {&in_tensor0, &in_tensor1}; + std::vector outputs = {&out_tensor}; + + ReverseSequenceParameter parameter = {0}; + parameter.batch_axis_ = 2; + parameter.seq_axis_ = 1; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_ReverseSequence}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + EXPECT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + EXPECT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + float expect[] = {8, 9, 18, 19, 20, 21, 14, 15, 0, 1, 10, 11, 12, 13, 6, 7, 16, 17, 2, 3, 4, 5, 22, 23, + 32, 33, 42, 43, 44, 45, 38, 39, 24, 25, 34, 35, 36, 37, 30, 31, 40, 41, 26, 27, 28, 29, 46, 47}; + EXPECT_EQ(out_tensor.ElementsNum(), 2 * 3 * 4 * 2); + + for (int i = 0; i < 2 * 3 * 4 * 2; i++) { + EXPECT_EQ(output_data[i], expect[i]); + } + + in_tensor0.SetData(nullptr); + in_tensor1.SetData(nullptr); + out_tensor.SetData(nullptr); +} + +TEST_F(TestReverseSequenceFp32, BatchSeqNotAdjacent) { + lite::tensor::Tensor in_tensor0(kNumberTypeFloat32, {2, 3, 4, 2}); + lite::tensor::Tensor in_tensor1(kNumberTypeInt32, {2}); + lite::tensor::Tensor out_tensor(kNumberTypeFloat32, {2, 3, 4, 2}); + float input_data0[] = {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}; + int input_data1[] = {2, 4}; + float output_data[2 * 3 * 4 * 2] = {0}; + in_tensor0.SetData(input_data0); + in_tensor1.SetData(input_data1); + out_tensor.SetData(output_data); + std::vector inputs = {&in_tensor0, &in_tensor1}; + std::vector outputs = {&out_tensor}; + + ReverseSequenceParameter parameter = {0}; + parameter.batch_axis_ = 0; + parameter.seq_axis_ = 2; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_ReverseSequence}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + EXPECT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + EXPECT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + float expect[] = {2, 3, 0, 1, 4, 5, 6, 7, 10, 11, 8, 9, 12, 13, 14, 15, 18, 19, 16, 17, 20, 21, 22, 23, + 30, 31, 28, 29, 26, 27, 24, 25, 38, 39, 36, 37, 34, 35, 32, 33, 46, 47, 44, 45, 42, 43, 40, 41}; + EXPECT_EQ(out_tensor.ElementsNum(), 2 * 3 * 4 * 2); + + for (int i = 0; i < 2 * 3 * 4 * 2; i++) { + EXPECT_EQ(output_data[i], expect[i]); + } + + in_tensor0.SetData(nullptr); + in_tensor1.SetData(nullptr); + out_tensor.SetData(nullptr); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/tile_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/tile_fp32_tests.cc new file mode 100644 index 0000000000..b8fe7ca185 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/tile_fp32_tests.cc @@ -0,0 +1,70 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 +#include +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/tile.h" +#include "mindspore/lite/src/kernel_registry.h" + +namespace mindspore { +class TestTileFp32 : public mindspore::CommonTest { + public: + TestTileFp32() {} +}; + +TEST_F(TestTileFp32, Tile) { + lite::tensor::Tensor in_tensor(kNumberTypeFloat32, {2, 2}); + lite::tensor::Tensor out_tensor(kNumberTypeFloat32, {4, 6}); + float input_data[] = {1, 2, 3, 4}; + float output_data[24] = {0}; + in_tensor.SetData(input_data); + out_tensor.SetData(output_data); + std::vector inputs = {&in_tensor}; + std::vector outputs = {&out_tensor}; + + TileParameter parameter = {0}; + parameter.in_dim_ = 2; + parameter.in_shape_[0] = 2; + parameter.in_shape_[1] = 2; + parameter.multiples_[0] = 2; + parameter.multiples_[1] = 3; + parameter.in_strides_[0] = 2; + parameter.in_strides_[1] = 1; + parameter.out_strides_[0] = 6; + parameter.out_strides_[1] = 1; + + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_Tile}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + EXPECT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + EXPECT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + float expect[] = {1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4, 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4}; + for (int i = 0; i < 24; ++i) { + EXPECT_EQ(output_data[i], expect[i]); + } + + in_tensor.SetData(nullptr); + out_tensor.SetData(nullptr); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/unique_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/unique_fp32_tests.cc new file mode 100644 index 0000000000..61281b0f6d --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/unique_fp32_tests.cc @@ -0,0 +1,70 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 +#include +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unique.h" +#include "mindspore/lite/src/kernel_registry.h" + +namespace mindspore { +class TestUniqueFp32 : public mindspore::CommonTest { + public: + TestUniqueFp32() {} +}; + +TEST_F(TestUniqueFp32, Unique) { + lite::tensor::Tensor in_tensor(kNumberTypeFloat32, {9}); + lite::tensor::Tensor out_tensor0(kNumberTypeFloat32, {9}); + lite::tensor::Tensor out_tensor1(kNumberTypeInt32, {9}); + float input_data[] = {1, 1, 2, 4, 4, 4, 7, 8, 8}; + float output_data0[9] = {0}; + int output_data1[9] = {0}; + in_tensor.SetData(input_data); + out_tensor0.SetData(output_data0); + out_tensor1.SetData(output_data1); + std::vector inputs = {&in_tensor}; + std::vector outputs = {&out_tensor0, &out_tensor1}; + + OpParameter parameter = {0}; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_Unique}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + EXPECT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, ¶meter, ctx.get(), desc, nullptr); + EXPECT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + float expect0[] = {1, 2, 4, 7, 8}; + int expect1[] = {0, 0, 1, 2, 2, 2, 3, 4, 4}; + EXPECT_EQ(out_tensor0.ElementsNum(), 5); + + for (int i = 0; i < 5; i++) { + EXPECT_EQ(output_data0[i], expect0[i]); + } + for (int i = 0; i < 9; ++i) { + EXPECT_EQ(output_data1[i], expect1[i]); + } + + in_tensor.SetData(nullptr); + out_tensor0.SetData(nullptr); + out_tensor1.SetData(nullptr); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/unstack_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/unstack_fp32_tests.cc new file mode 100644 index 0000000000..9504a99cbb --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/unstack_fp32_tests.cc @@ -0,0 +1,122 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 +#include +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.h" +#include "mindspore/lite/src/kernel_registry.h" + +namespace mindspore { +class TestUnstackFp32 : public mindspore::CommonTest { + public: + TestUnstackFp32() {} +}; + +TEST_F(TestUnstackFp32, Unstack) { + lite::tensor::Tensor in_tensor(kNumberTypeFloat32, {3, 4, 2}); + lite::tensor::Tensor out_tensor0(kNumberTypeFloat32, {3, 2}); + lite::tensor::Tensor out_tensor1(kNumberTypeFloat32, {3, 2}); + lite::tensor::Tensor out_tensor2(kNumberTypeFloat32, {3, 2}); + lite::tensor::Tensor out_tensor3(kNumberTypeFloat32, {3, 2}); + float input_data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + float output_data0[6] = {0}; + float output_data1[6] = {0}; + float output_data2[6] = {0}; + float output_data3[6] = {0}; + in_tensor.SetData(input_data); + out_tensor0.SetData(output_data0); + out_tensor1.SetData(output_data1); + out_tensor2.SetData(output_data2); + out_tensor3.SetData(output_data3); + std::vector inputs = {&in_tensor}; + std::vector outputs = {&out_tensor0, &out_tensor1, &out_tensor2, &out_tensor3}; + + UnstackParameter parameter = {{}, 4, -2, 3, 4, 2}; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_Unstack}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + EXPECT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + EXPECT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + float expect0[] = {1, 2, 9, 10, 17, 18}; + float expect1[] = {3, 4, 11, 12, 19, 20}; + float expect2[] = {5, 6, 13, 14, 21, 22}; + float expect3[] = {7, 8, 15, 16, 23, 24}; + for (int i = 0; i < 6; ++i) { + EXPECT_EQ(output_data0[i], expect0[i]); + EXPECT_EQ(output_data1[i], expect1[i]); + EXPECT_EQ(output_data2[i], expect2[i]); + EXPECT_EQ(output_data3[i], expect3[i]); + } + + in_tensor.SetData(nullptr); + out_tensor0.SetData(nullptr); + out_tensor1.SetData(nullptr); + out_tensor2.SetData(nullptr); + out_tensor3.SetData(nullptr); +} + +TEST_F(TestUnstackFp32, Unstack2) { + lite::tensor::Tensor in_tensor(kNumberTypeFloat32, {3, 4, 2}); + lite::tensor::Tensor out_tensor0(kNumberTypeFloat32, {4, 2}); + lite::tensor::Tensor out_tensor1(kNumberTypeFloat32, {4, 2}); + lite::tensor::Tensor out_tensor2(kNumberTypeFloat32, {4, 2}); + float input_data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}; + float output_data0[8] = {0}; + float output_data1[8] = {0}; + float output_data2[8] = {0}; + in_tensor.SetData(input_data); + out_tensor0.SetData(output_data0); + out_tensor1.SetData(output_data1); + out_tensor2.SetData(output_data2); + std::vector inputs = {&in_tensor}; + std::vector outputs = {&out_tensor0, &out_tensor1, &out_tensor2}; + + UnstackParameter parameter = {{}, 3, 0, 1, 3, 8}; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_Unstack}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + EXPECT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + EXPECT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + float expect0[] = {1, 2, 3, 4, 5, 6, 7, 8}; + float expect1[] = {9, 10, 11, 12, 13, 14, 15, 16}; + float expect2[] = {17, 18, 19, 20, 21, 22, 23, 24}; + for (int i = 0; i < 6; ++i) { + EXPECT_EQ(output_data0[i], expect0[i]); + EXPECT_EQ(output_data1[i], expect1[i]); + EXPECT_EQ(output_data2[i], expect2[i]); + } + + in_tensor.SetData(nullptr); + out_tensor0.SetData(nullptr); + out_tensor1.SetData(nullptr); + out_tensor2.SetData(nullptr); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/bias_add_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/bias_add_int8_tests.cc new file mode 100644 index 0000000000..d65632c5fd --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/bias_add_int8_tests.cc @@ -0,0 +1,75 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 +#include +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h" +#include "mindspore/lite/src/kernel_registry.h" + +using mindspore::lite::DeviceType; + +namespace mindspore { +class TestBiasAddInt8 : public mindspore::CommonTest { + public: + TestBiasAddInt8() {} +}; + +TEST_F(TestBiasAddInt8, BiasAdd) { + lite::tensor::Tensor in_tensor0(kNumberTypeInt8, {1, 2, 3, 2}); + lite::tensor::Tensor in_tensor1(kNumberTypeInt8, {2}); + lite::tensor::Tensor out_tensor(kNumberTypeInt8, {1, 2, 3, 2}); + int8_t input_data0[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + int8_t input_data1[] = {1, 1}; + int8_t output_data[12] = {0}; + in_tensor0.SetData(input_data0); + in_tensor1.SetData(input_data1); + out_tensor.SetData(output_data); + std::vector inputs = {&in_tensor0, &in_tensor1}; + std::vector outputs = {&out_tensor}; + + ArithmeticParameter parameter = {}; + int dims[] = {1, 2, 3, 4}; + parameter.ndim_ = 4; + for (int i = 0; i < 4; i++) { + parameter.in_shape0_[i] = dims[i]; + parameter.in_shape1_[i] = 1; + parameter.out_shape_[i] = dims[i]; + } + parameter.in_shape1_[3] = dims[3]; + + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_BiasAdd}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + EXPECT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + EXPECT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + float expect[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; + for (int i = 0; i < 12; ++i) { + EXPECT_EQ(output_data[i], expect[i]); + } + + in_tensor0.SetData(nullptr); + in_tensor1.SetData(nullptr); + out_tensor.SetData(nullptr); +} +} // namespace mindspore