This is an automated email from the ASF dual-hosted git repository.

mehrdadh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new f6cebb5d60 [microTVM] additional refactoring for enabling USE_MICRO in 
more builds (#13909)
f6cebb5d60 is described below

commit f6cebb5d6020b74e294ff6293d45a50e3a2f68a3
Author: Alan MacDonald <[email protected]>
AuthorDate: Tue Feb 14 15:10:54 2023 -0800

    [microTVM] additional refactoring for enabling USE_MICRO in more builds 
(#13909)
    
    Additional changes that make it possible to enable USE_MICRO across nearly 
all builds except for hexagon or when USE_RPC is disabled. This mainly 
standardizes how the microTVM RPC common files are built across all platforms. 
There will be a follow-up PR that will enable USE_MICRO for nearly all build 
types once the best mechanism and behaviors for doing so is determined.
---
 CMakeLists.txt                                | 10 +--
 cmake/modules/StandaloneCrt.cmake             | 93 +++++++++++----------------
 include/tvm/runtime/c_runtime_api.h           |  7 ++
 include/tvm/runtime/crt/microtvm_rpc_server.h |  2 +
 src/runtime/crt/common/crt_runtime_api.c      |  8 +--
 5 files changed, 52 insertions(+), 68 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index abe415957e..e48ea780e9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -577,16 +577,10 @@ include(cmake/modules/contrib/PAPI.cmake)
 if(USE_MICRO)
   # NOTE: cmake doesn't track dependencies at the file level across 
subdirectories. For the
   # Unix Makefiles generator, need to add these explicit target-level 
dependency)
+  add_dependencies(tvm_runtime arduino)
   add_dependencies(tvm_runtime crt)
+  add_dependencies(tvm_runtime host_standalone_crt)
   add_dependencies(tvm_runtime zephyr)
-  add_dependencies(tvm_runtime arduino)
-  if(MSVC)
-    target_link_libraries(tvm PRIVATE host_standalone_crt )
-    target_link_libraries(tvm_runtime PRIVATE host_standalone_crt)
-  else()
-    add_dependencies(tvm host_standalone_crt)
-    add_dependencies(tvm_runtime host_standalone_crt)
-  endif()
 endif()
 
 if(USE_CPP_RPC)
diff --git a/cmake/modules/StandaloneCrt.cmake 
b/cmake/modules/StandaloneCrt.cmake
index 1d4e213ec7..96fcf5092a 100644
--- a/cmake/modules/StandaloneCrt.cmake
+++ b/cmake/modules/StandaloneCrt.cmake
@@ -15,33 +15,21 @@
 # specific language governing permissions and limitations
 # under the License.
 
-
 if(USE_MICRO)
 
-if(MSVC)
-
-  # When building for Windows, use standard CMake for compatibility with
-  # Visual Studio build tools and not require Make to be on the system.
-
-  # TODO: test building with this MSVC conditional code removed
-  # when USE_MICRO is enabled
+  message(STATUS "Build microTVM RPC common")
 
-  set(CRT_CONFIG, "src/runtime/micro/crt_config.h")
+  # add microTVM RPC common files to TVM runtime build
+  list(APPEND TVM_CRT_SOURCES
+      3rdparty/libcrc/src/crcccitt.c
+      src/runtime/crt/microtvm_rpc_common/frame_buffer.cc
+      src/runtime/crt/microtvm_rpc_common/framing.cc
+      src/runtime/crt/microtvm_rpc_common/session.cc
+      src/runtime/crt/microtvm_rpc_common/write_stream.cc)
 
-  add_library(host_standalone_crt
-              STATIC
-              3rdparty/libcrc/src/crcccitt.c
-              src/runtime/crt/microtvm_rpc_common/frame_buffer.cc
-              src/runtime/crt/microtvm_rpc_common/framing.cc
-              src/runtime/crt/microtvm_rpc_common/session.cc
-              src/runtime/crt/microtvm_rpc_common/write_stream.cc)
+  list(APPEND RUNTIME_SRCS ${TVM_CRT_SOURCES})
+  include_directories(SYSTEM src/runtime/micro)
 
-  target_include_directories(host_standalone_crt
-                             PRIVATE
-                             3rdparty/libcrc/include
-                             src/runtime/micro)
-
-else()
 
   function(create_crt_library CRT_LIBRARY)
 
@@ -49,7 +37,7 @@ else()
     set(CRT_LIBRARY_SOURCES "")
 
     foreach(FILE_NAME IN LISTS ARGN)
-       list(APPEND CRT_LIBRARY_SOURCES ${FILE_NAME})
+      list(APPEND CRT_LIBRARY_SOURCES ${FILE_NAME})
     endforeach()
 
     add_library(${CRT_LIBRARY_NAME}
@@ -60,9 +48,9 @@ else()
     set(CRT_LIBRARIES ${CRT_LIBRARIES} ${CRT_LIBRARY_NAME} PARENT_SCOPE)
 
     target_include_directories(${CRT_LIBRARY_NAME}
-                               PUBLIC
-                               ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro/
-                               ${STANDALONE_CRT_BASE}/include)
+                              PUBLIC
+                              ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro/
+                              ${STANDALONE_CRT_BASE}/include)
 
     set_target_properties(${CRT_LIBRARY_NAME}
                           PROPERTIES
@@ -75,7 +63,7 @@ else()
 
   endfunction()
 
-  message(STATUS "Build standalone CRT for microTVM")
+  message(STATUS "Build microTVM standalone CRT")
 
   # Build an isolated build directory, separate from the TVM tree.
   list(APPEND CRT_FILE_COPY_JOBS
@@ -147,32 +135,36 @@ else()
                     
${RUNTIME_CRT_SOURCE_DIR}/aot_executor_module/aot_executor_module.c)
 
   create_crt_library(graph_executor
-                     ${RUNTIME_CRT_SOURCE_DIR}/graph_executor/graph_executor.c
-                     ${RUNTIME_CRT_SOURCE_DIR}/graph_executor/load_json.c)
+                    ${RUNTIME_CRT_SOURCE_DIR}/graph_executor/graph_executor.c
+                    ${RUNTIME_CRT_SOURCE_DIR}/graph_executor/load_json.c)
 
   create_crt_library(graph_executor_module
-                     
${RUNTIME_CRT_SOURCE_DIR}/graph_executor_module/graph_executor_module.c)
+                    
${RUNTIME_CRT_SOURCE_DIR}/graph_executor_module/graph_executor_module.c)
 
   create_crt_library(memory
-                     ${RUNTIME_CRT_SOURCE_DIR}/memory/page_allocator.c
-                     ${RUNTIME_CRT_SOURCE_DIR}/memory/stack_allocator.c)
+                    ${RUNTIME_CRT_SOURCE_DIR}/memory/page_allocator.c
+                    ${RUNTIME_CRT_SOURCE_DIR}/memory/stack_allocator.c)
 
   create_crt_library(microtvm_rpc_common
-                     ${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/crcccitt.c
-                     
${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/frame_buffer.cc
-                     ${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/framing.cc
-                     ${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/session.cc
-                     
${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/write_stream.cc)
+                    ${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/crcccitt.c
+                    
${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/frame_buffer.cc
+                    ${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/framing.cc
+                    ${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/session.cc
+                    
${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_common/write_stream.cc)
 
   create_crt_library(microtvm_rpc_server
-                     
${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_server/rpc_server.cc)
-
-  create_crt_library(common
-                     ${RUNTIME_CRT_SOURCE_DIR}/common/crt_backend_api.c
-                     ${RUNTIME_CRT_SOURCE_DIR}/common/crt_runtime_api.c
-                     ${RUNTIME_CRT_SOURCE_DIR}/common/func_registry.c
-                     ${RUNTIME_CRT_SOURCE_DIR}/common/ndarray.c
-                     ${RUNTIME_CRT_SOURCE_DIR}/common/packed_func.c)
+                    
${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_server/rpc_server.cc)
+
+  if(NOT MSVC)
+    # TODO: if we want to eventually build standalone_crt for windows
+    # these files would be needed, but for now don't build them
+    create_crt_library(common
+                      ${RUNTIME_CRT_SOURCE_DIR}/common/crt_backend_api.c
+                      ${RUNTIME_CRT_SOURCE_DIR}/common/crt_runtime_api.c
+                      ${RUNTIME_CRT_SOURCE_DIR}/common/func_registry.c
+                      ${RUNTIME_CRT_SOURCE_DIR}/common/ndarray.c
+                      ${RUNTIME_CRT_SOURCE_DIR}/common/packed_func.c)
+  endif()
 
   add_custom_target(host_standalone_crt DEPENDS ${CRT_LIBRARIES} 
standalone_crt)
 
@@ -188,15 +180,4 @@ else()
     gtest_discover_tests(crttest)
   endif()
 
-  set(TVM_CRT_LINKER_LIB host_standalone_crt_microtvm_rpc_common)
-  if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
-  list(APPEND TVM_RUNTIME_LINKER_LIBS -Wl,--whole-archive 
${TVM_CRT_LINKER_LIB} -Wl,--no-whole-archive)
-  elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang")
-  list(APPEND TVM_RUNTIME_LINKER_LIBS -Wl,-force_load ${TVM_CRT_LINKER_LIB})
-  else()
-  list(APPEND TVM_RUNTIME_LINKER_LIBS ${TVM_CRT_LINKER_LIB})
-  endif()
-
-endif()
-
 endif()
diff --git a/include/tvm/runtime/c_runtime_api.h 
b/include/tvm/runtime/c_runtime_api.h
index cd11466977..485e766ead 100644
--- a/include/tvm/runtime/c_runtime_api.h
+++ b/include/tvm/runtime/c_runtime_api.h
@@ -53,6 +53,13 @@
 #define TVM_DLL EMSCRIPTEN_KEEPALIVE
 #endif
 
+// helper macro to suppress unused warning
+#if defined(__GNUC__)
+#define TVM_ATTRIBUTE_UNUSED __attribute__((unused))
+#else
+#define TVM_ATTRIBUTE_UNUSED
+#endif
+
 #ifndef TVM_DLL
 #ifdef _WIN32
 #ifdef TVM_EXPORTS
diff --git a/include/tvm/runtime/crt/microtvm_rpc_server.h 
b/include/tvm/runtime/crt/microtvm_rpc_server.h
index 9a7ed54ffe..d185bfcddb 100644
--- a/include/tvm/runtime/crt/microtvm_rpc_server.h
+++ b/include/tvm/runtime/crt/microtvm_rpc_server.h
@@ -29,6 +29,8 @@
 #include <sys/types.h>
 #include <tvm/runtime/crt/error_codes.h>
 
+#include "../../../../src/support/ssize.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/runtime/crt/common/crt_runtime_api.c 
b/src/runtime/crt/common/crt_runtime_api.c
index 7df610b53c..f3aa741784 100644
--- a/src/runtime/crt/common/crt_runtime_api.c
+++ b/src/runtime/crt/common/crt_runtime_api.c
@@ -112,7 +112,7 @@ int TVMDeviceAllocDataSpaceWithScope(DLDevice dev, int 
ndim, const int64_t* shap
 
 int TVMDeviceFreeDataSpace(DLDevice dev, void* ptr) { return 
TVMPlatformMemoryFree(ptr, dev); }
 
-static bool IsContiguous(const DLTensor* arr) {
+TVM_ATTRIBUTE_UNUSED static bool IsContiguous(const DLTensor* arr) {
   if (arr->strides == NULL) return true;
   int64_t expected_stride = 1;
   for (int32_t i = arr->ndim; i != 0; --i) {
@@ -632,12 +632,12 @@ release_and_return : {
 }
 
 // Default implementation, overridden by the platform runtime.
-__attribute__((weak)) tvm_crt_error_t TVMPlatformGenerateRandom(uint8_t* 
buffer, size_t num_bytes) {
+TVM_WEAK tvm_crt_error_t TVMPlatformGenerateRandom(uint8_t* buffer, size_t 
num_bytes) {
   return kTvmErrorFunctionCallNotImplemented;
 }
 
 // Default implementation, overridden by the platform runtime.
-__attribute__((weak)) tvm_crt_error_t TVMPlatformBeforeMeasurement() { return 
kTvmErrorNoError; }
+TVM_WEAK tvm_crt_error_t TVMPlatformBeforeMeasurement() { return 
kTvmErrorNoError; }
 
 // Default implementation, overridden by the platform runtime.
-__attribute__((weak)) tvm_crt_error_t TVMPlatformAfterMeasurement() { return 
kTvmErrorNoError; }
+TVM_WEAK tvm_crt_error_t TVMPlatformAfterMeasurement() { return 
kTvmErrorNoError; }

Reply via email to