Compute Library  18.05
convolution3x3.cl
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, 2017 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 "helpers.h"
25 
26 #ifndef DATA_TYPE
27 #define DATA_TYPE short
28 #endif /* DATA_TYPE */
29 
30 #ifndef DATA_TYPE_OUT
31 #define DATA_TYPE_OUT uchar
32 #endif /* DATA_TYPE_OUT */
33 
43 inline VEC_DATA_TYPE(DATA_TYPE, 8) convolution1x3(__global const uchar *left_pixel,
44  const short left_coeff,
45  const short middle_coeff,
46  const short right_coeff)
47 {
48  uchar16 temp = vload16(0, left_pixel);
50  left = CONVERT(temp.s01234567, VEC_DATA_TYPE(DATA_TYPE, 8));
52  middle = CONVERT(temp.s12345678, VEC_DATA_TYPE(DATA_TYPE, 8));
54  right = CONVERT(temp.s23456789, VEC_DATA_TYPE(DATA_TYPE, 8));
55 
56  return left * (VEC_DATA_TYPE(DATA_TYPE, 8))left_coeff + middle * (VEC_DATA_TYPE(DATA_TYPE, 8))middle_coeff + right * (VEC_DATA_TYPE(DATA_TYPE, 8))right_coeff;
57 }
58 
83  Image *src,
84  const short mat0, const short mat1, const short mat2,
85  const short mat3, const short mat4, const short mat5,
86  const short mat6, const short mat7, const short mat8, uint scale)
87 {
88  // Output pixels
90  pixels;
91 
92  // Row 0
93  pixels = convolution1x3(offset(src, -1, -1), mat0, mat1, mat2);
94  // Row
95  pixels += convolution1x3(offset(src, -1, 0), mat3, mat4, mat5);
96  // Row 2
97  pixels += convolution1x3(offset(src, -1, 1), mat6, mat7, mat8);
98 
99  // Divide by the scale
100  return pixels / (VEC_DATA_TYPE(DATA_TYPE, 8))scale;
101 }
102 
103 #ifndef DYNAMIC_MATRIX_CONVOLUTION
104 
123 __kernel void convolution3x3_static(
126 {
129 
131  pixels = convolution3x3(&src,
132  MAT0, MAT1, MAT2, MAT3, MAT4, MAT5, MAT6, MAT7, MAT8, SCALE);
133 
134  // Store the result as is in dst
135  vstore8(CONVERT_SAT(pixels, VEC_DATA_TYPE(DATA_TYPE_OUT, 8)), 0, (__global DATA_TYPE_OUT *)dst.ptr);
136 }
137 
138 #endif // DYNAMIC_MATRIX_CONVOLUTION
#define CONVERT(x, type)
Definition: fixed_point.h:98
#define DATA_TYPE
#define CONVERT_SAT(a, b)
#define IMAGE_DECLARATION(name)
Definition: helpers.h:68
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:303
__kernel void convolution3x3_static(__global uchar *src_ptr, uint src_stride_x, uint src_step_x, uint src_stride_y, uint src_step_y, uint src_offset_first_element_in_bytes, __global uchar *dst_ptr, uint dst_stride_x, uint dst_step_x, uint dst_stride_y, uint dst_step_y, uint dst_offset_first_element_in_bytes)
Apply a 3x3 static convolution matrix to a single channel U8 input image and output a single channel ...
#define CONVERT_TO_IMAGE_STRUCT(name)
Definition: helpers.h:104
short8 convolution3x3(Image *src, const short mat0, const short mat1, const short mat2, const short mat3, const short mat4, const short mat5, const short mat6, const short mat7, const short mat8, uint scale)
Apply a 3x3 convolution matrix to a single channel U8 input image and return the result.
Structure to hold Image information.
Definition: helpers.h:142
__global uchar * ptr
Pointer to the starting postion of the buffer.
Definition: helpers.h:144
#define VEC_DATA_TYPE(type, size)
Definition: fixed_point.h:93
#define DATA_TYPE_OUT
convolution configure & src
short8 convolution1x3(__global const uchar *left_pixel, const short left_coeff, const short middle_coeff, const short right_coeff)
Compute a 1D horizontal convolution of size 3 for 8 bytes assuming the input is made of 1 channel of ...