OpenCV 4.9.0 Build with CUDA Failed on AGX Orin (JetPack 6.1) with Previously Provided Script

First of all, I hereby declare that I have already read Build opencv with cuda for Jetson AGX Orin but failed and 如何使用GPU版OpenCV? The solution to the problem seems very simple - just run the shell script provided.

However, the shell script that’s provided as the answers to the above 2 posts did not work for me. The make process produced an error at 20% progress.

7 errors detected in the compilation of “/home/spt/Downloads/workspace/opencv_contrib-4.9.0/modules/cudaarithm/src/cuda/minmax.cu”.
CMake Error at cuda_compile_1_generated_minmax.cu.o.RELEASE.cmake:282 (message):
Error generating file
/home/spt/Downloads/workspace/opencv-4.9.0/release/modules/cudaarithm/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_minmax.cu.o

17 errors detected in the compilation of “/home/spt/Downloads/workspace/opencv_contrib-4.9.0/modules/cudaarithm/src/cuda/minmaxloc.cu”.
CMake Error at cuda_compile_1_generated_minmaxloc.cu.o.RELEASE.cmake:282 (message):
Error generating file
/home/spt/Downloads/workspace/opencv-4.9.0/release/modules/cudaarithm/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_minmaxloc.cu.o

I have attached the full log here.

opencv4.9.0_install.log (1.2 MB)

Please kindly point out if there is a missing piece before running the script. I was under the impression that the script is a self-contained push-button script. The hardware that I am using is the Jetson AGX Orin 64GB Dev Kit.

Hi,

Thanks for reporting this.
We will give it a try and provide more info to you later.

Thanks.

Hi,

Please try the below script again.
https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.10.0_Jetpack6.1.sh

We have confirmed it can build and run as expected:

$ python3
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.10.0'
>>> cv2.cuda.printCudaDeviceInfo(0)
*** CUDA Device Query (Runtime API) version (CUDART static linking) *** 

Device count: 1

Device 0: "Orin"
  CUDA Driver Version / Runtime Version          12.60 / 12.60
  CUDA Capability Major/Minor version number:    8.7
  Total amount of global memory:                 62841 MBytes (65893351424 bytes)
  GPU Clock Speed:                               1.30 GHz
  Max Texture Dimension Size (x,y,z)             1D=(131072), 2D=(131072,65536), 3D=(16384,16384,16384)
  Max Layered Texture Size (dim) x layers        1D=(32768) x 2048, 2D=(32768,32768) x 2048
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per block:           1024
  Maximum sizes of each dimension of a block:    1024 x 1024 x 64
  Maximum sizes of each dimension of a grid:     2147483647 x 65535 x 65535
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and execution:                 Yes with 2 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            Yes
  Support host page-locked memory mapping:       Yes
  Concurrent kernel execution:                   Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support enabled:                No
  Device is using TCC driver mode:               No
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Bus ID / PCI location ID:           0 / 0
  Compute Mode:
      Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) 

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version  = 12.60, CUDA Runtime Version = 12.60, NumDevs = 1

>>> 

Thanks.

Thanks, @AastaLLL I can confirm that the script ran into completion without issue this time. I noticed that the change in the shell script was minimal - OpenCV version went from 4.9.0 to 4.10.0, and that was it. Does it mean JetPack 6.1 doesn’t support OpenCV 4.9.0? Is there a compatibility matrix somewhere that I can look up?

I went to the Python3 interpreter, but it couldn’t find any CUDA device:

$ python3
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.10.0'
>>> cv2.cuda.printCudaDeviceInfo(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.10.0) /io/opencv/modules/core/include/opencv2/core/private.cuda.hpp:106: error: (-216:No CUDA support) The library is compiled without CUDA support in function 'throw_no_cuda'

I took a closer look at your shell script, and found that the line 61 seems problematic.

echo ‘export PYTHONPATH=/usr/local/lib/python3.10/site-packages/:$PYTHONPATH’ >> ~/.bashrc

In my AGX Orin, there is actually no such path:

$ ls /usr/local/lib/python3.10
dist-packages

Under the dist-packages subfolder, I was able to locate cv2:

$ ls /usr/local/lib/python3.10/dist-packages/
cv2 jetson_stats-4.2.12.dist-info jtop numpy numpy-1.26.1.dist-info numpy.libs smbus2 smbus2-0.5.0.dist-info

I modified the $PYTHONPATH variable by replacing site-packages with dist-packages in my ~/.bashrc. After re-sourcing the .bashrc script, I was able to see CUDA device info in Python3, just like what you showed.

Should the line 61 in the shell script be modified?

Hi,

Thanks a lot. We will give it a check.

JetPack 6.1 uses CUDA 12.6 which requires a commit to support CUDA>12.4 so we move the version to 4.10.0 to get the fix.

Thanks.

Hi,

Did you give it a check?

I’ve also successfully install opencv4.10.0 using your script and confirm it can build and run expected.

My question is: if I want to run the opencv in venv then I have to activate the venv and running your script again - right? Is there any other way?

Thanks, Khanh

Never mind. I created a new virtual environment with the option --system-site-packages and now can use opencv within venv as well.

Thanks, Khanh