warp.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_DEVICE_WARP_HPP__
44 #define __OPENCV_GPU_DEVICE_WARP_HPP__
45 
46 namespace cv { namespace gpu { namespace device
47 {
48  struct Warp
49  {
50  enum
51  {
55  };
56 
58  static __device__ __forceinline__ unsigned int laneId()
59  {
60  unsigned int ret;
61  asm("mov.u32 %0, %laneid;" : "=r"(ret) );
62  return ret;
63  }
64 
65  template<typename It, typename T>
66  static __device__ __forceinline__ void fill(It beg, It end, const T& value)
67  {
68  for(It t = beg + laneId(); t < end; t += STRIDE)
69  *t = value;
70  }
71 
72  template<typename InIt, typename OutIt>
73  static __device__ __forceinline__ OutIt copy(InIt beg, InIt end, OutIt out)
74  {
75  for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE)
76  *out = *t;
77  return out;
78  }
79 
80  template<typename InIt, typename OutIt, class UnOp>
81  static __device__ __forceinline__ OutIt transform(InIt beg, InIt end, OutIt out, UnOp op)
82  {
83  for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE)
84  *out = op(*t);
85  return out;
86  }
87 
88  template<typename InIt1, typename InIt2, typename OutIt, class BinOp>
89  static __device__ __forceinline__ OutIt transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op)
90  {
91  unsigned int lane = laneId();
92 
93  InIt1 t1 = beg1 + lane;
94  InIt2 t2 = beg2 + lane;
95  for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, out += STRIDE)
96  *out = op(*t1, *t2);
97  return out;
98  }
99 
100  template <class T, class BinOp>
101  static __device__ __forceinline__ T reduce(volatile T *ptr, BinOp op)
102  {
103  const unsigned int lane = laneId();
104 
105  if (lane < 16)
106  {
107  T partial = ptr[lane];
108 
109  ptr[lane] = partial = op(partial, ptr[lane + 16]);
110  ptr[lane] = partial = op(partial, ptr[lane + 8]);
111  ptr[lane] = partial = op(partial, ptr[lane + 4]);
112  ptr[lane] = partial = op(partial, ptr[lane + 2]);
113  ptr[lane] = partial = op(partial, ptr[lane + 1]);
114  }
115 
116  return *ptr;
117  }
118 
119  template<typename OutIt, typename T>
120  static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value)
121  {
122  unsigned int lane = laneId();
123  value += lane;
124 
125  for(OutIt t = beg + lane; t < end; t += STRIDE, value += STRIDE)
126  *t = value;
127  }
128  };
129 }}} // namespace cv { namespace gpu { namespace device
130 
131 #endif /* __OPENCV_GPU_DEVICE_WARP_HPP__ */
static __device__ __forceinline__ unsigned int laneId()
Returns the warp lane ID of the calling thread.
Definition: warp.hpp:58
Definition: warp.hpp:53
const CvMat const CvMat const CvMat CvMat CvMat CvMat CvMat CvSize CvMat CvMat * T
Definition: calib3d.hpp:270
static __device__ __forceinline__ void fill(It beg, It end, const T &value)
Definition: warp.hpp:66
static __device__ __forceinline__ T reduce(volatile T *ptr, BinOp op)
Definition: warp.hpp:101
static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value)
Definition: warp.hpp:120
static __device__ __forceinline__ OutIt transform(InIt beg, InIt end, OutIt out, UnOp op)
Definition: warp.hpp:81
Definition: warp.hpp:54
GLsizei const GLfloat * value
Definition: core_c.h:341
GLuint GLuint end
const char * ptr
Definition: core_c.h:942
Definition: warp.hpp:48
double double end
Definition: core_c.h:774
GLdouble GLdouble t
static __device__ __forceinline__ OutIt transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op)
Definition: warp.hpp:89
static __device__ __forceinline__ OutIt copy(InIt beg, InIt end, OutIt out)
Definition: warp.hpp:73