From 09aaa63e4672875c854729041d10935267dc481b Mon Sep 17 00:00:00 2001 From: Umang Yadav <29876643+umangyadav@users.noreply.github.com> Date: Tue, 21 Mar 2023 22:05:07 -0400 Subject: [PATCH] Use version number as part of internal namespace symbol (#1633) prevent dynamically loading the target library that is not compiled with the same version of MIGraphX core lib. --- .github/workflows/ci.yaml | 4 ++++ CMakeLists.txt | 6 ++++-- Jenkinsfile | 2 +- src/CMakeLists.txt | 4 ++++ src/api/CMakeLists.txt | 5 ++++- src/driver/main.cpp | 7 +++++-- src/include/migraphx/config.hpp | 28 +++++++++++++++++++--------- src/version.h.in | 2 ++ 8 files changed, 43 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3b97c94aca0..c0e38cba952 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -63,6 +63,7 @@ jobs: -DMIGRAPHX_ENABLE_GPU=On \ -DMIGRAPHX_ENABLE_CPU=On \ -DMIGRAPHX_ENABLE_FPGA=On \ + -DBUILD_DEV=On \ -DROCM_ENABLE_GH_ANNOTATIONS=On \ -DCLANG_TIDY_DEPEND_ON_TARGET=Off \ -DCLANG_TIDY_CACHE=/data/tidy-cache \ @@ -108,6 +109,7 @@ jobs: cd build CXX=/opt/rocm/llvm/bin/clang++ CC=/opt/rocm/llvm/bin/clang cmake \ -DCPPCHECK_BUILD_DIR=/data/cppcheck-cache \ + -DBUILD_DEV=On \ -DROCM_ENABLE_GH_ANNOTATIONS=On \ .. make -j2 cppcheck @@ -257,6 +259,7 @@ jobs: rbuild build -d cget -s gh -T check \ -DCMAKE_BUILD_TYPE=${{matrix.configuration}} \ -DMIGRAPHX_ENABLE_PYTHON=${{matrix.configuration == 'release' && 'On' || 'Off'}} \ + -DBUILD_DEV=On \ -DCMAKE_CXX_FLAGS_DEBUG="-g1 -Os -fdebug-prefix-map=$PWD=. -fdebug-types-section -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=undefined" \ -DCMAKE_CXX_FLAGS_CODECOV="-g1 -Og -fdebug-prefix-map=$PWD=. -fdebug-types-section -fprofile-arcs -ftest-coverage -fno-omit-frame-pointer" \ -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld' \ @@ -352,6 +355,7 @@ jobs: rbuild build -d cget -s gh -T check \ -DCMAKE_BUILD_TYPE=${{matrix.configuration}} \ -DMIGRAPHX_ENABLE_PYTHON=${{matrix.configuration == 'release' && 'On' || 'Off'}} \ + -DBUILD_DEV=On \ -DCMAKE_CXX_FLAGS_DEBUG="-g1 -Os -fdebug-prefix-map=$PWD=. -fdebug-types-section -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=undefined" \ -DCMAKE_CXX_FLAGS_CODECOV="-g1 -Og -fdebug-prefix-map=$PWD=. -fdebug-types-section -fprofile-arcs -ftest-coverage -fno-omit-frame-pointer" \ -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld' \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 27fce49b00c..b4a730a1013 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,8 +67,10 @@ set(CMAKE_EXTRA_INCLUDE_FILES) include(ROCMSetupVersion) -rocm_setup_version(VERSION 2.6) -set(MIGRAPHX_SO_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) +option(BUILD_DEV "Build for development purpose only" OFF) + +rocm_setup_version(VERSION 2.6.0) +set(MIGRAPHX_SO_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) option( BUILD_SHARED_LIBS "Build as a shared library" ON ) diff --git a/Jenkinsfile b/Jenkinsfile index 05f6061685c..ff962fe48b9 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -28,7 +28,7 @@ def rocmtestnode(Map conf) { rm -rf build mkdir build cd build - cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ${flags} .. + cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_DEV=On ${flags} .. make -j\$(nproc) generate all doc package check VERBOSE=1 """ echo cmd diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd961180f34..0bd86c78f61 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -292,6 +292,10 @@ if(HAVE_HALF_EXPR) target_compile_definitions(migraphx PUBLIC -DHAS_HALF_V1) endif() +if(BUILD_DEV) + target_compile_definitions(migraphx PUBLIC -DBUILD_DEV) +endif() + rocm_export_targets( TARGETS migraphx::migraphx_c NAMESPACE migraphx:: diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index e97f6ded021..1354e386d72 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -26,7 +26,10 @@ add_library(migraphx_c api.cpp ) set_target_properties(migraphx_c PROPERTIES EXPORT_NAME c) -rocm_set_soversion(migraphx_c 3.0) + +# migraphx_c is stable API interface library. SO version of this should be +# bumped when binary compatibility is broken. +rocm_set_soversion(migraphx_c 3.0) rocm_clang_tidy_check(migraphx_c) target_link_libraries(migraphx_c PRIVATE migraphx migraphx_tf migraphx_onnx) diff --git a/src/driver/main.cpp b/src/driver/main.cpp index 41ba73a71d0..646a35d3671 100644 --- a/src/driver/main.cpp +++ b/src/driver/main.cpp @@ -455,7 +455,8 @@ struct version : command void run() const { std::cout << "MIGraphX Version: " << MIGRAPHX_VERSION_MAJOR << "." << MIGRAPHX_VERSION_MINOR - << std::endl; + << "." << MIGRAPHX_VERSION_PATCH << "." + << MIGRAPHX_STRINGIZE(MIGRAPHX_VERSION_TWEAK) << std::endl; } }; @@ -592,7 +593,9 @@ struct main_command void parse(argument_parser& ap) { std::string version_str = "MIGraphX Version: " + std::to_string(MIGRAPHX_VERSION_MAJOR) + - "." + std::to_string(MIGRAPHX_VERSION_MINOR); + "." + std::to_string(MIGRAPHX_VERSION_MINOR) + "." + + std::to_string(MIGRAPHX_VERSION_PATCH) + "." + + MIGRAPHX_STRINGIZE(MIGRAPHX_VERSION_TWEAK); ap(wrong_commands, {}, ap.metavar(""), ap.append()); ap(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help(get_command_help())); ap(nullptr, diff --git a/src/include/migraphx/config.hpp b/src/include/migraphx/config.hpp index 3e370bec480..ae15c61c8a4 100644 --- a/src/include/migraphx/config.hpp +++ b/src/include/migraphx/config.hpp @@ -24,22 +24,32 @@ #ifndef MIGRAPHX_GUARD_CONFIG_HPP #define MIGRAPHX_GUARD_CONFIG_HPP -namespace migraphx { - #if !defined(MIGRAPHX_USE_CLANG_TIDY) && !defined(DOXYGEN) + +#ifdef BUILD_DEV #define MIGRAPHX_INLINE_NS version_1 -#endif +#else +#include + +#define MIGRAPHX_VERSION_PRIMITIVE_CONCAT(x, y) x##_##y +#define MIGRAPHX_VERSION_CONCAT(x, y) MIGRAPHX_VERSION_PRIMITIVE_CONCAT(x, y) + +#define MIGRAPHX_VERSION \ + MIGRAPHX_VERSION_CONCAT( \ + MIGRAPHX_VERSION_CONCAT(MIGRAPHX_VERSION_MAJOR, MIGRAPHX_VERSION_MINOR), \ + MIGRAPHX_VERSION_PATCH) + +#define MIGRAPHX_INLINE_NS MIGRAPHX_VERSION_CONCAT(version, MIGRAPHX_VERSION) +#endif // build_dev +#endif // clang_tidy #ifdef DOXYGEN #define MIGRAPHX_INLINE_NS internal -#endif +#endif // doxygen #ifdef MIGRAPHX_USE_CLANG_TIDY #define MIGRAPHX_TIDY_CONST const #else #define MIGRAPHX_TIDY_CONST -#endif - -} // namespace migraphx - -#endif +#endif // tidy_const +#endif // clang_tidy diff --git a/src/version.h.in b/src/version.h.in index 2e908c7914b..783d1fefebe 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -24,4 +24,6 @@ // clang-format off #define MIGRAPHX_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ #define MIGRAPHX_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define MIGRAPHX_VERSION_PATCH @PROJECT_VERSION_PATCH@ +#define MIGRAPHX_VERSION_TWEAK @PROJECT_VERSION_TWEAK@ // clang-format on