From aa37e430ec1494bae48ac0cb486946a9b9e0d899 Mon Sep 17 00:00:00 2001 From: Ubospica Date: Fri, 15 Mar 2024 18:20:01 +0000 Subject: [PATCH 1/2] finish --- CMakeLists.txt | 12 ++++++++++++ cmake/config.cmake | 3 +++ include/tvm/runtime/container/map.h | 20 ++++++++++---------- tests/cpp/container_test.cc | 4 ++-- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d10a18c4f17e..c9d836b6812c 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 $) gtest_discover_tests(cpptest) diff --git a/cmake/config.cmake b/cmake/config.cmake index e175902f2de8..2666185fce96 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/include/tvm/runtime/container/map.h b/include/tvm/runtime/container/map.h index 53c37cc20e6b..eb86ddb7b8f9 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 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 MapNode::CreateFromRange(IterType first, IterType last) inline void MapNode::InsertMaybeReHash(const KVType& kv, ObjectPtr* map) { constexpr uint64_t kSmallMapMaxSize = SmallMapNode::kMaxSize; MapNode* base = static_cast(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/tests/cpp/container_test.cc b/tests/cpp/container_test.cc index 5c9af19f9bc9..9d2f1437b9ab 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 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; From 7f2bd4633f4b3d97aa2d7a19a886ef5ec8ffa565 Mon Sep 17 00:00:00 2001 From: Ubospica Date: Fri, 15 Mar 2024 18:36:01 +0000 Subject: [PATCH 2/2] update --- cmake/modules/LibInfo.cmake | 1 + src/support/libinfo.cc | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/cmake/modules/LibInfo.cmake b/cmake/modules/LibInfo.cmake index 5f82a0c78286..6d6b0b0c6e50 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/src/support/libinfo.cc b/src/support/libinfo.cc index 38159c42ebd3..4c863d7decfd 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 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},