From 7eedd51c1a1aac647a67543a63064128238fed28 Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Sun, 26 Jul 2020 23:10:59 -0700 Subject: [PATCH 1/9] add hexdump support utility --- src/support/hexdump.cc | 65 +++++++++++++++++++++++++++++++++++++++ src/support/hexdump.h | 44 ++++++++++++++++++++++++++ tests/cpp/support_test.cc | 53 +++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 src/support/hexdump.cc create mode 100644 src/support/hexdump.h create mode 100644 tests/cpp/support_test.cc diff --git a/src/support/hexdump.cc b/src/support/hexdump.cc new file mode 100644 index 000000000000..e6f7a97bdb4f --- /dev/null +++ b/src/support/hexdump.cc @@ -0,0 +1,65 @@ +/* + * 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. + */ + +/*! + * + * \file support/hexdump.cc + * \brief Print hex representation of BLOBs. + */ + +#include "hexdump.h" + +namespace tvm { +namespace support { + +void hexdump(const std::string& s, std::ostream& os) { + os << std::hex << std::setfill('0') << std::right; + + int addr_width = 4; + for (size_t addr_bytes = s.size() >> 16; addr_bytes != 0; addr_bytes >>= 4) { + addr_width++; + } + + + for (size_t cursor = 0; cursor < s.size(); cursor += 0x10) { + os << std::setw(addr_width) << cursor; + size_t row_end = cursor + 0x10; + if (row_end > s.size()) { + row_end = s.size(); + } + + os << " "; + for (size_t j = cursor; j < row_end; j++) { + os << " " << std::setw(2) << (unsigned int)(s[j] & 0xff); + } + + for (size_t j = row_end; j < cursor + 0x10; j++) { + os << " "; + } + + os << std::setw(1) << " "; + for (size_t j = cursor; j < row_end; j++) { + os << (isprint(s[j]) ? s[j] : '.'); + } + os << std::endl; + } +} + +} // namespace support +} // namespace tvm diff --git a/src/support/hexdump.h b/src/support/hexdump.h new file mode 100644 index 000000000000..89de72417c09 --- /dev/null +++ b/src/support/hexdump.h @@ -0,0 +1,44 @@ +/* + * 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. + */ + +/*! + * + * \file support/hexdump.h + * \brief Print hex representation of BLOBs. + */ +#ifndef TVM_SUPPORT_HEXDUMP_H_ +#define TVM_SUPPORT_HEXDUMP_H_ + +#include +#include + +namespace tvm { +namespace support { + +void hexdump(const std::string& s, std::ostream& os); + +inline std::string hexdump(const std::string& s) { + std::stringstream ss; + hexdump(s, ss); + return ss.str(); +} + +} // namespace support +} // namespace tvm +#endif // TVM_SUPPORT_STR_ESCAPE_H_ diff --git a/tests/cpp/support_test.cc b/tests/cpp/support_test.cc new file mode 100644 index 000000000000..ddbcbb4530ba --- /dev/null +++ b/tests/cpp/support_test.cc @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include +#include +#include "../../src/support/hexdump.h" + + +namespace tvm { +namespace test { + +TEST(HexDumpTests, Empty) { + EXPECT_EQ("", ::tvm::support::hexdump("")); +} + +TEST(HexDumpTests, Aligned) { + EXPECT_EQ("0000 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n" + "0010 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n", + ::tvm::support::hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" + "\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef")); +} + +TEST(HexDumpTests, Unaligned) { + EXPECT_EQ("0000 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n" + "0010 01 23 45 67 89 ab cd ef 01 .#Eg.....\n", + ::tvm::support::hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" + "\x01\x23\x45\x67\x89\xab\xcd\xef\x01")); +} + +} // namespace test +} // namespace tvm + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + testing::FLAGS_gtest_death_test_style = "threadsafe"; + return RUN_ALL_TESTS(); +} From e935dbed74b201ac13056d5ee454ba7228746093 Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Mon, 27 Jul 2020 12:10:47 -0700 Subject: [PATCH 2/9] build TVM as a static lib and link against tests --- CMakeLists.txt | 54 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19d582affed8..5e29fd84fbec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -347,9 +347,17 @@ else() set(CMAKE_CUDA_STANDARD 14) endif() -add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS}) -add_library(tvm_topi SHARED ${TOPI_SRCS}) -add_library(tvm_runtime SHARED ${RUNTIME_SRCS}) +add_library(tvm_static STATIC ${COMPILER_SRCS} ${RUNTIME_SRCS}) +add_library(tvm_topi_static STATIC ${TOPI_SRCS}) +add_library(tvm_runtime_static STATIC ${RUNTIME_SRCS}) + +add_library(tvm SHARED) +target_link_libraries(tvm tvm_static) +add_library(tvm_topi SHARED) +target_link_libraries(tvm_topi tvm_topi_static) +add_library(tvm_runtime SHARED) +target_link_libraries(tvm_runtime tvm_runtime_static) + if(USE_CPP_RPC) add_subdirectory("apps/cpp_rpc") @@ -357,28 +365,28 @@ endif() if(USE_RELAY_DEBUG) message(STATUS "Building Relay in debug mode...") - set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "USE_RELAY_DEBUG") - set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "DMLC_LOG_DEBUG") + set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "USE_RELAY_DEBUG") + set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "DMLC_LOG_DEBUG") else() - set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "NDEBUG") + set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "NDEBUG") endif(USE_RELAY_DEBUG) if(USE_FALLBACK_STL_MAP) message(STATUS "Building with STL Map...") - set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=1") - set_target_properties(tvm_topi PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=1") + set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=1") + set_target_properties(tvm_topi_static PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=1") else() message(STATUS "Building with TVM Map...") - set_target_properties(tvm PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=0") - set_target_properties(tvm_topi PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=0") + set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=0") + set_target_properties(tvm_topi_static PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=0") endif(USE_FALLBACK_STL_MAP) if(BUILD_FOR_HEXAGON) # Wrap pthread_create to allow setting custom stack size. - set_target_properties(tvm_runtime PROPERTIES LINK_FLAGS + set_target_properties(tvm_runtime_static PROPERTIES LINK_FLAGS "-Wl,--wrap=pthread_create") - target_include_directories(tvm_runtime + target_include_directories(tvm_runtime_static PUBLIC "${USE_HEXAGON_SDK}/libs/common/qurt/ADSPv62MP/include/posix" PUBLIC "${USE_HEXAGON_SDK}/libs/common/qurt/ADSPv62MP/include/qurt" PUBLIC "${USE_HEXAGON_SDK}/incs" @@ -390,14 +398,14 @@ if(USE_THREADS AND NOT BUILD_FOR_HEXAGON) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) - target_link_libraries(tvm Threads::Threads) - target_link_libraries(tvm_topi Threads::Threads) - target_link_libraries(tvm_runtime Threads::Threads) + target_link_libraries(tvm_static Threads::Threads) + target_link_libraries(tvm_topi_static Threads::Threads) + target_link_libraries(tvm_runtime_static Threads::Threads) endif() -target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) -target_link_libraries(tvm_topi tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) -target_link_libraries(tvm_runtime ${TVM_RUNTIME_LINKER_LIBS}) +target_link_libraries(tvm_static ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) +target_link_libraries(tvm_topi_static tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) +target_link_libraries(tvm_runtime_static ${TVM_RUNTIME_LINKER_LIBS}) if (HIDE_PRIVATE_SYMBOLS AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(HIDE_SYMBOLS_LINKER_FLAGS "-Wl,--exclude-libs,ALL") @@ -411,10 +419,10 @@ endif() # Related headers target_include_directories( - tvm + tvm_static PUBLIC "topi/include") target_include_directories( - tvm_topi + tvm_topi_static PUBLIC "topi/include") @@ -433,7 +441,7 @@ if(GTEST_INCLUDE_DIR AND GTEST_LIB) add_executable(${__execname} ${__srcpath}) list(APPEND TEST_EXECS ${__execname}) target_include_directories(${__execname} PUBLIC ${GTEST_INCLUDE_DIR}) - target_link_libraries(${__execname} tvm ${GTEST_LIB} pthread dl) + target_link_libraries(${__execname} tvm_static ${GTEST_LIB} pthread dl) set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_ALL 1) set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1) endforeach() @@ -487,6 +495,6 @@ endif(INSTALL_DEV) # More target definitions if(MSVC) - target_compile_definitions(tvm PRIVATE -DTVM_EXPORTS) - target_compile_definitions(tvm_runtime PRIVATE -DTVM_EXPORTS) + target_compile_definitions(tvm_static PRIVATE -DTVM_EXPORTS) + target_compile_definitions(tvm_runtime_static PRIVATE -DTVM_EXPORTS) endif() From 5aab1d5dd3cfbb67658d3637c552e757f2bb5c3d Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Mon, 27 Jul 2020 18:54:10 -0700 Subject: [PATCH 3/9] add empty.cc to work around lack of sources --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e29fd84fbec..62a71e49dd57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,11 +351,13 @@ add_library(tvm_static STATIC ${COMPILER_SRCS} ${RUNTIME_SRCS}) add_library(tvm_topi_static STATIC ${TOPI_SRCS}) add_library(tvm_runtime_static STATIC ${RUNTIME_SRCS}) -add_library(tvm SHARED) +file(WRITE empty.cc "") + +add_library(tvm SHARED empty.cc) target_link_libraries(tvm tvm_static) -add_library(tvm_topi SHARED) +add_library(tvm_topi SHARED empty.cc) target_link_libraries(tvm_topi tvm_topi_static) -add_library(tvm_runtime SHARED) +add_library(tvm_runtime SHARED empty.cc) target_link_libraries(tvm_runtime tvm_runtime_static) From b1ac15146e5b1e6f224ddf0dd03f4baf0036a003 Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Mon, 27 Jul 2020 18:54:18 -0700 Subject: [PATCH 4/9] cpplint --- src/support/hexdump.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/support/hexdump.h b/src/support/hexdump.h index 89de72417c09..9efaec9d9a78 100644 --- a/src/support/hexdump.h +++ b/src/support/hexdump.h @@ -27,6 +27,7 @@ #include #include +#include namespace tvm { namespace support { @@ -41,4 +42,4 @@ inline std::string hexdump(const std::string& s) { } // namespace support } // namespace tvm -#endif // TVM_SUPPORT_STR_ESCAPE_H_ +#endif // TVM_SUPPORT_HEXDUMP_H_ From fdc366a74aa4adfe68bbed868369aab482df6e60 Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Mon, 27 Jul 2020 18:57:56 -0700 Subject: [PATCH 5/9] git-clang-format --- src/support/hexdump.cc | 1 - tests/cpp/support_test.cc | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/support/hexdump.cc b/src/support/hexdump.cc index e6f7a97bdb4f..dc3d63ce6f59 100644 --- a/src/support/hexdump.cc +++ b/src/support/hexdump.cc @@ -36,7 +36,6 @@ void hexdump(const std::string& s, std::ostream& os) { addr_width++; } - for (size_t cursor = 0; cursor < s.size(); cursor += 0x10) { os << std::setw(addr_width) << cursor; size_t row_end = cursor + 0x10; diff --git a/tests/cpp/support_test.cc b/tests/cpp/support_test.cc index ddbcbb4530ba..fa0ab28a988c 100644 --- a/tests/cpp/support_test.cc +++ b/tests/cpp/support_test.cc @@ -19,28 +19,28 @@ #include #include -#include "../../src/support/hexdump.h" +#include "../../src/support/hexdump.h" namespace tvm { namespace test { -TEST(HexDumpTests, Empty) { - EXPECT_EQ("", ::tvm::support::hexdump("")); -} +TEST(HexDumpTests, Empty) { EXPECT_EQ("", ::tvm::support::hexdump("")); } TEST(HexDumpTests, Aligned) { - EXPECT_EQ("0000 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n" - "0010 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n", - ::tvm::support::hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" - "\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef")); + EXPECT_EQ( + "0000 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n" + "0010 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n", + ::tvm::support::hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" + "\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef")); } TEST(HexDumpTests, Unaligned) { - EXPECT_EQ("0000 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n" - "0010 01 23 45 67 89 ab cd ef 01 .#Eg.....\n", - ::tvm::support::hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" - "\x01\x23\x45\x67\x89\xab\xcd\xef\x01")); + EXPECT_EQ( + "0000 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n" + "0010 01 23 45 67 89 ab cd ef 01 .#Eg.....\n", + ::tvm::support::hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" + "\x01\x23\x45\x67\x89\xab\xcd\xef\x01")); } } // namespace test From 7fae6fc07b91145278047d93271a814872fc71ba Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Tue, 28 Jul 2020 11:09:44 -0700 Subject: [PATCH 6/9] try static linking tvm_topi_static against tvm_static * also adjust compiler flags. --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62a71e49dd57..865f75971846 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -406,7 +406,7 @@ if(USE_THREADS AND NOT BUILD_FOR_HEXAGON) endif() target_link_libraries(tvm_static ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) -target_link_libraries(tvm_topi_static tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) +target_link_libraries(tvm_topi_static tvm_static ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) target_link_libraries(tvm_runtime_static ${TVM_RUNTIME_LINKER_LIBS}) if (HIDE_PRIVATE_SYMBOLS AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -414,9 +414,9 @@ if (HIDE_PRIVATE_SYMBOLS AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Note: 'target_link_options' with 'PRIVATE' keyword would be cleaner # but it's not available until CMake 3.13. Switch to 'target_link_options' # once minimum CMake version is bumped up to 3.13 or above. - target_link_libraries(tvm ${HIDE_SYMBOLS_LINKER_FLAGS}) - target_link_libraries(tvm_topi ${HIDE_SYMBOLS_LINKER_FLAGS}) - target_link_libraries(tvm_runtime ${HIDE_SYMBOLS_LINKER_FLAGS}) + target_link_libraries(tvm_static ${HIDE_SYMBOLS_LINKER_FLAGS}) + target_link_libraries(tvm_topi_static ${HIDE_SYMBOLS_LINKER_FLAGS}) + target_link_libraries(tvm_runtime_static ${HIDE_SYMBOLS_LINKER_FLAGS}) endif() # Related headers From 6ecdef0843f55eadd061fd344b41d34deb82250a Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Wed, 29 Jul 2020 09:54:04 -0700 Subject: [PATCH 7/9] link tvm_allvisible separately for tests --- CMakeLists.txt | 93 +++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 865f75971846..f7246b1156db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,10 +120,10 @@ else(MSVC) set(CMAKE_C_FLAGS "-O2 -Wall -fPIC ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC ${CMAKE_CXX_FLAGS}") set(CMAKE_CUDA_FLAGS "-O2 -Xcompiler=-Wall -Xcompiler=-fPIC ${CMAKE_CUDA_FLAGS}") + set(TVM_VISIBILITY_FLAG "") if (HIDE_PRIVATE_SYMBOLS) message(STATUS "Hide private symbols...") - set(CMAKE_C_FLAGS "-fvisibility=hidden ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "-fvisibility=hidden ${CMAKE_CXX_FLAGS}") + set(TVM_VISIBILITY_FLAG "-fvisibility=hidden") endif(HIDE_PRIVATE_SYMBOLS) endif () if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND @@ -347,18 +347,16 @@ else() set(CMAKE_CUDA_STANDARD 14) endif() -add_library(tvm_static STATIC ${COMPILER_SRCS} ${RUNTIME_SRCS}) -add_library(tvm_topi_static STATIC ${TOPI_SRCS}) -add_library(tvm_runtime_static STATIC ${RUNTIME_SRCS}) +add_library(tvm_objs OBJECT ${COMPILER_SRCS} ${RUNTIME_SRCS}) +add_library(tvm_topi_objs OBJECT ${TOPI_SRCS}) +add_library(tvm_runtime_objs OBJECT ${RUNTIME_SRCS}) -file(WRITE empty.cc "") - -add_library(tvm SHARED empty.cc) -target_link_libraries(tvm tvm_static) -add_library(tvm_topi SHARED empty.cc) -target_link_libraries(tvm_topi tvm_topi_static) -add_library(tvm_runtime SHARED empty.cc) -target_link_libraries(tvm_runtime tvm_runtime_static) +add_library(tvm SHARED $) +set_property(TARGET tvm APPEND PROPERTY LINK_OPTIONS "${TVM_VISIBILITY_FLAGS}") +add_library(tvm_topi SHARED $) +set_property(TARGET tvm_topi APPEND PROPERTY LINK_OPTIONS "${TVM_VISIBILITY_FLAGS}") +add_library(tvm_runtime SHARED $) +set_property(TARGET tvm_runtime APPEND PROPERTY LINK_OPTIONS "${TVM_VISIBILITY_FLAGS}") if(USE_CPP_RPC) @@ -367,28 +365,28 @@ endif() if(USE_RELAY_DEBUG) message(STATUS "Building Relay in debug mode...") - set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "USE_RELAY_DEBUG") - set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "DMLC_LOG_DEBUG") + set_target_properties(tvm_objs PROPERTIES COMPILE_DEFINITIONS "USE_RELAY_DEBUG") + set_target_properties(tvm_objs PROPERTIES COMPILE_DEFINITIONS "DMLC_LOG_DEBUG") else() - set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "NDEBUG") + set_target_properties(tvm_objs PROPERTIES COMPILE_DEFINITIONS "NDEBUG") endif(USE_RELAY_DEBUG) if(USE_FALLBACK_STL_MAP) message(STATUS "Building with STL Map...") - set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=1") - set_target_properties(tvm_topi_static PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=1") + set_target_properties(tvm_objs PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=1") + set_target_properties(tvm_topi_objs PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=1") else() message(STATUS "Building with TVM Map...") - set_target_properties(tvm_static PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=0") - set_target_properties(tvm_topi_static PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=0") + set_target_properties(tvm_objs PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=0") + set_target_properties(tvm_topi_objs PROPERTIES COMPILE_DEFINITIONS "USE_FALLBACK_STL_MAP=0") endif(USE_FALLBACK_STL_MAP) if(BUILD_FOR_HEXAGON) # Wrap pthread_create to allow setting custom stack size. - set_target_properties(tvm_runtime_static PROPERTIES LINK_FLAGS + set_target_properties(tvm_runtime PROPERTIES LINK_FLAGS "-Wl,--wrap=pthread_create") - target_include_directories(tvm_runtime_static + target_include_directories(tvm_runtime PUBLIC "${USE_HEXAGON_SDK}/libs/common/qurt/ADSPv62MP/include/posix" PUBLIC "${USE_HEXAGON_SDK}/libs/common/qurt/ADSPv62MP/include/qurt" PUBLIC "${USE_HEXAGON_SDK}/incs" @@ -400,33 +398,42 @@ if(USE_THREADS AND NOT BUILD_FOR_HEXAGON) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) - target_link_libraries(tvm_static Threads::Threads) - target_link_libraries(tvm_topi_static Threads::Threads) - target_link_libraries(tvm_runtime_static Threads::Threads) + target_link_libraries(tvm Threads::Threads) + target_link_libraries(tvm_topi Threads::Threads) + target_link_libraries(tvm_runtime Threads::Threads) endif() -target_link_libraries(tvm_static ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) -target_link_libraries(tvm_topi_static tvm_static ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) -target_link_libraries(tvm_runtime_static ${TVM_RUNTIME_LINKER_LIBS}) - -if (HIDE_PRIVATE_SYMBOLS AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(HIDE_SYMBOLS_LINKER_FLAGS "-Wl,--exclude-libs,ALL") - # Note: 'target_link_options' with 'PRIVATE' keyword would be cleaner - # but it's not available until CMake 3.13. Switch to 'target_link_options' - # once minimum CMake version is bumped up to 3.13 or above. - target_link_libraries(tvm_static ${HIDE_SYMBOLS_LINKER_FLAGS}) - target_link_libraries(tvm_topi_static ${HIDE_SYMBOLS_LINKER_FLAGS}) - target_link_libraries(tvm_runtime_static ${HIDE_SYMBOLS_LINKER_FLAGS}) -endif() +target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) +target_link_libraries(tvm_topi tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) +target_link_libraries(tvm_runtime ${TVM_RUNTIME_LINKER_LIBS}) # Related headers target_include_directories( - tvm_static + tvm + PUBLIC "topi/include") +target_include_directories( + tvm_objs PUBLIC "topi/include") target_include_directories( - tvm_topi_static + tvm_topi_objs PUBLIC "topi/include") +set(TVM_TEST_LIBRARY_NAME tvm) +if (HIDE_PRIVATE_SYMBOLS AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + add_library(tvm_allvisible SHARED $) + target_include_directories(tvm_allvisible PUBLIC "$") + target_link_libraries(tvm_allvisible PUBLIC "$") + set(TVM_TEST_LIBRARY_NAME tvm_allvisible) + +set(HIDE_SYMBOLS_LINKER_FLAGS "-Wl,--exclude-libs,ALL") + # Note: 'target_link_options' with 'PRIVATE' keyword would be cleaner + # but it's not available until CMake 3.13. Switch to 'target_link_options' + # once minimum CMake version is bumped up to 3.13 or above. + target_link_libraries(tvm ${HIDE_SYMBOLS_LINKER_FLAGS}) + target_link_libraries(tvm_topi ${HIDE_SYMBOLS_LINKER_FLAGS}) + target_link_libraries(tvm_runtime ${HIDE_SYMBOLS_LINKER_FLAGS}) +endif() + # Tests set(TEST_EXECS "") @@ -443,7 +450,7 @@ if(GTEST_INCLUDE_DIR AND GTEST_LIB) add_executable(${__execname} ${__srcpath}) list(APPEND TEST_EXECS ${__execname}) target_include_directories(${__execname} PUBLIC ${GTEST_INCLUDE_DIR}) - target_link_libraries(${__execname} tvm_static ${GTEST_LIB} pthread dl) + target_link_libraries(${__execname} ${TVM_TEST_LIBRARY_NAME} ${GTEST_LIB} pthread dl) set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_ALL 1) set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1) endforeach() @@ -497,6 +504,6 @@ endif(INSTALL_DEV) # More target definitions if(MSVC) - target_compile_definitions(tvm_static PRIVATE -DTVM_EXPORTS) - target_compile_definitions(tvm_runtime_static PRIVATE -DTVM_EXPORTS) + target_compile_definitions(tvm_objs PRIVATE -DTVM_EXPORTS) + target_compile_definitions(tvm_runtime_objs PRIVATE -DTVM_EXPORTS) endif() From 7b6c93e036fc87cad6f9dca6aa1f0ca2e301d368 Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Mon, 17 Aug 2020 11:11:00 -0700 Subject: [PATCH 8/9] address tqchen comments --- src/support/hexdump.cc | 2 +- src/support/hexdump.h | 11 ++++++++--- tests/cpp/support_test.cc | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/support/hexdump.cc b/src/support/hexdump.cc index dc3d63ce6f59..6259815cddd6 100644 --- a/src/support/hexdump.cc +++ b/src/support/hexdump.cc @@ -28,7 +28,7 @@ namespace tvm { namespace support { -void hexdump(const std::string& s, std::ostream& os) { +void HexDump(const std::string& s, std::ostream& os) { os << std::hex << std::setfill('0') << std::right; int addr_width = 4; diff --git a/src/support/hexdump.h b/src/support/hexdump.h index 9efaec9d9a78..4d660c6d2bf7 100644 --- a/src/support/hexdump.h +++ b/src/support/hexdump.h @@ -32,11 +32,16 @@ namespace tvm { namespace support { -void hexdump(const std::string& s, std::ostream& os); +/*! \brief generate a hexdump of some binary data. + * \param s Binary data to print. + * \param os stream that receives the hexdump. + */ +void HexDump(const std::string& s, std::ostream& os); -inline std::string hexdump(const std::string& s) { +/*! \brief return a string containing a hexdump of the data in s */ +inline std::string HexDump(const std::string& s) { std::stringstream ss; - hexdump(s, ss); + HexDump(s, ss); return ss.str(); } diff --git a/tests/cpp/support_test.cc b/tests/cpp/support_test.cc index fa0ab28a988c..bc9b944c6550 100644 --- a/tests/cpp/support_test.cc +++ b/tests/cpp/support_test.cc @@ -25,13 +25,13 @@ namespace tvm { namespace test { -TEST(HexDumpTests, Empty) { EXPECT_EQ("", ::tvm::support::hexdump("")); } +TEST(HexDumpTests, Empty) { EXPECT_EQ("", ::tvm::support::HexDump("")); } TEST(HexDumpTests, Aligned) { EXPECT_EQ( "0000 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n" "0010 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n", - ::tvm::support::hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" + ::tvm::support::HexDump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" "\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef")); } @@ -39,7 +39,7 @@ TEST(HexDumpTests, Unaligned) { EXPECT_EQ( "0000 01 23 45 67 89 ab cd ef 01 23 45 67 89 ab cd ef .#Eg.....#Eg....\n" "0010 01 23 45 67 89 ab cd ef 01 .#Eg.....\n", - ::tvm::support::hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" + ::tvm::support::HexDump("\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef" "\x01\x23\x45\x67\x89\xab\xcd\xef\x01")); } From 362fe5e922b1a55ff8bf30b8fbe4481b9e8f3d15 Mon Sep 17 00:00:00 2001 From: Andrew Reusch Date: Tue, 18 Aug 2020 08:39:41 -0700 Subject: [PATCH 9/9] fix target_link_libraries arg --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b974bec82a9..d2ce02c1ab05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -381,8 +381,8 @@ if(USE_THREADS AND NOT BUILD_FOR_HEXAGON) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) - target_link_libraries(tvm_objs Threads::Threads) - target_link_libraries(tvm_runtime_objs Threads::Threads) + target_link_libraries(tvm Threads::Threads) + target_link_libraries(tvm_runtime Threads::Threads) endif() target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})