@@ -49,6 +49,7 @@ tvm_option(USE_FALLBACK_STL_MAP "Use TVM's POD compatible Map" OFF)
4949tvm_option(USE_ETHOSN "Build with Arm Ethos-N" OFF )
5050tvm_option(INDEX_DEFAULT_I64 "Defaults the index datatype to int64" ON )
5151tvm_option(USE_LIBBACKTRACE "Build libbacktrace to supply linenumbers on stack traces" AUTO)
52+ tvm_option(BUILD_STATIC_RUNTIME "Build static version of libtvm_runtime" OFF )
5253
5354# 3rdparty libraries
5455tvm_option(DLPACK_PATH "Path to DLPACK" "3rdparty/dlpack/include" )
@@ -73,6 +74,7 @@ tvm_option(USE_NNPACK "Build with nnpack support" OFF)
7374tvm_option(USE_RANDOM "Build with random support" ON )
7475tvm_option(USE_MICRO_STANDALONE_RUNTIME "Build with micro.standalone_runtime support" OFF )
7576tvm_option(USE_CPP_RPC "Build CPP RPC" OFF )
77+ tvm_option(USE_IOS_RPC "Build iOS RPC" OFF )
7678tvm_option(USE_TFLITE "Build with tflite support" OFF )
7779tvm_option(USE_TENSORFLOW_PATH "TensorFlow root path when use TFLite" none)
7880tvm_option(USE_COREML "Build with coreml support" OFF )
@@ -276,8 +278,18 @@ file(GLOB RUNTIME_SRCS
276278)
277279
278280if (BUILD_FOR_HEXAGON)
279- # Add file implementing posix_memalign.
280- list (APPEND RUNTIME_SRCS src/runtime/hexagon/hexagon_posix.cc)
281+ # Add file implementing posix_memalign when building the runtime as
282+ # a shared library.
283+ # This function is actually defined in the static libc, but when linking
284+ # a shared library, libc is not linked into it. Some runtime systems
285+ # don't implement posix_runtime, which causes runtime failires.
286+ # To avoid this issue, Hexagon runtime contains an implementation of
287+ # posix_memalign, but it should only be used with the dynamic TVM
288+ # runtime, since it would cause multiple definition errors with the
289+ # static one.
290+ if (NOT BUILD_STATIC_RUNTIME)
291+ list (APPEND RUNTIME_SRCS src/runtime/hexagon/hexagon_posix.cc)
292+ endif ()
281293
282294 add_definitions (-D_MACH_I32=int)
283295endif ()
@@ -403,7 +415,17 @@ add_library(tvm_runtime_objs OBJECT ${RUNTIME_SRCS})
403415
404416add_library (tvm SHARED $<TARGET_OBJECTS:tvm_objs> $<TARGET_OBJECTS:tvm_runtime_objs>)
405417set_property (TARGET tvm APPEND PROPERTY LINK_OPTIONS "${TVM_VISIBILITY_FLAG} " )
406- add_library (tvm_runtime SHARED $<TARGET_OBJECTS:tvm_runtime_objs>)
418+ if (BUILD_STATIC_RUNTIME)
419+ add_library (tvm_runtime STATIC $<TARGET_OBJECTS:tvm_runtime_objs>)
420+ set (NOTICE_MULTILINE
421+ "You have build static version of the TVM runtime library. Make "
422+ "sure to use --whole-archive when linking it into your project." )
423+ string (CONCAT NOTICE ${NOTICE_MULTILINE} )
424+ add_custom_command (TARGET tvm_runtime POST_BUILD
425+ COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --yellow --bold ${NOTICE} )
426+ else ()
427+ add_library (tvm_runtime SHARED $<TARGET_OBJECTS:tvm_runtime_objs>)
428+ endif ()
407429set_property (TARGET tvm_runtime APPEND PROPERTY LINK_OPTIONS "${TVM_VISIBILITY_FLAG} " )
408430target_compile_definitions (tvm_objs PUBLIC DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>)
409431target_compile_definitions (tvm_runtime_objs PUBLIC DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>)
@@ -424,6 +446,10 @@ if(USE_CPP_RPC)
424446 add_subdirectory ("apps/cpp_rpc" )
425447endif ()
426448
449+ if (USE_IOS_RPC)
450+ add_subdirectory ("apps/ios_rpc" )
451+ endif ()
452+
427453if (USE_RELAY_DEBUG)
428454 message (STATUS "Building Relay in debug mode..." )
429455 target_compile_definitions (tvm_objs PRIVATE "USE_RELAY_DEBUG" )
0 commit comments