1 // Copyright (C) 2018-2019 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 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
17 __kernel void prior_box_clustered(
18 const __global INPUT0_TYPE* input0,
19 const __global INPUT0_TYPE* input1,
20 __global OUTPUT0_TYPE* output)
22 const int num_priors_ = sizeof(width_)/sizeof(width_[0]);
23 const int var_size = sizeof(variance_)/sizeof(variance_[0]);
25 const float img_width = (img_w_ == 0) ? INPUT1_DIMS[3] : img_w_;
26 const float img_height = (img_h_ == 0) ? INPUT1_DIMS[2] : img_h_;
28 const float r_img_width = 1.f/img_width;
29 const float r_img_height = 1.f/img_height;
31 float step_w = (step_w_ == 0) ? step_ : step_w_;
32 float step_h = (step_h_ == 0) ? step_ : step_h_;
34 if ((step_w == 0) & (step_h == 0))
36 step_w = img_width / INPUT0_DIMS[3];
37 step_h = img_height / INPUT0_DIMS[2];
40 int h = get_global_id(0);
41 int w = get_global_id(1);
43 __global OUTPUT0_TYPE* top_data = output + h*INPUT0_DIMS[3]*num_priors_*4 + w*num_priors_*4;
44 __global OUTPUT0_TYPE* top_data_var = output + OUTPUT0_DIMS[2] + h*INPUT0_DIMS[3]*num_priors_*var_size + w * num_priors_ * var_size;
46 const float center_x = (w + offset_) * step_w;
47 const float center_y = (h + offset_) * step_h;
50 for (int s = 0; s < num_priors_; ++s)
52 const float box_width = width_[s];
53 const float box_height = height_[s];
55 OUTPUT0_TYPE xmin = (center_x - box_width*0.5f) * r_img_width;
56 OUTPUT0_TYPE ymin = (center_y - box_height*0.5f) * r_img_height;
57 OUTPUT0_TYPE xmax = (center_x + box_width*0.5f) * r_img_width;
58 OUTPUT0_TYPE ymax = (center_y + box_height*0.5f) * r_img_height;
62 xmin = min(max(xmin, (OUTPUT0_TYPE)(0.0f)), (OUTPUT0_TYPE)(1.0f));
63 ymin = min(max(ymin, (OUTPUT0_TYPE)(0.0f)), (OUTPUT0_TYPE)(1.0f));
64 xmax = min(max(xmax, (OUTPUT0_TYPE)(0.0f)), (OUTPUT0_TYPE)(1.0f));
65 ymax = min(max(ymax, (OUTPUT0_TYPE)(0.0f)), (OUTPUT0_TYPE)(1.0f));
68 top_data[idx++] = xmin;
69 top_data[idx++] = ymin;
70 top_data[idx++] = xmax;
71 top_data[idx++] = ymax;
73 for (int i = 0; i < var_size; i++)
75 top_data_var[s * var_size + i] = variance_[i];