VeriSilicon / tflite-vx-delegate

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

Compiling tensorflow delegate for A311D #176

Closed RichardPar closed 1 year ago

RichardPar commented 1 year ago

Hi there,

I am trying to compile the TFlite delegate and get stuck on missing includes.. I can see the files there - but the makefiles dont seem to reflect the includes..

cmake .. -DCONFIG=A311D
make vx_delegate -j4

ichard@dell:~/Source/wksp/tflite-vx-delegate/build$ make vx_delegate -j4
[  0%] Built target pthreadpool
[  0%] Built target absl_spinlock_wait
[  0%] Built target absl_log_severity
[  0%] Built target absl_strerror
[  0%] Built target absl_int128
[  0%] Built target absl_time_zone
[  0%] Building CXX object _deps/tim-vx-build/src/tim/CMakeFiles/tim-vx.dir/vx/builtin_op.cc.o
[  0%] Building CXX object _deps/tim-vx-build/src/tim/CMakeFiles/tim-vx.dir/vx/builtin_op_impl.cc.o
Consolidate compiler generated dependencies of target absl_exponential_biased
[  0%] Building CXX object _deps/tim-vx-build/src/tim/CMakeFiles/tim-vx.dir/vx/compile_option.cc.o
[  0%] Built target absl_exponential_biased
In file included from /home/richard/Source/wksp/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/utils/vsi_nn_util.h:32:0,
                 from /home/richard/Source/wksp/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/vsi_nn_log.h:28,
                 from /home/richard/Source/wksp/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/vsi_nn_pub.h:36,
                 from /home/richard/Source/wksp/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/builtin_op_impl.h:27,
                 from /home/richard/Source/wksp/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/builtin_op_impl.cc:24:
/home/richard/Source/wksp/tflite-vx-delegate/build/_deps/tim-vx-src/src/tim/vx/internal/include/vsi_nn_platform.h:36: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:90: _deps/tim-vx-build/src/tim/CMakeFiles/tim-vx.dir/vx/builtin_op_impl.cc.o] Error 1
make[3]: *** Waiting for unfinished jobs....

The file is present

richard@dell:~/Source/wksp/tflite-vx-delegate/build$ find -name vx_khr_cnn.h
./aarch64_A311D_6.4.8/include/VX/vx_khr_cnn.h

What am I missing? ..

Richard

RichardPar commented 1 year ago

There are 2 unpacked files below


wksp/tflite-vx-delegate/build/_deps/tim-vx-build

aarch64_A311D_6.4.8.tgz
gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

run tar -xf [filename] in their current directories to extract and then start building - before getting excited, there is another error in the linking stage

[ 96%] Building CXX object CMakeFiles/vx_delegate.dir/utils.cc.o
[ 96%] Building CXX object CMakeFiles/vx_delegate.dir/vx_delegate_adaptor.cc.o
[100%] Linking CXX shared library libvx_delegate.so
/usr/bin/ld: _deps/tim-vx-build/src/tim/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:251: libvx_delegate.so] Error 1
make[2]: *** [CMakeFiles/Makefile2:1313: CMakeFiles/vx_delegate.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:1320: CMakeFiles/vx_delegate.dir/rule] Error 2
make: *** [Makefile:169: vx_delegate] Error 2

Looks like its using the hosts LD and not the cross compilers - well all of tflite is being built for the wrong platform... its not cross compiling anything!

RichardPar commented 1 year ago

Finally got it compiled - don't know if it works yet..

you need to use the external toolchain cmake - Whoever done the build system was having a bad day and only done half the job

RichardPar commented 1 year ago

Got it working eventually.. The Galcore.ko bundled on Khadas Fenix Debian is version 6.4.8.7.1.1.1 - which DOES NOT WORK!

I used the older version and it passes tests. Galcore version 6.4.6.2 (which is in this Git repository)

khadas@Khadas:~/MasterTest$ python3 test.py 
Vx delegate: allowed_cache_mode set to 0.
Vx delegate: device num set to 0.
Vx delegate: allowed_builtin_code set to 0.
Vx delegate: error_during_init set to 0.
Vx delegate: error_during_prepare set to 0.
Vx delegate: error_during_invoke set to 0.
<tflite_runtime.interpreter.Delegate object at 0x7fb243ffd0>
========== INPUT DETAILS ========
[{'name': 'serving_default_input_1:0', 'index': 0, 'shape': array([  1, 256, 256,   3], dtype=int32), 'shape_signature': array([  1, 256, 256,   3], dtype=int32), 'dtype': <class 'numpy.uint8'>, 'quantization': (0.003921568859368563, 0), 'quantization_parameters': {'scales': array([0.00392157], dtype=float32), 'zero_points': array([0], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]

====== OUTPUT DETAILS ==========
[{'name': 'StatefulPartitionedCall:0', 'index': 408, 'shape': array([   1, 4032,    6], dtype=int32), 'shape_signature': array([   1, 4032,    6], dtype=int32), 'dtype': <class 'numpy.uint8'>, 'quantization': (0.003994452301412821, 0), 'quantization_parameters': {'scales': array([0.00399445], dtype=float32), 'zero_points': array([0], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]
W [HandleLayoutInfer:281]Op 162: default layout inference pass.
W [HandleLayoutInfer:281]Op 162: default layout inference pass.
W [HandleLayoutInfer:281]Op 162: default layout inference pass.
W [HandleLayoutInfer:281]Op 162: default layout inference pass.
W [HandleLayoutInfer:281]Op 162: default layout inference pass.
W [HandleLayoutInfer:281]Op 162: default layout inference pass.
[[[  8   8  18  18   0 249]
  [  8   9  18  22   0 249]
  [  7   9  18  22   0 249]
  ...
  [227 229  48  44   0 249]
  [224 221  54  58   0 249]
  [224 224 129 112   0 249]]]