• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019-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  */
24 #include "arm_compute/core/Types.h"
25 #include "arm_compute/runtime/CL/CLTensor.h"
26 #include "arm_compute/runtime/CL/CLTensorAllocator.h"
27 #include "arm_compute/runtime/CL/functions/CLDepthToSpaceLayer.h"
28 #include "tests/CL/CLAccessor.h"
29 #include "tests/PaddingCalculator.h"
30 #include "tests/datasets/DepthToSpaceDataset.h"
31 #include "tests/datasets/ShapeDatasets.h"
32 #include "tests/framework/Asserts.h"
33 #include "tests/framework/Macros.h"
34 #include "tests/framework/datasets/Datasets.h"
35 #include "tests/validation/Validation.h"
36 #include "tests/validation/fixtures/DepthToSpaceLayerFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 TEST_SUITE(CL)
45 TEST_SUITE(DepthToSpaceLayer)
46 
47 template <typename T>
48 using CLDepthToSpaceLayerFixture = DepthToSpaceLayerValidationFixture<CLTensor, CLAccessor, CLDepthToSpaceLayer, T>;
49 
50 // *INDENT-OFF*
51 // clang-format off
52 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
53                framework::dataset::make("InputInfo", { TensorInfo(TensorShape(16U, 8U, 4U, 4U), 1, DataType::F32),
54                                                        TensorInfo(TensorShape(16U, 8U, 4U, 4U), 1, DataType::F32),   // block < 2
55                                                        TensorInfo(TensorShape(16U, 8U, 2U, 4U), 1, DataType::F32),    // Mismatching data types
56                                                        TensorInfo(TensorShape(16U, 8U, 2U, 4U), 1, DataType::F32),    // Negative block shape
57                                                        TensorInfo(TensorShape(32U, 16U, 2U, 4U, 4U), 1, DataType::F32), // Wrong tensor shape
58                                                      }),
59                framework::dataset::make("BlockShape", { 2, 1, 2, 2, 2 })),
60                framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 16U, 1U, 4U), 1, DataType::F32),
61                                                        TensorInfo(TensorShape(64U, 16U, 1U, 4U), 1, DataType::F32),
62                                                        TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F16),
63                                                        TensorInfo(TensorShape(32U, 16U, 2U, 1U), 1, DataType::F32),
64                                                        TensorInfo(TensorShape(32U, 8U, 2U, 1U), 1, DataType::F32),
65                                                      })),
66                framework::dataset::make("Expected", { true, false, false, false, false})),
67                input_info, block_shape, output_info, expected)
68 {
69     bool has_error = bool(CLDepthToSpaceLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), block_shape));
70     ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
71 }
72 // clang-format on
73 // *INDENT-ON*
74 
75 TEST_SUITE(Float)
TEST_SUITE(FP32)76 TEST_SUITE(FP32)
77 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthToSpaceLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallDepthToSpaceLayerDataset(), framework::dataset::make("DataType",
78                                                                                                                        DataType::F32)),
79                                                                                                                framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
80 {
81     // Validate output
82     validate(CLAccessor(_target), _reference);
83 }
84 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthToSpaceLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeDepthToSpaceLayerDataset(), framework::dataset::make("DataType",
85                                                                                                                      DataType::F32)),
86                                                                                                              framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
87 {
88     // Validate output
89     validate(CLAccessor(_target), _reference);
90 }
91 TEST_SUITE_END() // FP32
92 
TEST_SUITE(FP16)93 TEST_SUITE(FP16)
94 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthToSpaceLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallDepthToSpaceLayerDataset(), framework::dataset::make("DataType",
95                                                                                                                       DataType::F16)),
96                                                                                                               framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
97 {
98     // Validate output
99     validate(CLAccessor(_target), _reference);
100 }
101 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthToSpaceLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeDepthToSpaceLayerDataset(), framework::dataset::make("DataType",
102                                                                                                                     DataType::F16)),
103                                                                                                             framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
104 {
105     // Validate output
106     validate(CLAccessor(_target), _reference);
107 }
108 TEST_SUITE_END() // FP16
109 TEST_SUITE_END() // Float
110 
111 TEST_SUITE_END() // DepthToSpace
112 TEST_SUITE_END() // CL
113 } // namespace validation
114 } // namespace test
115 } // namespace arm_compute
116