Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/dnn/src/opencl/prior_box.cl
16337 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (c) 2016-2017 Fabian David Tschopp, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#if defined(cl_khr_fp16)
43
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
44
#endif
45
46
__kernel void prior_box(const int nthreads,
47
const float stepX,
48
const float stepY,
49
__global const float* _offsetsX,
50
__global const float* _offsetsY,
51
const int offsetsX_size,
52
__global const float* _widths,
53
__global const float* _heights,
54
const int widths_size,
55
__global Dtype* dst,
56
const int _layerHeight,
57
const int _layerWidth,
58
const int imgHeight,
59
const int imgWidth)
60
{
61
for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))
62
{
63
int w = index % _layerWidth;
64
int h = index / _layerWidth;
65
__global Dtype* outputPtr;
66
67
outputPtr = dst + index * 4 * offsetsX_size * widths_size;
68
69
float _boxWidth, _boxHeight;
70
Dtype4 vec;
71
for (int i = 0; i < widths_size; ++i)
72
{
73
_boxWidth = _widths[i];
74
_boxHeight = _heights[i];
75
for (int j = 0; j < offsetsX_size; ++j)
76
{
77
Dtype center_x = (w + _offsetsX[j]) * (Dtype)stepX;
78
Dtype center_y = (h + _offsetsY[j]) * (Dtype)stepY;
79
80
vec.x = (center_x - _boxWidth * 0.5f) / imgWidth; // xmin
81
vec.y = (center_y - _boxHeight * 0.5f) / imgHeight; // ymin
82
vec.z = (center_x + _boxWidth * 0.5f) / imgWidth; // xmax
83
vec.w = (center_y + _boxHeight * 0.5f) / imgHeight; // ymax
84
vstore4(vec, 0, outputPtr);
85
86
outputPtr += 4;
87
}
88
}
89
}
90
}
91
92
__kernel void set_variance(const int nthreads,
93
const int offset,
94
const int variance_size,
95
__global const float* variance,
96
__global Dtype* dst)
97
{
98
for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))
99
{
100
Dtype4 var_vec;
101
102
if (variance_size == 1)
103
var_vec = (Dtype4)(variance[0]);
104
else
105
var_vec = convert_T(vload4(0, variance));
106
107
vstore4(var_vec, 0, dst + offset + index * 4);
108
}
109
}
110
111
__kernel void clip(const int nthreads,
112
__global Dtype* dst)
113
{
114
for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))
115
{
116
Dtype4 vec = vload4(index, dst);
117
vstore4(clamp(vec, 0.0f, 1.0f), index, dst);
118
}
119
}
120
121