Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/dnn/src/opencl/col2im.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) 2017, Intel Corporation, all rights reserved.
14
// Copyright (c) 2016-2017 Fabian David Tschopp, all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
22
//
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
26
//
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
29
//
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
40
//
41
//M*/
42
43
__kernel void col2im(const int n, __global const T* data_col,
44
const int data_col_offset,
45
const int channels,
46
const int height, const int width,
47
const int height_col, const int width_col,
48
const int coeff_h, const int coeff_w,
49
__global const T* biasvec,
50
const int bias_offset,
51
__global T* data_im,
52
const int data_im_offset)
53
{
54
data_col = data_col + data_col_offset;
55
biasvec = biasvec + bias_offset;
56
data_im = data_im + data_im_offset;
57
int index = get_global_id(0);
58
59
if(index < n)
60
{
61
T val = 0.f;
62
int w = index % width + PAD_W;
63
int h = (index / width) % height + PAD_H;
64
int c = index / (width * height);
65
int h_col_start = (h < KERNEL_H) ? 0 : (h - KERNEL_H) / STRIDE_H + 1;
66
int h_col_end = min(h / STRIDE_H + 1, height_col);
67
int plane_size_col = height_col * width_col;
68
int offset = (c * KERNEL_H * KERNEL_W + h * KERNEL_W + w) * plane_size_col;
69
70
int w_col_start = (w < KERNEL_W) ? 0 : (w - KERNEL_W) / STRIDE_W + 1;
71
int w_col_end = min(w / STRIDE_W + 1, width_col);
72
73
for (int h_col = h_col_start; h_col < h_col_end; ++h_col)
74
for (int w_col = w_col_start; w_col < w_col_end; ++w_col)
75
val += data_col[offset + h_col * coeff_h + w_col * coeff_w];
76
77
data_im[index] = val + biasvec[c];
78
}
79
}
80
81