Skip to content

Commit

Permalink
[TOOL][NATIVE] Android native application for deploy and run (#13791)
Browse files Browse the repository at this point in the history
* [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 <egor.churaev@gmail.com>

* Update apps/cpp_rtvm/README.md

Co-authored-by: Egor Churaev <egor.churaev@gmail.com>

* * review comments.

* * proof reading

* Update apps/cpp_rtvm/README.md

Co-authored-by: Egor Churaev <egor.churaev@gmail.com>

* * review

Co-authored-by: Egor Churaev <egor.churaev@gmail.com>
  • Loading branch information
srkreddy1238 and echuraev authored Jan 24, 2023
1 parent 1d89071 commit 1f40b92
Show file tree
Hide file tree
Showing 19 changed files with 1,248 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "3rdparty/OpenCL-Headers"]
path = 3rdparty/OpenCL-Headers
url = https://github.com/KhronosGroup/OpenCL-Headers.git
[submodule "3rdparty/cnpy"]
path = 3rdparty/cnpy
url = https://github.com/rogersce/cnpy.git
1 change: 1 addition & 0 deletions 3rdparty/cnpy
Submodule cnpy added at 4e8810
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,10 @@ if(USE_CPP_RPC)
add_subdirectory("apps/cpp_rpc")
endif()

if(USE_CPP_RTVM)
add_subdirectory("apps/cpp_rtvm")
endif()

if(USE_IOS_RPC)
add_subdirectory("apps/ios_rpc")
endif()
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ MIT License
3rdparty/libcrc
3rdparty/cma
3rdparty/compiler-rt/builtin_fp16.h
3rdparty/cnpy

The Unlicense
-------------
Expand Down
98 changes: 98 additions & 0 deletions apps/cpp_rtvm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
cmake_policy(SET CMP0069 NEW) # suppress cmake warning about IPO

set(RTVM_SOURCES
main.cc
tvm_runner.cc
../../3rdparty/cnpy/cnpy.cpp
)
set(TVM_RUNNER_SOURCES
tvm_runner.cc
../../3rdparty/cnpy/cnpy.cpp
)

set(RTVM_LINKER_LIBS "")

if(WIN32)
list(APPEND RTVM_SOURCES win32_process.cc)
list(APPEND TVM_RUNNER_SOURCES win32_process.cc)
endif()

# Set output to same directory as the other TVM libs
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_executable(rtvm ${RTVM_SOURCES})
add_library(tvm_runner_objs OBJECT ${TVM_RUNNER_SOURCES})
add_library(tvm_runner SHARED $<TARGET_OBJECTS:tvm_runner_objs>)

include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_property(TARGET rtvm PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
endif()

if(WIN32)
target_compile_definitions(rtvm PUBLIC -DNOMINMAX)
endif()

if (OS)
if (OS STREQUAL "Linux")
set_property(TARGET rtvm PROPERTY LINK_FLAGS -lpthread)
set_property(TARGET tvm_runner PROPERTY LINK_FLAGS -lpthread)
endif()
endif()

if(USE_OPENCL)
if (ANDROID_ABI)
if(DEFINED ENV{ANDROID_NDK_MAJOR})
if($ENV{ANDROID_NDK_MAJOR} VERSION_LESS "23")
set_property(TARGET rtvm PROPERTY LINK_FLAGS -fuse-ld=gold)
set_property(TARGET tvm_runner PROPERTY LINK_FLAGS -fuse-ld=gold)
endif()
endif()
endif()
endif()

target_include_directories(
rtvm
PUBLIC "../../include"
PUBLIC "../../3rdparty/cnpy"
PUBLIC DLPACK_PATH
PUBLIC DMLC_PATH
)

if (BUILD_FOR_ANDROID AND USE_HEXAGON)
get_hexagon_sdk_property("${USE_HEXAGON_SDK}" "${USE_HEXAGON_ARCH}"
DSPRPC_LIB DSPRPC_LIB_DIRS
)
if(DSPRPC_LIB_DIRS)
link_directories(${DSPRPC_LIB_DIRS})
else()
message(WARNING "Could not locate some Hexagon SDK components")
endif()
list(APPEND RTVM_LINKER_LIBS cdsprpc log)
endif()

if(USE_ETHOSN)
if (ETHOSN_RUNTIME_LIBRARY)
list(APPEND RTVM_LINKER_LIBS ${ETHOSN_RUNTIME_LIBRARY})
else()
message(WARNING "Could not locate Arm(R) Ethos(TM)-N runtime library components")
endif()
endif()

if(BUILD_STATIC_RUNTIME)
list(APPEND RTVM_LINKER_LIBS -Wl,--whole-archive tvm_runtime -Wl,--no-whole-archive z)
else()
list(APPEND RTVM_LINKER_LIBS tvm_runtime z)
endif()

target_link_libraries(rtvm ${RTVM_LINKER_LIBS})

# Build tvm_runner as a exportable lib
target_include_directories(
tvm_runner_objs
PUBLIC "../../include"
PUBLIC "../../3rdparty/cnpy"
PUBLIC DLPACK_PATH
PUBLIC DMLC_PATH
)
target_link_libraries(tvm_runner ${RTVM_LINKER_LIBS})
Loading

0 comments on commit 1f40b92

Please sign in to comment.