GitLab 运行程序无法构建 OpenCV,无法找到 contrib 模块,但本地相同的 CMakeLists.txt 设法做到这一点

问题描述 投票:0回答:1

我在 Windows 服务器上设置了一个运行器(shell 执行器),其功能比我自己的计算机强大得多。运行程序已成功注册到本地托管的最新 GitLab 实例。两台计算机均已安装 CUDA 12.2 和 CUDA 12.2 的 cuDNN 8.9.5.30(cuDNN 复制到 CUDA 目录中),包括。

PATH
CUDA_PATH
进行相应设置。

我的项目由多个依赖项组成,我不想在本地构建这些依赖项,而是想使用 CMake 和/或 Git 来下载和使用。因此,我将其分为 2 个存储库 - 一个用于我的应用程序,另一个用于依赖项。我的最终目标是添加从存储库自动下载工件以及主应用程序的 CMake 项目中的依赖项。

依赖项之一是具有 GPU 支持的 OpenCV。 Dependency 存储库的结构如下:

*
|
+-- REAMDE.md
|
+-- .gitmodules
|
+-- .gitignore
|
+-- .gitlab-ci.yml
|
+-- deps
     |
     +-- [submodule] opencv
     |
     +-- [submodule] opencv_contrib
     |
     +-- [submodules] other depenencies
     |
     +-- CMakeLists.txt

.gitsubmodules
看起来像

[submodule "deps/opencv"]
    path = deps/opencv
    url = https://github.com/opencv/opencv.git
    branch="4.x"
[submodule "deps/opencv_contrib"]
    path = deps/opencv_contrib
    url = https://github.com/opencv/opencv_contrib.git
    branch="4.x"

CMakeLists.txt

cmake_minimum_required(VERSION 3.22)
project(Dependencies)

# Disable examples, tests and docs
set(BUILD_EXAMPLES OFF)
set(BUILD_TESTS OFF)
set(BUILD_DOCS OFF)
# Disable GUI
set(WITH_QT OFF)
set(WITH_GTK OFF)
set(WITH_WIN32UI OFF)
# Disable video
set(WITH_MSMF OFF)
set(WITH_FFMPEG OFF)
set(WITH_DSHOW OFF)
# Language support
set(BUILD_JAVA OFF)
set(BUILD_opencv_python2 OFF)
set(BUILD_opencv_python3 OFF)

if(BuildOpenCV_CPU_BASE)
    add_subdirectory(opencv)
elseif(BuildOpenCV_GPU)
    set(OPENCV_ENABLE_NONFREE OFF)
    set(WITH_CUDA ON)   # Currently using 11.8
    set(WITH_CUDNN ON)
    set(OPENCV_DNN_CUDA ON)
    set(CUDA_ARCH_BIN=6.1)
    set(WITH_NVCUVID OFF)
    set(WITH_NVCUVENC OFF)
    set(OPENCV_EXTRA_MODULES_PATH
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudaarithm"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudabgsegm"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudacodec"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudafeatures2d"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudafilters"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudaimgproc"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudalegacy"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudaobjdetect"
        #"${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudaoptflow"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudastereo"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudawarping"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudev"
    )
    add_subdirectory(opencv)
endif()

而我的

.gitlab-ci.yml

stages:
  - build

build-4.x-gpu-release:
  stage: build
  tags:
    - srv
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
    GIT_SUBMODULE_PATHS: deps/*
  artifacts:
    paths:
      - build\bin\Release\*.dll
  script:
    - echo "build-4.x-gpu-release"
    - cd deps
    - cmake -Bbuild -G "Visual Studio 16 2019" -DBuildOpenCV_GPU=ON
    - cmake.exe --build build --target ALL_BUILD --config Release

在我的本地计算机上,当我重复

CI
作业的
script
中看到的步骤时,我能够配置该项目,甚至编译它。在服务器上,我的运行程序报告(在 GitLab WebUI 中)OpenCV GPU 需要启用 contrib 模块中的
cudev
模块

CMake Error at opencv/modules/core/CMakeLists.txt:158 (message):
  CUDA: OpenCV requires enabled 'cudev' module from 'opencv_contrib'
  repository: https://github.com/opencv/opencv_contrib
-- Configuring incomplete, errors occurred!

我还尝试使用

-S
cmake
参数指定源目录,这样我也许可以防止在 CI 作业中更改目录时出现一些混乱。

我可以在日志中看到 cuDNN 和 CUDA 都被正确检测到:

Found CUDNN: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/lib/x64/cudnn.lib (found suitable version "8.9.5", minimum required is "7.5")
-- CUDA detected: 12.2

我还可以看到(通过在我自己的

OPENCV_EXTRA_MODULES_PATH
中打印出
CMakeLists.txt
的额外调试消息,我选择的所有模块都被正确检测到,特别是
cudev
可以在

找到)
D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudev

其中

D:/GITLAB/build
是 Windows 运行程序(shell 执行程序)运行所有 CI 作业的目录。

请注意,我在同一阶段还有多个其他作业(例如

DirectXTex
spdlog
imgui
),构建时没有任何问题。

CI 作业的完整输出如下所示:

Running with gitlab-runner 17.2.1 (9882d9c7)
  on SZA-GIN002 6LxqbndAy, system ID: s_8ceec5130a1f
Preparing the "shell" executor 00:00
Using Shell (powershell) executor...
Preparing environment 00:00
Running on SZA-GIN002...
Getting source from Git repository 00:22
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/.git/
Checking out 83c3b28c as detached HEAD (ref is main)...
Removing artifacts/
Removing deps/build/
git-lfs/2.11.0 (GitHub; windows amd64; go 1.14.2; git 48b28d97)
Updating/initializing submodules recursively with git depth set to 20...
Synchronizing submodule url for 'deps/opencv'
Synchronizing submodule url for 'deps/opencv_contrib'
Entering 'deps/DirectXTex'
Entering 'deps/opencv'
Entering 'deps/opencv_contrib'
Entering 'deps/DirectXTex'
HEAD is now at 2f84f54 Add cubemap support for OpenEXR (#483)
Entering 'deps/opencv'
HEAD is now at 1acf722 Merge pull request #25970 from savuor:rv/hal_pyrdown
Entering 'deps/opencv_contrib'
HEAD is now at 2413f86 Merge pull request #3600 from chacha21:remap_relative
Updated submodules
Synchronizing submodule url for 'deps/opencv'
Synchronizing submodule url for 'deps/opencv_contrib'
Entering 'deps/DirectXTex'
Entering 'deps/opencv'
Entering 'deps/opencv_contrib'
git-lfs/2.11.0 (GitHub; windows amd64; go 1.14.2; git 48b28d97)
Entering 'deps/DirectXTex'
Entering 'deps/opencv'
Entering 'deps/opencv_contrib'
Downloading artifacts 00:04
Version:      17.2.1
Git revision: 9882d9c7
Git branch:   17-2-stable
GO version:   go1.22.5
Built:        2024-07-25T17:34:51+0000
OS/Arch:      windows/amd64
Downloading artifacts for build-spdlog-debug (7005794)...
Runtime platform                                    arch=amd64 os=windows pid=61248 revision=9882d9c7 version=17.2.1
Downloading artifacts from coordinator... ok        host=gitlab-srv.example.com id=7005794 responseStatus=200 OK token=glcbt-64
Downloading artifacts for build-DirectXTex-debug (7005795)...
Runtime platform                                    arch=amd64 os=windows pid=103904 revision=9882d9c7 version=17.2.1
Downloading artifacts from coordinator... ok        host=gitlab-srv.example.com id=7005795 responseStatus=200 OK token=glcbt-64
Downloading artifacts for build-imgui-debug (7005796)...
Runtime platform                                    arch=amd64 os=windows pid=18808 revision=9882d9c7 version=17.2.1
Downloading artifacts from coordinator... ok        host=gitlab-srv.example.com id=7005796 responseStatus=200 OK token=glcbt-64
Executing "step_script" stage of the job script 02:41
$ echo "build-4.x-gpu-release"
build-4.x-gpu-release
$ cd deps
$ cmake -Bbuild -G "Visual Studio 16 2019" -DBuildOpenCV_GPU=ON
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.14393.
-- The C compiler identification is MSVC 19.20.27525.0
-- The CXX compiler identification is MSVC 19.20.27525.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Modules paths: D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudaarithm;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudabgsegm;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudacodec;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudafeatures2d;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudafilters;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudaimgproc;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudalegacy;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudaobjdetect;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudastereo;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudawarping;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudev
-- 'Release' build type is used by default. Use CMAKE_BUILD_TYPE to specify build type (Release or Debug)
-- ocv_init_download: Unable to recognize git server of OpenCV source code. Using github.com to download 3rdparty components.
-- Detected processor: AMD64
-- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "3.2")
-- Performing Test HAVE_CXX_FP:PRECISE
-- Performing Test HAVE_CXX_FP:PRECISE - Success
-- Performing Test HAVE_C_FP:PRECISE
-- Performing Test HAVE_C_FP:PRECISE - Success
-- Performing Test HAVE_CPU_SSE3_SUPPORT (check file: opencv/cmake/checks/cpu_sse3.cpp)
-- Performing Test HAVE_CPU_SSE3_SUPPORT - Success
-- Performing Test HAVE_CPU_SSSE3_SUPPORT (check file: opencv/cmake/checks/cpu_ssse3.cpp)
-- Performing Test HAVE_CPU_SSSE3_SUPPORT - Success
-- Performing Test HAVE_CPU_SSE4_1_SUPPORT (check file: opencv/cmake/checks/cpu_sse41.cpp)
-- Performing Test HAVE_CPU_SSE4_1_SUPPORT - Success
-- Performing Test HAVE_CPU_POPCNT_SUPPORT (check file: opencv/cmake/checks/cpu_popcnt.cpp)
-- Performing Test HAVE_CPU_POPCNT_SUPPORT - Success
-- Performing Test HAVE_CPU_SSE4_2_SUPPORT (check file: opencv/cmake/checks/cpu_sse42.cpp)
-- Performing Test HAVE_CPU_SSE4_2_SUPPORT - Success
-- Performing Test HAVE_CXX_ARCH:AVX (check file: opencv/cmake/checks/cpu_avx.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX - Success
-- Performing Test HAVE_CXX_ARCH:AVX2 (check file: opencv/cmake/checks/cpu_avx2.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX2 - Success
-- Performing Test HAVE_CXX_ARCH:AVX512 (check file: opencv/cmake/checks/cpu_avx512.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX512 - Failed
-- AVX_512F is not supported by C++ compiler
-- AVX512_COMMON is not supported by C++ compiler
-- AVX512_SKX is not supported by C++ compiler
-- Dispatch optimization AVX512_SKX is not available, skipped
-- Performing Test HAVE_CPU_BASELINE_FLAGS
-- Performing Test HAVE_CPU_BASELINE_FLAGS - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_1
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_1 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_2
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_2 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_FP16
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_FP16 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX2
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX2 - Success
-- Performing Test HAVE_CXX_W15240
-- Performing Test HAVE_CXX_W15240 - Success
-- Performing Test HAVE_C_W15240
-- Performing Test HAVE_C_W15240 - Success
-- Looking for malloc.h
-- Looking for malloc.h - found
-- Looking for _aligned_malloc
-- Looking for _aligned_malloc - found
-- Looking for fseeko
-- Looking for fseeko - not found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - failed
-- libjpeg-turbo: VERSION = 3.0.3, BUILD = opencv-4.10.0-dev-libjpeg-turbo
-- Check size of size_t
-- Check size of size_t - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Looking for include file intrin.h
-- Looking for include file intrin.h - found
-- Looking for a ASM_NASM compiler
-- Looking for a ASM_NASM compiler - NOTFOUND
-- SIMD extensions disabled: could not find NASM compiler.  Performance will suffer.
-- Looking for assert.h
-- Looking for assert.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for io.h
-- Looking for io.h - found
-- Looking for limits.h
-- Looking for limits.h - found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for search.h
-- Looking for search.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Performing Test C_HAS_inline
-- Performing Test C_HAS_inline - Success
-- Check size of signed short
-- Check size of signed short - done
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Check size of signed int
-- Check size of signed int - done
-- Check size of unsigned int
-- Check size of unsigned int - done
-- Check size of signed long
-- Check size of signed long - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Check size of signed long long
-- Check size of signed long long - done
-- Check size of unsigned long long
-- Check size of unsigned long long - done
-- Check size of unsigned char *
-- Check size of unsigned char * - done
-- Check size of size_t
-- Check size of size_t - done
-- Check size of ptrdiff_t
-- Check size of ptrdiff_t - done
-- Looking for memmove
-- Looking for memmove - not found
-- Looking for setmode
-- Looking for setmode - found
-- Looking for strcasecmp
-- Looking for strcasecmp - not found
-- Looking for strchr
-- Looking for strchr - found
-- Looking for strrchr
-- Looking for strrchr - found
-- Looking for strstr
-- Looking for strstr - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtoull
-- Looking for strtoull - found
-- Looking for lfind
-- Looking for lfind - found
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.10.0-dev-openjp2-2.5.0
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for stdio.h
-- Looking for stdio.h - found
-- Looking for math.h
-- Looking for math.h - found
-- Looking for float.h
-- Looking for float.h - found
-- Looking for time.h
-- Looking for time.h - found
-- Looking for stdarg.h
-- Looking for stdarg.h - found
-- Looking for ctype.h
-- Looking for ctype.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for strings.h
-- Looking for strings.h - not found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for unistd.h
-- Looking for unistd.h - not found
-- Looking for include file malloc.h
-- Looking for include file malloc.h - found
-- Looking for _aligned_malloc
-- Looking for _aligned_malloc - found
-- Looking for posix_memalign
-- Looking for posix_memalign - not found
-- Looking for memalign
-- Looking for memalign - not found
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
-- IPPICV: Downloading ippicv_2021.12.0_win_intel64_20240425_general.zip from https://raw.githubusercontent.com/opencv/opencv_3rdparty/7f55c0c26be418d494615afca15218566775c725/ippicv/ippicv_2021.12.0_win_intel64_20240425_general.zip
-- found Intel IPP (ICV version): 2021.12.0 [2021.12.0]
-- at: D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/build/opencv/3rdparty/ippicv/ippicv_win/icv
-- found Intel IPP Integration Wrappers sources: 2021.12.0
-- at: D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/build/opencv/3rdparty/ippicv/ippicv_win/iw
-- Found CUDNN: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/lib/x64/cudnn.lib (found suitable version "8.9.5", minimum required is "7.5")
-- CUDA detected: 12.2
-- CUDA: NVCC target flags -gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_89,code=sm_89;-gencode;arch=compute_90,code=sm_90;-D_FORCE_INLINES;-gencode;arch=compute_90,code=compute_90
-- CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Looking for sgemm_
-- Looking for sgemm_ - not found
-- Found Threads: TRUE
-- Could NOT find BLAS (missing: BLAS_LIBRARIES) 
-- Could NOT find LAPACK (missing: LAPACK_LIBRARIES) 
    Reason given by package: LAPACK could not be found because dependency BLAS could not be found.
-- No support for DirectML (d3d12, dxcore, directml libs are required)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- ADE: Downloading v0.1.2d.zip from https://github.com/opencv/ade/archive/v0.1.2d.zip
-- Looking for mfapi.h
-- Looking for mfapi.h - found
-- Looking for vidcap.h
-- Looking for vidcap.h - found
-- Allocator metrics storage type: 'long long'
CMake Error at opencv/modules/core/CMakeLists.txt:158 (message):
  CUDA: OpenCV requires enabled 'cudev' module from 'opencv_contrib'
  repository: https://github.com/opencv/opencv_contrib
-- Configuring incomplete, errors occurred!
windows opencv cmake gitlab-ci gitlab-ci-runner
1个回答
0
投票

显然(虽然我找不到任何相关文档)

OPENCV_EXTRA_MODULES_PATH
中列出的模块路径的顺序很重要。

我所要做的就是将

<OPENCV_CONTRIB_ROOT_DIR>/modules/cudev
放在
OPENCV_EXTRA_MODULES_PATH
的开头:

set(OPENCV_EXTRA_MODULES_PATH
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudev" # <------------ !!!IMPORTANT!!!
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudaarithm"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudabgsegm"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudacodec"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudafeatures2d"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudafilters"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudaimgproc"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudalegacy"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudaobjdetect"
        #"${DEPS_ROOT_DIR}/opencv_contrib/modules/cudaoptflow"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudastereo"
        "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudawarping"
    )
© www.soinside.com 2019 - 2024. All rights reserved.