reduce.hpp
Go to the documentation of this file.
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_GPU_REDUCE_HPP__
44 #define __OPENCV_GPU_REDUCE_HPP__
45 
46 #include <thrust/tuple.h>
47 #include "detail/reduce.hpp"
49 
50 namespace cv { namespace gpu { namespace device
51 {
52  template <int N, typename T, class Op>
53  __device__ __forceinline__ void reduce(volatile T* smem, T& val, unsigned int tid, const Op& op)
54  {
55  reduce_detail::Dispatcher<N>::reductor::template reduce<volatile T*, T&, const Op&>(smem, val, tid, op);
56  }
57  template <int N,
58  typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9,
59  typename R0, typename R1, typename R2, typename R3, typename R4, typename R5, typename R6, typename R7, typename R8, typename R9,
60  class Op0, class Op1, class Op2, class Op3, class Op4, class Op5, class Op6, class Op7, class Op8, class Op9>
61  __device__ __forceinline__ void reduce(const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>& smem,
62  const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>& val,
63  unsigned int tid,
64  const thrust::tuple<Op0, Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8, Op9>& op)
65  {
67  const thrust::tuple<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>&,
68  const thrust::tuple<R0, R1, R2, R3, R4, R5, R6, R7, R8, R9>&,
69  const thrust::tuple<Op0, Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8, Op9>&>(smem, val, tid, op);
70  }
71 
72  template <unsigned int N, typename K, typename V, class Cmp>
73  __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key, volatile V* svals, V& val, unsigned int tid, const Cmp& cmp)
74  {
75  reduce_key_val_detail::Dispatcher<N>::reductor::template reduce<volatile K*, K&, volatile V*, V&, const Cmp&>(skeys, key, svals, val, tid, cmp);
76  }
77  template <unsigned int N,
78  typename K,
79  typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9,
80  typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9,
81  class Cmp>
82  __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key,
83  const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals,
84  const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val,
85  unsigned int tid, const Cmp& cmp)
86  {
88  const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>&,
89  const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>&,
90  const Cmp&>(skeys, key, svals, val, tid, cmp);
91  }
92  template <unsigned int N,
93  typename KP0, typename KP1, typename KP2, typename KP3, typename KP4, typename KP5, typename KP6, typename KP7, typename KP8, typename KP9,
94  typename KR0, typename KR1, typename KR2, typename KR3, typename KR4, typename KR5, typename KR6, typename KR7, typename KR8, typename KR9,
95  typename VP0, typename VP1, typename VP2, typename VP3, typename VP4, typename VP5, typename VP6, typename VP7, typename VP8, typename VP9,
96  typename VR0, typename VR1, typename VR2, typename VR3, typename VR4, typename VR5, typename VR6, typename VR7, typename VR8, typename VR9,
97  class Cmp0, class Cmp1, class Cmp2, class Cmp3, class Cmp4, class Cmp5, class Cmp6, class Cmp7, class Cmp8, class Cmp9>
98  __device__ __forceinline__ void reduceKeyVal(const thrust::tuple<KP0, KP1, KP2, KP3, KP4, KP5, KP6, KP7, KP8, KP9>& skeys,
99  const thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9>& key,
100  const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>& svals,
101  const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>& val,
102  unsigned int tid,
103  const thrust::tuple<Cmp0, Cmp1, Cmp2, Cmp3, Cmp4, Cmp5, Cmp6, Cmp7, Cmp8, Cmp9>& cmp)
104  {
106  const thrust::tuple<KP0, KP1, KP2, KP3, KP4, KP5, KP6, KP7, KP8, KP9>&,
107  const thrust::tuple<KR0, KR1, KR2, KR3, KR4, KR5, KR6, KR7, KR8, KR9>&,
108  const thrust::tuple<VP0, VP1, VP2, VP3, VP4, VP5, VP6, VP7, VP8, VP9>&,
109  const thrust::tuple<VR0, VR1, VR2, VR3, VR4, VR5, VR6, VR7, VR8, VR9>&,
110  const thrust::tuple<Cmp0, Cmp1, Cmp2, Cmp3, Cmp4, Cmp5, Cmp6, Cmp7, Cmp8, Cmp9>&
111  >(skeys, key, svals, val, tid, cmp);
112  }
113 
114  // smem_tuple
115 
116  template <typename T0>
117  __device__ __forceinline__
118  thrust::tuple<volatile T0*>
119  smem_tuple(T0* t0)
120  {
121  return thrust::make_tuple((volatile T0*) t0);
122  }
123 
124  template <typename T0, typename T1>
125  __device__ __forceinline__
126  thrust::tuple<volatile T0*, volatile T1*>
127  smem_tuple(T0* t0, T1* t1)
128  {
129  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1);
130  }
131 
132  template <typename T0, typename T1, typename T2>
133  __device__ __forceinline__
134  thrust::tuple<volatile T0*, volatile T1*, volatile T2*>
135  smem_tuple(T0* t0, T1* t1, T2* t2)
136  {
137  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2);
138  }
139 
140  template <typename T0, typename T1, typename T2, typename T3>
141  __device__ __forceinline__
142  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*>
143  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3)
144  {
145  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3);
146  }
147 
148  template <typename T0, typename T1, typename T2, typename T3, typename T4>
149  __device__ __forceinline__
150  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*>
151  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4)
152  {
153  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4);
154  }
155 
156  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
157  __device__ __forceinline__
158  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*>
159  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5)
160  {
161  return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5);
162  }
163 
164  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
165  __device__ __forceinline__
166  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*>
167  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6)
168  {
169  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);
170  }
171 
172  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
173  __device__ __forceinline__
174  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*>
175  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7)
176  {
177  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);
178  }
179 
180  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
181  __device__ __forceinline__
182  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*, volatile T8*>
183  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7, T8* t8)
184  {
185  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);
186  }
187 
188  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
189  __device__ __forceinline__
190  thrust::tuple<volatile T0*, volatile T1*, volatile T2*, volatile T3*, volatile T4*, volatile T5*, volatile T6*, volatile T7*, volatile T8*, volatile T9*>
191  smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7, T8* t8, T9* t9)
192  {
193  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);
194  }
195 }}}
196 
197 #endif // __OPENCV_GPU_UTILITY_HPP__
__device__ __forceinline__ void reduce(volatile T *smem, T &val, unsigned int tid, const Op &op)
Definition: reduce.hpp:53
const CvMat const CvMat const CvMat CvSize const CvMat const CvMat CvMat CvMat * R2
Definition: calib3d.hpp:284
CvFileNode const CvStringHashNode * key
Definition: core_c.h:1584
const CvMat const CvMat const CvMat CvMat CvMat CvMat CvMat CvSize CvMat CvMat * T
Definition: calib3d.hpp:270
tuple make_tuple()
Definition: ts_gtest.h:1355
const CvMat const CvMat const CvMat CvSize const CvMat const CvMat CvMat * R1
Definition: calib3d.hpp:284
GLuint GLfloat * val
Definition: reduce_key_val.hpp:483
const CvMat const CvMat const CvMat CvSize const CvMat const CvMat CvMat CvMat CvMat * P1
Definition: calib3d.hpp:284
const CvArr const CvArr * V
Definition: core_c.h:733
__device__ __forceinline__ thrust::tuple< volatile T0 * > smem_tuple(T0 *t0)
Definition: reduce.hpp:119
__device__ __forceinline__ void reduceKeyVal(volatile K *skeys, K &key, volatile V *svals, V &val, unsigned int tid, const Cmp &cmp)
Definition: reduce.hpp:73
const CvMat const CvMat const CvMat CvSize const CvMat const CvMat CvMat CvMat CvMat CvMat * P2
Definition: calib3d.hpp:284