使用 yocto project. bitbake meta-toolchain 得到 /opt/下面的交叉编译.
source /opt/fsl-wayland/4.0/environment-setup-cortexa53-crypto-fsl-linux 这样得到了 $CC 的环境变量. 这样 makefile 或者直接命令行用 $CC即可使用交叉编译器.
TensorFlowlite 的编译
1.
用 yocto project. bitbake imx-image-full 这个要非常非常久的时间. 下载编译需要至少 300GB 空间.
2. 直接下载 tensorflow-lite-imx, 然后编译得到 .a 或者 .so
静态编译 . 得到 libtensorflow-lite.a
-
mkdir build_static
-
cd build_static
-
-
ARMCC_PREFIX=aarch64-fsl-linux-
-
ARMCC_FLAGS="-funsafe-math-optimizations -mcpu=cortex-a53 -march=armv8-a+crc+crypto -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/fsl-wayland/4.0/sysroots/cortexa53-crypto-fsl-linux"
-
cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc \
-
-DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ \
-
-DCMAKE_C_FLAGS="${ARMCC_FLAGS}" \
-
-DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" \
-
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-
-DCMAKE_SYSTEM_NAME=Linux \
-
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-
../tensorflow/lite/
-
-
得到 libtensorflow-lite.a
-
-
其中会编译到 label_image 的测试程序. 编译连接为
-
cd /home/ray/imx8mp/tensorflow-imx/build/examples/label_image
-
-
/opt/fsl-wayland/4.0/sysroots/x86_64-fslsdk-linux/usr/bin/cmake -E cmake_link_script CMakeFiles/label_image.dir/link.txt --verbose=1
-
-
/opt/fsl-wayland/4.0/sysroots/x86_64-fslsdk-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-g++ --sysroot=/opt/fsl-wayland/4.0/sysroots/cortexa53-crypto-fsl-linux -O2 -pipe -g -feliminate-unused-debug-types -O3 -DNDEBUG -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now CMakeFiles/label_image.dir/bitmap_helpers.cc.o CMakeFiles/label_image.dir/label_image.cc.o CMakeFiles/label_image.dir/home/ray/imx8mp/tensorflow-imx/tensorflow/core/util/stats_calculator.cc.o CMakeFiles/label_image.dir/__/__/profiling/memory_info.cc.o CMakeFiles/label_image.dir/__/__/profiling/profile_summarizer.cc.o CMakeFiles/label_image.dir/__/__/profiling/profile_summary_formatter.cc.o CMakeFiles/label_image.dir/__/__/profiling/time.cc.o CMakeFiles/label_image.dir/__/__/tools/command_line_flags.cc.o CMakeFiles/label_image.dir/__/__/tools/delegates/default_execution_provider.cc.o CMakeFiles/label_image.dir/__/__/tools/delegates/delegate_provider.cc.o CMakeFiles/label_image.dir/__/__/tools/evaluation/utils.cc.o CMakeFiles/label_image.dir/__/__/tools/tool_params.cc.o CMakeFiles/label_image.dir/__/__/tools/delegates/xnnpack_delegate_provider.cc.o CMakeFiles/label_image.dir/__/__/tools/delegates/external_delegate_provider.cc.o -o label_image ../../libtensorflow-lite.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_internal.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_marshalling.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_reflection.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_config.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_program_name.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_private_handle_accessor.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag_internal.a ../../_deps/abseil-cpp-build/absl/container/libabsl_raw_hash_set.a ../../_deps/abseil-cpp-build/absl/container/libabsl_hashtablez_sampler.a ../../_deps/abseil-cpp-build/absl/base/libabsl_exponential_biased.a ../../_deps/abseil-cpp-build/absl/hash/libabsl_hash.a ../../_deps/abseil-cpp-build/absl/hash/libabsl_city.a ../../_deps/abseil-cpp-build/absl/hash/libabsl_wyhash.a ../../_deps/abseil-cpp-build/absl/status/libabsl_status.a ../../_deps/abseil-cpp-build/absl/strings/libabsl_cord.a ../../_deps/abseil-cpp-build/absl/types/libabsl_bad_optional_access.a ../../_deps/abseil-cpp-build/absl/strings/libabsl_str_format_internal.a ../../_deps/abseil-cpp-build/absl/synchronization/libabsl_synchronization.a ../../_deps/abseil-cpp-build/absl/debugging/libabsl_stacktrace.a ../../_deps/abseil-cpp-build/absl/debugging/libabsl_symbolize.a ../../_deps/abseil-cpp-build/absl/debugging/libabsl_debugging_internal.a ../../_deps/abseil-cpp-build/absl/debugging/libabsl_demangle_internal.a ../../_deps/abseil-cpp-build/absl/synchronization/libabsl_graphcycles_internal.a ../../_deps/abseil-cpp-build/absl/base/libabsl_malloc_internal.a ../../_deps/abseil-cpp-build/absl/time/libabsl_time.a ../../_deps/abseil-cpp-build/absl/strings/libabsl_strings.a ../../_deps/abseil-cpp-build/absl/strings/libabsl_strings_internal.a ../../_deps/abseil-cpp-build/absl/base/libabsl_throw_delegate.a ../../_deps/abseil-cpp-build/absl/base/libabsl_base.a ../../_deps/abseil-cpp-build/absl/base/libabsl_spinlock_wait.a -lrt ../../_deps/abseil-cpp-build/absl/numeric/libabsl_int128.a ../../_deps/abseil-cpp-build/absl/time/libabsl_civil_time.a ../../_deps/abseil-cpp-build/absl/time/libabsl_time_zone.a ../../_deps/abseil-cpp-build/absl/types/libabsl_bad_variant_access.a ../../_deps/abseil-cpp-build/absl/base/libabsl_raw_logging_internal.a ../../_deps/abseil-cpp-build/absl/base/libabsl_log_severity.a ../../_deps/farmhash-build/libfarmhash.a ../../_deps/fft2d-build/libfft2d_fftsg2d.a ../../_deps/fft2d-build/libfft2d_fftsg.a ../../_deps/flatbuffers-build/libflatbuffers.a ../../_deps/ruy-build/ruy/libruy_context_get_ctx.a ../../_deps/ruy-build/ruy/libruy_context.a ../../_deps/ruy-build/ruy/libruy_frontend.a ../../_deps/ruy-build/ruy/libruy_kernel_arm.a ../../_deps/ruy-build/ruy/libruy_kernel_avx.a ../../_deps/ruy-build/ruy/libruy_kernel_avx2_fma.a ../../_deps/ruy-build/ruy/libruy_kernel_avx512.a ../../_deps/ruy-build/ruy/libruy_apply_multiplier.a ../../_deps/ruy-build/ruy/libruy_pack_arm.a ../../_deps/ruy-build/ruy/libruy_pack_avx.a ../../_deps/ruy-build/ruy/libruy_pack_avx2_fma.a ../../_deps/ruy-build/ruy/libruy_pack_avx512.a ../../_deps/ruy-build/ruy/libruy_prepare_packed_matrices.a ../../_deps/ruy-build/ruy/libruy_trmul.a ../../_deps/ruy-build/ruy/libruy_ctx.a ../../_deps/ruy-build/ruy/libruy_allocator.a ../../_deps/ruy-build/ruy/libruy_prepacked_cache.a ../../_deps/ruy-build/ruy/libruy_system_aligned_alloc.a ../../_deps/ruy-build/ruy/libruy_have_built_path_for_avx.a ../../_deps/ruy-build/ruy/libruy_have_built_path_for_avx2_fma.a ../../_deps/ruy-build/ruy/libruy_have_built_path_for_avx512.a ../../_deps/ruy-build/ruy/libruy_thread_pool.a ../../_deps/ruy-build/ruy/libruy_blocking_counter.a ../../_deps/ruy-build/ruy/libruy_wait.a ../../_deps/ruy-build/ruy/libruy_denormal.a ../../_deps/ruy-build/ruy/libruy_block_map.a ../../_deps/ruy-build/ruy/libruy_tune.a ../../_deps/ruy-build/ruy/libruy_cpuinfo.a ../../_deps/ruy-build/ruy/profiler/libruy_profiler_instrumentation.a -pthread -ldl ../../_deps/xnnpack-build/libXNNPACK.a /opt/fsl-wayland/4.0/sysroots/cortexa53-crypto-fsl-linux/usr/lib/libm.so ../../_deps/cpuinfo-build/libcpuinfo.a ../../_deps/clog-build/libclog.a ../../pthreadpool/libpthreadpool.a
-
动态库编译
-
修改 tensorflow/lite/CMakefile, 改成 ON
-
加个环境变量
-
TFLITE_BUILD_SHARED_LIB=1 ## 从 tensorflow/lite/CMakefile 中得到的.
-
执行静态库编译步骤. 得到 so
-
-
最后label_image 的编译命令为.
-
cd /home/ray/imx8mp/tensorflow-imx/so_build/tools/benchmark && /opt/fsl-wayland/4.0/sysroots/x86_64-fslsdk-linux/usr/bin/cmake -E cmake_link_script CMakeFiles/benchmark_model.dir/link.txt --verbose=1
/opt/fsl-wayland/4.0/sysroots/x86_64-fslsdk-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-g++ --sysroot=/opt/fsl-wayland/4.0/sysroots/cortexa53-crypto-fsl-linux -O2 -pipe -g -feliminate-unused-debug-types -O3 -DNDEBUG -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now CMakeFiles/benchmark_model.dir/benchmark_main.cc.o CMakeFiles/benchmark_model.dir/benchmark_model.cc.o CMakeFiles/benchmark_model.dir/benchmark_tflite_model.cc.o CMakeFiles/benchmark_model.dir/benchmark_utils.cc.o CMakeFiles/benchmark_model.dir/profiling_listener.cc.o CMakeFiles/benchmark_model.dir/home/ray/imx8mp/tensorflow-imx/tensorflow/core/util/stats_calculator.cc.o CMakeFiles/benchmark_model.dir/__/__/kernels/internal/utils/sparsity_format_converter.cc.o CMakeFiles/benchmark_model.dir/__/__/profiling/memory_info.cc.o CMakeFiles/benchmark_model.dir/__/__/profiling/memory_usage_monitor.cc.o CMakeFiles/benchmark_model.dir/__/__/profiling/profile_summarizer.cc.o CMakeFiles/benchmark_model.dir/__/__/profiling/profile_summary_formatter.cc.o CMakeFiles/benchmark_model.dir/__/__/profiling/time.cc.o CMakeFiles/benchmark_model.dir/__/command_line_flags.cc.o CMakeFiles/benchmark_model.dir/__/delegates/default_execution_provider.cc.o CMakeFiles/benchmark_model.dir/__/delegates/delegate_provider.cc.o CMakeFiles/benchmark_model.dir/__/evaluation/utils.cc.o CMakeFiles/benchmark_model.dir/__/tool_params.cc.o CMakeFiles/benchmark_model.dir/benchmark_performance_options.cc.o CMakeFiles/benchmark_model.dir/__/delegates/xnnpack_delegate_provider.cc.o CMakeFiles/benchmark_model.dir/__/delegates/external_delegate_provider.cc.o -o benchmark_model -Wl,-rpath,/home/ray/imx8mp/tensorflow-imx/so_build ../../libtensorflow-lite.so.2.8.0 ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_internal.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_marshalling.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_reflection.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_config.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_program_name.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_private_handle_accessor.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag.a ../../_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag_internal.a ../../_deps/abseil-cpp-build/absl/container/libabsl_raw_hash_set.a ../../_deps/abseil-cpp-build/absl/container/libabsl_hashtablez_sampler.a ../../_deps/abseil-cpp-build/absl/base/libabsl_exponential_biased.a ../../_deps/abseil-cpp-build/absl/hash/libabsl_hash.a ../../_deps/abseil-cpp-build/absl/hash/libabsl_city.a ../../_deps/abseil-cpp-build/absl/hash/libabsl_wyhash.a ../../_deps/abseil-cpp-build/absl/status/libabsl_status.a ../../_deps/abseil-cpp-build/absl/strings/libabsl_cord.a ../../_deps/abseil-cpp-build/absl/types/libabsl_bad_optional_access.a ../../_deps/abseil-cpp-build/absl/strings/libabsl_str_format_internal.a ../../_deps/abseil-cpp-build/absl/synchronization/libabsl_synchronization.a ../../_deps/abseil-cpp-build/absl/debugging/libabsl_stacktrace.a ../../_deps/abseil-cpp-build/absl/debugging/libabsl_symbolize.a ../../_deps/abseil-cpp-build/absl/debugging/libabsl_debugging_internal.a ../../_deps/abseil-cpp-build/absl/debugging/libabsl_demangle_internal.a ../../_deps/abseil-cpp-build/absl/synchronization/libabsl_graphcycles_internal.a ../../_deps/abseil-cpp-build/absl/base/libabsl_malloc_internal.a ../../_deps/abseil-cpp-build/absl/time/libabsl_time.a ../../_deps/abseil-cpp-build/absl/strings/libabsl_strings.a ../../_deps/abseil-cpp-build/absl/strings/libabsl_strings_internal.a ../../_deps/abseil-cpp-build/absl/base/libabsl_throw_delegate.a ../../_deps/abseil-cpp-build/absl/base/libabsl_base.a ../../_deps/abseil-cpp-build/absl/base/libabsl_spinlock_wait.a -lrt ../../_deps/abseil-cpp-build/absl/numeric/libabsl_int128.a ../../_deps/abseil-cpp-build/absl/time/libabsl_civil_time.a ../../_deps/abseil-cpp-build/absl/time/libabsl_time_zone.a ../../_deps/abseil-cpp-build/absl/types/libabsl_bad_variant_access.a ../../_deps/abseil-cpp-build/absl/base/libabsl_raw_logging_internal.a ../../_deps/abseil-cpp-build/absl/base/libabsl_log_severity.a ../../_deps/farmhash-build/libfarmhash.a ../../_deps/fft2d-build/libfft2d_fftsg2d.a ../../_deps/fft2d-build/libfft2d_fftsg.a ../../_deps/flatbuffers-build/libflatbuffers.a ../../_deps/ruy-build/ruy/libruy_context_get_ctx.a ../../_deps/ruy-build/ruy/libruy_context.a ../../_deps/ruy-build/ruy/libruy_frontend.a ../../_deps/ruy-build/ruy/libruy_kernel_arm.a ../../_deps/ruy-build/ruy/libruy_kernel_avx.a ../../_deps/ruy-build/ruy/libruy_kernel_avx2_fma.a ../../_deps/ruy-build/ruy/libruy_kernel_avx512.a ../../_deps/ruy-build/ruy/libruy_apply_multiplier.a ../../_deps/ruy-build/ruy/libruy_pack_arm.a ../../_deps/ruy-build/ruy/libruy_pack_avx.a ../../_deps/ruy-build/ruy/libruy_pack_avx2_fma.a ../../_deps/ruy-build/ruy/libruy_pack_avx512.a ../../_deps/ruy-build/ruy/libruy_prepare_packed_matrices.a ../../_deps/ruy-build/ruy/libruy_trmul.a ../../_deps/ruy-build/ruy/libruy_ctx.a ../../_deps/ruy-build/ruy/libruy_allocator.a ../../_deps/ruy-build/ruy/libruy_prepacked_cache.a ../../_deps/ruy-build/ruy/libruy_system_aligned_alloc.a ../../_deps/ruy-build/ruy/libruy_have_built_path_for_avx.a ../../_deps/ruy-build/ruy/libruy_have_built_path_for_avx2_fma.a ../../_deps/ruy-build/ruy/libruy_have_built_path_for_avx512.a ../../_deps/ruy-build/ruy/libruy_thread_pool.a ../../_deps/ruy-build/ruy/libruy_blocking_counter.a ../../_deps/ruy-build/ruy/libruy_wait.a ../../_deps/ruy-build/ruy/libruy_denormal.a ../../_deps/ruy-build/ruy/libruy_block_map.a ../../_deps/ruy-build/ruy/libruy_tune.a ../../_deps/ruy-build/ruy/libruy_cpuinfo.a ../../_deps/ruy-build/ruy/profiler/libruy_profiler_instrumentation.a -pthread -ldl ../../_deps/xnnpack-build/libXNNPACK.a /opt/fsl-wayland/4.0/sysroots/cortexa53-crypto-fsl-linux/usr/lib/libm.so ../../_deps/cpuinfo-build/libcpuinfo.a ../../_deps/clog-build/libclog.a ../../pthreadpool/libpthreadpool.a
-
-
阅读(1961) | 评论(0) | 转发(0) |