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/** This function accumulates an input image into output image. 27 * 28 * @param[in] input_ptr Pointer to the source image. Supported data types: U8 29 * @param[in] input_stride_x Stride of the source image in X dimension (in bytes) 30 * @param[in] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) 31 * @param[in] input_stride_y Stride of the source image in Y dimension (in bytes) 32 * @param[in] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) 33 * @param[in] input_offset_first_element_in_bytes The offset of the first element in the source image 34 * @param[out] accu_ptr Pointer to the destination image. Supported data types: S16 35 * @param[in] accu_stride_x Stride of the destination image in X dimension (in bytes) 36 * @param[in] accu_step_x accu_stride_x * number of elements along X processed per workitem(in bytes) 37 * @param[in] accu_stride_y Stride of the destination image in Y dimension (in bytes) 38 * @param[in] accu_step_y accu_stride_y * number of elements along Y processed per workitem(in bytes) 39 * @param[in] accu_offset_first_element_in_bytes The offset of the first element in the destination image 40 */ 41__kernel void accumulate( 42 IMAGE_DECLARATION(input), 43 IMAGE_DECLARATION(accu)) 44{ 45 // Get pixels pointer 46 Image input = CONVERT_TO_IMAGE_STRUCT(input); 47 Image accu = CONVERT_TO_IMAGE_STRUCT(accu); 48 49 // Load data 50 uchar16 in_data = vload16(0, input.ptr); 51 short16 accu_data = vload16(0, (__global short *)accu.ptr); 52 53 // Perform accumulation 54 short16 res = add_sat(convert_short16(in_data), accu_data); 55 56 // Store result 57 vstore16(res, 0, (__global short *)accu.ptr); 58} 59 60/** This function accumulates a weighted value from an input image to an output image. 61 * 62 * @param[in] input_ptr Pointer to the source image. Supported data types: U8 63 * @param[in] input_stride_x Stride of the source image in X dimension (in bytes) 64 * @param[in] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) 65 * @param[in] input_stride_y Stride of the source image in Y dimension (in bytes) 66 * @param[in] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) 67 * @param[in] input_offset_first_element_in_bytes The offset of the first element in the source image 68 * @param[out] accu_ptr Pointer to the destination image. Supported data types: S16 69 * @param[in] accu_stride_x Stride of the destination image in X dimension (in bytes) 70 * @param[in] accu_step_x accu_stride_x * number of elements along X processed per workitem(in bytes) 71 * @param[in] accu_stride_y Stride of the destination image in Y dimension (in bytes) 72 * @param[in] accu_step_y accu_stride_y * number of elements along Y processed per workitem(in bytes) 73 * @param[in] accu_offset_first_element_in_bytes The offset of the first element in the destination image 74 * @param[in] alpha The float scalar value with a value in the range of 0 to 1 75 */ 76__kernel void accumulate_weighted( 77 IMAGE_DECLARATION(input), 78 IMAGE_DECLARATION(accu), 79 const float alpha) 80{ 81 // Get pixels pointer 82 Image input = CONVERT_TO_IMAGE_STRUCT(input); 83 Image accu = CONVERT_TO_IMAGE_STRUCT(accu); 84 85 // Load data 86 const float16 in_data = convert_float16(vload16(0, input.ptr)); 87 const float16 accu_data = convert_float16(vload16(0, accu.ptr)); 88 89 // Calculate weighted accumulation 90 const uchar16 res = convert_uchar16((1.0f - alpha) * accu_data + alpha * in_data); 91 92 // Store result 93 vstore16(res, 0, accu.ptr); 94} 95 96/** This function accumulates a squared value from an input image to an output image. 97 * 98 * @param[in] input_ptr Pointer to the source image. Supported data types: U8 99 * @param[in] input_stride_x Stride of the source image in X dimension (in bytes) 100 * @param[in] input_step_x input_stride_x * number of elements along X processed per workitem(in bytes) 101 * @param[in] input_stride_y Stride of the source image in Y dimension (in bytes) 102 * @param[in] input_step_y input_stride_y * number of elements along Y processed per workitem(in bytes) 103 * @param[in] input_offset_first_element_in_bytes The offset of the first element in the source image 104 * @param[out] accu_ptr Pointer to the destination image. Supported data types: S16 105 * @param[in] accu_stride_x Stride of the destination image in X dimension (in bytes) 106 * @param[in] accu_step_x accu_stride_x * number of elements along X processed per workitem(in bytes) 107 * @param[in] accu_stride_y Stride of the destination image in Y dimension (in bytes) 108 * @param[in] accu_step_y accu_stride_y * number of elements along Y processed per workitem(in bytes) 109 * @param[in] accu_offset_first_element_in_bytes The offset of the first element in the destination image 110 * @param[in] shift The U32 scalar value with a value in the range of 0 to 15 111 */ 112__kernel void accumulate_squared( 113 IMAGE_DECLARATION(input), 114 IMAGE_DECLARATION(accu), 115 const uint shift) 116{ 117 // Get pixels pointer 118 Image input = CONVERT_TO_IMAGE_STRUCT(input); 119 Image accu = CONVERT_TO_IMAGE_STRUCT(accu); 120 121 // Load data 122 ushort16 in_data = convert_ushort16(vload16(0, input.ptr)); 123 uint16 accu_data = convert_uint16(vload16(0, (__global short *)accu.ptr)); 124 125 // Calculate squared accumulation 126 short16 res = convert_short16_sat(accu_data + convert_uint16((in_data * in_data) >> shift)); 127 128 // Store result 129 vstore16(res, 0, (__global short *)accu.ptr); 130} 131