VeriSilicon / tflite-vx-delegate

Tensorflow Lite external delegate based on TIM-VX
MIT License
41 stars 23 forks source link

Unable to build vx_delegate for A311D #201

Open ZephyrLabs opened 8 months ago

ZephyrLabs commented 8 months ago

I have searched a lot and still could not find the necessary documentation to compile the vx_delegate for the A311D on linux.

To verify, these are the commands I used to build the delegate.

cmake .. -DCONFIG=A311D -DEXTERNAL_VIV_SDK=$(pwd)/aarch64_A311D_6.4.8/include
Cmake logs (no errors suggested) -- Setting build type to Release, for debug builds use'-DCMAKE_BUILD_TYPE=Debug'. -- The C compiler identification is GNU 11.4.0 -- The CXX compiler identification is GNU 11.4.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Warning at build/abseil-cpp/CMakeLists.txt:70 (message): A future Abseil release will default ABSL_PROPAGATE_CXX_STD to ON for CMake 3.8 and up. We recommend enabling this option to ensure your project still builds correctly. -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE -- Performing Test standard_math_library_linked_to_automatically -- Performing Test standard_math_library_linked_to_automatically - Success -- Standard libraries to link to explicitly: none -- Performing Test COMPILER_SUPPORT_WERROR -- Performing Test COMPILER_SUPPORT_WERROR - Success -- Performing Test COMPILER_SUPPORT_pedantic -- Performing Test COMPILER_SUPPORT_pedantic - Success -- Performing Test COMPILER_SUPPORT_Wall -- Performing Test COMPILER_SUPPORT_Wall - Success -- Performing Test COMPILER_SUPPORT_Wextra -- Performing Test COMPILER_SUPPORT_Wextra - Success -- Performing Test COMPILER_SUPPORT_Wundef -- Performing Test COMPILER_SUPPORT_Wundef - Success -- Performing Test COMPILER_SUPPORT_Wcastalign -- Performing Test COMPILER_SUPPORT_Wcastalign - Success -- Performing Test COMPILER_SUPPORT_Wcharsubscripts -- Performing Test COMPILER_SUPPORT_Wcharsubscripts - Success -- Performing Test COMPILER_SUPPORT_Wnonvirtualdtor -- Performing Test COMPILER_SUPPORT_Wnonvirtualdtor - Success -- Performing Test COMPILER_SUPPORT_Wunusedlocaltypedefs -- Performing Test COMPILER_SUPPORT_Wunusedlocaltypedefs - Success -- Performing Test COMPILER_SUPPORT_Wpointerarith -- Performing Test COMPILER_SUPPORT_Wpointerarith - Success -- Performing Test COMPILER_SUPPORT_Wwritestrings -- Performing Test COMPILER_SUPPORT_Wwritestrings - Success -- Performing Test COMPILER_SUPPORT_Wformatsecurity -- Performing Test COMPILER_SUPPORT_Wformatsecurity - Success -- Performing Test COMPILER_SUPPORT_Wshorten64to32 -- Performing Test COMPILER_SUPPORT_Wshorten64to32 - Failed -- Performing Test COMPILER_SUPPORT_Wlogicalop -- Performing Test COMPILER_SUPPORT_Wlogicalop - Success -- Performing Test COMPILER_SUPPORT_Wenumconversion -- Performing Test COMPILER_SUPPORT_Wenumconversion - Success -- Performing Test COMPILER_SUPPORT_Wcpp11extensions -- Performing Test COMPILER_SUPPORT_Wcpp11extensions - Failed -- Performing Test COMPILER_SUPPORT_Wdoublepromotion -- Performing Test COMPILER_SUPPORT_Wdoublepromotion - Success -- Performing Test COMPILER_SUPPORT_Wshadow -- Performing Test COMPILER_SUPPORT_Wshadow - Success -- Performing Test COMPILER_SUPPORT_Wnopsabi -- Performing Test COMPILER_SUPPORT_Wnopsabi - Success -- Performing Test COMPILER_SUPPORT_Wnovariadicmacros -- Performing Test COMPILER_SUPPORT_Wnovariadicmacros - Success -- Performing Test COMPILER_SUPPORT_Wnolonglong -- Performing Test COMPILER_SUPPORT_Wnolonglong - Success -- Performing Test COMPILER_SUPPORT_fnochecknew -- Performing Test COMPILER_SUPPORT_fnochecknew - Success -- Performing Test COMPILER_SUPPORT_fnocommon -- Performing Test COMPILER_SUPPORT_fnocommon - Success -- Performing Test COMPILER_SUPPORT_fstrictaliasing -- Performing Test COMPILER_SUPPORT_fstrictaliasing - Success -- Performing Test COMPILER_SUPPORT_wd981 -- Performing Test COMPILER_SUPPORT_wd981 - Failed -- Performing Test COMPILER_SUPPORT_wd2304 -- Performing Test COMPILER_SUPPORT_wd2304 - Failed -- Performing Test COMPILER_SUPPORT_OPENMP -- Performing Test COMPILER_SUPPORT_OPENMP - Success -- The Fortran compiler identification is unknown -- Could NOT find CLANG_FORMAT: Found unsuitable version "0.0", but required is exact version "9" (found CLANG_FORMAT_EXECUTABLE-NOTFOUND) -- -- Configured Eigen 3.4.90 -- -- Performing Test FARMHASH_HAS_BUILTIN_EXPECT -- Performing Test FARMHASH_HAS_BUILTIN_EXPECT - Success -- Proceeding with version: 2.0.6.v2.0.6 -- Looking for strtof_l -- Looking for strtof_l - found -- Looking for strtoull_l -- Looking for strtoull_l - found -- CMAKE_CXX_FLAGS: -std=c++0x -Wall -pedantic -Werror -Wextra -Werror=shadow -faligned-new -Werror=implicit-fallthrough=2 -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter -fsigned-char -- Found Python3: /usr/bin/python3.10 (found suitable version "3.10.12", minimum required is "3.5") found components: Interpreter -- The ASM compiler identification is GNU -- Found assembler: /usr/bin/cc -- Downloading clog to /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/clog-source (define CLOG_SOURCE_DIR to avoid it) -- Configuring done -- Generating done -- Build files have been written to: /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/clog-download [ 11%] Creating directories for 'clog' [ 22%] Performing download step (download, verify and extract) for 'clog' -- Downloading... dst='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/clog-download/clog-prefix/src/4b5a76c4de21265ddba98fc8f259e136ad11411b.zip' timeout='none' inactivity timeout='none' -- Using src='https://github.com/pytorch/cpuinfo/archive/4b5a76c4de21265ddba98fc8f259e136ad11411b.zip' -- verifying file... file='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/clog-download/clog-prefix/src/4b5a76c4de21265ddba98fc8f259e136ad11411b.zip' -- Downloading... done -- extracting... src='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/clog-download/clog-prefix/src/4b5a76c4de21265ddba98fc8f259e136ad11411b.zip' dst='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/clog-source' -- extracting... [tar xfz] -- extracting... [analysis] -- extracting... [rename] -- extracting... [clean up] -- extracting... done [ 33%] No update step for 'clog' [ 44%] No patch step for 'clog' [ 55%] No configure step for 'clog' [ 66%] No build step for 'clog' [ 77%] No install step for 'clog' [ 88%] No test step for 'clog' [100%] Completed 'clog' [100%] Built target clog -- Downloading FP16 to /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FP16-source (define FP16_SOURCE_DIR to avoid it) -- Configuring done -- Generating done -- Build files have been written to: /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FP16-download [ 11%] Creating directories for 'fp16' [ 22%] Performing download step (download, verify and extract) for 'fp16' -- Downloading... dst='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FP16-download/fp16-prefix/src/0a92994d729ff76a58f692d3028ca1b64b145d91.zip' timeout='none' inactivity timeout='none' -- Using src='https://github.com/Maratyszcza/FP16/archive/0a92994d729ff76a58f692d3028ca1b64b145d91.zip' -- [download 4% complete] -- [download 13% complete] -- [download 15% complete] -- [download 22% complete] -- [download 39% complete] -- [download 43% complete] -- [download 45% complete] -- [download 69% complete] -- [download 100% complete] -- verifying file... file='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FP16-download/fp16-prefix/src/0a92994d729ff76a58f692d3028ca1b64b145d91.zip' -- Downloading... done -- extracting... src='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FP16-download/fp16-prefix/src/0a92994d729ff76a58f692d3028ca1b64b145d91.zip' dst='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FP16-source' -- extracting... [tar xfz] -- extracting... [analysis] -- extracting... [rename] -- extracting... [clean up] -- extracting... done [ 33%] No update step for 'fp16' [ 44%] No patch step for 'fp16' [ 55%] No configure step for 'fp16' [ 66%] No build step for 'fp16' [ 77%] No install step for 'fp16' [ 88%] No test step for 'fp16' [100%] Completed 'fp16' [100%] Built target fp16 -- Downloading FXdiv to /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FXdiv-source (define FXDIV_SOURCE_DIR to avoid it) -- Configuring done -- Generating done -- Build files have been written to: /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FXdiv-download [ 11%] Creating directories for 'fxdiv' [ 22%] Performing download step (download, verify and extract) for 'fxdiv' -- Downloading... dst='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FXdiv-download/fxdiv-prefix/src/b408327ac2a15ec3e43352421954f5b1967701d1.zip' timeout='none' inactivity timeout='none' -- Using src='https://github.com/Maratyszcza/FXdiv/archive/b408327ac2a15ec3e43352421954f5b1967701d1.zip' -- verifying file... file='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FXdiv-download/fxdiv-prefix/src/b408327ac2a15ec3e43352421954f5b1967701d1.zip' -- Downloading... done -- extracting... src='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FXdiv-download/fxdiv-prefix/src/b408327ac2a15ec3e43352421954f5b1967701d1.zip' dst='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/FXdiv-source' -- extracting... [tar xfz] -- extracting... [analysis] -- extracting... [rename] -- extracting... [clean up] -- extracting... done [ 33%] No update step for 'fxdiv' [ 44%] No patch step for 'fxdiv' [ 55%] No configure step for 'fxdiv' [ 66%] No build step for 'fxdiv' [ 77%] No install step for 'fxdiv' [ 88%] No test step for 'fxdiv' [100%] Completed 'fxdiv' [100%] Built target fxdiv -- Downloading pthreadpool to /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/pthreadpool-source (define PTHREADPOOL_SOURCE_DIR to avoid it) -- Configuring done -- Generating done -- Build files have been written to: /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/pthreadpool-download [ 11%] Creating directories for 'pthreadpool' [ 22%] Performing download step (download, verify and extract) for 'pthreadpool' -- Downloading... dst='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/pthreadpool-download/pthreadpool-prefix/src/545ebe9f225aec6dca49109516fac02e973a3de2.zip' timeout='none' inactivity timeout='none' -- Using src='https://github.com/Maratyszcza/pthreadpool/archive/545ebe9f225aec6dca49109516fac02e973a3de2.zip' -- [download 21% complete] -- [download 24% complete] -- [download 26% complete] -- [download 27% complete] -- [download 36% complete] -- [download 50% complete] -- [download 59% complete] -- [download 66% complete] -- [download 68% complete] -- [download 70% complete] -- [download 100% complete] -- verifying file... file='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/pthreadpool-download/pthreadpool-prefix/src/545ebe9f225aec6dca49109516fac02e973a3de2.zip' -- Downloading... done -- extracting... src='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/pthreadpool-download/pthreadpool-prefix/src/545ebe9f225aec6dca49109516fac02e973a3de2.zip' dst='/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/pthreadpool-source' -- extracting... [tar xfz] -- extracting... [analysis] -- extracting... [rename] -- extracting... [clean up] -- extracting... done [ 33%] No update step for 'pthreadpool' [ 44%] No patch step for 'pthreadpool' [ 55%] No configure step for 'pthreadpool' [ 66%] No build step for 'pthreadpool' [ 77%] No install step for 'pthreadpool' [ 88%] No test step for 'pthreadpool' [100%] Completed 'pthreadpool' [100%] Built target pthreadpool -- Downloading PSimd to /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/psimd-source (define PSIMD_SOURCE_DIR to avoid it) -- Configuring done -- Generating done -- Build files have been written to: /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/psimd-download [ 11%] Creating directories for 'psimd' [ 22%] Performing download step (git clone) for 'psimd' Cloning into 'psimd-source'... Your branch is up to date with 'origin/master'. Already on 'master' [ 33%] Performing update step for 'psimd' HEAD is now at 072586a Fix psimd_qfma_f32 for FMA-enabled x86 processors [ 44%] No patch step for 'psimd' [ 55%] No configure step for 'psimd' [ 66%] No build step for 'psimd' [ 77%] No install step for 'psimd' [ 88%] No test step for 'psimd' [100%] Completed 'psimd' [100%] Built target psimd Downloading A311D toolchain ... -- [download 0% complete] -- [download 1% complete] -- [download 2% complete] -- [download 3% complete] -- [download 4% complete] -- [download 5% complete] -- [download 6% complete] -- [download 7% complete] -- [download 8% complete] -- [download 9% complete] -- [download 10% complete] -- [download 11% complete] -- [download 12% complete] -- [download 13% complete] -- [download 14% complete] -- [download 15% complete] -- [download 16% complete] -- [download 17% complete] -- [download 18% complete] -- [download 19% complete] -- [download 20% complete] -- [download 21% complete] -- [download 22% complete] -- [download 23% complete] -- [download 24% complete] -- [download 25% complete] -- [download 26% complete] -- [download 27% complete] -- [download 28% complete] -- [download 29% complete] -- [download 30% complete] -- [download 31% complete] -- [download 32% complete] -- [download 33% complete] -- [download 34% complete] -- [download 35% complete] -- [download 36% complete] -- [download 37% complete] -- [download 38% complete] -- [download 39% complete] -- [download 40% complete] -- [download 41% complete] -- [download 42% complete] -- [download 43% complete] -- [download 44% complete] -- [download 45% complete] -- [download 46% complete] -- [download 47% complete] -- [download 48% complete] -- [download 49% complete] -- [download 50% complete] -- [download 51% complete] -- [download 52% complete] -- [download 53% complete] -- [download 54% complete] -- [download 55% complete] -- [download 56% complete] -- [download 57% complete] -- [download 58% complete] -- [download 59% complete] -- [download 60% complete] -- [download 61% complete] -- [download 62% complete] -- [download 63% complete] -- [download 64% complete] -- [download 65% complete] -- [download 66% complete] -- [download 67% complete] -- [download 68% complete] -- [download 69% complete] -- [download 70% complete] -- [download 71% complete] -- [download 72% complete] -- [download 73% complete] -- [download 74% complete] -- [download 75% complete] -- [download 76% complete] -- [download 77% complete] -- [download 78% complete] -- [download 79% complete] -- [download 80% complete] -- [download 81% complete] -- [download 82% complete] -- [download 83% complete] -- [download 84% complete] -- [download 85% complete] -- [download 86% complete] -- [download 87% complete] -- [download 88% complete] -- [download 89% complete] -- [download 90% complete] -- [download 91% complete] -- [download 92% complete] -- [download 93% complete] -- [download 94% complete] -- [download 95% complete] -- [download 96% complete] -- [download 97% complete] -- [download 98% complete] -- [download 99% complete] -- [download 100% complete] Downloading A311D SDK ... -- [download 0% complete] -- [download 1% complete] -- [download 2% complete] -- [download 3% complete] -- [download 4% complete] -- [download 5% complete] -- [download 6% complete] -- [download 7% complete] -- [download 8% complete] -- [download 9% complete] -- [download 10% complete] -- [download 11% complete] -- [download 12% complete] -- [download 13% complete] -- [download 14% complete] -- [download 15% complete] -- [download 16% complete] -- [download 17% complete] -- [download 18% complete] -- [download 19% complete] -- [download 20% complete] -- [download 21% complete] -- [download 22% complete] -- [download 23% complete] -- [download 24% complete] -- [download 25% complete] -- [download 26% complete] -- [download 27% complete] -- [download 28% complete] -- [download 29% complete] -- [download 30% complete] -- [download 31% complete] -- [download 32% complete] -- [download 33% complete] -- [download 34% complete] -- [download 35% complete] -- [download 36% complete] -- [download 37% complete] -- [download 38% complete] -- [download 39% complete] -- [download 40% complete] -- [download 41% complete] -- [download 42% complete] -- [download 43% complete] -- [download 44% complete] -- [download 45% complete] -- [download 46% complete] -- [download 47% complete] -- [download 48% complete] -- [download 49% complete] -- [download 50% complete] -- [download 51% complete] -- [download 52% complete] -- [download 53% complete] -- [download 54% complete] -- [download 55% complete] -- [download 56% complete] -- [download 57% complete] -- [download 58% complete] -- [download 59% complete] -- [download 60% complete] -- [download 61% complete] -- [download 62% complete] -- [download 63% complete] -- [download 64% complete] -- [download 65% complete] -- [download 66% complete] -- [download 67% complete] -- [download 68% complete] -- [download 69% complete] -- [download 70% complete] -- [download 71% complete] -- [download 72% complete] -- [download 73% complete] -- [download 74% complete] -- [download 75% complete] -- [download 76% complete] -- [download 77% complete] -- [download 78% complete] -- [download 79% complete] -- [download 80% complete] -- [download 81% complete] -- [download 82% complete] -- [download 83% complete] -- [download 84% complete] -- [download 85% complete] -- [download 86% complete] -- [download 87% complete] -- [download 88% complete] -- [download 89% complete] -- [download 90% complete] -- [download 91% complete] -- [download 92% complete] -- [download 93% complete] -- [download 94% complete] -- [download 95% complete] -- [download 96% complete] -- [download 97% complete] -- [download 98% complete] -- [download 99% complete] -- [download 100% complete] src/tim/vx src/tim/vx/internal -- Using ovxlib vip -- OVXLIB include directory: /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include;/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/src -- Using platform -- Configuring done -- Generating done -- Build files have been written to: /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build

After running make I get,

[  0%] Building CXX object _deps/tim-vx-build/src/tim/CMakeFiles/tim-vx.dir/vx/builtin_op.cc.o
In file included from /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/vsi_nn_platform.h:27:0,
                 from /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/utils/vsi_nn_util.h:32,
                 from /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/vsi_nn_log.h:28,
                 from /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/vsi_nn_pub.h:36,
                 from /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/builtin_op_impl.h:27,
                 from /home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/builtin_op.cc:26:
/home/zephyr/Documents/npu/tflite_vx/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/vsi_nn_feature_config.h:6:10: fatal error: VX/vx_khr_cnn.h: No such file or directory
 #include <VX/vx_khr_cnn.h>
          ^~~~~~~~~~~~~~~~~
compilation terminated.
make[3]: *** [_deps/tim-vx-build/src/tim/CMakeFiles/tim-vx.dir/build.make:76: _deps/tim-vx-build/src/tim/CMakeFiles/tim-vx.dir/vx/builtin_op.cc.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:6768: _deps/tim-vx-build/src/tim/CMakeFiles/tim-vx.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:1327: CMakeFiles/vx_delegate.dir/rule] Error 2
make: *** [Makefile:169: vx_delegate] Error 2

Could someone provide details on how to compile for the A311D ? All I see are mixed experiences of some unable to build and others able to build it without any step by step instructions.

Thank you in advance!

sunshinemyson commented 8 months ago

@ZephyrLabs ,

Please try to build & install TIM-VX firstly, then build vx-delegate with cmake -DTIM_VX_INSTALL=

Thanks

ZephyrLabs commented 8 months ago

@ZephyrLabs ,

Please try to build & install TIM-VX firstly, then build vx-delegate with cmake -DTIM_VX_INSTALL=

Thanks

@sunshinemyson I built TIM-VX with the right configuration for A311D and it successfully was built however back to building vx_delegate with cmake -DTIM_VX_INSTALL= pointing to the right directory ,

[100%] Linking CXX shared library libvx_delegate.so
/usr/bin/ld: /home/zephyr/Documents/npu/tflite_vx/tim-vx/build/install/lib/libtim-vx.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/vx_delegate.dir/build.make:244: libvx_delegate.so] Error 1
make[2]: *** [CMakeFiles/Makefile2:1269: CMakeFiles/vx_delegate.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:1276: CMakeFiles/vx_delegate.dir/rule] Error 2
make: *** [Makefile:169: vx_delegate] Error 2

It seems It's using the wrong linker, is there any additional configuration missing, perhaps relating to the toolchain directory ?

ZephyrLabs commented 8 months ago

Hello @sunshinemyson could you provide any guidance towards this issue ?

ZephyrLabs commented 8 months ago

I've solved this issue by just making the necessary changes to cross compile. I will share what I did for anyone trying to build the vx_delegate for the A311D or S905D3.

Cloning repo

Follow the official instructions to first download TIM-VX and TFLite VX delegate repositories.

mkdir wksp && cd wksp
# tim-vx is optional, it will be downloaded by CMake automatically for none-cross build
# if you want to do cross build with cmake, you have to build tim-vx firstly
git clone https://github.com/VeriSilicon/TIM-VX.git tim-vx
git clone https://github.com/VeriSilicon/tflite-vx-delegate.git

Build TIM-VX

Build the necessary Binaries TIM-VX, the -DCONFIG will change based on the SoC.

cd tim-vx
mkdir build && cd build

If you plan on building for the

after the configuration, run make -j4 and make install to build TIM-VX appropriately. The prepared TIM-VX install location is in wksp/tim-vx/build/install/

Also you need to make sure you have the cross compiler in an appropriate location, so that the next steps can have access to it. here we will copy the cross compiler to /opt run cp gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu -r /opt/


Build Tflite-vx-delegate

Configure cross compiling

Now proceed to build the vx delegate, say you are in the wksp/tim-vx/build, you will need to navigate to the tflite vx delegate directory with

cd ../../tflite-vx-delegate

Here is where you make the crucial changes to enable cross compiling. Copy this patch into a cross_compile.patch file in tflite-vx-delegate folder and git apply cross_compile.patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f06aa05..94f983e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,36 @@ cmake_minimum_required(VERSION 3.16)
 option(TFLITE_ENABLE_MULTI_DEVICE       "Enable multi devices support"          OFF)
 option(TFLITE_ENABLE_OPTIMIZE           "Enable optimize tiny yolov4"           OFF)

+# Platform defines.
+set(CMAKE_SYSTEM_NAME Linux)
+set(CMAKE_CROSSCOMPILING 1)
+set(DE_CPU "DE_CPU_ARM")
+set(CMAKE_SYSTEM_PROCESSOR "aarch64")
+
+
+set(CROSS_COMPILE_ENV "/opt/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu")
+set(ROOTFS "${CROSS_COMPILE_ENV}/aarch64-linux-gnu/libc")
+set(CMAKE_SYSROOT "${ROOTFS}")
+
+# Toolchain/compiler base.
+set(CROSS_COMPILE "${CROSS_COMPILE_ENV}/bin/aarch64-linux-gnu-" CACHE STRING "Cross compiler prefix")
+set(CMAKE_C_COMPILER "${CROSS_COMPILE}gcc")
+set(CMAKE_CXX_COMPILER "${CROSS_COMPILE}g++")
+
+set(CMAKE_FIND_ROOT_PATH
+        "${ROOTFS}/lib"
+        )
+
+# Search libs and include files (but not programs) from toolchain dir.
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY FIRST)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+
+add_definitions(-mtune=cortex-a53)

Note that this patch depends on the cross compiler being in /opt/

For the S905D3 alone, you will need to remove the add_definitions(-mtune=cortex-a53) line as it uses A55 cpu cores

Cross compile

now you can cross compile the delegate easily with the rest of the steps, remember to use the right path to the installed tim-vx, ie wksp/tim-vx/build/install/

mkdir build && cd build
cmake .. -DTIM_VX_INSTALL=../../tim-vx/build/install/
make vx_delegate -j4

The libvx_delegate.so file should be present in the build folder you are in.

Enjoy.

sunshinemyson commented 8 months ago

@ZephyrLabs ,

Thanks for the proposal, we will try to make a formal solution.

ZephyrLabs commented 8 months ago

Hello @sunshinemyson it seems there is a new issue

cc1: error: invalid feature modifier in ‘-march=armv8.2-a+bf16’
make[2]: *** [_deps/xnnpack-build/CMakeFiles/all_microkernels.dir/build.make:40242: _deps/xnnpack-build/CMakeFiles/all_microkernels.dir/src/bf16-gemm/gen/1x4c8-minmax-neonbf16-bfdot.c.o] Error 1
make[2]: *** Waiting for unfinished jobs..

Is there a newer cross-compiler which is recommended to use which supports this ?

chenfeiyue-cfy commented 7 months ago

Sorry for late reply. You need to ask your SoC for latest toolchain files. Besides that, A311D and S905D3 are two different chips, what toolchain to used is determined by chip manufacturers ,thanks.

ZephyrLabs commented 7 months ago

HI @chenfeiyue-cfy , sorry there must be confusion, I am not able to build tflite-vx-delegate with default steps and the toolchain specified by yourself. can you verify if it works on your side ?

Regards.

chenfeiyue-cfy commented 7 months ago

Hello @sunshinemyson it seems there is a new issue

cc1: error: invalid feature modifier in ‘-march=armv8.2-a+bf16’
make[2]: *** [_deps/xnnpack-build/CMakeFiles/all_microkernels.dir/build.make:40242: _deps/xnnpack-build/CMakeFiles/all_microkernels.dir/src/bf16-gemm/gen/1x4c8-minmax-neonbf16-bfdot.c.o] Error 1
make[2]: *** Waiting for unfinished jobs..

Is there a newer cross-compiler which is recommended to use which supports this ?

Here are some notes:

  1. The toolchain is not provided by us, we only received it from the manufacturer. It was generated by SoC vendor.
  2. Looks like you met build issue in XNNPack building, try disabling xnnpack build with -DTFLITE_ENABLE_XNNPACK=OFF and perhaps you will compile sucessfully.
  3. If it still not works, pelase Do Not set "-march=armv8.2-a+bf16" Thanks!
sunshinemyson commented 5 months ago

@chenfeiyue-cfy @ZephyrLabs ,

"-march=armv8.2-a+bf16" this is depends on your toolchains version. I have such failure before because given "arch" is not compatible with toolchain compiler version.

@ZephyrLabs , Please try @chenfeiyue-cfy 's suggestion.

Thanks