diff --git a/CMakeLists.txt b/CMakeLists.txt index abe415957e33..e48ea780e95d 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 1d4e213ec71a..96fcf5092aa8 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 cd1146697759..485e766ead05 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 9a7ed54ffe95..d185bfcddb6c 100644 --- a/include/tvm/runtime/crt/microtvm_rpc_server.h +++ b/include/tvm/runtime/crt/microtvm_rpc_server.h @@ -29,6 +29,8 @@ #include #include +#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 7df610b53c45..f3aa74178415 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; }