Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions cmake/modules/LibInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
20 changes: 10 additions & 10 deletions include/tvm/runtime/container/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -280,15 +280,15 @@ 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)
: state_marker(self->state_marker), index(index), self(self) {}

#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 */
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/support/libinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions tests/cpp/container_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down