My goal is to cross compile OpenCV with CUDA support on my x86 host for an aarch64 target (Nvidia Xavier NX).
I am using this image as my build environment.
As an aside, I was successfully able to compile mxnet with CUDA support in that environment.
The environment has cuda-cross-aarch64
installed.
Here are some more details:
root@e77fb8d9c2f0:/usr/local/cuda# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
root@e77fb8d9c2f0:/usr/local/cuda# which nvcc
/usr/local/cuda/bin/nvcc
The environment correctly has the x86_64-linux
cuda target installed:
root@e77fb8d9c2f0:/usr/local/cuda/targets# ls -la
total 20
drwxr-xr-x 1 root root 4096 Apr 24 03:07 .
drwxr-xr-x 1 root root 4096 Apr 24 03:08 ..
drwxr-xr-x 1 root root 4096 Apr 24 03:07 aarch64-linux
drwxr-xr-x 1 root root 4096 Apr 20 05:29 x86_64-linux
Now here is where the challenge is.
I am trying to compile OpenCV, and I am using the following cmake command:
cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/targets/aarch64-linux -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_LIBRARY_PATH=/usr/local/cuda/targets/aarch64-linux/lib/stubs -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.1/modules -D WITH_CUDA=ON -D opencv_cudev=ON -DCUDA_ARCH_BIN='7.2' -DBUILD_opencv_cudev=ON -D WITH_CAROTENE=OFF -D BUILD_LIST=core,imgcodecs,imgproc,calib3d,videoio,highgui,cudev,cudaimgproc,cudaarithm,cudawarping -D BUILD_SHARED_LIBS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_opencv_apps=OFF -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D FORCE_VTK=OFF -D WITH_FFMPEG=OFF -D WITH_GDAL=OFF -D WITH_IPP=OFF -D WITH_OPENEXR=OFF -D WITH_OPENGL=OFF -D WITH_QT=OFF -D WITH_TBB=OFF -D WITH_XINE=OFF -D BUILD_JPEG=ON -D BUILD_ZLIB=ON -D BUILD_PNG=ON -D BUILD_TIFF=ON -D BUILD_BUILD_JASPER=OFF -D WITH_ITT=OFF -D WITH_LAPACK=OFF -D WITH_OPENCL=OFF -D WITH_TIFF=ON -D WITH_PNG=ON -D WITH_OPENCLAMDFFT=OFF -D WITH_OPENCLAMDBLAS=OFF -D WITH_VA_INTEL=OFF -D WITH_WEBP=OFF -D WITH_JASPER=OFF ..
The toolchain file contains the following:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_CUDA_COMPILER nvcc)
set(CMAKE_CUDA_HOST_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_FIND_ROOT_PATH "/usr/aarch64-linux-gnu")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
When running the command, CUDA is not found!
CMake Warning at cmake/OpenCVFindLibsPerf.cmake:35 (message):
OpenCV is not able to find/configure CUDA SDK (required by WITH_CUDA).
CUDA support will be disabled in OpenCV build.
To eliminate this warning remove WITH_CUDA=ON CMake configuration option.
Call Stack (most recent call first):
CMakeLists.txt:786 (include)
I opened an issue with the OpenCV team here, but they think the issue is not related to OpenCV, but instead my environment may not be set up correctly which is prevening the call to find_package(CUDA)
from succeeding.
Are you able to help me out? Are my CMake command incorrect? Or has my environment been potentially set up incorrectly. And if so, what’s the fix?