Compute Library
 23.08
FillBorder.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2020 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  */
26 #include "tests/CL/CLAccessor.h"
27 #include "tests/Globals.h"
28 #include "tests/datasets/BorderModeDataset.h"
29 #include "tests/datasets/ShapeDatasets.h"
30 #include "tests/framework/Macros.h"
33 
34 namespace arm_compute
35 {
36 namespace test
37 {
38 namespace validation
39 {
40 TEST_SUITE(CL)
41 TEST_SUITE(FillBorder)
42 
43 // *INDENT-OFF*
44 // clang-format off
46  framework::dataset::make("PaddingSize", PaddingSize{ 0 }),
47  framework::dataset::make("PaddingSize", PaddingSize{ 1, 0, 1, 2 })),
48  framework::dataset::make("PaddingSize", PaddingSize{ 10 }));
49 
50 const auto BorderSizesDataset = framework::dataset::make("BorderSize", 0, 6);
51 
53  datasets::SmallShapes(),
54  datasets::BorderModes()),
58  shape, border_mode, size, padding, data_type)
59 // clang-format on
60 // *INDENT-ON*
61 {
62  BorderSize border_size{ static_cast<unsigned int>(size) };
63 
64  std::mt19937 generator(library->seed());
65  std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
66  const uint8_t border_value = distribution_u8(generator);
67  const uint8_t tensor_value = distribution_u8(generator);
68 
69  // Create tensors
70  CLTensor src = create_tensor<CLTensor>(shape, data_type);
71 
72  src.info()->extend_padding(padding);
73 
74  // Allocate tensor
75  src.allocator()->allocate();
76 
77  // Check padding is as required
78  validate(src.info()->padding(), padding);
79 
80  // Fill tensor with constant value
81  std::uniform_int_distribution<uint8_t> distribution{ tensor_value, tensor_value };
82  library->fill(CLAccessor(src), distribution, 0);
83 
84  // Create and configure kernel
85  CLFillBorderKernel fill_border;
86  fill_border.configure(&src, border_size, border_mode, border_value);
87 
88  // Run kernel
89  fill_border.run(fill_border.window(), CLScheduler::get().queue());
90 
91  // Validate border
92  border_size.limit(padding);
93  validate(CLAccessor(src), border_size, border_mode, &border_value);
94 
95  // Validate tensor
96  validate(CLAccessor(src), &tensor_value);
97 }
98 
101 } // namespace validation
102 } // namespace test
103 } // namespace arm_compute
Datasets.h
arm_compute::test::validation::TEST_SUITE_END
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
Definition: DequantizationLayer.cpp:111
arm_compute::test::validation::src
SimpleTensor< float > src
Definition: DFT.cpp:155
arm_compute::test::validation::DATA_TEST_CASE
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)
Definition: ActivationLayer.cpp:100
arm_compute::test::validation::combine
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
arm_compute::BorderSize
Container for 2D border size.
Definition: Types.h:242
arm_compute::test::validation::BorderSizesDataset
const auto BorderSizesDataset
Definition: FillBorder.cpp:50
arm_compute::CLFillBorderKernel
Interface for filling the border of a kernel.
Definition: CLFillBorderKernel.h:36
arm_compute::test::validation::PaddingSizesDataset
const auto PaddingSizesDataset
Definition: FillBorder.cpp:45
arm_compute::CLTensor
Basic implementation of the OpenCL tensor interface.
Definition: CLTensor.h:41
CLAccessor.h
arm_compute::test::validation::validate
validate(CLAccessor(output_state), expected_output)
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
arm_compute::test::framework::DatasetMode::ALL
@ ALL
arm_compute::test::CLAccessor
Accessor implementation for CLTensor objects.
Definition: CLAccessor.h:36
arm_compute::test::framework::dataset::concat
JoinDataset< T, U > concat(T &&dataset1, U &&dataset2)
Helper function to create a JoinDataset.
Definition: JoinDataset.h:160
CLFillBorderKernel.h
arm_compute::DataType::U8
@ U8
unsigned 8-bit number
CLScheduler.h
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
Macros.h
arm_compute::CLScheduler::get
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:103
arm_compute::test::framework::dataset::make
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
Definition: ContainerDataset.h:160
arm_compute::test::validation::data_type
data_type
Definition: Cast.cpp:223
Validation.h
arm_compute::test::library
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:77
arm_compute::IKernel::window
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
Globals.h
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::CLFillBorderKernel::run
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
Definition: CLFillBorderKernel.cpp:200
arm_compute::test::validation::TEST_SUITE
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
arm_compute::test::validation::distribution
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
arm_compute::CLScheduler::queue
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:39
arm_compute::CLFillBorderKernel::configure
void configure(const CLCompileContext &compile_context, ICLTensor *tensor, BorderSize border_size, BorderMode border_mode, const PixelValue &constant_border_value=PixelValue())
Initialise the kernel's input, output and border mode.
Definition: CLFillBorderKernel.cpp:64