feed_kernel.cl 2.4 KB
Newer Older
L
liuruilong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* 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. */

Y
yangfei 已提交
15
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
Y
yangfei 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
__kernel void feed(__global float *in,
                   __write_only image2d_t output_image,
                   __private const int out_H,
                   __private const int out_W,
                   __private const int out_C,
                   __private const int Stride0,
                   __private const int Stride1,
                   __private const int Stride2){

            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_n = out_nh/out_H;
            const int out_h = out_nh%out_H;

            const int in_n = out_n;
            const int in_c0 = out_c * 4 + 0;
            const int in_c1 = out_c * 4 + 1;
            const int in_c2 = out_c * 4 + 2;
            const int in_c3 = out_c * 4 + 3;
            const int in_h = out_h;
            const int in_w = out_w;


            int input_pos0 = in_n * Stride2 + in_c0 * Stride1 + in_h * Stride0 + in_w;
            int input_pos1 = in_n * Stride2 + in_c1 * Stride1 + in_h * Stride0 + in_w;
            int input_pos2 = in_n * Stride2 + in_c2 * Stride1 + in_h * Stride0 + in_w;
            int input_pos3 = in_n * Stride2 + in_c3 * Stride1 + in_h * Stride0 + in_w;

            int2 output_pos;
            output_pos.x = out_c * out_W + out_w;
            output_pos.y = out_nh;

            half4 output = (half4)0.0f;
            output.x = convert_half(in[input_pos0]);
            if(out_C - 4 * out_c>=2){
             output.y = convert_half(in[input_pos1]);
            }
            if(out_C - 4 * out_c>=3){
            output.z = convert_half(in[input_pos2]);
            }
            if(out_C - 4 * out_c>=4){
             output.w = convert_half(in[input_pos3]);
            }
            write_imageh(output_image, output_pos, output);

Y
yangfei 已提交
62
 }