|
| 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 | +#define Dtype float |
| 43 | +#define Dtype4 float4 |
| 44 | + |
| 45 | +__kernel void prior_box(const int nthreads, |
| 46 | + const Dtype stepX, |
| 47 | + const Dtype stepY, |
| 48 | + const Dtype _minSize, |
| 49 | + const Dtype _maxSize, |
| 50 | + __global const Dtype* _offsetsX, |
| 51 | + __global const Dtype* _offsetsY, |
| 52 | + const int offsetsX_size, |
| 53 | + __global const Dtype* _aspectRatios, |
| 54 | + const int aspectRatios_size, |
| 55 | + __global const Dtype* scales, |
| 56 | + __global Dtype* dst, |
| 57 | + const int _layerHeight, |
| 58 | + const int _layerWidth, |
| 59 | + const int imgHeight, |
| 60 | + const int imgWidth) |
| 61 | +{ |
| 62 | + for (int index = get_global_id(0); index < nthreads; index += get_global_size(0)) |
| 63 | + { |
| 64 | + int w = index % _layerWidth; |
| 65 | + int h = index / _layerWidth; |
| 66 | + __global Dtype* outputPtr; |
| 67 | + int aspect_count = (_maxSize > 0) ? 1 : 0; |
| 68 | + outputPtr = dst + index * 4 * offsetsX_size * (1 + aspect_count + aspectRatios_size); |
| 69 | + |
| 70 | + Dtype _boxWidth, _boxHeight; |
| 71 | + Dtype4 vec; |
| 72 | + _boxWidth = _boxHeight = _minSize * scales[0]; |
| 73 | + for (int i = 0; i < offsetsX_size; ++i) |
| 74 | + { |
| 75 | + float center_x = (w + _offsetsX[i]) * stepX; |
| 76 | + float center_y = (h + _offsetsY[i]) * stepY; |
| 77 | + |
| 78 | + vec.x = (center_x - _boxWidth * 0.5f) / imgWidth; // xmin |
| 79 | + vec.y = (center_y - _boxHeight * 0.5f) / imgHeight; // ymin |
| 80 | + vec.z = (center_x + _boxWidth * 0.5f) / imgWidth; // xmax |
| 81 | + vec.w = (center_y + _boxHeight * 0.5f) / imgHeight; // ymax |
| 82 | + vstore4(vec, 0, outputPtr); |
| 83 | + |
| 84 | + outputPtr += 4; |
| 85 | + } |
| 86 | + |
| 87 | + if (_maxSize > 0) |
| 88 | + { |
| 89 | + _boxWidth = _boxHeight = native_sqrt(_minSize * _maxSize) * scales[1]; |
| 90 | + |
| 91 | + for (int i = 0; i < offsetsX_size; ++i) |
| 92 | + { |
| 93 | + float center_x = (w + _offsetsX[i]) * stepX; |
| 94 | + float center_y = (h + _offsetsY[i]) * stepY; |
| 95 | + |
| 96 | + vec.x = (center_x - _boxWidth * 0.5f) / imgWidth; // xmin |
| 97 | + vec.y = (center_y - _boxHeight * 0.5f) / imgHeight; // ymin |
| 98 | + vec.z = (center_x + _boxWidth * 0.5f) / imgWidth; // xmax |
| 99 | + vec.w = (center_y + _boxHeight * 0.5f) / imgHeight; // ymax |
| 100 | + vstore4(vec, 0, outputPtr); |
| 101 | + |
| 102 | + outputPtr += 4; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + for (int r = 0; r < aspectRatios_size; ++r) |
| 107 | + { |
| 108 | + float ar = native_sqrt(_aspectRatios[r]); |
| 109 | + float scale = scales[(_maxSize > 0 ? 2 : 1) + r]; |
| 110 | + |
| 111 | + _boxWidth = _minSize * ar * scale; |
| 112 | + _boxHeight = _minSize / ar * scale; |
| 113 | + |
| 114 | + for (int i = 0; i < offsetsX_size; ++i) |
| 115 | + { |
| 116 | + float center_x = (w + _offsetsX[i]) * stepX; |
| 117 | + float center_y = (h + _offsetsY[i]) * stepY; |
| 118 | + |
| 119 | + vec.x = (center_x - _boxWidth * 0.5f) / imgWidth; // xmin |
| 120 | + vec.y = (center_y - _boxHeight * 0.5f) / imgHeight; // ymin |
| 121 | + vec.z = (center_x + _boxWidth * 0.5f) / imgWidth; // xmax |
| 122 | + vec.w = (center_y + _boxHeight * 0.5f) / imgHeight; // ymax |
| 123 | + vstore4(vec, 0, outputPtr); |
| 124 | + |
| 125 | + outputPtr += 4; |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +__kernel void set_variance(const int nthreads, |
| 132 | + const int offset, |
| 133 | + const int variance_size, |
| 134 | + __global const Dtype* variance, |
| 135 | + __global Dtype* dst) |
| 136 | +{ |
| 137 | + for (int index = get_global_id(0); index < nthreads; index += get_global_size(0)) |
| 138 | + { |
| 139 | + Dtype4 var_vec; |
| 140 | + |
| 141 | + if (variance_size == 1) |
| 142 | + var_vec = (Dtype4)(variance[0]); |
| 143 | + else |
| 144 | + var_vec = vload4(0, variance); |
| 145 | + |
| 146 | + vstore4(var_vec, 0, dst + offset + index * 4); |
| 147 | + } |
| 148 | +} |
0 commit comments