Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 1 | /* |
Sanghoon Lee | c8d2316 | 2018-01-12 16:19:10 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 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/Helpers.h" |
| 25 | |
| 26 | #include "Convolution.h" |
| 27 | #include "Utils.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace test |
| 32 | { |
| 33 | namespace validation |
| 34 | { |
| 35 | namespace reference |
| 36 | { |
| 37 | template <typename T> |
Sanghoon Lee | c8d2316 | 2018-01-12 16:19:10 +0000 | [diff] [blame] | 38 | SimpleTensor<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 Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 41 | { |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 42 | ARM_COMPUTE_ERROR_ON(scale == 0); |
| 43 | ARM_COMPUTE_ERROR_ON(scale >= std::numeric_limits<int32_t>::max()); |
Sanghoon Lee | c8d2316 | 2018-01-12 16:19:10 +0000 | [diff] [blame] | 44 | |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 45 | SimpleTensor<T> dst(src.shape(), output_data_type); |
| 46 | SimpleTensor<int32_t> sum(src.shape(), output_data_type); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 47 | |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 48 | for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 49 | { |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 50 | 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 Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 53 | } |
Georgios Pinitas | e9146ed | 2018-02-07 16:05:47 +0000 | [diff] [blame] | 54 | |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 55 | return dst; |
| 56 | } |
| 57 | |
Sanghoon Lee | c8d2316 | 2018-01-12 16:19:10 +0000 | [diff] [blame] | 58 | template 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); |
| 60 | template 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 Lee | d7ba539 | 2017-12-13 11:28:50 +0000 | [diff] [blame] | 61 | const unsigned int widht, const unsigned int height); |
Sanghoon Lee | c8a85ba | 2017-11-29 11:23:14 +0000 | [diff] [blame] | 62 | } // namespace reference |
| 63 | } // namespace validation |
| 64 | } // namespace test |
| 65 | } // namespace arm_compute |