blob: 2950d5e95737f1971b43691f8782311e26b2e250 [file] [log] [blame]
Pablo Marquez Tello4e2bbbb2023-01-09 17:21:01 +00001/*
2 * Copyright (c) 2023 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 *
Michael Tyler74921ee2023-04-12 17:43:17 +010013 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
Pablo Marquez Tello4e2bbbb2023-01-09 17:21:01 +000015 *
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
Pablo Marquez Tello4e2bbbb2023-01-09 17:21:01 +000025#include "depthwise_common.hpp"
26
Michael Tyler74921ee2023-04-12 17:43:17 +010027#include "utils.hpp"
28
Pablo Marquez Tello4e2bbbb2023-01-09 17:21:01 +000029using arm_gemm::iceildiv;
30
31namespace arm_conv {
32namespace depthwise {
33
34std::tuple<size_t, size_t, size_t, size_t, size_t>
35get_reduced_view_for_dilation(size_t out_size, size_t in_size, const size_t d,
36 const size_t dilation_factor,
37 const size_t kernel_size, const size_t stride,
38 const size_t orig_pad_before) {
39 // Get the valid output range
40 out_size = iceildiv(out_size - d, dilation_factor);
41
42 // Compute the start offset and the amount of padding which applies to this
43 // portion of the work.
44 size_t start_pos = d * stride, pad_before = 0;
45 if (start_pos < orig_pad_before) {
46 pad_before = iceildiv(orig_pad_before - start_pos, dilation_factor);
47 }
48 start_pos += pad_before * dilation_factor - orig_pad_before;
49
50 // Hence compute the valid input range
51 in_size = start_pos < in_size
52 ? iceildiv(in_size - start_pos, dilation_factor)
53 : 0;
54
55 // Finally, compute the "after" padding
56 const size_t reqd_input = (out_size - 1) * stride + kernel_size;
57 size_t pad_after = 0;
58 if (reqd_input > (pad_before + in_size)) {
59 pad_after = reqd_input - (pad_before + in_size);
60 }
61
62 return std::make_tuple(out_size, in_size, start_pos, pad_before, pad_after);
63}
64
65} // namespace depthwise
66} // namespace arm_conv