blob: dd2c7982f418f417ab130648742a0fd82b526579 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016, 2017 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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/** This function computes the horizontal integral of the image.
27 *
28 * @param[in] src_ptr Pointer to the source image. Supported data types: U8
29 * @param[in] src_stride_x Stride of the source image in X dimension (in bytes)
30 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
31 * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes)
32 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
33 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image
34 * @param[out] dst_ptr Pointer to the destination image. Supported data types: U32
35 * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes)
36 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
37 * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes)
38 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
39 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image
40 */
41__kernel void integral_horizontal(
42 IMAGE_DECLARATION(src),
43 IMAGE_DECLARATION(dst))
44{
45 Image src = CONVERT_TO_IMAGE_STRUCT(src);
46 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
47
48 uint prev = 0;
49
50 for(uint j = 0; j < src_step_x; j += 16)
51 {
52 barrier(CLK_GLOBAL_MEM_FENCE);
53 uint16 res = convert_uint16(vload16(0, offset(&src, j, 0)));
54 res.s0 += prev;
55 res.s1 += res.s0;
56 res.s2 += res.s1;
57 res.s3 += res.s2;
58 res.s4 += res.s3;
59 res.s5 += res.s4;
60 res.s6 += res.s5;
61 res.s7 += res.s6;
62 res.s8 += res.s7;
63 res.s9 += res.s8;
64 res.sA += res.s9;
65 res.sB += res.sA;
66 res.sC += res.sB;
67 res.sD += res.sC;
68 res.sE += res.sD;
69 res.sF += res.sE;
70 prev = res.sF;
71 vstore16(res, 0, (__global uint *)offset(&dst, j, 0));
72 }
73}
74
75/** This function computes the vertical integral of the image.
76 *
77 * @param[in,out] src_ptr Pointer to the source image. Supported data types: U32
78 * @param[in] src_stride_x Stride of the source image in X dimension (in bytes)
79 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
80 * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes)
81 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
82 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image
83 * @param[in] height Image height.
84 */
85__kernel void integral_vertical(
86 IMAGE_DECLARATION(src),
87 uint height)
88{
89 Image src = CONVERT_TO_IMAGE_STRUCT(src);
90
91 uint8 prev = vload8(0, (__global uint *)offset(&src, 0, 0));
92 for(uint j = 1; j < height; ++j)
93 {
94 barrier(CLK_GLOBAL_MEM_FENCE);
95 uint8 res = vload8(0, (__global uint *)offset(&src, 0, j));
96 res += prev;
97 vstore8(res, 0, (__global uint *)offset(&src, 0, j));
98 prev = res;
99 }
100}