opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.4k stars 5.76k forks source link

Unable to build cudaoptflow #2834

Closed LaurentBerger closed 3 years ago

LaurentBerger commented 3 years ago
Detailed description
-- General configuration for OpenCV 4.5.1-dev =====================================
--   Version control:               4.4.0-967-g13a1105318
--
--   Extra modules:
--     Location (extra):            G:/Lib/opencv_contrib/modules
--     Version control (extra):     4.1.1-495-g0b8aecd9e
--
--   Platform:
--     Timestamp:                   2021-01-25T11:38:22Z
--     Host:                        Windows 10.0.19041 AMD64
--     CMake:                       3.18.4
--     CMake generator:             Visual Studio 15 2017 Win64
--     CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe
--     MSVC:                        1916
--     Configuration:               Debug Release
--   NVIDIA CUDA:                   YES (ver 11.2, CUFFT CUBLAS)
--     NVIDIA GPU arch:             86
--     NVIDIA PTX archs:
--

Error is

1>------ Build started: Project: opencv_cudaoptflow, Configuration: Release x64 ------
1>Building NVCC (Device) object modules/cudaoptflow/CMakeFiles/cuda_compile_1.dir/src/cuda/Release/cuda_compile_1_generated_farneback.cu.obj
1>farneback.cu
1>farneback.cu
1>Building NVCC (Device) object modules/cudaoptflow/CMakeFiles/cuda_compile_1.dir/src/cuda/Release/cuda_compile_1_generated_nvidiaOpticalFlow.cu.obj
1>nvidiaOpticalFlow.cu
1>nvidiaOpticalFlow.cu
1>Building NVCC (Device) object modules/cudaoptflow/CMakeFiles/cuda_compile_1.dir/src/cuda/Release/cuda_compile_1_generated_pyrlk.cu.obj
1>pyrlk.cu
1>pyrlk.cu
1>G:/Lib/opencv/modules/core/include\opencv2/core/cuda/common.hpp(102): warning C4996: 'cudaBindTexture2D': was declared deprecated
1>f:\program files\nvidia gpu computing toolkit\cuda\v11.2\include\cuda_runtime_api.h(8475): note: see declaration of 'cudaBindTexture2D'
1>G:/Lib/opencv_contrib/modules/cudaoptflow/src/cuda/pyrlk.cu(104): note: see reference to function template instantiation 'void cv::cuda::device::bindTexture<unsigned char>(const textureReference *,const cv::cuda::PtrStepSz<unsigned char> &)' being compiled
1>Building NVCC (Device) object modules/cudaoptflow/CMakeFiles/cuda_compile_1.dir/src/cuda/Release/cuda_compile_1_generated_tvl1flow.cu.obj
1>tvl1flow.cu
1>G:/Lib/opencv/modules/core/include\opencv2/core/types.hpp(530): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/types.hpp(532): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/types.hpp(771): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(257): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(568): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(2681): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(2682): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(3549): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/persistence.hpp(463): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/persistence.hpp(466): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(115): warning : base class dllexport/dllimport specification differs from that of the derived class
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(135): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(138): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(139): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(140): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/cuda.hpp(501): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/cuda.hpp(693): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/cuda.hpp(729): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/types.hpp(530): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/types.hpp(532): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/types.hpp(771): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(257): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(568): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(2681): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(2682): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/mat.hpp(3549): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/persistence.hpp(463): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/persistence.hpp(466): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(115): warning : base class dllexport/dllimport specification differs from that of the derived class
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(135): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(138): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(139): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core.hpp(140): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/cuda.hpp(501): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/cuda.hpp(693): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>G:/Lib/opencv/modules/core/include\opencv2/core/cuda.hpp(729): warning : field of class type without a DLL interface used in a class with a DLL interface
1>
1>tvl1flow.cu
1>G:/Lib/opencv/modules/core/include\opencv2/core/cuda/common.hpp(102): warning C4996: 'cudaBindTexture2D': was declared deprecated
1>f:\program files\nvidia gpu computing toolkit\cuda\v11.2\include\cuda_runtime_api.h(8475): note: see declaration of 'cudaBindTexture2D'
1>G:/Lib/opencv_contrib/modules/cudaoptflow/src/cuda/tvl1flow.cu(260): note: see reference to function template instantiation 'void cv::cuda::device::bindTexture<float>(const textureReference *,const cv::cuda::PtrStepSz<float> &)' being compiled
1>   Creating library G:/Lib/build/opencv/lib/Release/opencv_cudaoptflow451.lib and object G:/Lib/build/opencv/lib/Release/opencv_cudaoptflow451.exp
1>nvidiaOpticalFlow.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::optflow_nvidia::FlowUpsample(void *,unsigned int,unsigned int,unsigned int,void *,unsigned int,unsigned int,unsigned int,unsigned int)" (?FlowUpsample@optflow_nvidia@device@cuda@cv@@YAXPEAXIII0IIII@Z) referenced in function "public: virtual void __cdecl `anonymous namespace'::NvidiaOpticalFlowImpl_2::calc(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputOutputArray const &,class cv::cuda::Stream &,class cv::_InputArray const &,class cv::_OutputArray const &)" (?calc@NvidiaOpticalFlowImpl_2@?A0xf83298cd@@UEAAXAEBV_InputArray@cv@@0AEBV_InputOutputArray@4@AEAVStream@cuda@4@0AEBV_OutputArray@4@@Z)
1>G:\Lib\build\opencv\bin\Release\opencv_cudaoptflow451.dll : fatal error LNK1120: 1 unresolved externals
1>Done building project "opencv_cudaoptflow.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What's wrong ? @tomoaki0705 @vchiluka5

tomoaki0705 commented 3 years ago
 -- General configuration for OpenCV 4.5.1-dev =====================================
--   Version control:               4.4.0-967-g13a1105318
--
--   Extra modules:
--     Location (extra):            G:/Lib/opencv_contrib/modules
--     Version control (extra):     4.1.1-495-g0b8aecd9e

If this is info is not a typo,, it seems you are mixing recent master with old contrib branch. If I understand correctly, that's not supported, and that will be the cause of this build failure. Is this information precise ? Is there any particular reason you wish to mix old contrib and recent master ?

LaurentBerger commented 3 years ago

I don't think so https://github.com/LaurentBerger/opencv_contrib even with master and https://github.com/LaurentBerger/opencv Merge pull request opencv#19078 from zihaomu:dasiamrpn_tracker_c_plus…13a1105 16 hours ago

I don't know why Version control (extra): 4.1.1-495-g0b8aecd9e is

in opencv_contrib git log gives me :

$ git log
commit 0b8aecd9ebb605f2c07c2cd21f987645eabcfd52 (HEAD -> master, upstream/master                                        , origin/master, origin/HEAD)
Merge: d733a8010 6e52be36a
Author: Alexander Alekhin <alexander.a.alekhin@gmail.com>
Date:   Mon Jan 25 07:44:10 2021 +0000

    Merge pull request #2824 from tomoaki0705:fixBuildCudaOptFlow

commit 6e52be36a5560f2f4242171f71a5904ddf597e59
Author: Tomoaki Teshima <tomoaki.teshima@gmail.com>
Date:   Mon Jan 25 08:40:01 2021 +0900

    disable NVIDIA Optical Flow SDK when CUDA < 10.0
      * follow the review comment
      * add missing constructors when not covered
      * add definition in cu file
tomoaki0705 commented 3 years ago

I don't know why Version control (extra): 4.1.1-495-g0b8aecd9e is

Right. My bad. Nothing wrong on this point.

Any chance you have a copy of cmake output that contains such message below ? https://github.com/opencv/opencv_contrib/blob/0b8aecd9ebb605f2c07c2cd21f987645eabcfd52/modules/cudaoptflow/CMakeLists.txt#L26

What I see is that the error message indicates that this is a linker error

1>nvidiaOpticalFlow.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cuda::device::optflow_nvidia::FlowUpsample(void *,unsigned int,unsigned int,unsigned int,void *,unsigned int,unsigned int,unsigned int,unsigned int)" (?FlowUpsample@optflow_nvidia@device@cuda@cv@@YAXPEAXIII0IIII@Z) referenced in function "public: virtual void __cdecl `anonymous namespace'::NvidiaOpticalFlowImpl_2::calc(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputOutputArray const &,class cv::cuda::Stream &,class cv::_InputArray const &,class cv::_OutputArray const &)" (?calc@NvidiaOpticalFlowImpl_2@?A0xf83298cd@@UEAAXAEBV_InputArray@cv@@0AEBV_InputOutputArray@4@AEAVStream@cuda@4@0AEBV_OutputArray@4@@Z)

This means that HAVE_NVIDIA_OPTFLOW macro has been defined in nvidiaOpticalFlow.cpp

#elif !defined HAVE_NVIDIA_OPTFLOW
 :
#else
 :
cv::cuda::device::optflow_nvidia::FlowUpsample((void*)m_flowXYcuDevPtr, nSrcWidth, nSrcPitch,...
 :
#endif

but not in nvidiaOpticalFlow.cu

#ifdef HAVE_NVIDIA_OPTFLOW
 :
void FlowUpsample(void* srcDevPtr, uint32_t nSrcWidth, uint32_t nSrcPitch, uint32_t nSrcHeight,
 :
#endif //HAVE_NVIDIA_OPTFLOW

The only reason I can imagine is that cmake cache (this is a general guess). Any chance that you re-run the cmake on existing build directory ? (I really hate to say this but there's nothing else I can say, unless there is more clear reproducer)

LaurentBerger commented 3 years ago

Now I rebuild everything with -DBUILD_opencv_cudaoptflow=OFF I can test it twomorow now When I built with cudaoptflow=ON I deleted all contents of my build opencv folder.

my cmakeoutput (empty build folder ) is

cmakeoutput.txt

line 306 : -- Building with NVIDIA Optical Flow API 2.0

alalek commented 3 years ago

@LaurentBerger You may want to fetch tags from upstream repository: git fetch -t upstream (use -t option)

Build error is confirmed.

alalek commented 3 years ago

Linux is failing too (with CUDA 10.0):

../..../../lib/libopencv_cudaoptflow.so.4.5.1: undefined reference to cv::cuda::device::optflow_nvidia::FlowUpsample(void*, unsigned int, unsigned int,/lib/libopencv_cudaoptflow.so.4.5.1: undefined reference tocv::cuda::device::optflow_nvidia::FlowUpsample(void, unsigned int, unsigned int, unsigned int, void, unsigned int, unsigned int, unsigned int, unsigned int)' unsigned int, void*, unsigned int, unsigned int, unsigned int, unsigned int)'

relates #2824

tomoaki0705 commented 3 years ago

My fault. I didn't confirm properly after #2824 was merged. My apologies. Now #2836 lets the build pass.