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

tqchen 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 e57ab7a9dc [Fix] Introduce TVM_DEBUG_WITH_ABI_CHANGE to warn ABI 
changes in debug mode (#16728)
e57ab7a9dc is described below

commit e57ab7a9dc5ebf4e55586d968c95b47d2d80cbdc
Author: Yixin Dong <[email protected]>
AuthorDate: Sat Mar 16 17:30:37 2024 +0800

    [Fix] Introduce TVM_DEBUG_WITH_ABI_CHANGE to warn ABI changes in debug mode 
(#16728)
    
    * finish
    
    * update
---
 CMakeLists.txt                      | 12 ++++++++++++
 cmake/config.cmake                  |  3 +++
 cmake/modules/LibInfo.cmake         |  1 +
 include/tvm/runtime/container/map.h | 20 ++++++++++----------
 src/support/libinfo.cc              |  5 +++++
 tests/cpp/container_test.cc         |  4 ++--
 6 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d10a18c4f1..c9d836b681 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,6 +62,7 @@ tvm_option(USE_AOT_EXECUTOR "Build with AOT executor" ON)
 tvm_option(USE_PROFILER "Build profiler for the VM and graph executor" ON)
 tvm_option(USE_OPENMP "Build with OpenMP thread pool implementation" OFF)
 tvm_option(USE_RELAY_DEBUG "Building Relay in debug mode..." OFF)
+tvm_option(TVM_DEBUG_WITH_ABI_CHANGE "Enable debug code that may cause ABI 
changes" OFF)
 tvm_option(USE_RTTI "Build with RTTI" ON)
 tvm_option(USE_MSVC_MT "Build with MT" OFF)
 tvm_option(USE_MICRO "Build with Micro TVM support" OFF)
@@ -667,6 +668,13 @@ else()
   target_compile_definitions(tvm_libinfo_objs PRIVATE "NDEBUG")
 endif(USE_RELAY_DEBUG)
 
+if(TVM_DEBUG_WITH_ABI_CHANGE)
+  message(STATUS "Building with debug code that may cause ABI changes...")
+  target_compile_definitions(tvm_objs PRIVATE "TVM_DEBUG_WITH_ABI_CHANGE")
+  target_compile_definitions(tvm_runtime_objs PRIVATE 
"TVM_DEBUG_WITH_ABI_CHANGE")
+  target_compile_definitions(tvm_libinfo_objs PRIVATE 
"TVM_DEBUG_WITH_ABI_CHANGE")
+endif(TVM_DEBUG_WITH_ABI_CHANGE)
+
 if(USE_FALLBACK_STL_MAP)
   message(STATUS "Building with STL Map...")
   target_compile_definitions(tvm_objs PRIVATE "USE_FALLBACK_STL_MAP=1")
@@ -771,6 +779,10 @@ if(GTEST_FOUND)
   else()
     target_compile_definitions(cpptest PRIVATE "NDEBUG")
   endif()
+  if(TVM_DEBUG_WITH_ABI_CHANGE)
+    target_compile_definitions(cpptest PRIVATE "TVM_DEBUG_WITH_ABI_CHANGE")
+  endif(TVM_DEBUG_WITH_ABI_CHANGE)
+
   # For some reason, compile definitions are not propagated correctly, so we 
manually add them here
   target_compile_definitions(cpptest PUBLIC 
$<TARGET_PROPERTY:tvm,INTERFACE_COMPILE_DEFINITIONS>)
   gtest_discover_tests(cpptest)
diff --git a/cmake/config.cmake b/cmake/config.cmake
index e175902f2d..2666185fce 100644
--- a/cmake/config.cmake
+++ b/cmake/config.cmake
@@ -320,6 +320,9 @@ set(USE_ANTLR OFF)
 # Whether use Relay debug mode
 set(USE_RELAY_DEBUG OFF)
 
+# Whether to enable debug code that may cause ABI changes
+set(TVM_DEBUG_WITH_ABI_CHANGE OFF)
+
 # Whether to build fast VTA simulator driver
 set(USE_VTA_FSIM OFF)
 
diff --git a/cmake/modules/LibInfo.cmake b/cmake/modules/LibInfo.cmake
index 5f82a0c782..6d6b0b0c6e 100644
--- a/cmake/modules/LibInfo.cmake
+++ b/cmake/modules/LibInfo.cmake
@@ -112,6 +112,7 @@ function(add_lib_info src_file)
     TVM_INFO_USE_PT_TVMDSOOP="${USE_PT_TVMDSOOP}"
     TVM_INFO_USE_RANDOM="${USE_RANDOM}"
     TVM_INFO_USE_RELAY_DEBUG="${USE_RELAY_DEBUG}"
+    TVM_INFO_TVM_DEBUG_WITH_ABI_CHANGE="${TVM_DEBUG_WITH_ABI_CHANGE}"
     TVM_INFO_USE_ROCBLAS="${USE_ROCBLAS}"
     TVM_INFO_USE_ROCM="${USE_ROCM}"
     TVM_INFO_USE_RCCL="${USE_RCCL}"
diff --git a/include/tvm/runtime/container/map.h 
b/include/tvm/runtime/container/map.h
index 53c37cc20e..eb86ddb7b8 100644
--- a/include/tvm/runtime/container/map.h
+++ b/include/tvm/runtime/container/map.h
@@ -38,12 +38,12 @@
 namespace tvm {
 namespace runtime {
 
-#if TVM_LOG_DEBUG
+#if TVM_DEBUG_WITH_ABI_CHANGE
 #define TVM_MAP_FAIL_IF_CHANGED() \
   ICHECK(state_marker == self->state_marker) << "Concurrent modification of 
the Map";
 #else
 #define TVM_MAP_FAIL_IF_CHANGED()
-#endif  // TVM_LOG_DEBUG
+#endif  // TVM_DEBUG_WITH_ABI_CHANGE
 
 #if (USE_FALLBACK_STL_MAP != 0)
 
@@ -241,11 +241,11 @@ class MapNode : public Object {
     using pointer = KVType*;
     using reference = KVType&;
 /*! \brief Default constructor */
-#if TVM_LOG_DEBUG
+#if TVM_DEBUG_WITH_ABI_CHANGE
     iterator() : state_marker(0), index(0), self(nullptr) {}
 #else
     iterator() : index(0), self(nullptr) {}
-#endif  // TVM_LOG_DEBUG
+#endif  // TVM_DEBUG_WITH_ABI_CHANGE
     /*! \brief Compare iterators */
     bool operator==(const iterator& other) const {
       TVM_MAP_FAIL_IF_CHANGED()
@@ -280,7 +280,7 @@ class MapNode : public Object {
     }
 
    protected:
-#if TVM_LOG_DEBUG
+#if TVM_DEBUG_WITH_ABI_CHANGE
     uint64_t state_marker;
     /*! \brief Construct by value */
     iterator(uint64_t index, const MapNode* self)
@@ -288,7 +288,7 @@ class MapNode : public Object {
 
 #else
     iterator(uint64_t index, const MapNode* self) : index(index), self(self) {}
-#endif  // TVM_LOG_DEBUG
+#endif  // TVM_DEBUG_WITH_ABI_CHANGE
     /*! \brief The position on the array */
     uint64_t index;
     /*! \brief The container it points to */
@@ -304,9 +304,9 @@ class MapNode : public Object {
   static inline ObjectPtr<MapNode> Empty();
 
  protected:
-#if TVM_LOG_DEBUG
+#if TVM_DEBUG_WITH_ABI_CHANGE
   uint64_t state_marker;
-#endif  // TVM_LOG_DEBUG
+#endif  // TVM_DEBUG_WITH_ABI_CHANGE
   /*!
    * \brief Create the map using contents from the given iterators.
    * \param first Begin of iterator
@@ -1233,9 +1233,9 @@ inline ObjectPtr<Object> 
MapNode::CreateFromRange(IterType first, IterType last)
 inline void MapNode::InsertMaybeReHash(const KVType& kv, ObjectPtr<Object>* 
map) {
   constexpr uint64_t kSmallMapMaxSize = SmallMapNode::kMaxSize;
   MapNode* base = static_cast<MapNode*>(map->get());
-#if TVM_LOG_DEBUG
+#if TVM_DEBUG_WITH_ABI_CHANGE
   base->state_marker++;
-#endif  // TVM_LOG_DEBUG
+#endif  // TVM_DEBUG_WITH_ABI_CHANGE
   if (base->slots_ < kSmallMapMaxSize) {
     SmallMapNode::InsertMaybeReHash(kv, map);
   } else if (base->slots_ == kSmallMapMaxSize) {
diff --git a/src/support/libinfo.cc b/src/support/libinfo.cc
index 38159c42eb..4c863d7dec 100644
--- a/src/support/libinfo.cc
+++ b/src/support/libinfo.cc
@@ -127,6 +127,10 @@
 #define TVM_INFO_USE_RELAY_DEBUG "NOT-FOUND"
 #endif
 
+#ifndef TVM_INFO_TVM_DEBUG_WITH_ABI_CHANGE
+#define TVM_INFO_TVM_DEBUG_WITH_ABI_CHANGE "NOT-FOUND"
+#endif
+
 #ifndef TVM_INFO_USE_RTTI
 #define TVM_INFO_USE_RTTI "NOT-FOUND"
 #endif
@@ -344,6 +348,7 @@ TVM_DLL Map<String, String> GetLibInfo() {
       {"USE_PT_TVMDSOOP", TVM_INFO_USE_PT_TVMDSOOP},
       {"USE_RANDOM", TVM_INFO_USE_RANDOM},
       {"USE_RELAY_DEBUG", TVM_INFO_USE_RELAY_DEBUG},
+      {"TVM_DEBUG_WITH_ABI_CHANGE", TVM_INFO_TVM_DEBUG_WITH_ABI_CHANGE},
       {"USE_ROCBLAS", TVM_INFO_USE_ROCBLAS},
       {"USE_ROCM", TVM_INFO_USE_ROCM},
       {"USE_RCCL", TVM_INFO_USE_RCCL},
diff --git a/tests/cpp/container_test.cc b/tests/cpp/container_test.cc
index 5c9af19f9b..9d2f1437b9 100644
--- a/tests/cpp/container_test.cc
+++ b/tests/cpp/container_test.cc
@@ -524,7 +524,7 @@ TEST(Map, Erase) {
   }
 }
 
-#if TVM_LOG_DEBUG
+#if TVM_DEBUG_WITH_ABI_CHANGE
 TEST(Map, Race) {
   using namespace tvm::runtime;
   Map<Integer, Integer> m;
@@ -537,7 +537,7 @@ TEST(Map, Race) {
   // changed. iterator should be re-obtained
   EXPECT_ANY_THROW({ auto& kv = *it; });
 }
-#endif  // TVM_LOG_DEBUG
+#endif  // TVM_DEBUG_WITH_ABI_CHANGE
 
 TEST(String, MoveFromStd) {
   using namespace std;

Reply via email to