From 42d14b4713cca94dd4382e7f951eef782a13a166 Mon Sep 17 00:00:00 2001 From: Alan MacDonald Date: Mon, 12 Dec 2022 13:17:24 -0800 Subject: [PATCH 1/5] build standalone_crt with cmake instead of makefile --- cmake/modules/StandaloneCrt.cmake | 238 ++++++++++++++++-------------- 1 file changed, 126 insertions(+), 112 deletions(-) diff --git a/cmake/modules/StandaloneCrt.cmake b/cmake/modules/StandaloneCrt.cmake index 8c25cf48df27..f3e67d5bf83e 100644 --- a/cmake/modules/StandaloneCrt.cmake +++ b/cmake/modules/StandaloneCrt.cmake @@ -40,129 +40,143 @@ if(MSVC) else() - message(STATUS "Build standalone CRT for microTVM") + function(create_crt_library CRT_LIBRARY_NAME) + set(cmake_crt_lib_name host_standalone_crt_${CRT_LIBRARY_NAME}) - function(tvm_crt_define_targets) - # Build an isolated build directory, separate from the TVM tree. - list(APPEND CRT_FILE_COPY_JOBS - "3rdparty/libcrc/include *.h -> include" - "3rdparty/libcrc/src crcccitt.c -> src/runtime/crt/microtvm_rpc_common" - "3rdparty/libcrc/tab gentab_ccitt.inc -> src/runtime/crt/tab" - "3rdparty/dlpack/include *.h -> include" - "3rdparty/dmlc-core/include *.h -> include" - "include/tvm/runtime c_*_api.h -> include/tvm/runtime" - "include/tvm/runtime metadata_types.h -> include/tvm/runtime" - "include/tvm/runtime/crt *.h -> include/tvm/runtime/crt" - "src/runtime/crt Makefile -> ." - "src/runtime/crt/include *.h -> include" - "src/runtime/crt/aot_executor *.c -> src/runtime/crt/aot_executor" - "src/runtime/crt/aot_executor_module *.c -> src/runtime/crt/aot_executor_module" - "src/runtime/crt/common *.c -> src/runtime/crt/common" - "src/runtime/crt/graph_executor *.c -> src/runtime/crt/graph_executor" - "src/runtime/crt/graph_executor_module *.c -> src/runtime/crt/graph_executor_module" - "src/runtime/crt/host *.cc -> template/host" - "src/runtime/crt/host *.py -> template/host" - "src/runtime/crt/host Makefile.template -> template/host" - "src/runtime/crt/memory *.c -> src/runtime/crt/memory" - "src/runtime/crt/microtvm_rpc_common *.cc -> src/runtime/crt/microtvm_rpc_common" - "src/runtime/crt/microtvm_rpc_server *.cc -> src/runtime/crt/microtvm_rpc_server" - "src/runtime/minrpc *.h -> src/runtime/minrpc" - "src/support generic_arena.h -> src/support" - "src/support ssize.h -> src/support" - "src/runtime/crt crt_config-template.h -> template" - ) - - set(standalone_crt_base "${CMAKE_CURRENT_BINARY_DIR}/standalone_crt") - - foreach(job_spec IN LISTS CRT_FILE_COPY_JOBS) - string(REPLACE " " ";" job_spec "${job_spec}") - list(LENGTH job_spec job_spec_length) - math(EXPR job_spec_length_mod "${job_spec_length} % 3") - if(NOT "${job_spec_length_mod}" EQUAL 1) - message(FATAL_ERROR "CRT copy job spec list length is ${job_spec_length}; parsed job spec is ${job_spec}") - endif() - math(EXPR job_spec_stop "${job_spec_length} - 3") - - list(GET job_spec 0 job_src_base) - set(job_src_base "${CMAKE_CURRENT_SOURCE_DIR}/${job_src_base}") - foreach(copy_pattern_index RANGE 1 "${job_spec_stop}" 3) - list(GET job_spec ${copy_pattern_index} copy_pattern) - math(EXPR copy_dest_index "${copy_pattern_index} + 2") - list(GET job_spec ${copy_dest_index} copy_dest) - - tvm_file_glob(GLOB_RECURSE copy_files - RELATIVE "${job_src_base}" - "${job_src_base}/${copy_pattern}") - list(LENGTH copy_files copy_files_length) - if("${copy_files_length}" EQUAL 0) - message(FATAL_ERROR "CRT copy job matched 0 files: ${job_src_base}/${copy_pattern} -> ${copy_dest}") - endif() - foreach(copy_src IN LISTS copy_files) - get_filename_component(dest_path "${standalone_crt_base}/${copy_dest}/${copy_src}" ABSOLUTE) - tvm_micro_add_copy_file(host_isolated_build_deps ${job_src_base}/${copy_src} ${dest_path}) - endforeach() - endforeach() + set(CRT_LIBRARY_SOURCES "") + foreach(FILE_NAME IN LISTS ARGN) + list(APPEND CRT_LIBRARY_SOURCES ${FILE_NAME}) endforeach() - add_custom_target(standalone_crt DEPENDS ${host_isolated_build_deps}) + add_library(${cmake_crt_lib_name} + STATIC + ${CRT_LIBRARY_SOURCES}) - get_filename_component(host_build_dir_abspath "${CMAKE_CURRENT_BINARY_DIR}/host_standalone_crt" ABSOLUTE) + set(CMAKE_CRT_LIBRARIES ${CMAKE_CRT_LIBRARIES} ${cmake_crt_lib_name} PARENT_SCOPE) - if(${VERBOSE}) - set(make_quiet QUIET=) - else(${VERBOSE}) - set(make_quiet ) - endif(${VERBOSE}) + set_property(TARGET ${cmake_crt_lib_name} PROPERTY POSITION_INDEPENDENT_CODE ON) - list(APPEND crt_libraries memory graph_executor microtvm_rpc_server microtvm_rpc_common common) # NOTE: listed in link order. - foreach(crt_lib_name IN LISTS crt_libraries) - list(APPEND crt_library_paths "host_standalone_crt/lib${crt_lib_name}.a") - endforeach() + target_include_directories(${cmake_crt_lib_name} PUBLIC ${STANDALONE_CRT_INCLUDE_PATH} ${CRT_CONFIG_INCLUDE_PATH}) - set(make_common_args - "CRT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro/crt_config.h" - "BUILD_DIR=${host_build_dir_abspath}" - "EXTRA_CFLAGS=-fPIC" - "EXTRA_CXXFLAGS=-fPIC" - "EXTRA_LDFLAGS=-fPIC" - "${make_quiet}") - - add_custom_command( - OUTPUT ${crt_library_paths} - COMMAND make ARGS ${make_common_args} clean - COMMAND make ARGS ${make_common_args} all - WORKING_DIRECTORY "${standalone_crt_base}" - DEPENDS standalone_crt ${host_isolated_build_deps}) - - add_custom_target(host_standalone_crt DEPENDS ${crt_library_paths}) - - foreach(crt_lib IN LISTS crt_libraries) - set(cmake_crt_lib_name host_standalone_crt_${crt_lib}) - list(APPEND cmake_crt_libraries ${cmake_crt_lib_name}) - add_library(${cmake_crt_lib_name} STATIC IMPORTED GLOBAL) - set(cmake_crt_lib_path "${CMAKE_CURRENT_BINARY_DIR}/host_standalone_crt/lib${crt_lib}.a") - add_dependencies(${cmake_crt_lib_name} host_standalone_crt "${cmake_crt_lib_path}") - set_target_properties(${cmake_crt_lib_name} PROPERTIES - IMPORTED_LOCATION "${cmake_crt_lib_path}" - IMPORTED_OBJECTS "${cmake_crt_lib_path}" - PUBLIC_HEADER "${crt_headers}") - endforeach() + set_target_properties(${cmake_crt_lib_name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${standalone_crt_base}/build) - # Create the `crttest` target if we can find GTest. If not, we create dummy - # targets that give the user an informative error message. - if(GTEST_FOUND) - tvm_file_glob(GLOB TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests/crt/*.cc) - add_executable(crttest ${TEST_SRCS}) - target_include_directories(crttest SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/standalone_crt/include ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro) - target_link_libraries(crttest PRIVATE ${cmake_crt_libraries} GTest::GTest GTest::Main pthread dl) - set_target_properties(crttest PROPERTIES EXCLUDE_FROM_ALL 1) - set_target_properties(crttest PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1) - gtest_discover_tests(crttest) - endif() + # make these libraries dependent on standalone_crt which depends on host_isolated_build_deps to avoid + # race with the file copy jobs + add_dependencies(${cmake_crt_lib_name} standalone_crt) endfunction() - tvm_crt_define_targets() + message(STATUS "Build standalone CRT for microTVM") + + # Build an isolated build directory, separate from the TVM tree. + list(APPEND CRT_FILE_COPY_JOBS + "3rdparty/libcrc/include *.h -> include" + "3rdparty/libcrc/src crcccitt.c -> src/runtime/crt/microtvm_rpc_common" + "3rdparty/libcrc/tab gentab_ccitt.inc -> src/runtime/crt/tab" + "3rdparty/dlpack/include *.h -> include" + "3rdparty/dmlc-core/include *.h -> include" + "include/tvm/runtime c_*_api.h -> include/tvm/runtime" + "include/tvm/runtime metadata_types.h -> include/tvm/runtime" + "include/tvm/runtime/crt *.h -> include/tvm/runtime/crt" + "src/runtime/crt Makefile -> ." + "src/runtime/crt/include *.h -> include" + "src/runtime/crt/aot_executor *.c -> src/runtime/crt/aot_executor" + "src/runtime/crt/aot_executor_module *.c -> src/runtime/crt/aot_executor_module" + "src/runtime/crt/common *.c -> src/runtime/crt/common" + "src/runtime/crt/graph_executor *.c -> src/runtime/crt/graph_executor" + "src/runtime/crt/graph_executor_module *.c -> src/runtime/crt/graph_executor_module" + "src/runtime/crt/host *.cc -> template/host" + "src/runtime/crt/host *.py -> template/host" + "src/runtime/crt/host Makefile.template -> template/host" + "src/runtime/crt/memory *.c -> src/runtime/crt/memory" + "src/runtime/crt/microtvm_rpc_common *.cc -> src/runtime/crt/microtvm_rpc_common" + "src/runtime/crt/microtvm_rpc_server *.cc -> src/runtime/crt/microtvm_rpc_server" + "src/runtime/minrpc *.h -> src/runtime/minrpc" + "src/support generic_arena.h -> src/support" + "src/support ssize.h -> src/support" + "src/runtime/crt crt_config-template.h -> template" + ) + + set(standalone_crt_base "${CMAKE_CURRENT_BINARY_DIR}/standalone_crt") + + foreach(job_spec IN LISTS CRT_FILE_COPY_JOBS) + string(REPLACE " " ";" job_spec "${job_spec}") + list(LENGTH job_spec job_spec_length) + math(EXPR job_spec_length_mod "${job_spec_length} % 3") + if(NOT "${job_spec_length_mod}" EQUAL 1) + message(FATAL_ERROR "CRT copy job spec list length is ${job_spec_length}; parsed job spec is ${job_spec}") + endif() + math(EXPR job_spec_stop "${job_spec_length} - 3") + + list(GET job_spec 0 job_src_base) + set(job_src_base "${CMAKE_CURRENT_SOURCE_DIR}/${job_src_base}") + foreach(copy_pattern_index RANGE 1 "${job_spec_stop}" 3) + list(GET job_spec ${copy_pattern_index} copy_pattern) + math(EXPR copy_dest_index "${copy_pattern_index} + 2") + list(GET job_spec ${copy_dest_index} copy_dest) + + tvm_file_glob(GLOB_RECURSE copy_files + RELATIVE "${job_src_base}" + "${job_src_base}/${copy_pattern}") + list(LENGTH copy_files copy_files_length) + if("${copy_files_length}" EQUAL 0) + message(FATAL_ERROR "CRT copy job matched 0 files: ${job_src_base}/${copy_pattern} -> ${copy_dest}") + endif() + foreach(copy_src IN LISTS copy_files) + get_filename_component(dest_path "${standalone_crt_base}/${copy_dest}/${copy_src}" ABSOLUTE) + tvm_micro_add_copy_file(host_isolated_build_deps ${job_src_base}/${copy_src} ${dest_path}) + endforeach() + endforeach() + endforeach() + + add_custom_target(standalone_crt DEPENDS ${host_isolated_build_deps}) + + get_filename_component(host_build_dir_abspath "${CMAKE_CURRENT_BINARY_DIR}/host_standalone_crt" ABSOLUTE) + + set(CRT_CONFIG_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro/") + set(STANDALONE_CRT_INCLUDE_PATH "${standalone_crt_base}/include") + set(CMAKE_CRT_LIBRARIES "") + + # NOTE: these create_crt_library() targets are in link order and common needs to be last + + create_crt_library(graph_executor + ${standalone_crt_base}/src/runtime/crt/graph_executor/graph_executor.c + ${standalone_crt_base}/src/runtime/crt/graph_executor/load_json.c) + + create_crt_library(memory + ${standalone_crt_base}/src/runtime/crt/memory/page_allocator.c + ${standalone_crt_base}/src/runtime/crt/memory/stack_allocator.c) + + create_crt_library(microtvm_rpc_common + ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/crcccitt.c + ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/frame_buffer.cc + ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/framing.cc + ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/session.cc + ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/write_stream.cc) + + create_crt_library(microtvm_rpc_server + ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_server/rpc_server.cc) + + create_crt_library(common + ${standalone_crt_base}/src/runtime/crt/common/crt_backend_api.c + ${standalone_crt_base}/src/runtime/crt/common/crt_runtime_api.c + ${standalone_crt_base}/src/runtime/crt/common/func_registry.c + ${standalone_crt_base}/src/runtime/crt/common/ndarray.c + ${standalone_crt_base}/src/runtime/crt/common/packed_func.c) + + add_custom_target(host_standalone_crt DEPENDS ${CMAKE_CRT_LIBRARIES} standalone_crt) + + # Create the `crttest` target if we can find GTest. If not, we create dummy + # targets that give the user an informative error message. + if(GTEST_FOUND) + tvm_file_glob(GLOB TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests/crt/*.cc) + add_executable(crttest ${TEST_SRCS}) + target_include_directories(crttest SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/standalone_crt/include ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro) + target_link_libraries(crttest PRIVATE ${CMAKE_CRT_LIBRARIES} GTest::GTest GTest::Main pthread dl) + set_target_properties(crttest PROPERTIES EXCLUDE_FROM_ALL 1) + set_target_properties(crttest PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1) + gtest_discover_tests(crttest) + endif() set(TVM_CRT_LINKER_LIB host_standalone_crt_microtvm_rpc_common) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") From 8f7438a2f3c61fc72415c09851f7b72ab688c138 Mon Sep 17 00:00:00 2001 From: Alan MacDonald Date: Mon, 12 Dec 2022 17:19:30 -0800 Subject: [PATCH 2/5] clean-up and uppercase more variables --- cmake/modules/StandaloneCrt.cmake | 70 ++++++++++++++++--------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/cmake/modules/StandaloneCrt.cmake b/cmake/modules/StandaloneCrt.cmake index f3e67d5bf83e..16bed16ccb8a 100644 --- a/cmake/modules/StandaloneCrt.cmake +++ b/cmake/modules/StandaloneCrt.cmake @@ -40,29 +40,35 @@ if(MSVC) else() - function(create_crt_library CRT_LIBRARY_NAME) - set(cmake_crt_lib_name host_standalone_crt_${CRT_LIBRARY_NAME}) + function(create_crt_library CRT_LIBRARY) + set(CRT_LIBRARY_NAME host_standalone_crt_${CRT_LIBRARY}) set(CRT_LIBRARY_SOURCES "") + foreach(FILE_NAME IN LISTS ARGN) list(APPEND CRT_LIBRARY_SOURCES ${FILE_NAME}) endforeach() - add_library(${cmake_crt_lib_name} + add_library(${CRT_LIBRARY_NAME} STATIC ${CRT_LIBRARY_SOURCES}) - set(CMAKE_CRT_LIBRARIES ${CMAKE_CRT_LIBRARIES} ${cmake_crt_lib_name} PARENT_SCOPE) - - set_property(TARGET ${cmake_crt_lib_name} PROPERTY POSITION_INDEPENDENT_CODE ON) + # add this library to the list of CRT libraries + set(CRT_LIBRARIES ${CRT_LIBRARIES} ${CRT_LIBRARY_NAME} PARENT_SCOPE) - target_include_directories(${cmake_crt_lib_name} PUBLIC ${STANDALONE_CRT_INCLUDE_PATH} ${CRT_CONFIG_INCLUDE_PATH}) + target_include_directories(${CRT_LIBRARY_NAME} + PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro/" + "${STANDALONE_CRT_BASE}/include") - set_target_properties(${cmake_crt_lib_name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${standalone_crt_base}/build) + set_target_properties(${CRT_LIBRARY_NAME} + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${STANDALONE_CRT_BASE}/build + POSITION_INDEPENDENT_CODE ON) # make these libraries dependent on standalone_crt which depends on host_isolated_build_deps to avoid # race with the file copy jobs - add_dependencies(${cmake_crt_lib_name} standalone_crt) + add_dependencies(${CRT_LIBRARY_NAME} standalone_crt) endfunction() @@ -97,7 +103,7 @@ else() "src/runtime/crt crt_config-template.h -> template" ) - set(standalone_crt_base "${CMAKE_CURRENT_BINARY_DIR}/standalone_crt") + set(STANDALONE_CRT_BASE "${CMAKE_CURRENT_BINARY_DIR}/standalone_crt") foreach(job_spec IN LISTS CRT_FILE_COPY_JOBS) string(REPLACE " " ";" job_spec "${job_spec}") @@ -123,7 +129,7 @@ else() message(FATAL_ERROR "CRT copy job matched 0 files: ${job_src_base}/${copy_pattern} -> ${copy_dest}") endif() foreach(copy_src IN LISTS copy_files) - get_filename_component(dest_path "${standalone_crt_base}/${copy_dest}/${copy_src}" ABSOLUTE) + get_filename_component(dest_path "${STANDALONE_CRT_BASE}/${copy_dest}/${copy_src}" ABSOLUTE) tvm_micro_add_copy_file(host_isolated_build_deps ${job_src_base}/${copy_src} ${dest_path}) endforeach() endforeach() @@ -133,38 +139,36 @@ else() get_filename_component(host_build_dir_abspath "${CMAKE_CURRENT_BINARY_DIR}/host_standalone_crt" ABSOLUTE) - set(CRT_CONFIG_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro/") - set(STANDALONE_CRT_INCLUDE_PATH "${standalone_crt_base}/include") - set(CMAKE_CRT_LIBRARIES "") - - # NOTE: these create_crt_library() targets are in link order and common needs to be last + set(CRT_LIBRARIES "") + set(RUNTIME_CRT_SOURCE_DIR ${STANDALONE_CRT_BASE}/src/runtime/crt) + # these create_crt_library() targets are in link order and the common library needs to be last create_crt_library(graph_executor - ${standalone_crt_base}/src/runtime/crt/graph_executor/graph_executor.c - ${standalone_crt_base}/src/runtime/crt/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(memory - ${standalone_crt_base}/src/runtime/crt/memory/page_allocator.c - ${standalone_crt_base}/src/runtime/crt/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 - ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/crcccitt.c - ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/frame_buffer.cc - ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/framing.cc - ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_common/session.cc - ${standalone_crt_base}/src/runtime/crt/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 - ${standalone_crt_base}/src/runtime/crt/microtvm_rpc_server/rpc_server.cc) + ${RUNTIME_CRT_SOURCE_DIR}/microtvm_rpc_server/rpc_server.cc) create_crt_library(common - ${standalone_crt_base}/src/runtime/crt/common/crt_backend_api.c - ${standalone_crt_base}/src/runtime/crt/common/crt_runtime_api.c - ${standalone_crt_base}/src/runtime/crt/common/func_registry.c - ${standalone_crt_base}/src/runtime/crt/common/ndarray.c - ${standalone_crt_base}/src/runtime/crt/common/packed_func.c) + ${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) - add_custom_target(host_standalone_crt DEPENDS ${CMAKE_CRT_LIBRARIES} standalone_crt) + add_custom_target(host_standalone_crt DEPENDS ${CRT_LIBRARIES} standalone_crt) # Create the `crttest` target if we can find GTest. If not, we create dummy # targets that give the user an informative error message. @@ -172,7 +176,7 @@ else() tvm_file_glob(GLOB TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests/crt/*.cc) add_executable(crttest ${TEST_SRCS}) target_include_directories(crttest SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/standalone_crt/include ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro) - target_link_libraries(crttest PRIVATE ${CMAKE_CRT_LIBRARIES} GTest::GTest GTest::Main pthread dl) + target_link_libraries(crttest PRIVATE ${CRT_LIBRARIES} GTest::GTest GTest::Main pthread dl) set_target_properties(crttest PROPERTIES EXCLUDE_FROM_ALL 1) set_target_properties(crttest PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1) gtest_discover_tests(crttest) From beb280cb1658f9cd5cb4e90aa4106cc937a66554 Mon Sep 17 00:00:00 2001 From: Alan MacDonald Date: Tue, 13 Dec 2022 14:19:48 -0800 Subject: [PATCH 3/5] add other crt libraries to build; update library build output directory to match previous location; remove unused variable; --- cmake/modules/StandaloneCrt.cmake | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cmake/modules/StandaloneCrt.cmake b/cmake/modules/StandaloneCrt.cmake index 16bed16ccb8a..745bb295a8ee 100644 --- a/cmake/modules/StandaloneCrt.cmake +++ b/cmake/modules/StandaloneCrt.cmake @@ -58,12 +58,12 @@ else() target_include_directories(${CRT_LIBRARY_NAME} PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro/" - "${STANDALONE_CRT_BASE}/include") + ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/micro/ + ${STANDALONE_CRT_BASE}/include) set_target_properties(${CRT_LIBRARY_NAME} PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY ${STANDALONE_CRT_BASE}/build + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/host_standalone_crt POSITION_INDEPENDENT_CODE ON) # make these libraries dependent on standalone_crt which depends on host_isolated_build_deps to avoid @@ -103,7 +103,7 @@ else() "src/runtime/crt crt_config-template.h -> template" ) - set(STANDALONE_CRT_BASE "${CMAKE_CURRENT_BINARY_DIR}/standalone_crt") + set(STANDALONE_CRT_BASE ${CMAKE_CURRENT_BINARY_DIR}/standalone_crt) foreach(job_spec IN LISTS CRT_FILE_COPY_JOBS) string(REPLACE " " ";" job_spec "${job_spec}") @@ -137,16 +137,23 @@ else() add_custom_target(standalone_crt DEPENDS ${host_isolated_build_deps}) - get_filename_component(host_build_dir_abspath "${CMAKE_CURRENT_BINARY_DIR}/host_standalone_crt" ABSOLUTE) - set(CRT_LIBRARIES "") set(RUNTIME_CRT_SOURCE_DIR ${STANDALONE_CRT_BASE}/src/runtime/crt) # these create_crt_library() targets are in link order and the common library needs to be last + create_crt_library(aot_executor + ${RUNTIME_CRT_SOURCE_DIR}/aot_executor/aot_executor.c) + + create_crt_library(aot_executor_module + ${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) + create_crt_library(graph_executor_module + ${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) From bfe69ed8b11406e4f876f8a071d6a36024466cc4 Mon Sep 17 00:00:00 2001 From: Alan MacDonald Date: Wed, 14 Dec 2022 10:23:01 -0800 Subject: [PATCH 4/5] remove executable permissions from crt.h --- include/tvm/runtime/crt/crt.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 include/tvm/runtime/crt/crt.h diff --git a/include/tvm/runtime/crt/crt.h b/include/tvm/runtime/crt/crt.h old mode 100755 new mode 100644 From 165af8d718ecc549691f832a06da0d1077aee1c9 Mon Sep 17 00:00:00 2001 From: Alan MacDonald Date: Tue, 3 Jan 2023 15:40:27 -0800 Subject: [PATCH 5/5] add comment with MSVC conditional TODO --- cmake/modules/StandaloneCrt.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/modules/StandaloneCrt.cmake b/cmake/modules/StandaloneCrt.cmake index 745bb295a8ee..306e4af13c0c 100644 --- a/cmake/modules/StandaloneCrt.cmake +++ b/cmake/modules/StandaloneCrt.cmake @@ -23,6 +23,9 @@ 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 + set(CRT_CONFIG, "src/runtime/micro/crt_config.h") add_library(host_standalone_crt