Create OpenCV in Visual Studio 2012 with CUDA

I need to compile OpenCV 2.4.5 with Visual Studio 2012. In particular, I'm interested in compiling the gpu module with Cuda 5.0.

To enable CUDA compilation in VS2012, I followed this guide .

I use CMake to create a VS2012 solution, then for each .cu file I change the element type from "Custom build rule" to "CUDA C / C ++"

I can compile most of the project files, but in some files I have an unpleasant problem.

For example, fgd_bgfg.cu cause

error C2039: 'ParameterType': not a member ':: resume :: GPU device :: TypeTraits'

But in type_traits.hpp I can read

typedef typename type_traits_detail::Select<IsSimpleParameter<UnqualifiedType>::value, T, typename type_traits_detail::AddParameterType<T>::type>::type ParameterType; 

This is a really annoying problem that I can’t get rid of!

I can’t believe that no one has already built opencv with VS2012 and GPU, some tips?

+4
source share
1 answer

It seems that the CUDA compiler cannot handle the template technique. A simple way is a TypeTraits template with three primitive types: double, float, int. I'm not sure if this path is correct, but the CUDA compiler will not complain.

The codes are listed here:

 template<> struct TypeTraits<double> { typedef type_traits_detail::UnConst<double>::type NonConstType; typedef type_traits_detail::UnVolatile<double>::type NonVolatileType; typedef type_traits_detail::UnVolatile<typename type_traits_detail::UnConst<double>::type>::type UnqualifiedType; typedef type_traits_detail::PointerTraits<double>::type PointeeType; typedef type_traits_detail::ReferenceTraits<double>::type ReferredType; enum { isConst = type_traits_detail::UnConst<double>::value }; enum { isVolatile = type_traits_detail::UnVolatile<double>::value }; enum { isReference = type_traits_detail::ReferenceTraits<double>::value }; enum { isPointer = type_traits_detail::PointerTraits<typename type_traits_detail::ReferenceTraits<double>::type>::value }; enum { isUnsignedInt = type_traits_detail::IsUnsignedIntegral<double>::value }; enum { isSignedInt = type_traits_detail::IsSignedIntergral<double>::value }; enum { isIntegral = type_traits_detail::IsIntegral<double>::value }; enum { isFloat = type_traits_detail::IsFloat<double>::value }; enum { isArith = isIntegral || isFloat }; enum { isVec = type_traits_detail::IsVec<double>::value }; typedef double ParameterType; }; template<> struct TypeTraits<float> { typedef type_traits_detail::UnConst<float>::type NonConstType; typedef type_traits_detail::UnVolatile<float>::type NonVolatileType; typedef type_traits_detail::UnVolatile<typename type_traits_detail::UnConst<float>::type>::type UnqualifiedType; typedef type_traits_detail::PointerTraits<float>::type PointeeType; typedef type_traits_detail::ReferenceTraits<float>::type ReferredType; enum { isConst = type_traits_detail::UnConst<float>::value }; enum { isVolatile = type_traits_detail::UnVolatile<float>::value }; enum { isReference = type_traits_detail::ReferenceTraits<float>::value }; enum { isPointer = type_traits_detail::PointerTraits<typename type_traits_detail::ReferenceTraits<float>::type>::value }; enum { isUnsignedInt = type_traits_detail::IsUnsignedIntegral<float>::value }; enum { isSignedInt = type_traits_detail::IsSignedIntergral<float>::value }; enum { isIntegral = type_traits_detail::IsIntegral<float>::value }; enum { isFloat = type_traits_detail::IsFloat<float>::value }; enum { isArith = isIntegral || isFloat }; enum { isVec = type_traits_detail::IsVec<float>::value }; typedef float ParameterType; }; template<> struct TypeTraits<int> { typedef type_traits_detail::UnConst<int>::type NonConstType; typedef type_traits_detail::UnVolatile<int>::type NonVolatileType; typedef type_traits_detail::UnVolatile<typename type_traits_detail::UnConst<int>::type>::type UnqualifiedType; typedef type_traits_detail::PointerTraits<int>::type PointeeType; typedef type_traits_detail::ReferenceTraits<int>::type ReferredType; enum { isConst = type_traits_detail::UnConst<int>::value }; enum { isVolatile = type_traits_detail::UnVolatile<int>::value }; enum { isReference = type_traits_detail::ReferenceTraits<int>::value }; enum { isPointer = type_traits_detail::PointerTraits<typename type_traits_detail::ReferenceTraits<int>::type>::value }; enum { isUnsignedInt = type_traits_detail::IsUnsignedIntegral<int>::value }; enum { isSignedInt = type_traits_detail::IsSignedIntergral<int>::value }; enum { isIntegral = type_traits_detail::IsIntegral<int>::value }; enum { isFloat = type_traits_detail::IsFloat<int>::value }; enum { isArith = isIntegral || isFloat }; enum { isVec = type_traits_detail::IsVec<int>::value }; typedef int ParameterType; }; 

copy the code into type_traits.hpp behind the original TypeTraits definition. Build ... then a victim.

Good luck :-D

+1
source

Source: https://habr.com/ru/post/1482849/


All Articles