/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #pragma OPENCL EXTENSION cl_khr_fp16 : enable __kernel void lrn(__read_only image2d_t input_image, __write_only image2d_t output_image, __private const int out_C, __private const int out_W, __private const int n, __private const float k, __private const float alpha, __private const float beta){ const int out_c = get_global_id(0); const int out_w = get_global_id(1); const int out_nh = get_global_id(2); const int out_c0 = out_c * 4; const int out_c1 = out_c * 4 + 1; const int out_c2 = out_c * 4+ 2; const int out_c3 = out_c * 4+ 3; const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; const int start = -(n-1)/2; const end = start + n; float sqr_sum0 = 0.0f; float sqr_sum1 = 0.0f; float sqr_sum2 = 0.0f; float sqr_sum3 = 0.0f; int input_c0,input_c1,input_c2,input_c3; int2 input_pos0,input_pos1,input_pos2,input_pos3; float4 input0,input1,input2,input3; for(int i = start; i < end ;i++){ if(out_c0 + i>=0&&out_c0 + i=0&&out_c1 + i=0&&out_c2 + i=0&&out_c3 + i=2){ output.y = input.y / (pow(k + alpha * (sqr_sum1),beta)); } if(out_C - 4 * out_c>=3){ output.z = input.z / (pow(k + alpha * (sqr_sum2),beta)); } if(out_C - 4 * out_c>=4){ output.w = input.w / (pow(k + alpha * (sqr_sum3),beta)); } half4 tmp = convert_half4(output); write_imageh(output_image, output_pos, tmp); }