OpenCV 4.2.0 and CuDNN for Jetson Nano?

Jetpack 4.3
Installed with sdkmanager 1.0.0.5517

lsof /usr/lib/aarch64-linux-gnu/libcudnn.so.7.6.3
COMMAND PID USER  FD   TYPE DEVICE SIZE/OFF    NODE NAME
bash      1 root txt    REG  179,1  1046904 1431900 /bin/bash
bash      1 root mem    REG  179,1    43336 1432994 /lib/aarch64-linux-gnu/libnss_files-2.27.so
bash      1 root mem    REG  179,1    76592 1432988 /lib/aarch64-linux-gnu/libnsl-2.27.so
bash      1 root mem    REG  179,1    43344 1432998 /lib/aarch64-linux-gnu/libnss_nis-2.27.so
bash      1 root mem    REG  179,1    31344 1432990 /lib/aarch64-linux-gnu/libnss_compat-2.27.so
bash      1 root mem    REG  179,1  1341080 1432914 /lib/aarch64-linux-gnu/libc-2.27.so
bash      1 root mem    REG  179,1    18544 1432931 /lib/aarch64-linux-gnu/libdl-2.27.so
bash      1 root mem    REG  179,1   162432 1433041 /lib/aarch64-linux-gnu/libtinfo.so.5.9
bash      1 root mem    REG  179,1   125896 1432888 /lib/aarch64-linux-gnu/ld-2.27.so
lsof     46 root txt    REG  179,1   171304 1442074 /usr/bin/lsof
lsof     46 root mem    REG  179,1   137848 1433018 /lib/aarch64-linux-gnu/libpthread-2.27.so
lsof     46 root mem    REG  179,1    18544 1432931 /lib/aarch64-linux-gnu/libdl-2.27.so
lsof     46 root mem    REG  179,1   399136 1433015 /lib/aarch64-linux-gnu/libpcre.so.3.13.3
lsof     46 root mem    REG  179,1  1341080 1432914 /lib/aarch64-linux-gnu/libc-2.27.so
lsof     46 root mem    REG  179,1   134296 1433028 /lib/aarch64-linux-gnu/libselinux.so.1
lsof     46 root mem    REG  179,1   125896 1432888 /lib/aarch64-linux-gnu/ld-2.27.so
lsof     47 root txt    REG  179,1   171304 1442074 /usr/bin/lsof
lsof     47 root mem    REG  179,1   137848 1433018 /lib/aarch64-linux-gnu/libpthread-2.27.so
lsof     47 root mem    REG  179,1    18544 1432931 /lib/aarch64-linux-gnu/libdl-2.27.so
lsof     47 root mem    REG  179,1   399136 1433015 /lib/aarch64-linux-gnu/libpcre.so.3.13.3
lsof     47 root mem    REG  179,1  1341080 1432914 /lib/aarch64-linux-gnu/libc-2.27.so
lsof     47 root mem    REG  179,1   134296 1433028 /lib/aarch64-linux-gnu/libselinux.so.1
lsof     47 root mem    REG  179,1   125896 1432888 /lib/aarch64-linux-gnu/ld-2.27.so
root@c74dcc260e4c:/# apt search cudnn
Sorting... Done
Full Text Search... Done
libcudnn7/stable 7.6.3.28-1+cuda10.0 arm64
  cuDNN runtime libraries

libcudnn7-dev/stable 7.6.3.28-1+cuda10.0 arm64
  cuDNN development libraries and headers

libcudnn7-doc/stable 7.6.3.28-1+cuda10.0 arm64
  cuDNN documents and samples

nvidia-container-csv-cudnn/stable 7.6.3.28-1+cuda10.0 arm64
  Jetpack CUDNN CSV file

I don’t think that image can work unless Nvidia rebuilds it. my understanding of nvidia docker on Tegra is this kind of hacky. It bind mounts a bunch of stuff from the host, so things need to always be in sync. My understanding is it was done to reduce image size. I hope they find a better way. It’s why I’ve been avoiding Nvidia docker on Tegra.

will there be any chance to install cudnn with apt in the future? within l4T container?

Looks like you should be able to already:

Tegra:

 $ apt search cudnn
Sorting... Done
Full Text Search... Done
libcudnn7/stable,now 7.6.3.28-1+cuda10.0 arm64 [installed]
  cuDNN runtime libraries

libcudnn7-dev/stable,now 7.6.3.28-1+cuda10.0 arm64 [installed]
  cuDNN development libraries and headers

x86-64:

 $ apt search cudnn
Sorting... Done
Full Text Search... Done
libcudnn7/unknown,now 7.6.5.32-1+cuda10.2 amd64 [installed,automatic]
  cuDNN runtime libraries

libcudnn7-dev/unknown,now 7.6.5.32-1+cuda10.2 amd64 [installed]
  cuDNN development libraries and headers

That’s a possible solution to make a unified Dockerfile for Tegra and x86.

Edit: you will probably have to install nvidia’s apt sources and keys on a stock Ubuntu aarch64 image (or find an nvidia one with online apt repos already enabled). Unfortunately nvidia has no keyserver for Tegra so you’ll have to grab it from the bsp tarball. This means no unified Dockerfile, i suppose, but it does mean fewer differences at least.

yes, I caninstall libcudnn7 on a generic arm64 ubuntu within docker container at Jetson:

However it won’t work for l4t container because of the existing binding with the system wide configuration, probably:

unable to make backup link of './usr/lib/aarch64-linux-gnu/libcudnn.so.7.6.3' before installing new version: Invalid cross-device link dmesg: read kernel buffer failed: Operation not permitted 

Yes. The L4T image can’t work because of how it’s designed, however it might edit: it does (reading comprehension fail) if you start from Ubuntu aarch64.

FROM ubuntu:bionic

... build args and stuff ...

RUN download L4T bsp \
    && extract \
    && copy apt key as asc and use `apt-key` \
    && add apt sources (this is board dependent unfortunately, so a build argument may be what you want) \
    && delete tarball and extracted files

RUN apt-get update && apt-get install -y --no-install-recommends \
    all \
    your \
    runtime \
    deps \
    including \
    tensorrt

RUN apt-get update && apt-get install -y --no-install-recommends \
    all-dev \
    build-dev \
    deps-dev \
    && get your app source \
    && build source \
    && make install \
    && delete source \
    && apt-get purge -y --autoremove \
    all-dev \
    build-dev \
    deps-dev

USER appuser:appuser (create it above somewhere)
ENTRYPOINT [ "yourapp", "--someflag" ]

Is the basic idea. I have no idea if it will work but I if you install all of the things inside the image It could possibly avoid the bind mount related issues.

I am unsure of how and if you can turn that off with nvidia docker on Tegra. I haven’t used it so IDK if the -v options are passed in a wrapper script or an alias or what. You’ll have to investigate and modify accordingly
 Or wait for Nvidia to modify the design so it works as on x86, which is frankly great.

Ideally, IMO, a Dockerfile that works on x86-64 nvidia-docker should also work on Tegra, and if it doesn’t, nvidia-docker needs fixing (and potentially apt repos and a lot of other things).

I also am getting the same issue with installation of opencv 4.3 on Xavier; It locates that cudnn is installed, but it would not recognise it to be a fit fro opencv installation

(Reading database ... 194764 files and directories currently installed.)
Preparing to unpack libcudnn8-dev_8.0.0.145-1+cuda10.2_arm64.deb ...
update-alternatives: removing manually selected alternative - switching libcudnn to auto mode
Unpacking libcudnn8-dev (8.0.0.145-1+cuda10.2) over (8.0.0.145-1+cuda10.2) ...
Setting up libcudnn8-dev (8.0.0.145-1+cuda10.2) ...
update-alternatives: using /usr/include/aarch64-linux-gnu/cudnn_v8.h to provide /usr/include/cudnn.h (libcudnn) in auto mode
nvidia@linux:~/Downloads/deb$ sudo ldconfig
nvidia@linux:~/Downloads/deb$ cd ..
nvidia@linux:~/Downloads$ cd ..
nvidia@linux:~$ cd opencv-4.3.0/
nvidia@linux:~/opencv-4.3.0$ cd build/
nvidia@linux:~/opencv-4.3.0/build$ cmake -D WITH_CUDA=ON -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -DWITH_CUBLAS=1 -D CUDA_ARCH_BIN="7.2" -D CUDA_ARCH_PTX="" -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=ON  -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.3.0/modules -D  BUILD_opencv_python3=yes  -D PYTHON_LIBRARY=/usr/lib/python3.6/config-3.6m-aarch64-linux-gnu/libpython3.6m.so  -D BUILD_opencv_cudacodec=OFF -D OPENCV_GENERATE_PKGCONFIG=ON  ..
-- Detected processor: aarch64
-- Looking for ccache - not found
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found suitable version "1.2.11", minimum required is "1.2.3") 
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1)
-- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR) 
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found version "1.2.11") 
-**- Could NOT find CUDNN: Found unsuitable version "..", but required is at least "7.5" (found /usr/lib/aarch64-linux-gnu/libcudnn.so)**
-- CUDA detected: 10.2
-- CUDA NVCC target flags: -gencode;arch=compute_72,code=sm_72;-D_FORCE_INLINES
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR) 

If you check my Docker Hub page, I have working images for OpenCV 4.2.0 and 4.3.0, however they can’t work with the latest jetpack for now because of the way nvidia Docker works on Tegra (bind mounting libs).

https://hub.docker.com/r/mdegans/tegra-opencv/tags

For the moment, 4.3.0 won’t build with cudnn8. I expect to OpenCV maintainers will fix it shortly. It’s a “won’t fix” issue on my build script currently. If you care about using cudnn and OpenCV, you may have to downgrade the package if that’s at all possible. Normally you could pin it, but since there are different apt sources
 :-\

You would try adding: -D CUDNN_VERSION="8.0" to your cmake command.

1 Like

That’s a good suggestion @Honey_Patouceul. I added it to the issue. If anybody tries it, please let me know if it works or not. RN I need my machines on 4.3 for some extended testing.

Hello,
Work perfectly ! But i have another error


Starting cmake
-- Detected processor: aarch64
-- Looking for ccache - found (/usr/bin/ccache)
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found suitable version "1.2.11", minimum required is "1.2.3")
-- Found OpenJPEG: openjp2 (found version "2.3.1")
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found version "1.2.11")
-- Found TBB (env): /usr/lib/aarch64-linux-gnu/libtbb.so
 
**CMake Error at cmake/FindCUDNN.cmake:68 (file): file failed to open for reading (No such file or directory): /usr/lib/aarch64-linux-gnu/cudnn.h**
**Call Stack (most recent call first):**
**  cmake/OpenCVUtils.cmake:131 (find_package)**
**  cmake/OpenCVDetectCUDA.cmake:42 (find_host_package)**
**  cmake/OpenCVFindLibsPerf.cmake:43 (include)**
**  CMakeLists.txt:687 (include)**


-- Found CUDNN: /usr/lib/aarch64-linux-gnu/libcudnn.so (found suitable version "8.0", minimum required is "7.5")
-- CUDA detected: 10.2

– cuDNN: YES (ver 8.0)

It’s done.
i find :

Starting cmake
-- Detected processor: aarch64
-- Looking for ccache - found (/usr/bin/ccache)
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found suitable version "1.2.11", minimum required is "1.2.3")
-- Found OpenJPEG: openjp2 (found version "2.3.1")
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found version "1.2.11")
-- Found TBB (env): /usr/lib/aarch64-linux-gnu/libtbb.so
-- Found CUDNN: /usr/lib/aarch64-linux-gnu/libcudnn.so (found suitable version "8.0", minimum required is "7.5")
-- CUDA detected: 10.2
-- CUDA NVCC target flags: -gencode;arch=compute_72,code=sm_72;-D_FORCE_INLINES

with :

-D WITH_CUDNN=ON \
-D WITH_V4L=ON \
-D OPENCV_DNN_CUDA=ON \
-D CUDNN_VERSION='8.0' \
-D CUDNN_INCLUDE_DIR='/usr/include/' \

OpenCV4.3
JetPack 4.4 DP

3 Likes

Tyvm for testing, @Hergo! Can you submit a PR? If. It I will do it and make a note of your contribution.

I’m french sorry i don’t understand PR ?

A pull request on GitHub. There are several people including myself that have OpenCV build scripts That will need to be updated with the fix.

https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.1.1_Jetson.sh

If you’ve never done one before, that’s fine too. In this case I’ll probably add it later today or on Monday to the development branch, and post a note back here giving you and @Honey_Patouceul credit.

yes, the argument specifying the version of CUDNN works.
maybe it will even work for installing the latest opencv with cudnn within a l4t container

1 Like

I got the whole open CV in a container thing working.

https://hub.docker.com/r/mdegans/tegra-opencv/tags

If you’re using JetPack 4.4, you’ll probably have to wait for a new build, but JetPack 4.3 works with OpenCV 4.2 and 4.3. I will launch a new build tomorrow and push it to Docker hub, but I’m not sure what tags I’ll use for JetPack 4.4.

@mdegans
Thank you for sharing.

hi,

sorry but for me it’s not Jetson Nano, it’s Xavier :

NVIDIA Jetson AGX Xavier - Jetpack 4.4 DP [L4T 32.4.2]

 - Up Time:        1 days 0:50:36                                                     Version: 2.0.4
 - Jetpack:        4.4 DP [L4T 32.4.2]                                                 Author: Raffaello Bonghi
 - Board:                                                                              e-mail: raffaello@rnext.it
   * Board(s):     P2888-0001, P2822-0000
   * Code Name:    galen
   * GPU-Arch:     7.2
   * SN:           
   * SOC:          tegra194 - ID:25
   * Type:         AGX Xavier
 - Libraries:
   * CUDA:         10.2.89
   * OpenCV:       4.3.0-dev compiled CUDA: YES
   * TensorRT:     7.1.0.16
   * VisionWorks:  1.6.0.501
   * cuDNN:        8.0.0.145
 - Hostname:       xavier
 - Interfaces:
   * eth0:         
   * docker0:      

OpenCV4.3 :

--   CPU/HW features:
--     Baseline:                    NEON FP16
--       required:                  NEON
--       disabled:                  VFPV3
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 7.5.0)
--     C++ flags (Release):         [...]
--     C++ flags (Debug):           [...]
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           [...]
--     C flags (Debug):            [...]
--     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed
--     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed
--     ccache:                      YES
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 [...]
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv java js matlab ovis python2 python3 sfm
--     Applications:                tests perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   GUI:
--     GTK+:                        YES (ver 3.22.30)
--       GThread :                  YES (ver 2.56.4)
--       GtkGlExt:                  NO
--     OpenGL support:              NO
--     VTK support:                 YES (ver 8.2.0)
--
--   Media I/O:
--     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        /usr/lib/aarch64-linux-gnu/libwebp.so (ver encoder: 0x020e)
--     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34)
--     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
--     JPEG 2000:                   OpenJPEG (ver 2.3.1)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      YES (2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (57.107.100)
--       avformat:                  YES (57.83.100)
--       avutil:                    YES (55.78.100)
--       swscale:                   YES (4.8.100)
--       avresample:                YES (3.7.0)
--     GStreamer:                   YES (1.14.5)
--     v4l/v4l2:                    YES (linux/videodev2.h)
--
--   Parallel framework:            TBB (ver 2017.0 interface 9107)
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Lapack:                      YES (/usr/lib/aarch64-linux-gnu/liblapack.so /usr/lib/aarch64-linux-gnu/libcblas.so /usr/lib/aarch64-linux-gnu/libatlas.so)
--     Eigen:                       YES (ver 3.3.4)
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
--
--   NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             72
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 8.0)
--
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/hergo/Téléchargements/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 /home/hergo/Téléchargements/opencv43/bin/python3 (ver 3.6.9)
--     Libraries:                   NO
--     numpy:                       NO (Python3 wrappers can not be generated)
--     install path:                -
--
--   Python (for build):            /home/hergo/Téléchargements/opencv43/bin/python3
--     Pylint:                      /usr/bin/pylint (ver: 1.8.3, checks: 176)
--     Flake8:                      /usr/bin/flake8 (ver: 3.5.0)
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    /usr/local
-- -----------------------------------------------------------------

About the architecture issue and docker hub, I’m not sure why the metadata is wrong for that particular image. It may be the base image. It certainly something worth investigating, but is aarch64 for sure and it does work.

Re Argus: I think you just need to bind mount the Argus socket, it’s in /tmp. IIRC, --runtime nvidia does this for you.