Compute Library
 22.11
FillBorder.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2020, 2022 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 #include "tests/Globals.h"
26 #include "tests/NEON/Accessor.h"
27 #include "tests/datasets/BorderModeDataset.h"
28 #include "tests/datasets/ShapeDatasets.h"
29 #include "tests/framework/Macros.h"
32 
33 namespace arm_compute
34 {
35 namespace test
36 {
37 namespace validation
38 {
39 TEST_SUITE(NEON)
40 TEST_SUITE(FillBorder)
41 
42 // *INDENT-OFF*
43 // clang-format off
44 const auto PaddingSizesDataset = concat(concat(
45  framework::dataset::make("PaddingSize", PaddingSize{ 0 }),
46  framework::dataset::make("PaddingSize", PaddingSize{ 1, 0, 1, 2 })),
47  framework::dataset::make("PaddingSize", PaddingSize{ 10 }));
48 
49 const auto BorderSizesDataset = framework::dataset::make("BorderSize", 0, 6);
50 
52  datasets::SmallShapes(),
53  datasets::BorderModes()),
57  shape, border_mode, size, padding, data_type)
58 // clang-format on
59 // *INDENT-ON*
60 {
61  BorderSize border_size{ static_cast<unsigned int>(size) };
62 
63  std::mt19937 generator(library->seed());
64  std::uniform_int_distribution<uint32_t> distribution_u8(0, 255);
65  const uint8_t border_value = distribution_u8(generator);
66  const uint8_t tensor_value = distribution_u8(generator);
67 
68  // Create tensors
69  Tensor src = create_tensor<Tensor>(shape, data_type);
70 
71  src.info()->extend_padding(padding);
72 
73  // Allocate tensor
74  src.allocator()->allocate();
75 
76  // Check padding is as required
77  validate(src.info()->padding(), padding);
78 
79  // Fill tensor with constant value
80  std::uniform_int_distribution<uint32_t> distribution{ tensor_value, tensor_value };
81  library->fill(Accessor(src), distribution, 0);
82 
83  // Create and configure kernel
84  NEFillBorderKernel fill_border;
85  fill_border.configure(&src, border_size, border_mode, border_value);
86 
87  // Run kernel
88  fill_border.run(fill_border.window(), ThreadInfo());
89 
90  // Validate border
91  border_size.limit(padding);
92  validate(Accessor(src), border_size, border_mode, &border_value);
93 
94  // Validate tensor
95  validate(Accessor(src), &tensor_value);
96 }
97 
100 } // namespace validation
101 } // namespace test
102 } // namespace arm_compute
1 channel, 1 U8 per channel
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2022 Arm Limited.
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:76
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
validate(CLAccessor(output_state), expected_output)
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
BorderSize PaddingSize
Container for 2D padding size.
Definition: Types.h:397
JoinDataset< T, U > concat(T &&dataset1, U &&dataset2)
Helper function to create a JoinDataset.
Definition: JoinDataset.h:160
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65