• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019 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 
25 #pragma once
26 
27 #include <cstddef>
28 
29 // Utilities for copying tensor tiles and adding/removing padding.
30 namespace padding
31 {
32 
33 /* Copy a tile and apply padding to the output copy.
34  */
35 template <typename T>
36 void copy_and_pad_tile(
37   unsigned int tile_rows,
38   unsigned int tile_cols,
39   unsigned int n_channels,
40   const T *inptr,
41   unsigned int in_row_stride,
42   unsigned int in_col_stride,
43   T* outptr,
44   unsigned int out_row_stride,
45   unsigned int out_col_stride,
46   unsigned int pad_top,
47   unsigned int pad_left,
48   unsigned int pad_bottom,
49   unsigned int pad_right,
50   T pad_value=static_cast<T>(0)
51 );
52 
53 /** Copy a tile and remove padding elements in the output.
54  */
55 template <unsigned int TileRows, unsigned int TileCols>
56 class CopyCropped
57 {
58   public:
59     static void execute(
60       size_t size,  // Amount of data to copy
61       const void *inptr,
62       size_t in_row_stride,
63       size_t in_col_stride,
64       void *outptr,
65       size_t out_row_stride,
66       size_t out_col_stride,
67       unsigned int pad_top,
68       unsigned int pad_left,
69       unsigned int pad_bottom,
70       unsigned int pad_right
71     );
72 };
73 
74 template <typename T>
75 void crop_and_copy_tile(
76   unsigned int tile_rows,
77   unsigned int tile_cols,
78   unsigned int n_channels,
79   const T *inptr,
80   unsigned int in_row_stride,
81   unsigned int in_col_stride,
82   T *outptr,
83   unsigned int out_row_stride,
84   unsigned int out_col_stride,
85   unsigned int crop_top,
86   unsigned int crop_left,
87   unsigned int crop_bottom,
88   unsigned int crop_right
89 );
90 
91 }
92