Skip to content

Instantly share code, notes, and snippets.

@time-river
Last active January 20, 2023 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save time-river/7d94a0bc2a153be3251594889b545769 to your computer and use it in GitHub Desktop.
Save time-river/7d94a0bc2a153be3251594889b545769 to your computer and use it in GitHub Desktop.
Ubuntu 22.04 + OpenCV 4.2 + CUDA fixed
shiFrom 0d99590a7433a11308d3d848c8c11c6d219c68b9 Mon Sep 17 00:00:00 2001
From: "fu.lin" <linfu@autox.ai>
Date: Thu, 12 Jan 2023 23:20:15 +0800
Subject: [PATCH 1/2] debian: compat ubuntu22.04
ref:
- https://github.com/NVlabs/instant-ngp/issues/119
- https://github.com/opencv/opencv/commit/52844614c466a37f64347aca0698157e9bb2e41e
- https://github.com/opencv/opencv/issues/23083
Signed-off-by: fu.lin <linfu@autox.ai>
---
CMakeLists.txt | 3 +++
cmake/OpenCVCompilerOptions.cmake | 8 ++------
cmake/OpenCVDetectCUDA.cmake | 15 +++++++++++++--
debian/control | 11 ++++-------
debian/rules | 7 ++++++-
modules/core/src/parallel.cpp | 1 -
6 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8ccad4d..0802a8a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,9 @@
#
# ----------------------------------------------------------------------------
+set(CMAKE_C_COMPILER /usr/bin/gcc-10)
+set(CMAKE_CXX_COMPILER /usr/bin/g++-10)
+
# Disable in-source builds to prevent source tree corruption.
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "
diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake
index 6e7fc3b..860f614 100644
--- a/cmake/OpenCVCompilerOptions.cmake
+++ b/cmake/OpenCVCompilerOptions.cmake
@@ -229,12 +229,8 @@ if(CV_GCC OR CV_CLANG)
set(WITH_VTK OFF) # There are issues with VTK 6.0
endif()
- if(ENABLE_LTO)
- add_extra_compiler_option(-flto)
- endif()
- if(ENABLE_THIN_LTO)
- add_extra_compiler_option(-flto=thin)
- endif()
+ # prevent `Error: symbol `fatbinData' is already defined`
+ add_extra_compiler_option(-fno-lto)
set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} -DNDEBUG")
if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} ${OPENCV_EXTRA_FLAGS_DEBUG} " MATCHES "-O")
diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake
index 509f417..8d021a8 100644
--- a/cmake/OpenCVDetectCUDA.cmake
+++ b/cmake/OpenCVDetectCUDA.cmake
@@ -62,7 +62,14 @@ if(CUDA_FOUND)
message(STATUS "CUDA detected: " ${CUDA_VERSION})
- set(_generations "Fermi" "Kepler" "Maxwell" "Pascal" "Volta" "Turing")
+ set(_generations "Fermi" "Kepler" "Maxwell" "Pascal" "Volta" "Turing" "Ampere")
+ set(_arch_fermi "2.0")
+ set(_arch_kepler "3.0;3.5;3.7")
+ set(_arch_maxwell "5.0;5.2")
+ set(_arch_pascal "6.0;6.1")
+ set(_arch_volta "7.0")
+ set(_arch_turing "7.5")
+ set(_arch_ampere "8.0")
if(NOT CMAKE_CROSSCOMPILING)
list(APPEND _generations "Auto")
endif()
@@ -99,6 +106,8 @@ if(CUDA_FOUND)
set(__cuda_arch_bin "7.0")
elseif(CUDA_GENERATION STREQUAL "Turing")
set(__cuda_arch_bin "7.5")
+ elseif(CUDA_GENERATION STREQUAL "Ampere")
+ set(__cuda_arch_bin "8.0")
elseif(CUDA_GENERATION STREQUAL "Auto")
execute_process( COMMAND ${DETECT_ARCHS_COMMAND}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
@@ -136,8 +145,10 @@ if(CUDA_FOUND)
set(__cuda_arch_bin "2.0 3.0 3.5 3.7 5.0 5.2 6.0 6.1")
elseif(CUDA_VERSION VERSION_LESS "10.0")
set(__cuda_arch_bin "3.0 3.5 3.7 5.0 5.2 6.0 6.1 7.0")
+ elseif(CUDA_VERSION VERSION_LESS "12.0")
+ set(__cuda_arch_bin "3.5 3.7 5.0 5.2 6.0 6.1 7.0 7.5 8.0")
else()
- set(__cuda_arch_bin "3.0 3.5 3.7 5.0 5.2 6.0 6.1 7.0 7.5")
+ set(__cuda_arch_bin "3.5 3.7 5.0 5.2 6.0 6.1 7.0 7.5 8.0")
endif()
endif()
endif()
diff --git a/debian/control b/debian/control
index 041e496..acc184c 100644
--- a/debian/control
+++ b/debian/control
@@ -17,8 +17,7 @@ Build-Depends:
ninja-build,
libavcodec-dev,
libavformat-dev,
- libavresample-dev,
- libdc1394-22-dev [linux-any],
+ libdc1394-dev [linux-any],
libeigen3-dev,
libgdal-dev,
libgdcm-dev [!hppa !m68k !powerpcspe !sh4 !sparc64 !x32],
@@ -40,7 +39,7 @@ Build-Depends:
libtesseract-dev,
libtiff-dev,
libv4l-dev [linux-any],
- libvtk6-dev,
+ libvtk7-dev,
libvtkgdcm-dev [!alpha !ppc64 !x32],
libgdcm-tools,
libgstreamer1.0-dev,
@@ -395,7 +394,6 @@ Section: libdevel
Architecture: any
Multi-Arch: same
Depends:
- libavresample-dev,
libgphoto2-dev,
libopencv-imgcodecs-dev (= ${binary:Version}),
libopencv-videoio4.2 (= ${binary:Version}),
@@ -493,8 +491,7 @@ Multi-Arch: same
Depends:
libavcodec-dev (>= 0.svn20080206),
libavformat-dev,
- libavresample-dev,
- libdc1394-22-dev [!kfreebsd-amd64 !kfreebsd-i386 !hurd-i386],
+ libdc1394-dev [!kfreebsd-amd64 !kfreebsd-i386 !hurd-i386],
libgphoto2-dev,
libjpeg-dev,
libopencv-highgui4.2 (= ${binary:Version}),
@@ -1027,7 +1024,7 @@ Pre-Depends:
${misc:Pre-Depends},
Depends:
libopencv-core4.2 (= ${binary:Version}),
- libvtk6.3,
+ libvtk7.1p,
${misc:Depends},
${shlibs:Depends},
Description: computer vision 3D data visualization library
diff --git a/debian/rules b/debian/rules
index eacc768..f0e613e 100755
--- a/debian/rules
+++ b/debian/rules
@@ -84,7 +84,7 @@ CMAKE_FLAGS = \
-DPROTOBUF_UPDATE_FILES=ON \
-DWITH_ADE=OFF \
-DWITH_CAROTENE=OFF \
- -DWITH_CUDA=OFF \
+ -DWITH_CUDA=ON \
-DWITH_EIGEN=ON \
-DWITH_FFMPEG=ON \
-DWITH_GDAL=ON \
@@ -109,6 +109,8 @@ CMAKE_FLAGS = \
-DWITH_UNICAP=OFF \
-DWITH_VTK=ON \
-DWITH_XINE=OFF \
+ -DENABLE_LTO=OFF \
+ -DENABLE_THIN_LTO=OFF \
$(CMAKE_ARCH_FLAGS)
%:
@@ -189,3 +191,6 @@ override_dh_missing:
override_dh_gencontrol:
dh_numpy3 -p python3-opencv
dh_gencontrol
+
+override_dh_shlibdeps:
+ dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp
index 82c0fb8..adcffa6 100644
--- a/modules/core/src/parallel.cpp
+++ b/modules/core/src/parallel.cpp
@@ -90,7 +90,6 @@
#if defined HAVE_TBB
#include "tbb/tbb.h"
#include "tbb/task.h"
- #include "tbb/tbb_stddef.h"
#if TBB_INTERFACE_VERSION >= 8000
#include "tbb/task_arena.h"
#endif
--
2.34.1
From 4026c9e23dc7191fc1bcfbb0b8ccb5c69a7cc9bb Mon Sep 17 00:00:00 2001
From: "fu.lin" <linfu@autox.ai>
Date: Fri, 13 Jan 2023 13:40:39 +0800
Subject: [PATCH 2/2] debian: add libopen-cuda pkg
Signed-off-by: fu.lin <linfu@autox.ai>
---
debian/control | 24 ++++++++++++++++++++++
debian/libopencv-cuda-dev.docs | 1 +
debian/libopencv-cuda-dev.install | 10 +++++++++
debian/libopencv-cuda4.2.install | 2 ++
debian/libopencv-cuda4.2.lintian-overrides | 1 +
5 files changed, 38 insertions(+)
create mode 100644 debian/libopencv-cuda-dev.docs
create mode 100644 debian/libopencv-cuda-dev.install
create mode 100644 debian/libopencv-cuda4.2.install
create mode 100644 debian/libopencv-cuda4.2.lintian-overrides
diff --git a/debian/control b/debian/control
index acc184c..38d54dc 100644
--- a/debian/control
+++ b/debian/control
@@ -106,6 +106,7 @@ Depends:
libopencv-videostab-dev (= ${binary:Version}),
libopencv-viz-dev (= ${binary:Version}),
libopencv4.2-java (= ${source:Version}),
+ libopencv-cuda-dev ( = ${binary:Version}),
pkg-config,
${misc:Depends},
${shlibs:Depends},
@@ -1291,3 +1292,26 @@ Description: Python 3 bindings for the computer vision library
of high level functionalities for video acquisition, image processing and
analysis, structural analysis, motion analysis and object tracking, object
recognition, camera calibration and 3D reconstruction.
+
+Package: libopencv-cuda4.2
+Section: libs
+Architecture: any
+Multi-Arch: same
+Pre-Depends:
+ ${misc:Pre-Depends},
+Depends:
+ ${misc:Depends},
+ ${shlibs:Depends},
+Description: computer vision cuda support library
+
+Package: libopencv-cuda-dev
+Section: libdevel
+Architecture: any
+Multi-Arch: same
+Pre-Depends:
+ ${misc:Pre-Depends},
+Depends:
+ libopencv-cuda4.2 (= ${binary:Version}),
+ ${misc:Depends},
+ ${shlibs:Depends},
+Description: computer vision cuda support development library
diff --git a/debian/libopencv-cuda-dev.docs b/debian/libopencv-cuda-dev.docs
new file mode 100644
index 0000000..e174728
--- /dev/null
+++ b/debian/libopencv-cuda-dev.docs
@@ -0,0 +1 @@
+debian/README.Debian
diff --git a/debian/libopencv-cuda-dev.install b/debian/libopencv-cuda-dev.install
new file mode 100644
index 0000000..e7e6db6
--- /dev/null
+++ b/debian/libopencv-cuda-dev.install
@@ -0,0 +1,10 @@
+# head files
+usr/include/opencv4/opencv2/cuda*.hpp
+usr/include/opencv4/opencv2/cudalegacy/*.hpp
+usr/include/opencv4/opencv2/cudev.hpp
+usr/include/opencv4/opencv2/cudev/*
+# libraries
+usr/lib/*/libopencv_cuda*.a
+usr/lib/*/libopencv_cuda*.so
+usr/lib/x86_64-linux-gnu/libopencv_cudev.a
+usr/lib/x86_64-linux-gnu/libopencv_cudev.so
diff --git a/debian/libopencv-cuda4.2.install b/debian/libopencv-cuda4.2.install
new file mode 100644
index 0000000..b39b998
--- /dev/null
+++ b/debian/libopencv-cuda4.2.install
@@ -0,0 +1,2 @@
+usr/lib/*/libopencv_cuda*.so.*
+usr/lib/*/libopencv_cudev.so.*
diff --git a/debian/libopencv-cuda4.2.lintian-overrides b/debian/libopencv-cuda4.2.lintian-overrides
new file mode 100644
index 0000000..02222d1
--- /dev/null
+++ b/debian/libopencv-cuda4.2.lintian-overrides
@@ -0,0 +1 @@
+no-symbols-control-file
--
2.34.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment