EstervQrCode 1.1.1
Library for qr code manipulation
reduce.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_REDUCE_HPP
44 #define OPENCV_CUDA_REDUCE_HPP
45 
46 #ifndef THRUST_DEBUG // eliminate -Wundef warning
47 #define THRUST_DEBUG 0
48 #endif
49 
50 #include <thrust/tuple.h>
51 #include "detail/reduce.hpp"
52 #include "detail/reduce_key_val.hpp"
53 
59 
60 namespace cv { namespace cuda { namespace device
61 {
62  template <int N, typename T, class Op>
63  __device__ __forceinline__ void reduce(volatile T* smem, T& val, unsigned int tid, const Op& op)
64  {
65  reduce_detail::Dispatcher<N>::reductor::template reduce<volatile T*, T&, const Op&>(smem, val, tid, op);
66  }
67  template <unsigned int N, typename K, typename V, class Cmp>
68  __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key, volatile V* svals, V& val, unsigned int tid, const Cmp& cmp)
69  {
70  reduce_key_val_detail::Dispatcher<N>::reductor::template reduce<volatile K*, K&, volatile V*, V&, const Cmp&>(skeys, key, svals, val, tid, cmp);
71  }
72 #if (CUDART_VERSION < 12040) // details: https://github.com/opencv/opencv_contrib/issues/3690
73  template <int N,
74  typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9,
75  typename R0, typename R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7, typename R8, typename R9,
76  class Op0, class Op1, class Op2, class Op3, class Op4, class Op5, class Op6, class Op7, class Op8, class Op9>
77  __device__ __forceinline__ void reduce(const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>& smem,
78  const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>& val,
79  unsigned int tid,
80  const thrust::tuple<Op0, Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8, Op9>& op)
81  {
82  reduce_detail::Dispatcher<N>::reductor::template reduce<
83  const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>&,
84  const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>&,
85  const thrust::tuple<Op0, Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8, Op9>&>(smem, val, tid, op);
86  }
87 
88  template <unsigned int N,
89  typename K,
90  typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9,
91  typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9,
92  class Cmp>
93  __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key,
94  const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals,
95  const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val,
96  unsigned int tid, const Cmp& cmp)
97  {
98  reduce_key_val_detail::Dispatcher<N>::reductor::template reduce<volatile K*, K&,
99  const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>&,
100  const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>&,
101  const Cmp&>(skeys, key, svals, val, tid, cmp);
102  }
103 
104  template <unsigned int N,
105  typename KP0, typename KP1, typename KP2, typename KP3, typename KP4, typename KP5, typename KP6, typename KP7, typename KP8, typename KP9,
106  typename KR0, typename KR1, typename KR2, typename KR3, typename KR4, typename KR5, typename KR6, typename KR7, typename KR8, typename KR9,
107  typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9,
108  typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9,
109  class Cmp0, class Cmp1, class Cmp2, class Cmp3, class Cmp4, class Cmp5, class Cmp6, class Cmp7, class Cmp8, class Cmp9>
110  __device__ __forceinline__ void reduceKeyVal(const thrust::tuple<KP0, KP1, KP2, KP3, KP4, KP5, KP6, KP7, KP8, KP9>& skeys,
111  const thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9>& key,
112  const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals,
113  const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val,
114  unsigned int tid,
115  const thrust::tuple<Cmp0, Cmp1, Cmp2, Cmp3, Cmp4, Cmp5, Cmp6, Cmp7, Cmp8, Cmp9>& cmp)
116  {
117  reduce_key_val_detail::Dispatcher<N>::reductor::template reduce<
118  const thrust::tuple<KP0, KP1, KP2, KP3, KP4, KP5, KP6, KP7, KP8, KP9>&,
119  const thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9>&,
120  const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>&,
121  const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>&,
122  const thrust::tuple<Cmp0, Cmp1, Cmp2, Cmp3, Cmp4, Cmp5, Cmp6, Cmp7, Cmp8, Cmp9>&
123  >(skeys, key, svals, val, tid, cmp);
124  }
125 #else
126  template <int N, typename... P, typename... R, class... Op>
127  __device__ __forceinline__ void reduce(const thrust::tuple<P...>& smem, const thrust::tuple<R...>& val, unsigned int tid, const thrust::tuple<Op...>& op)
128  {
129  reduce_detail::Dispatcher<N>::reductor::template reduce<const thrust::tuple<P...>&, const thrust::tuple<R...>&, const thrust::tuple<Op...>&>(smem, val, tid, op);
130  }
131 
132  template <unsigned int N, typename K, typename... VP, typename... VR, class Cmp>
133  __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key, const thrust::tuple<VP...>& svals, const thrust::tuple<VR...>& val, unsigned int tid, const Cmp& cmp)
134  {
135  reduce_key_val_detail::Dispatcher<N>::reductor::template reduce<volatile K*, K&, const thrust::tuple<VP...>&, const thrust::tuple<VR...>&, const Cmp&>(skeys, key, svals, val, tid, cmp);
136  }
137 
138  template <unsigned int N, typename... KP, typename... KR, typename... VP, typename... VR, class... Cmp>
139  __device__ __forceinline__ void reduceKeyVal(const thrust::tuple<KP...>& skeys, const thrust::tuple<KR...>& key, const thrust::tuple<VP...>& svals, const thrust::tuple<VR...>& val, unsigned int tid, const thrust::tuple<Cmp...>& cmp)
140  {
141  reduce_key_val_detail::Dispatcher<N>::reductor::template reduce<const thrust::tuple<KP...>&, const thrust::tuple<KR...>&, const thrust::tuple<VP...>&, const thrust::tuple<VR...>&, const thrust::tuple<Cmp...>&>(skeys, key, svals, val, tid, cmp);
142  }
143 #endif
144 
145  // smem_tuple
146 
147  template <typename T0>
148  __device__ __forceinline__
149  thrust::tuple<volatile T0*>
150  smem_tuple(T0* t0)
151  {
152  return thrust::make_tuple((volatile T0*) t0);
153  }
154 
155  template <typename T0, typename T1>
156  __device__ __forceinline__
157  thrust::tuple<volatile T0*, volatile T1*>
158  smem_tuple(T0* t0, T1* t1)
159  {
160  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1);
161  }
162 
163  template <typename T0, typename T1, typename T2>
164  __device__ __forceinline__
165  thrust::tuple<volatile T0*, volatile T1*, volatile T2*>
166  smem_tuple(T0* t0, T1* t1, T2* t2)
167  {
168  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2);
169  }
170 
171  template <typename T0, typename T1, typename T2, typename T3>
172  __device__ __forceinline__
173  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*>
174  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3)
175  {
176  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3);
177  }
178 
179  template <typename T0, typename T1, typename T2, typename T3, typename T4>
180  __device__ __forceinline__
181  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*>
182  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4)
183  {
184  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4);
185  }
186 
187  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
188  __device__ __forceinline__
189  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*>
190  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5)
191  {
192  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5);
193  }
194 
195  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
196  __device__ __forceinline__
197  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*>
198  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6)
199  {
200  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6);
201  }
202 
203  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
204  __device__ __forceinline__
205  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*>
206  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7)
207  {
208  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7);
209  }
210 
211  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
212  __device__ __forceinline__
213  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*, volatile T8*>
214  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7, T8* t8)
215  {
216  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7, (volatile T8*) t8);
217  }
218 
219  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
220  __device__ __forceinline__
221  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*, volatile T8*, volatile T9*>
222  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7, T8* t8, T9* t9)
223  {
224  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7, (volatile T8*) t8, (volatile T9*) t9);
225  }
226 }}}
227 
229 
230 #endif // OPENCV_CUDA_REDUCE_HPP
InputArrayOfArrays InputArrayOfArrays InputOutputArray InputOutputArray InputOutputArray InputOutputArray Size InputOutputArray InputOutputArray T
Definition: calib3d.hpp:1867
InputArrayOfArrays InputArrayOfArrays InputOutputArray InputOutputArray InputOutputArray InputOutputArray Size InputOutputArray R
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.
const CvArr const CvArr * V
Definition: core_c.h:1341
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441