Compute Library  18.05
mean_stddev.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 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
27 #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable
28 
43 __kernel void mean_stddev_accumulate(
45  uint height,
46  __global ulong *global_sum
47 #ifdef STDDEV
48  ,
49  __global ulong *global_sum_sq
50 #endif /* STDDEV */
51 )
52 {
53  // Get pixels pointer
55 
56  uint8 tmp_sum = 0;
57 #ifdef STDDEV
58  uint8 tmp_sum_sq = 0;
59 #endif /* STDDEV */
60  // Calculate partial sum
61  for(int i = 0; i < height; i++)
62  {
63  // Load data
64  uint8 data = convert_uint8(vload8(0, offset(&src, 0, i)));
65 
66  tmp_sum += data;
67 #ifdef STDDEV
68  tmp_sum_sq += data * data;
69 #endif /* STDDEV */
70  }
71  // Perform reduction
72  tmp_sum.s0123 += tmp_sum.s4567;
73  tmp_sum.s01 += tmp_sum.s23;
74  atom_add(global_sum, tmp_sum.s0 + tmp_sum.s1);
75 
76 #ifdef STDDEV
77  tmp_sum_sq.s0123 += tmp_sum_sq.s4567;
78  tmp_sum_sq.s01 += tmp_sum_sq.s23;
79  atom_add(global_sum_sq, tmp_sum_sq.s0 + tmp_sum_sq.s1);
80 #endif /* STDDEV */
81 }
82 
83 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable
84 #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : disable
#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
#define CONVERT_TO_IMAGE_STRUCT(name)
Definition: helpers.h:104
Structure to hold Image information.
Definition: helpers.h:142
__kernel void mean_stddev_accumulate(__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, uint height, __global ulong *global_sum, __global ulong *global_sum_sq)
This function calculates the sum and sum of squares of a given input image.
Definition: mean_stddev.cl:43
convolution configure & src