You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ju...@apache.org on 2021/03/20 08:28:07 UTC
[tvm] branch main updated: [RUNTIME] Cleanup build for libbacktrace
(#7706)
This is an automated email from the ASF dual-hosted git repository.
junrushao 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 10cd83d [RUNTIME] Cleanup build for libbacktrace (#7706)
10cd83d is described below
commit 10cd83d0a4db708ea3e494f47a4fed308369aec6
Author: Tianqi Chen <tq...@users.noreply.github.com>
AuthorDate: Sat Mar 20 04:27:48 2021 -0400
[RUNTIME] Cleanup build for libbacktrace (#7706)
* [RUNTIME] Cleanup build for libbacktrace
- Introduce TVM_USE_LIBBACKTRACE value macro to be consistent
wth other value macros(instead of relying on disabled flag).
- Introduce AUTO mode for libbacktrace
- Temporary disable MacOS support in light of recent bug report.
- Refactor out the libbacktrace.cmake to libs
- Properly use TVM_DLL so that code is cross platform.
- Fallback to the weaker dmlc impl when backtrace is disabled.
* Update Logging.cmake
* Update the macro check order to be consistent with the rest.
---
CMakeLists.txt | 25 +++------------
cmake/config.cmake | 10 ++++--
cmake/{modules => libs}/Libbacktrace.cmake | 0
cmake/modules/Logging.cmake | 46 +++++++++++++++++++++++++++
conda/recipe/build.sh | 1 +
include/tvm/runtime/logging.h | 29 +++++++++++------
src/runtime/logging.cc | 28 ++++++++--------
tests/scripts/task_config_build_cpu.sh | 1 +
tests/scripts/task_config_build_gpu.sh | 1 +
tests/scripts/task_config_build_gpu_vulkan.sh | 1 +
10 files changed, 96 insertions(+), 46 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1aa3e68..6d37bd4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,11 +48,7 @@ tvm_option(USE_TF_TVMDSOOP "Build with TensorFlow TVMDSOOp" OFF)
tvm_option(USE_FALLBACK_STL_MAP "Use TVM's POD compatible Map" OFF)
tvm_option(USE_ETHOSN "Build with Arm Ethos-N" OFF)
tvm_option(INDEX_DEFAULT_I64 "Defaults the index datatype to int64" ON)
-set(_LIBBACKTRACE_DEFAULT OFF)
-if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "Linux")
- set(_LIBBACKTRACE_DEFAULT ON)
-endif()
-tvm_option(USE_LIBBACKTRACE "Build libbacktrace to supply linenumbers on stack traces" ${_LIBBACKTRACE_DEFAULT})
+tvm_option(USE_LIBBACKTRACE "Build libbacktrace to supply linenumbers on stack traces" AUTO)
# 3rdparty libraries
tvm_option(DLPACK_PATH "Path to DLPACK" "3rdparty/dlpack/include")
@@ -395,26 +391,13 @@ add_library(tvm SHARED $<TARGET_OBJECTS:tvm_objs> $<TARGET_OBJECTS:tvm_runtime_o
set_property(TARGET tvm APPEND PROPERTY LINK_OPTIONS "${TVM_VISIBILITY_FLAG}")
add_library(tvm_runtime SHARED $<TARGET_OBJECTS:tvm_runtime_objs>)
set_property(TARGET tvm_runtime APPEND PROPERTY LINK_OPTIONS "${TVM_VISIBILITY_FLAG}")
-
target_compile_definitions(tvm_objs PUBLIC DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>)
target_compile_definitions(tvm_runtime_objs PUBLIC DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>)
target_compile_definitions(tvm PUBLIC DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>)
target_compile_definitions(tvm_runtime PUBLIC DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>)
-if(USE_LIBBACKTRACE)
- message(STATUS "Building with libbacktrace...")
- include(cmake/modules/Libbacktrace.cmake)
- target_link_libraries(tvm PRIVATE libbacktrace)
- target_link_libraries(tvm_runtime PRIVATE libbacktrace)
- add_dependencies(tvm_runtime_objs libbacktrace)
- # pre 3.12 versions of cmake cannot propagate include directories from imported targets so we set them manually
- target_include_directories(tvm PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace/include")
- target_include_directories(tvm_objs PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace/include")
- target_include_directories(tvm_runtime PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace/include")
- target_include_directories(tvm_runtime_objs PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace/include")
-else()
- target_compile_definitions(tvm_objs PRIVATE TVM_BACKTRACE_DISABLED)
- target_compile_definitions(tvm_runtime_objs PRIVATE TVM_BACKTRACE_DISABLED)
-endif()
+
+# logging option for libbacktrace
+include(cmake/modules/Logging.cmake)
if(USE_MICRO)
# NOTE: cmake doesn't track dependencies at the file level across subdirectories. For the
diff --git a/cmake/config.cmake b/cmake/config.cmake
index 8c090dc..98d1d97 100644
--- a/cmake/config.cmake
+++ b/cmake/config.cmake
@@ -277,6 +277,10 @@ set(USE_TARGET_ONNX OFF)
set(USE_BNNS OFF)
# Whether to use libbacktrace
-# Libbacktrace provides line and column information on stack traces from errors. It is only
-# supported on linux and macOS.
-# set(USE_LIBBACKTRACE OFF)
+# Libbacktrace provides line and column information on stack traces from errors.
+# It is only supported on linux and macOS.
+# Possible values:
+# - AUTO: auto set according to system information and feasibility
+# - ON: enable libbacktrace
+# - OFF: disable libbacktrace
+set(USE_LIBBACKTRACE AUTO)
diff --git a/cmake/modules/Libbacktrace.cmake b/cmake/libs/Libbacktrace.cmake
similarity index 100%
rename from cmake/modules/Libbacktrace.cmake
rename to cmake/libs/Libbacktrace.cmake
diff --git a/cmake/modules/Logging.cmake b/cmake/modules/Logging.cmake
new file mode 100644
index 0000000..91c0fd0
--- /dev/null
+++ b/cmake/modules/Logging.cmake
@@ -0,0 +1,46 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This script configures the logging module and dependency on libbacktrace
+
+if("${USE_LIBBACKTRACE}" STREQUAL "AUTO")
+ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
+ set(USE_LIBBACKTRACE ON)
+ else()
+ set(USE_LIBBACKTRACE OFF)
+ endif()
+ message(STATUS "Autoset: USE_LIBBACKTRACE=" ${USE_LIBBACKTRACE} " in " ${CMAKE_SYSTEM_NAME})
+endif()
+
+
+if(USE_LIBBACKTRACE)
+ message(STATUS "Building with libbacktrace...")
+ include(cmake/libs/Libbacktrace.cmake)
+ target_link_libraries(tvm PRIVATE libbacktrace)
+ target_link_libraries(tvm_runtime PRIVATE libbacktrace)
+ add_dependencies(tvm_runtime_objs libbacktrace)
+ # pre 3.12 versions of cmake cannot propagate include directories from imported targets so we set them manually
+ target_include_directories(tvm PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace/include")
+ target_include_directories(tvm_objs PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace/include")
+ target_include_directories(tvm_runtime PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace/include")
+ target_include_directories(tvm_runtime_objs PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libbacktrace/include")
+ target_compile_definitions(tvm_objs PRIVATE TVM_USE_LIBBACKTRACE=1)
+ target_compile_definitions(tvm_runtime_objs PRIVATE TVM_USE_LIBBACKTRACE=1)
+else()
+ target_compile_definitions(tvm_objs PRIVATE TVM_USE_LIBBACKTRACE=0)
+ target_compile_definitions(tvm_runtime_objs PRIVATE TVM_USE_LIBBACKTRACE=0)
+endif()
diff --git a/conda/recipe/build.sh b/conda/recipe/build.sh
index c9e7631..828e3c3 100755
--- a/conda/recipe/build.sh
+++ b/conda/recipe/build.sh
@@ -52,6 +52,7 @@ cmake -DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DUSE_GRAPH_RUNTIME_DEBUG=ON \
-DUSE_LLVM=ON \
-DINSTALL_DEV=ON \
+ -DUSE_LIBBACKTRACE=AUTO \
${GPU_OPT} ${TOOLCHAIN_OPT} \
${SRC_DIR}
diff --git a/include/tvm/runtime/logging.h b/include/tvm/runtime/logging.h
index 952a5ff..c5986a9 100644
--- a/include/tvm/runtime/logging.h
+++ b/include/tvm/runtime/logging.h
@@ -30,6 +30,7 @@
#define TVM_RUNTIME_LOGGING_H_
#include <dmlc/common.h>
+#include <tvm/runtime/c_runtime_api.h>
#include <ctime>
#include <iomanip>
@@ -37,7 +38,22 @@
#include <sstream>
#include <string>
-#include "tvm/runtime/c_runtime_api.h"
+/*!
+ * \brief Macro helper for exception throwing.
+ */
+#ifdef _MSC_VER
+#define TVM_THROW_EXCEPTION noexcept(false) __declspec(noreturn)
+#else
+#define TVM_THROW_EXCEPTION noexcept(false)
+#endif
+
+/*!
+ * \brief Whether or not use libbacktrace library
+ * for getting backtrace information
+ */
+#ifndef TVM_USE_LIBBACKTRACE
+#define TVM_USE_LIBBACKTRACE 0
+#endif
// a technique that enables overriding macro names on the number of parameters. This is used
// to define other macros below
@@ -124,19 +140,14 @@
#define COND_CHECK_2(quit_on_assert, x) COND_CHECK_3(quit_on_assert, x, return false)
#define COND_LOG_2(quit_on_assert, x) COND_LOG_3(quit_on_assert, x, return false)
-#ifdef _MSC_VER
-#define TVM_THROW_EXCEPTION noexcept(false) __declspec(noreturn)
-#else
-#define TVM_THROW_EXCEPTION noexcept(false)
-#endif
-
namespace tvm {
namespace runtime {
-/* \brief Generate a backtrace when called.
+/*!
+ * \brief Generate a backtrace when called.
* \return A multiline string of the backtrace. There will be either one or two lines per frame.
*/
-std::string Backtrace();
+TVM_DLL std::string Backtrace();
/*! \brief Base error type for TVM. Wraps a string message. */
class Error : public ::dmlc::Error { // for backwards compatibility
diff --git a/src/runtime/logging.cc b/src/runtime/logging.cc
index 8a44ec0..0d8577a 100644
--- a/src/runtime/logging.cc
+++ b/src/runtime/logging.cc
@@ -17,19 +17,7 @@
* under the License.
*/
-#ifdef TVM_BACKTRACE_DISABLED
-#include <string>
-
-// TODO(bkimball,tkonolige) This inline function is to work around a linking error I am having when
-// using MSVC If the function definition is in logging.cc then the linker can't find it no matter
-// what kind of attributes (dllexport) I decorate it with. This is temporary and will be addressed
-// when we get backtrace working on Windows.
-namespace tvm {
-namespace runtime {
-__declspec(dllexport) std::string Backtrace() { return ""; }
-} // namespace runtime
-} // namespace tvm
-#else
+#if TVM_USE_LIBBACKTRACE
#include <backtrace.h>
#include <cxxabi.h>
@@ -148,4 +136,18 @@ std::string Backtrace() {
}
} // namespace runtime
} // namespace tvm
+
+#else
+
+#include <dmlc/logging.h>
+
+#include <string>
+
+namespace tvm {
+namespace runtime {
+// Fallback to the dmlc implementation when backtrace is not available.
+std::string Backtrace() { return dmlc::StackTrace(); }
+} // namespace runtime
+} // namespace tvm
+
#endif
diff --git a/tests/scripts/task_config_build_cpu.sh b/tests/scripts/task_config_build_cpu.sh
index aa5581b..2af91d7 100755
--- a/tests/scripts/task_config_build_cpu.sh
+++ b/tests/scripts/task_config_build_cpu.sh
@@ -45,3 +45,4 @@ echo set\(USE_ETHOSN /opt/arm/ethosn-driver\) >> config.cmake
echo set\(USE_ETHOSN_HW OFF\) >> config.cmake
echo set\(USE_VITIS_AI ON\) >> config.cmake
echo set\(USE_VERILATOR ON\) >> config.cmake
+echo set\(USE_LIBBACKTRACE ON\) >> config.cmake
diff --git a/tests/scripts/task_config_build_gpu.sh b/tests/scripts/task_config_build_gpu.sh
index 13dfb41..7338555 100755
--- a/tests/scripts/task_config_build_gpu.sh
+++ b/tests/scripts/task_config_build_gpu.sh
@@ -44,3 +44,4 @@ echo set\(USE_BLAS openblas\) >> config.cmake
echo set\(CMAKE_CXX_COMPILER g++\) >> config.cmake
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
echo set\(USE_TENSORRT_CODEGEN ON\) >> config.cmake
+echo set\(USE_LIBBACKTRACE AUTO\) >> config.cmake
diff --git a/tests/scripts/task_config_build_gpu_vulkan.sh b/tests/scripts/task_config_build_gpu_vulkan.sh
index 5865dc9..f12d0f9 100755
--- a/tests/scripts/task_config_build_gpu_vulkan.sh
+++ b/tests/scripts/task_config_build_gpu_vulkan.sh
@@ -28,5 +28,6 @@ echo set\(USE_ROCM ON\) >> config.cmake
echo set\(USE_VULKAN ON\) >> config.cmake
echo set\(USE_MICRO ON\) >> config.cmake
echo set\(USE_PROFILER ON\) >> config.cmake
+echo set\(USE_LIBBACKTRACE OFF\) >> config.cmake
echo set\(CMAKE_CXX_COMPILER clang-7\) >> config.cmake
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake