opencvcudaembedded-linuxyoctotegra

Cross compile OpenCV with CUDA on x86-64 host for nvidia tk1 (arm) target using Yocto Project?


I want to build a custom Linux using the Yocto Project for a system using the nvidia tegra k1 processor, which has an arm cortex A 15 (32bit) and a GPU. Furthermore, OpenCV (version >= 3.0) with CUDA support needs to be installed.

Now when Bitbake tries to compile OpenCV with CUDA it crashes because nvcc throws an error Syntax error: word unexpected (expecting ")") which I learned is usually the case if you try to run an nvcc binary that is for the wrong system (e.g. 32bit-nvcc on 64bit-system). So I guess it just runs the nvcc that is suppost for the target system and therefore crashes.

  1. I don't know whether I need to compile using the usual x86-64bit-nvcc of the host system or (if this exists) some cross-compilation-nvcc.
  2. I need to know how I can involve said compiler into bitbake's process that builds OpenCV.

Solution

  • I figured it out:

    1. One needs to use an nvcc binary that supports the host architecture. To specify the target architecture on can pass it cross compilation flags (see http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#cross-compilation). These are passed via the the cmake flag -DCUDA_NVCC_FLAGS
    2. EXTRA_OECMAKE_append = "-DCUDA_NVCC_EXECUTABLE=${PATH_TO_THE_NVCC_BINARY}"

    The whole statement in the bbappend file could look like this

    EXTRA_OECMAKE_append = " \
        -DCUDA_NVCC_EXECUTABLE=${NVCC_BINARY} \ 
        -DCUDA_NVCC_FLAGS="--compiler-bindir ${GCC_BINARY}"  \
        "