Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f40b92

Browse files
srkreddy1238echuraev
andauthoredJan 24, 2023
[TOOL][NATIVE] Android native application for deploy and run (#13791)
* [TOOL][NATIVE] Android native appliction for deploy and run This application helps as a reference for verifying and integration of TVM compiled models on Android targets natively independent of RPC setup. tvmc will be used to for compiling tuning and to run it before deployment. This PR also covers * Enabling clml for tvmc compilation tool. * Graph runtime api "get_output_info" to return output tensor specification similar to "get_input_into" * This tool adds and enabled 3rdparty dependency "cnpy" to deal with npz files. * Update apps/cpp_rtvm/README.md Co-authored-by: Egor Churaev <[email protected]> * Update apps/cpp_rtvm/README.md Co-authored-by: Egor Churaev <[email protected]> * * review comments. * * proof reading * Update apps/cpp_rtvm/README.md Co-authored-by: Egor Churaev <[email protected]> * * review Co-authored-by: Egor Churaev <[email protected]>
1 parent 1d89071 commit 1f40b92

File tree

19 files changed

+1248
-3
lines changed

19 files changed

+1248
-3
lines changed
 

‎.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
[submodule "3rdparty/OpenCL-Headers"]
2020
path = 3rdparty/OpenCL-Headers
2121
url = https://github.com/KhronosGroup/OpenCL-Headers.git
22+
[submodule "3rdparty/cnpy"]
23+
path = 3rdparty/cnpy
24+
url = https://github.com/rogersce/cnpy.git

‎3rdparty/cnpy

Submodule cnpy added at 4e8810b

‎CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ if(USE_CPP_RPC)
593593
add_subdirectory("apps/cpp_rpc")
594594
endif()
595595

596+
if(USE_CPP_RTVM)
597+
add_subdirectory("apps/cpp_rtvm")
598+
endif()
599+
596600
if(USE_IOS_RPC)
597601
add_subdirectory("apps/ios_rpc")
598602
endif()

‎LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ MIT License
234234
3rdparty/libcrc
235235
3rdparty/cma
236236
3rdparty/compiler-rt/builtin_fp16.h
237+
3rdparty/cnpy
237238

238239
The Unlicense
239240
-------------

‎apps/cpp_rtvm/CMakeLists.txt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
cmake_policy(SET CMP0069 NEW) # suppress cmake warning about IPO
2+
3+
set(RTVM_SOURCES
4+
main.cc
5+
tvm_runner.cc
6+
../../3rdparty/cnpy/cnpy.cpp
7+
)
8+
set(TVM_RUNNER_SOURCES
9+
tvm_runner.cc
10+
../../3rdparty/cnpy/cnpy.cpp
11+
)
12+
13+
set(RTVM_LINKER_LIBS "")
14+
15+
if(WIN32)
16+
list(APPEND RTVM_SOURCES win32_process.cc)
17+
list(APPEND TVM_RUNNER_SOURCES win32_process.cc)
18+
endif()
19+
20+
# Set output to same directory as the other TVM libs
21+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
22+
add_executable(rtvm ${RTVM_SOURCES})
23+
add_library(tvm_runner_objs OBJECT ${TVM_RUNNER_SOURCES})
24+
add_library(tvm_runner SHARED $<TARGET_OBJECTS:tvm_runner_objs>)
25+
26+
include(CheckIPOSupported)
27+
check_ipo_supported(RESULT result OUTPUT output)
28+
if(result)
29+
set_property(TARGET rtvm PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
30+
endif()
31+
32+
if(WIN32)
33+
target_compile_definitions(rtvm PUBLIC -DNOMINMAX)
34+
endif()
35+
36+
if (OS)
37+
if (OS STREQUAL "Linux")
38+
set_property(TARGET rtvm PROPERTY LINK_FLAGS -lpthread)
39+
set_property(TARGET tvm_runner PROPERTY LINK_FLAGS -lpthread)
40+
endif()
41+
endif()
42+
43+
if(USE_OPENCL)
44+
if (ANDROID_ABI)
45+
if(DEFINED ENV{ANDROID_NDK_MAJOR})
46+
if($ENV{ANDROID_NDK_MAJOR} VERSION_LESS "23")
47+
set_property(TARGET rtvm PROPERTY LINK_FLAGS -fuse-ld=gold)
48+
set_property(TARGET tvm_runner PROPERTY LINK_FLAGS -fuse-ld=gold)
49+
endif()
50+
endif()
51+
endif()
52+
endif()
53+
54+
target_include_directories(
55+
rtvm
56+
PUBLIC "../../include"
57+
PUBLIC "../../3rdparty/cnpy"
58+
PUBLIC DLPACK_PATH
59+
PUBLIC DMLC_PATH
60+
)
61+
62+
if (BUILD_FOR_ANDROID AND USE_HEXAGON)
63+
get_hexagon_sdk_property("${USE_HEXAGON_SDK}" "${USE_HEXAGON_ARCH}"
64+
DSPRPC_LIB DSPRPC_LIB_DIRS
65+
)
66+
if(DSPRPC_LIB_DIRS)
67+
link_directories(${DSPRPC_LIB_DIRS})
68+
else()
69+
message(WARNING "Could not locate some Hexagon SDK components")
70+
endif()
71+
list(APPEND RTVM_LINKER_LIBS cdsprpc log)
72+
endif()
73+
74+
if(USE_ETHOSN)
75+
if (ETHOSN_RUNTIME_LIBRARY)
76+
list(APPEND RTVM_LINKER_LIBS ${ETHOSN_RUNTIME_LIBRARY})
77+
else()
78+
message(WARNING "Could not locate Arm(R) Ethos(TM)-N runtime library components")
79+
endif()
80+
endif()
81+
82+
if(BUILD_STATIC_RUNTIME)
83+
list(APPEND RTVM_LINKER_LIBS -Wl,--whole-archive tvm_runtime -Wl,--no-whole-archive z)
84+
else()
85+
list(APPEND RTVM_LINKER_LIBS tvm_runtime z)
86+
endif()
87+
88+
target_link_libraries(rtvm ${RTVM_LINKER_LIBS})
89+
90+
# Build tvm_runner as a exportable lib
91+
target_include_directories(
92+
tvm_runner_objs
93+
PUBLIC "../../include"
94+
PUBLIC "../../3rdparty/cnpy"
95+
PUBLIC DLPACK_PATH
96+
PUBLIC DMLC_PATH
97+
)
98+
target_link_libraries(tvm_runner ${RTVM_LINKER_LIBS})

0 commit comments

Comments
 (0)
Please sign in to comment.