blob: ad2d4892baa5fe84baa5ebad68be61c9ce4be81a [file] [log] [blame]
Georgios Pinitasb785dd42019-09-19 12:09:32 +01001/*
Georgios Pinitas856f66e2021-04-22 21:13:21 +01002 * Copyright (c) 2019-2021 Arm Limited.
Georgios Pinitasb785dd42019-09-19 12:09:32 +01003 *
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 */
24#include "arm_compute/runtime/BlobLifetimeManager.h"
25#include "arm_compute/runtime/CL/CLBufferAllocator.h"
Georgios Pinitas2ff00092019-09-30 16:50:08 +010026#include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h"
Georgios Pinitasb785dd42019-09-19 12:09:32 +010027#include "arm_compute/runtime/CL/functions/CLL2NormalizeLayer.h"
28#include "arm_compute/runtime/MemoryGroup.h"
29#include "arm_compute/runtime/MemoryManagerOnDemand.h"
30#include "arm_compute/runtime/PoolManager.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010031#include "src/core/CL/kernels/CLFillBorderKernel.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010032#include "src/core/CL/kernels/CLIm2ColKernel.h"
33#include "src/core/CL/kernels/CLL2NormalizeLayerKernel.h"
34#include "src/core/CL/kernels/CLReductionOperationKernel.h"
35#include "src/core/CL/kernels/CLWeightsReshapeKernel.h"
Georgios Pinitasb785dd42019-09-19 12:09:32 +010036#include "tests/AssetsLibrary.h"
37#include "tests/CL/CLAccessor.h"
38#include "tests/Globals.h"
39#include "tests/Utils.h"
40#include "tests/framework/Asserts.h"
41#include "tests/framework/Macros.h"
42#include "tests/framework/datasets/Datasets.h"
Georgios Pinitas2ff00092019-09-30 16:50:08 +010043#include "tests/validation/Validation.h"
Georgios Pinitasb785dd42019-09-19 12:09:32 +010044#include "tests/validation/fixtures/UNIT/DynamicTensorFixture.h"
45
46namespace arm_compute
47{
48namespace test
49{
50namespace validation
51{
52namespace
53{
Georgios Pinitas2ff00092019-09-30 16:50:08 +010054constexpr AbsoluteTolerance<float> absolute_tolerance_float(0.0001f); /**< Absolute Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
55RelativeTolerance<float> tolerance_f32(0.1f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
56constexpr float tolerance_num = 0.07f; /**< Tolerance number */
Michalis Spyrou5cb49dc2019-12-03 13:42:25 +000057} // namespace
Georgios Pinitas2ff00092019-09-30 16:50:08 +010058
Michalis Spyrou5cb49dc2019-12-03 13:42:25 +000059#ifndef DOXYGEN_SKIP_THIS
Georgios Pinitasb785dd42019-09-19 12:09:32 +010060using CLL2NormLayerWrapper = SimpleFunctionWrapper<MemoryManagerOnDemand, CLL2NormalizeLayer, ICLTensor>;
61template <>
62void CLL2NormLayerWrapper::configure(ICLTensor *src, ICLTensor *dst)
63{
64 _func.configure(src, dst, 0, 0.0001f);
65}
Michalis Spyrou5cb49dc2019-12-03 13:42:25 +000066#endif // DOXYGEN_SKIP_THIS
Georgios Pinitasb785dd42019-09-19 12:09:32 +010067TEST_SUITE(CL)
68TEST_SUITE(UNIT)
69TEST_SUITE(DynamicTensor)
70
Georgios Pinitas2ff00092019-09-30 16:50:08 +010071using BlobMemoryManagementService = MemoryManagementService<CLBufferAllocator, BlobLifetimeManager, PoolManager, MemoryManagerOnDemand>;
72using CLDynamicTensorType3SingleFunction = DynamicTensorType3SingleFunction<CLTensor, CLAccessor, BlobMemoryManagementService, CLL2NormLayerWrapper>;
Georgios Pinitasb785dd42019-09-19 12:09:32 +010073
74/** Tests the memory manager with dynamic input and output tensors.
75 *
76 * Create and manage the tensors needed to run a simple function. After the function is executed,
77 * change the input and output size requesting more memory and go through the manage/allocate process.
78 * The memory manager should be able to update the inner structures and allocate the requested memory
79 * */
80FIXTURE_DATA_TEST_CASE(DynamicTensorType3Single, CLDynamicTensorType3SingleFunction, framework::DatasetMode::ALL,
81 framework::dataset::zip(framework::dataset::make("Level0Shape", { TensorShape(12U, 11U, 3U), TensorShape(256U, 8U, 12U) }),
82 framework::dataset::make("Level1Shape", { TensorShape(67U, 31U, 15U), TensorShape(11U, 2U, 3U) })))
83{
84 ARM_COMPUTE_EXPECT(internal_l0.size() == internal_l1.size(), framework::LogLevel::ERRORS);
85 ARM_COMPUTE_EXPECT(cross_l0.size() == cross_l1.size(), framework::LogLevel::ERRORS);
86
87 const unsigned int internal_size = internal_l0.size();
88 const unsigned int cross_size = cross_l0.size();
89 if(input_l0.total_size() < input_l1.total_size())
90 {
91 for(unsigned int i = 0; i < internal_size; ++i)
92 {
93 ARM_COMPUTE_EXPECT(internal_l0[i].size < internal_l1[i].size, framework::LogLevel::ERRORS);
94 }
95 for(unsigned int i = 0; i < cross_size; ++i)
96 {
97 ARM_COMPUTE_EXPECT(cross_l0[i].size < cross_l1[i].size, framework::LogLevel::ERRORS);
98 }
99 }
100 else
101 {
102 for(unsigned int i = 0; i < internal_size; ++i)
103 {
104 ARM_COMPUTE_EXPECT(internal_l0[i].size == internal_l1[i].size, framework::LogLevel::ERRORS);
105 }
106 for(unsigned int i = 0; i < cross_size; ++i)
107 {
108 ARM_COMPUTE_EXPECT(cross_l0[i].size == cross_l1[i].size, framework::LogLevel::ERRORS);
109 }
110 }
111}
112
Georgios Pinitas2ff00092019-09-30 16:50:08 +0100113using CLDynamicTensorType3ComplexFunction = DynamicTensorType3ComplexFunction<CLTensor, CLAccessor, BlobMemoryManagementService, CLConvolutionLayer>;
114/** Tests the memory manager with dynamic input and output tensors.
115 *
116 * Create and manage the tensors needed to run a complex function. After the function is executed,
117 * change the input and output size requesting more memory and go through the manage/allocate process.
118 * The memory manager should be able to update the inner structures and allocate the requested memory
119 * */
120FIXTURE_DATA_TEST_CASE(DynamicTensorType3Complex, CLDynamicTensorType3ComplexFunction, framework::DatasetMode::ALL,
121 framework::dataset::zip(framework::dataset::zip(framework::dataset::zip(framework::dataset::zip(
122 framework::dataset::make("InputShape", { std::vector<TensorShape>{ TensorShape(12U, 12U, 16U), TensorShape(64U, 64U, 16U) } }),
123 framework::dataset::make("WeightsManager", { TensorShape(3U, 3U, 16U, 5U) })),
124 framework::dataset::make("BiasShape", { TensorShape(5U) })),
125 framework::dataset::make("OutputShape", { std::vector<TensorShape>{ TensorShape(12U, 12U, 5U), TensorShape(64U, 64U, 5U) } })),
126 framework::dataset::make("PadStrideInfo", { PadStrideInfo(1U, 1U, 1U, 1U) })))
127{
128 for(unsigned int i = 0; i < num_iterations; ++i)
129 {
130 run_iteration(i);
131 validate(CLAccessor(dst_target), dst_ref, tolerance_f32, tolerance_num, absolute_tolerance_float);
132 }
133}
134
Georgios Pinitas3d426c52019-10-10 19:35:43 +0100135using CLDynamicTensorType2PipelineFunction = DynamicTensorType2PipelineFunction<CLTensor, CLAccessor, BlobMemoryManagementService, CLConvolutionLayer>;
136/** Tests the memory manager with dynamic input and output tensors.
137 *
138 * Create and manage the tensors needed to run a pipeline. After the function is executed, resize the input size and rerun.
139 */
140FIXTURE_DATA_TEST_CASE(DynamicTensorType2Pipeline, CLDynamicTensorType2PipelineFunction, framework::DatasetMode::ALL,
141 framework::dataset::make("InputShape", { std::vector<TensorShape>{ TensorShape(12U, 12U, 6U), TensorShape(128U, 128U, 6U) } }))
142{
143}
144
Georgios Pinitasb785dd42019-09-19 12:09:32 +0100145TEST_SUITE_END() // DynamicTensor
146TEST_SUITE_END() // UNIT
147TEST_SUITE_END() // CL
148} // namespace validation
149} // namespace test
150} // namespace arm_compute