Skip to content

Commit 43105f5

Browse files
author
zhangdanfeng
committed
tflite compile script
Signed-off-by: zhangdanfeng <craft.zhang@space-t.cn>
1 parent 6564707 commit 43105f5

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

scripts/make_riscv.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
set -e
77

8+
make clean
9+
810
export TARGET_TOOLCHAIN_PREFIX=riscv64-unknown-linux-gnu-
911

1012
export TFLITE_BUILD_DIR=/home/craft/workspace/gem5/tensorflow_src/buildrv64
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
# tf v2.9.1 tested
6+
7+
set -e
8+
9+
# change to your path
10+
mkdir -p build_tflite
11+
12+
CMAKE_ARGS=()
13+
14+
# CMake-level configuration
15+
CMAKE_ARGS+=("-DCMAKE_MAKE_PROGRAM=make")
16+
CMAKE_ARGS+=("-DCMAKE_CROSSCOMPILING=1")
17+
CMAKE_ARGS+=("-DCMAKE_TOOLCHAIN_FILE=$(pwd)/scripts/tf/cmake/riscv64.JDSK.toolchain.cmake")
18+
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=RelWithDebInfo")
19+
20+
# Cross-compilation options for Google Benchmark
21+
22+
CMAKE_ARGS+=("-DHAVE_POSIX_REGEX=0")
23+
CMAKE_ARGS+=("-DHAVE_STEADY_CLOCK=0")
24+
CMAKE_ARGS+=("-DHAVE_STD_REGEX=0")
25+
26+
# install
27+
CMAKE_ARGS+=("-DCMAKE_INSTALL_PREFIX=$(pwd)/tflite")
28+
CMAKE_ARGS+=("-DTFLITE_ENABLE_INSTALL=ON")
29+
ABSL_ENABLE_INSTALL
30+
CMAKE_ARGS+=("-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON")
31+
CMAKE_ARGS+=("-Dabsl_DIR=$(pwd)/tflite/lib/cmake/absl")
32+
CMAKE_ARGS+=("-DEigen3_DIR=$(pwd)/tflite/share/eigen3/cmake")
33+
CMAKE_ARGS+=("-DFlatbuffers_DIR=$(pwd)/tflite/lib/cmake/flatbuffers")
34+
CMAKE_ARGS+=("-DNEON_2_SSE_DIR=$(pwd)/tflite/lib/cmake/NEON_2_SSE")
35+
CMAKE_ARGS+=("-Dcpuinfo_DIR=$(pwd)/tflite/share/cpuinfo")
36+
CMAKE_ARGS+=("-Druy_DIR=$(pwd)/tflite/lib/cmake/ruy")
37+
38+
# xnnpack
39+
CMAKE_ARGS+=("-DTFLITE_ENABLE_XNNPACK=ON")
40+
41+
# Use-specified CMake arguments go last to allow overridding defaults
42+
CMAKE_ARGS+=($@)
43+
44+
# change to your path
45+
pushd build_tflite
46+
47+
ccmake ../../tensorflow/tensorflow/lite "${CMAKE_ARGS[@]}"
48+
49+
cmake --build .
50+
51+
popd
52+
53+
# cp
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# CMake Toolchain file for crosscompiling on ARM.
3+
#
4+
# Target operating system name.
5+
set(CMAKE_SYSTEM_NAME Linux)
6+
set(CMAKE_SYSTEM_PROCESSOR aarch64)
7+
set(CMAKE_CROSSCOMPILING TRUE)
8+
9+
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
10+
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")
11+
12+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
13+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
14+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
15+
16+
# 增加SVE支持
17+
set(CMAKE_C_FLAGS "-march=armv8-a+sve")
18+
set(CMAKE_CXX_FLAGS "-march=armv8-a+sve")
19+
20+
# cache flags
21+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags")
22+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# CMake Toolchain file for crosscompiling on RV64.
3+
#
4+
# Target operating system name.
5+
#
6+
# usage: cmake -DCMAKE_TOOLCHAIN_FILE=riscv64.JDSK.toolchain.cmake
7+
#
8+
# static link
9+
#
10+
11+
set(CMAKE_SYSTEM_NAME Linux)
12+
set(CMAKE_SYSTEM_PROCESSOR riscv64)
13+
14+
if(DEFINED ENV{RISCV_ROOT_PATH})
15+
file(TO_CMAKE_PATH $ENV{RISCV_ROOT_PATH} RISCV_ROOT_PATH)
16+
else()
17+
message(FATAL_ERROR "RISCV_ROOT_PATH env must be defined")
18+
endif()
19+
20+
set(RISCV_ROOT_PATH ${RISCV_ROOT_PATH} CACHE STRING "root path to riscv toolchain")
21+
22+
set(CMAKE_C_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-gnu-gcc")
23+
set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-gnu-g++")
24+
25+
set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv64-unknown-linux-gnu")
26+
set(CMAKE_SYSROOT "${RISCV_ROOT_PATH}/sysroot")
27+
28+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
29+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
30+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
31+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
32+
33+
# march
34+
set(CMAKE_C_FLAGS "-march=rv64gcv -mabi=lp64d")
35+
set(CMAKE_CXX_FLAGS "-march=rv64gcv -mabi=lp64d")
36+
37+
# c/c++ std
38+
set(CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}")
39+
set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
40+
41+
# cache flags
42+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags")
43+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags")
44+
45+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
46+
47+
FIND_LIBRARY(LIBM libm.a)
48+
FIND_LIBRARY(LIBRT librt.a)

0 commit comments

Comments
 (0)