1 // Copyright (c) 2016-2017 Intel Corporation
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #include "include/include_all.cl"
17 KERNEL(convolution_gpu_yxfb_ref)(
18 const __global UNIT_TYPE* input,
19 __global UNIT_TYPE* output,
20 const __global UNIT_TYPE* filter,
22 const __global UNIT_TYPE* bias,
26 UNIT_TYPE result = UNIT_VAL_ZERO;
28 const uint batch_offset = (uint)get_global_id(0) % INPUT0_BATCH_NUM;
29 const uint ofm_offset = (uint)get_global_id(0) / INPUT0_BATCH_NUM;
30 const uint out_x = (uint)get_global_id(1);
31 const uint out_y = (uint)get_global_id(2);
33 const int x = (int)out_x * STRIDE_SIZE_X - PADDING_SIZE_X;
34 const int y = (int)out_y * STRIDE_SIZE_Y - PADDING_SIZE_Y;
36 #if DEPTHWISE_SEPARABLE_OPT
37 const uint in_split_offset = (ofm_offset / FILTER_OFM_NUM) * INPUT0_FEATURE_PITCH * FILTER_IFM_NUM;
39 const uint in_split_offset = split_idx * INPUT0_FEATURE_PITCH * FILTER_IFM_NUM;
41 const uint input_offset = INPUT0_OFFSET + batch_offset*INPUT0_BATCH_PITCH + in_split_offset;
43 for (uint i = 0; i < FILTER_SIZE_Y; i++)
45 const int input_offset_y = y + i * DILATION_SIZE_Y;
46 const bool zero_y = input_offset_y >= INPUT0_SIZE_Y || input_offset_y < 0;
50 for (uint j = 0; j < FILTER_SIZE_X; j++)
52 const int input_offset_x = x + j * DILATION_SIZE_X;
53 const bool zero = input_offset_x >= INPUT0_SIZE_X || input_offset_x < 0;
57 uint input_idx = input_offset + (uint)input_offset_x*INPUT0_X_PITCH + (uint)input_offset_y*INPUT0_Y_PITCH;
58 uint filter_idx = ofm_offset*FILTER_OFM_PITCH + i*FILTER_Y_PITCH + j*FILTER_X_PITCH;
60 for (uint h = 0; h < FILTER_IFM_NUM; h++)
62 result = fma(input[input_idx], filter[filter_idx], result);
63 filter_idx += FILTER_IFM_PITCH;
64 input_idx += INPUT0_FEATURE_PITCH;
71 result += bias[ofm_offset];
73 const uint out_split_offset = split_idx * OUTPUT_FEATURE_PITCH * FILTER_OFM_NUM;
74 const uint dst_index = batch_offset*OUTPUT_BATCH_PITCH + ofm_offset*OUTPUT_FEATURE_PITCH + out_y*OUTPUT_Y_PITCH + out_x*OUTPUT_X_PITCH + OUTPUT_OFFSET + out_split_offset;
75 output[dst_index] = ACTIVATION(result, NL_M, NL_N);