EstervQrCode 1.1.1
Library for qr code manipulation
block.hpp
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) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., 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 #ifndef OPENCV_CUDA_DEVICE_BLOCK_HPP
44 #define OPENCV_CUDA_DEVICE_BLOCK_HPP
45 
51 
52 namespace cv { namespace cuda { namespace device
53 {
54  struct Block
55  {
56  static __device__ __forceinline__ unsigned int id()
57  {
58  return blockIdx.x;
59  }
60 
61  static __device__ __forceinline__ unsigned int stride()
62  {
63  return blockDim.x * blockDim.y * blockDim.z;
64  }
65 
66  static __device__ __forceinline__ void sync()
67  {
68  __syncthreads();
69  }
70 
71  static __device__ __forceinline__ int flattenedThreadId()
72  {
73  return threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x;
74  }
75 
76  template<typename It, typename T>
77  static __device__ __forceinline__ void fill(It beg, It end, const T& value)
78  {
79  int STRIDE = stride();
80  It t = beg + flattenedThreadId();
81 
82  for(; t < end; t += STRIDE)
83  *t = value;
84  }
85 
86  template<typename OutIt, typename T>
87  static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value)
88  {
89  int STRIDE = stride();
90  int tid = flattenedThreadId();
91  value += tid;
92 
93  for(OutIt t = beg + tid; t < end; t += STRIDE, value += STRIDE)
94  *t = value;
95  }
96 
97  template<typename InIt, typename OutIt>
98  static __device__ __forceinline__ void copy(InIt beg, InIt end, OutIt out)
99  {
100  int STRIDE = stride();
101  InIt t = beg + flattenedThreadId();
102  OutIt o = out + (t - beg);
103 
104  for(; t < end; t += STRIDE, o += STRIDE)
105  *o = *t;
106  }
107 
108  template<typename InIt, typename OutIt, class UnOp>
109  static __device__ __forceinline__ void transform(InIt beg, InIt end, OutIt out, UnOp op)
110  {
111  int STRIDE = stride();
112  InIt t = beg + flattenedThreadId();
113  OutIt o = out + (t - beg);
114 
115  for(; t < end; t += STRIDE, o += STRIDE)
116  *o = op(*t);
117  }
118 
119  template<typename InIt1, typename InIt2, typename OutIt, class BinOp>
120  static __device__ __forceinline__ void transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op)
121  {
122  int STRIDE = stride();
123  InIt1 t1 = beg1 + flattenedThreadId();
124  InIt2 t2 = beg2 + flattenedThreadId();
125  OutIt o = out + (t1 - beg1);
126 
127  for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, o += STRIDE)
128  *o = op(*t1, *t2);
129  }
130 
131  template<int CTA_SIZE, typename T, class BinOp>
132  static __device__ __forceinline__ void reduce(volatile T* buffer, BinOp op)
133  {
134  int tid = flattenedThreadId();
135  T val = buffer[tid];
136 
137  if (CTA_SIZE >= 1024) { if (tid < 512) buffer[tid] = val = op(val, buffer[tid + 512]); __syncthreads(); }
138  if (CTA_SIZE >= 512) { if (tid < 256) buffer[tid] = val = op(val, buffer[tid + 256]); __syncthreads(); }
139  if (CTA_SIZE >= 256) { if (tid < 128) buffer[tid] = val = op(val, buffer[tid + 128]); __syncthreads(); }
140  if (CTA_SIZE >= 128) { if (tid < 64) buffer[tid] = val = op(val, buffer[tid + 64]); __syncthreads(); }
141 
142  if (tid < 32)
143  {
144  if (CTA_SIZE >= 64) { buffer[tid] = val = op(val, buffer[tid + 32]); }
145  if (CTA_SIZE >= 32) { buffer[tid] = val = op(val, buffer[tid + 16]); }
146  if (CTA_SIZE >= 16) { buffer[tid] = val = op(val, buffer[tid + 8]); }
147  if (CTA_SIZE >= 8) { buffer[tid] = val = op(val, buffer[tid + 4]); }
148  if (CTA_SIZE >= 4) { buffer[tid] = val = op(val, buffer[tid + 2]); }
149  if (CTA_SIZE >= 2) { buffer[tid] = val = op(val, buffer[tid + 1]); }
150  }
151  }
152 
153  template<int CTA_SIZE, typename T, class BinOp>
154  static __device__ __forceinline__ T reduce(volatile T* buffer, T init, BinOp op)
155  {
156  int tid = flattenedThreadId();
157  T val = buffer[tid] = init;
158  __syncthreads();
159 
160  if (CTA_SIZE >= 1024) { if (tid < 512) buffer[tid] = val = op(val, buffer[tid + 512]); __syncthreads(); }
161  if (CTA_SIZE >= 512) { if (tid < 256) buffer[tid] = val = op(val, buffer[tid + 256]); __syncthreads(); }
162  if (CTA_SIZE >= 256) { if (tid < 128) buffer[tid] = val = op(val, buffer[tid + 128]); __syncthreads(); }
163  if (CTA_SIZE >= 128) { if (tid < 64) buffer[tid] = val = op(val, buffer[tid + 64]); __syncthreads(); }
164 
165  if (tid < 32)
166  {
167  if (CTA_SIZE >= 64) { buffer[tid] = val = op(val, buffer[tid + 32]); }
168  if (CTA_SIZE >= 32) { buffer[tid] = val = op(val, buffer[tid + 16]); }
169  if (CTA_SIZE >= 16) { buffer[tid] = val = op(val, buffer[tid + 8]); }
170  if (CTA_SIZE >= 8) { buffer[tid] = val = op(val, buffer[tid + 4]); }
171  if (CTA_SIZE >= 4) { buffer[tid] = val = op(val, buffer[tid + 2]); }
172  if (CTA_SIZE >= 2) { buffer[tid] = val = op(val, buffer[tid + 1]); }
173  }
174  __syncthreads();
175  return buffer[0];
176  }
177 
178  template <typename T, class BinOp>
179  static __device__ __forceinline__ void reduce_n(T* data, unsigned int n, BinOp op)
180  {
181  int ftid = flattenedThreadId();
182  int sft = stride();
183 
184  if (sft < n)
185  {
186  for (unsigned int i = sft + ftid; i < n; i += sft)
187  data[ftid] = op(data[ftid], data[i]);
188 
189  __syncthreads();
190 
191  n = sft;
192  }
193 
194  while (n > 1)
195  {
196  unsigned int half = n/2;
197 
198  if (ftid < half)
199  data[ftid] = op(data[ftid], data[n - ftid - 1]);
200 
201  __syncthreads();
202 
203  n = n - half;
204  }
205  }
206  };
207 }}}
208 
210 
211 #endif /* OPENCV_CUDA_DEVICE_BLOCK_HPP */
T copy(T... args)
T fill(T... args)
InputArrayOfArrays InputArrayOfArrays InputOutputArray InputOutputArray InputOutputArray InputOutputArray Size InputOutputArray InputOutputArray T
Definition: calib3d.hpp:1867
CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype=-1)
Reduces a matrix to a vector.
CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m)
Performs the matrix transformation of every array element.
int CvScalar value
Definition: core_c.h:720
double double end
Definition: core_c.h:1381
void * data
Definition: core_c.h:427
CvPoint CvPoint void * buffer
Definition: imgproc_c.h:357
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441