include/opencv2/gpu/device/warp.hpp
Go to the documentation of this file.
00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                           License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Third party copyrights are property of their respective owners.
00016 //
00017 // Redistribution and use in source and binary forms, with or without modification,
00018 // are permitted provided that the following conditions are met:
00019 //
00020 //   * Redistribution's of source code must retain the above copyright notice,
00021 //     this list of conditions and the following disclaimer.
00022 //
00023 //   * Redistribution's in binary form must reproduce the above copyright notice,
00024 //     this list of conditions and the following disclaimer in the documentation
00025 //     and/or other materials provided with the distribution.
00026 //
00027 //   * The name of the copyright holders may not be used to endorse or promote products
00028 //     derived from this software without specific prior written permission.
00029 //
00030 // This software is provided by the copyright holders and contributors "as is" and
00031 // any express or implied warranties, including, but not limited to, the implied
00032 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00033 // In no event shall the Intel Corporation or contributors be liable for any direct,
00034 // indirect, incidental, special, exemplary, or consequential damages
00035 // (including, but not limited to, procurement of substitute goods or services;
00036 // loss of use, data, or profits; or business interruption) however caused
00037 // and on any theory of liability, whether in contract, strict liability,
00038 // or tort (including negligence or otherwise) arising in any way out of
00039 // the use of this software, even if advised of the possibility of such damage.
00040 //
00041 //M*/
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 }}} // namespace cv { namespace gpu { namespace device
00111 
00112 #endif /* __OPENCV_GPU_DEVICE_WARP_HPP__ */