Skip to content

Commit e57ab7a

Browse files
authored
[Fix] Introduce TVM_DEBUG_WITH_ABI_CHANGE to warn ABI changes in debug mode (#16728)
* finish * update
1 parent feb1043 commit e57ab7a

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ tvm_option(USE_AOT_EXECUTOR "Build with AOT executor" ON)
6262
tvm_option(USE_PROFILER "Build profiler for the VM and graph executor" ON)
6363
tvm_option(USE_OPENMP "Build with OpenMP thread pool implementation" OFF)
6464
tvm_option(USE_RELAY_DEBUG "Building Relay in debug mode..." OFF)
65+
tvm_option(TVM_DEBUG_WITH_ABI_CHANGE "Enable debug code that may cause ABI changes" OFF)
6566
tvm_option(USE_RTTI "Build with RTTI" ON)
6667
tvm_option(USE_MSVC_MT "Build with MT" OFF)
6768
tvm_option(USE_MICRO "Build with Micro TVM support" OFF)
@@ -667,6 +668,13 @@ else()
667668
target_compile_definitions(tvm_libinfo_objs PRIVATE "NDEBUG")
668669
endif(USE_RELAY_DEBUG)
669670

671+
if(TVM_DEBUG_WITH_ABI_CHANGE)
672+
message(STATUS "Building with debug code that may cause ABI changes...")
673+
target_compile_definitions(tvm_objs PRIVATE "TVM_DEBUG_WITH_ABI_CHANGE")
674+
target_compile_definitions(tvm_runtime_objs PRIVATE "TVM_DEBUG_WITH_ABI_CHANGE")
675+
target_compile_definitions(tvm_libinfo_objs PRIVATE "TVM_DEBUG_WITH_ABI_CHANGE")
676+
endif(TVM_DEBUG_WITH_ABI_CHANGE)
677+
670678
if(USE_FALLBACK_STL_MAP)
671679
message(STATUS "Building with STL Map...")
672680
target_compile_definitions(tvm_objs PRIVATE "USE_FALLBACK_STL_MAP=1")
@@ -771,6 +779,10 @@ if(GTEST_FOUND)
771779
else()
772780
target_compile_definitions(cpptest PRIVATE "NDEBUG")
773781
endif()
782+
if(TVM_DEBUG_WITH_ABI_CHANGE)
783+
target_compile_definitions(cpptest PRIVATE "TVM_DEBUG_WITH_ABI_CHANGE")
784+
endif(TVM_DEBUG_WITH_ABI_CHANGE)
785+
774786
# For some reason, compile definitions are not propagated correctly, so we manually add them here
775787
target_compile_definitions(cpptest PUBLIC $<TARGET_PROPERTY:tvm,INTERFACE_COMPILE_DEFINITIONS>)
776788
gtest_discover_tests(cpptest)

cmake/config.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ set(USE_ANTLR OFF)
320320
# Whether use Relay debug mode
321321
set(USE_RELAY_DEBUG OFF)
322322

323+
# Whether to enable debug code that may cause ABI changes
324+
set(TVM_DEBUG_WITH_ABI_CHANGE OFF)
325+
323326
# Whether to build fast VTA simulator driver
324327
set(USE_VTA_FSIM OFF)
325328

cmake/modules/LibInfo.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ function(add_lib_info src_file)
112112
TVM_INFO_USE_PT_TVMDSOOP="${USE_PT_TVMDSOOP}"
113113
TVM_INFO_USE_RANDOM="${USE_RANDOM}"
114114
TVM_INFO_USE_RELAY_DEBUG="${USE_RELAY_DEBUG}"
115+
TVM_INFO_TVM_DEBUG_WITH_ABI_CHANGE="${TVM_DEBUG_WITH_ABI_CHANGE}"
115116
TVM_INFO_USE_ROCBLAS="${USE_ROCBLAS}"
116117
TVM_INFO_USE_ROCM="${USE_ROCM}"
117118
TVM_INFO_USE_RCCL="${USE_RCCL}"

include/tvm/runtime/container/map.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
namespace tvm {
3939
namespace runtime {
4040

41-
#if TVM_LOG_DEBUG
41+
#if TVM_DEBUG_WITH_ABI_CHANGE
4242
#define TVM_MAP_FAIL_IF_CHANGED() \
4343
ICHECK(state_marker == self->state_marker) << "Concurrent modification of the Map";
4444
#else
4545
#define TVM_MAP_FAIL_IF_CHANGED()
46-
#endif // TVM_LOG_DEBUG
46+
#endif // TVM_DEBUG_WITH_ABI_CHANGE
4747

4848
#if (USE_FALLBACK_STL_MAP != 0)
4949

@@ -241,11 +241,11 @@ class MapNode : public Object {
241241
using pointer = KVType*;
242242
using reference = KVType&;
243243
/*! \brief Default constructor */
244-
#if TVM_LOG_DEBUG
244+
#if TVM_DEBUG_WITH_ABI_CHANGE
245245
iterator() : state_marker(0), index(0), self(nullptr) {}
246246
#else
247247
iterator() : index(0), self(nullptr) {}
248-
#endif // TVM_LOG_DEBUG
248+
#endif // TVM_DEBUG_WITH_ABI_CHANGE
249249
/*! \brief Compare iterators */
250250
bool operator==(const iterator& other) const {
251251
TVM_MAP_FAIL_IF_CHANGED()
@@ -280,15 +280,15 @@ class MapNode : public Object {
280280
}
281281

282282
protected:
283-
#if TVM_LOG_DEBUG
283+
#if TVM_DEBUG_WITH_ABI_CHANGE
284284
uint64_t state_marker;
285285
/*! \brief Construct by value */
286286
iterator(uint64_t index, const MapNode* self)
287287
: state_marker(self->state_marker), index(index), self(self) {}
288288

289289
#else
290290
iterator(uint64_t index, const MapNode* self) : index(index), self(self) {}
291-
#endif // TVM_LOG_DEBUG
291+
#endif // TVM_DEBUG_WITH_ABI_CHANGE
292292
/*! \brief The position on the array */
293293
uint64_t index;
294294
/*! \brief The container it points to */
@@ -304,9 +304,9 @@ class MapNode : public Object {
304304
static inline ObjectPtr<MapNode> Empty();
305305

306306
protected:
307-
#if TVM_LOG_DEBUG
307+
#if TVM_DEBUG_WITH_ABI_CHANGE
308308
uint64_t state_marker;
309-
#endif // TVM_LOG_DEBUG
309+
#endif // TVM_DEBUG_WITH_ABI_CHANGE
310310
/*!
311311
* \brief Create the map using contents from the given iterators.
312312
* \param first Begin of iterator
@@ -1233,9 +1233,9 @@ inline ObjectPtr<Object> MapNode::CreateFromRange(IterType first, IterType last)
12331233
inline void MapNode::InsertMaybeReHash(const KVType& kv, ObjectPtr<Object>* map) {
12341234
constexpr uint64_t kSmallMapMaxSize = SmallMapNode::kMaxSize;
12351235
MapNode* base = static_cast<MapNode*>(map->get());
1236-
#if TVM_LOG_DEBUG
1236+
#if TVM_DEBUG_WITH_ABI_CHANGE
12371237
base->state_marker++;
1238-
#endif // TVM_LOG_DEBUG
1238+
#endif // TVM_DEBUG_WITH_ABI_CHANGE
12391239
if (base->slots_ < kSmallMapMaxSize) {
12401240
SmallMapNode::InsertMaybeReHash(kv, map);
12411241
} else if (base->slots_ == kSmallMapMaxSize) {

src/support/libinfo.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
#define TVM_INFO_USE_RELAY_DEBUG "NOT-FOUND"
128128
#endif
129129

130+
#ifndef TVM_INFO_TVM_DEBUG_WITH_ABI_CHANGE
131+
#define TVM_INFO_TVM_DEBUG_WITH_ABI_CHANGE "NOT-FOUND"
132+
#endif
133+
130134
#ifndef TVM_INFO_USE_RTTI
131135
#define TVM_INFO_USE_RTTI "NOT-FOUND"
132136
#endif
@@ -344,6 +348,7 @@ TVM_DLL Map<String, String> GetLibInfo() {
344348
{"USE_PT_TVMDSOOP", TVM_INFO_USE_PT_TVMDSOOP},
345349
{"USE_RANDOM", TVM_INFO_USE_RANDOM},
346350
{"USE_RELAY_DEBUG", TVM_INFO_USE_RELAY_DEBUG},
351+
{"TVM_DEBUG_WITH_ABI_CHANGE", TVM_INFO_TVM_DEBUG_WITH_ABI_CHANGE},
347352
{"USE_ROCBLAS", TVM_INFO_USE_ROCBLAS},
348353
{"USE_ROCM", TVM_INFO_USE_ROCM},
349354
{"USE_RCCL", TVM_INFO_USE_RCCL},

tests/cpp/container_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ TEST(Map, Erase) {
524524
}
525525
}
526526

527-
#if TVM_LOG_DEBUG
527+
#if TVM_DEBUG_WITH_ABI_CHANGE
528528
TEST(Map, Race) {
529529
using namespace tvm::runtime;
530530
Map<Integer, Integer> m;
@@ -537,7 +537,7 @@ TEST(Map, Race) {
537537
// changed. iterator should be re-obtained
538538
EXPECT_ANY_THROW({ auto& kv = *it; });
539539
}
540-
#endif // TVM_LOG_DEBUG
540+
#endif // TVM_DEBUG_WITH_ABI_CHANGE
541541

542542
TEST(String, MoveFromStd) {
543543
using namespace std;

0 commit comments

Comments
 (0)