1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11
// For Open Source Computer Vision Library
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.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
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.
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.
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.
46
#include "opencv2/cudalegacy/NCV.hpp"
50
static void swap(T &p1, T &p2)
59
static T divUp(T a, T b)
61
return (a + b - 1) / b;
66
struct functorAddValues
68
static __device__ __inline__ void assign(volatile T *dst, volatile T *src)
70
//Works only for integral types. If you see compiler error here, then you have to specify how to copy your object as a set of integral fields.
73
static __device__ __inline__ void reduce(volatile T &in1out, const volatile T &in2)
81
struct functorMinValues
83
static __device__ __inline__ void assign(volatile T *dst, volatile T *src)
85
//Works only for integral types. If you see compiler error here, then you have to specify how to copy your object as a set of integral fields.
88
static __device__ __inline__ void reduce(volatile T &in1out, const volatile T &in2)
90
in1out = in1out > in2 ? in2 : in1out;
96
struct functorMaxValues
98
static __device__ __inline__ void assign(volatile T *dst, volatile T *src)
100
//Works only for integral types. If you see compiler error here, then you have to specify how to copy your object as a set of integral fields.
103
static __device__ __inline__ void reduce(volatile T &in1out, const volatile T &in2)
105
in1out = in1out > in2 ? in1out : in2;
110
template<typename Tdata, class Tfunc, Ncv32u nThreads>
111
static __device__ Tdata subReduce(Tdata threadElem)
115
__shared__ Tdata _reduceArr[nThreads];
116
volatile Tdata *reduceArr = _reduceArr;
117
functor.assign(reduceArr + threadIdx.x, &threadElem);
120
if (nThreads >= 256 && threadIdx.x < 128)
122
functor.reduce(reduceArr[threadIdx.x], reduceArr[threadIdx.x + 128]);
126
if (nThreads >= 128 && threadIdx.x < 64)
128
functor.reduce(reduceArr[threadIdx.x], reduceArr[threadIdx.x + 64]);
132
if (threadIdx.x < 32)
136
functor.reduce(reduceArr[threadIdx.x], reduceArr[threadIdx.x + 32]);
138
if (nThreads >= 32 && threadIdx.x < 16)
140
functor.reduce(reduceArr[threadIdx.x], reduceArr[threadIdx.x + 16]);
141
functor.reduce(reduceArr[threadIdx.x], reduceArr[threadIdx.x + 8]);
142
functor.reduce(reduceArr[threadIdx.x], reduceArr[threadIdx.x + 4]);
143
functor.reduce(reduceArr[threadIdx.x], reduceArr[threadIdx.x + 2]);
144
functor.reduce(reduceArr[threadIdx.x], reduceArr[threadIdx.x + 1]);
150
functor.assign(&reduceRes, reduceArr);
155
#endif //_ncv_alg_hpp_