blob: e3d4b4ac1e70e8654235cb61c4e160acec6fbaa9 [file] [log] [blame]
Sanghoon Leec8a85ba2017-11-29 11:23:14 +00001/*
Sanghoon Leec8d23162018-01-12 16:19:10 +00002 * Copyright (c) 2017-2018 ARM Limited.
Sanghoon Leec8a85ba2017-11-29 11:23:14 +00003 *
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/Helpers.h"
25
26#include "Convolution.h"
27#include "Utils.h"
28
29namespace arm_compute
30{
31namespace test
32{
33namespace validation
34{
35namespace reference
36{
37template <typename T>
Sanghoon Leec8d23162018-01-12 16:19:10 +000038SimpleTensor<T> convolution(const SimpleTensor<uint8_t> &src, DataType output_data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value,
39 const unsigned int width,
40 const unsigned int height)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000041{
Georgios Pinitase9146ed2018-02-07 16:05:47 +000042 ARM_COMPUTE_ERROR_ON(scale == 0);
43 ARM_COMPUTE_ERROR_ON(scale >= std::numeric_limits<int32_t>::max());
Sanghoon Leec8d23162018-01-12 16:19:10 +000044
Georgios Pinitase9146ed2018-02-07 16:05:47 +000045 SimpleTensor<T> dst(src.shape(), output_data_type);
46 SimpleTensor<int32_t> sum(src.shape(), output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000047
Georgios Pinitase9146ed2018-02-07 16:05:47 +000048 for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000049 {
Georgios Pinitase9146ed2018-02-07 16:05:47 +000050 const Coordinates id = index2coord(src.shape(), element_idx);
51 apply_2d_spatial_filter(id, src, sum, TensorShape(width, height), conv, 1, border_mode, constant_border_value);
52 dst[element_idx] = saturate_cast<T>(tensor_elem_at<int32_t>(sum, id, border_mode, constant_border_value) / static_cast<int>(scale));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000053 }
Georgios Pinitase9146ed2018-02-07 16:05:47 +000054
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000055 return dst;
56}
57
Sanghoon Leec8d23162018-01-12 16:19:10 +000058template SimpleTensor<uint8_t> convolution(const SimpleTensor<uint8_t> &src, DataType output_data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value,
59 const unsigned int widht, const unsigned int height);
60template SimpleTensor<int16_t> convolution(const SimpleTensor<uint8_t> &src, DataType output_data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value,
Sanghoon Leed7ba5392017-12-13 11:28:50 +000061 const unsigned int widht, const unsigned int height);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000062} // namespace reference
63} // namespace validation
64} // namespace test
65} // namespace arm_compute