Skip to content

Commit b6dc1ec

Browse files
committed
Get cudalegacy to compile with clang CUDA and without CUDA
1 parent 6733762 commit b6dc1ec

File tree

8 files changed

+28
-26
lines changed

8 files changed

+28
-26
lines changed

modules/cudalegacy/include/opencv2/cudalegacy.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@
4444
#define OPENCV_CUDALEGACY_HPP
4545

4646
#include "opencv2/core/cuda.hpp"
47+
#if defined (HAVE_CUDA) && !defined (CUDA_DISABLER)
4748
#include "opencv2/cudalegacy/NCV.hpp"
4849
#include "opencv2/cudalegacy/NPP_staging.hpp"
4950
#include "opencv2/cudalegacy/NCVPyramid.hpp"
5051
#include "opencv2/cudalegacy/NCVHaarObjectDetection.hpp"
5152
#include "opencv2/cudalegacy/NCVBroxOpticalFlow.hpp"
53+
#endif
5254
#include "opencv2/video/background_segm.hpp"
5355

5456
/**

modules/cudalegacy/src/NCV.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//
4141
//M*/
4242

43+
#if defined (HAVE_CUDA) && !defined (CUDA_DISABLER)
4344
#include "precomp.hpp"
4445

4546
//==============================================================================
@@ -886,3 +887,4 @@ NCVStatus ncvDrawRects_32u_host(Ncv32u *h_dst,
886887
{
887888
return drawRectsWrapperHost(h_dst, dstStride, dstWidth, dstHeight, h_rects, numRects, color);
888889
}
890+
#endif

modules/cudalegacy/src/cuda/NCVBroxOpticalFlow.cu

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,6 @@ NCVStatus NCVBroxOpticalFlow(const NCVBroxOpticalFlowDescriptor desc,
695695
//prepare image pyramid
696696
ImagePyramid pyr(desc.number_of_outer_iterations);
697697

698-
cudaChannelFormatDesc channel_desc = cudaCreateChannelDesc<float>();
699-
700698
float scale = 1.0f;
701699

702700
//cuda arrays for frames

modules/cudalegacy/src/cuda/NCVHaarObjectDetection.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ __global__ void applyHaarClassifierAnchorParallel(cv::cudev::TexturePtr<Ncv32u>
193193
if (tbDoAtomicCompaction) bInactiveThread = true; else return;
194194
}
195195

196-
if (!tbDoAtomicCompaction || tbDoAtomicCompaction && !bInactiveThread)
196+
if (!tbDoAtomicCompaction || (tbDoAtomicCompaction && !bInactiveThread))
197197
{
198198
outMaskVal = d_inMask[maskOffset];
199199
y_offs = outMaskVal >> 16;
@@ -210,7 +210,7 @@ __global__ void applyHaarClassifierAnchorParallel(cv::cudev::TexturePtr<Ncv32u>
210210
if (tbDoAtomicCompaction) bInactiveThread = true; else return;
211211
}
212212

213-
if (!tbDoAtomicCompaction || tbDoAtomicCompaction && !bInactiveThread)
213+
if (!tbDoAtomicCompaction || (tbDoAtomicCompaction && !bInactiveThread))
214214
{
215215
maskOffset = y_offs * mask2Dstride + x_offs;
216216

modules/cudalegacy/src/cuda/NCVPixelOperations.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ template<> struct TConvVec2Base<double1> {typedef Ncv64f TBase;};
8484
template<> struct TConvVec2Base<double3> {typedef Ncv64f TBase;};
8585
template<> struct TConvVec2Base<double4> {typedef Ncv64f TBase;};
8686

87-
#define NC(T) (sizeof(T) / sizeof(TConvVec2Base<T>::TBase))
87+
#define NC(T) (sizeof(T) / sizeof(typename TConvVec2Base<T>::TBase))
8888

8989
template<typename TBase, Ncv32u NC> struct TConvBase2Vec;
9090
template<> struct TConvBase2Vec<Ncv8u, 1> {typedef uchar1 TVec;};
@@ -115,7 +115,7 @@ template<typename Tin> inline __host__ __device__ void _TDemoteClampNN(Tin &a, N
115115
template<typename Tin> inline __host__ __device__ void _TDemoteClampNN(Tin &a, Ncv32u &out) {out = (Ncv32u)CLAMP(a+0.5f, 0, UINT_MAX);}
116116
template<typename Tin> inline __host__ __device__ void _TDemoteClampNN(Tin &a, Ncv32f &out) {out = (Ncv32f)a;}
117117

118-
template<typename Tout> inline Tout _pixMakeZero();
118+
template<typename Tout> inline __host__ __device__ Tout _pixMakeZero();
119119
template<> inline __host__ __device__ uchar1 _pixMakeZero<uchar1>() {return make_uchar1(0);}
120120
template<> inline __host__ __device__ uchar3 _pixMakeZero<uchar3>() {return make_uchar3(0,0,0);}
121121
template<> inline __host__ __device__ uchar4 _pixMakeZero<uchar4>() {return make_uchar4(0,0,0,0);}

modules/cudalegacy/src/cuda/NPP_staging.cu

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,24 @@ const Ncv32u NUM_SCAN_THREADS = 256;
8585
const Ncv32u LOG2_NUM_SCAN_THREADS = 8;
8686

8787

88-
template<class T_in, class T_out>
88+
template<class T_in, class T_out, bool tbDoSqr>
8989
struct _scanElemOp
9090
{
91-
template<bool tbDoSqr>
92-
static inline __host__ __device__ T_out scanElemOp(T_in elem)
93-
{
94-
return scanElemOp( elem, Int2Type<(int)tbDoSqr>() );
95-
}
96-
97-
private:
98-
99-
template <int v> struct Int2Type { enum { value = v }; };
91+
static __host__ __device__ T_out scanElemOp(T_in elem);
92+
};
10093

101-
static inline __host__ __device__ T_out scanElemOp(T_in elem, Int2Type<0>)
102-
{
103-
return (T_out)elem;
94+
template<class T_in, class T_out>
95+
struct _scanElemOp<T_in, T_out, false>
96+
{
97+
static inline __host__ __device__ T_out scanElemOp(T_in elem) {
98+
return (T_out)(elem);
10499
}
100+
};
105101

106-
static inline __host__ __device__ T_out scanElemOp(T_in elem, Int2Type<1>)
107-
{
102+
template<class T_in, class T_out>
103+
struct _scanElemOp<T_in, T_out, true>
104+
{
105+
static inline __host__ __device__ T_out scanElemOp(T_in elem) {
108106
return (T_out)(elem*elem);
109107
}
110108
};
@@ -177,15 +175,15 @@ __global__ void scanRows(cv::cudev::TexturePtr<Ncv8u> tex8u, T_in *d_src, Ncv32u
177175
Ncv32u curElemOffs = offsetX + threadIdx.x;
178176
T_out curScanElem;
179177

180-
T_in curElem;
178+
T_in curElem = 0;
181179
T_out curElemMod;
182180

183181
if (curElemOffs < srcWidth)
184182
{
185183
//load elements
186184
curElem = readElem<T_in>(tex8u, d_src, texOffs, srcStride, curElemOffs);
187185
}
188-
curElemMod = _scanElemOp<T_in, T_out>::scanElemOp<tbDoSqr>(curElem);
186+
curElemMod = _scanElemOp<T_in, T_out, tbDoSqr>::scanElemOp(curElem);
189187

190188
//inclusive scan
191189
curScanElem = cv::cudev::blockScanInclusive<NUM_SCAN_THREADS>(curElemMod, shmem, threadIdx.x);

modules/cudalegacy/src/cuda/needle_map.cu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ namespace cv { namespace cuda { namespace device
7676
// now add the column sums
7777
const uint X = threadIdx.x;
7878

79-
if (X | 0xfe == 0xfe) // bit 0 is 0
79+
if (X | (0xfe == 0xfe)) // bit 0 is 0
8080
{
8181
u_col_sum[threadIdx.x] += u_col_sum[threadIdx.x + 1];
8282
v_col_sum[threadIdx.x] += v_col_sum[threadIdx.x + 1];
8383
}
8484

85-
if (X | 0xfe == 0xfc) // bits 0 & 1 == 0
85+
if (X | (0xfe == 0xfc)) // bits 0 & 1 == 0
8686
{
8787
u_col_sum[threadIdx.x] += u_col_sum[threadIdx.x + 2];
8888
v_col_sum[threadIdx.x] += v_col_sum[threadIdx.x + 2];
8989
}
9090

91-
if (X | 0xf8 == 0xf8)
91+
if (X | (0xf8 == 0xf8))
9292
{
9393
u_col_sum[threadIdx.x] += u_col_sum[threadIdx.x + 4];
9494
v_col_sum[threadIdx.x] += v_col_sum[threadIdx.x + 4];

modules/cudalegacy/src/precomp.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
#endif
8181

8282
#include "opencv2/core/private.cuda.hpp"
83+
#if defined (HAVE_CUDA) && !defined (CUDA_DISABLER)
8384
#include "opencv2/cudalegacy/private.hpp"
85+
#endif
8486

8587
#endif /* __OPENCV_PRECOMP_H__ */

0 commit comments

Comments
 (0)