Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __OPENCV_GPU_DEVICE_WARP_HPP__
00044 #define __OPENCV_GPU_DEVICE_WARP_HPP__
00045
00046 namespace cv { namespace gpu { namespace device
00047 {
00048 struct Warp
00049 {
00050 enum
00051 {
00052 LOG_WARP_SIZE = 5,
00053 WARP_SIZE = 1 << LOG_WARP_SIZE,
00054 STRIDE = WARP_SIZE
00055 };
00056
00058 static __device__ __forceinline__ unsigned int laneId()
00059 {
00060 unsigned int ret;
00061 asm("mov.u32 %0, %laneid;" : "=r"(ret) );
00062 return ret;
00063 }
00064
00065 template<typename It, typename T>
00066 static __device__ __forceinline__ void fill(It beg, It end, const T& value)
00067 {
00068 for(It t = beg + laneId(); t < end; t += STRIDE)
00069 *t = value;
00070 }
00071
00072 template<typename InIt, typename OutIt>
00073 static __device__ __forceinline__ OutIt copy(InIt beg, InIt end, OutIt out)
00074 {
00075 for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE)
00076 *out = *t;
00077 return out;
00078 }
00079
00080 template<typename InIt, typename OutIt, class UnOp>
00081 static __device__ __forceinline__ OutIt transform(InIt beg, InIt end, OutIt out, UnOp op)
00082 {
00083 for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE)
00084 *out = op(*t);
00085 return out;
00086 }
00087
00088 template<typename InIt1, typename InIt2, typename OutIt, class BinOp>
00089 static __device__ __forceinline__ OutIt transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op)
00090 {
00091 unsigned int lane = laneId();
00092
00093 InIt1 t1 = beg1 + lane;
00094 InIt2 t2 = beg2 + lane;
00095 for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, out += STRIDE)
00096 *out = op(*t1, *t2);
00097 return out;
00098 }
00099
00100 template<typename OutIt, typename T>
00101 static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value)
00102 {
00103 unsigned int lane = laneId();
00104 value += lane;
00105
00106 for(OutIt t = beg + lane; t < end; t += STRIDE, value += STRIDE)
00107 *t = value;
00108 }
00109 };
00110 }}}
00111
00112 #endif