From b92866d2c20d6a074b31cea86ce45aa4e193ebdb Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Sun, 24 Apr 2022 14:46:30 +0800 Subject: [PATCH] fix(build): fix build depends dirty file issue GitOrigin-RevId: 435d8b5c50ca7ce6034274d06c7239bd9a35f270 --- CMakeLists.txt | 14 ++++++++++++++ imperative/python/src/common.cpp | 8 ++++++++ src/core/impl/version.cpp | 8 ++++++-- src/cuda_sm_gen.h.in | 6 ++++++ src/git_full_hash_header.h.in | 6 ++++++ src/megbrain_build_config.h.in | 3 --- 6 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/cuda_sm_gen.h.in create mode 100644 src/git_full_hash_header.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ebf15c21..55c40bdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1224,10 +1224,24 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE) # Write out megbrain_build_config.h It defines macros needed by both megbrain and dnn +# please don't put the configuration that is easy to change at +# megbrain_build_config.h.in for example cuda_sm_gen.h.in and git_full_hash_header.h.in, +# which will lead to CMake build dirty file issue configure_file(src/megbrain_build_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/genfiles/megbrain_build_config.h) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/genfiles/megbrain_build_config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +if(MGE_WITH_CUDA) + configure_file(src/cuda_sm_gen.h.in + ${CMAKE_CURRENT_BINARY_DIR}/genfiles/cuda_sm_gen.h) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/genfiles/cuda_sm_gen.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +endif() + +configure_file(src/git_full_hash_header.h.in + ${CMAKE_CURRENT_BINARY_DIR}/genfiles/git_full_hash_header.h) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/genfiles/git_full_hash_header.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) add_subdirectory(dnn) diff --git a/imperative/python/src/common.cpp b/imperative/python/src/common.cpp index cb71c0c8..066627eb 100644 --- a/imperative/python/src/common.cpp +++ b/imperative/python/src/common.cpp @@ -20,6 +20,10 @@ #include "megbrain/graph.h" #include "megbrain/imperative/physical_tensor.h" +#if MEGDNN_WITH_CUDA +#include "cuda_sm_gen.h" +#endif + namespace py = pybind11; using namespace mgb; using namespace imperative; @@ -248,7 +252,11 @@ void init_common(py::module m) { m.def("get_device_prop", &CompNode::get_device_prop); m.def("get_supported_sm_versions", []() { +#if MEGDNN_WITH_CUDA static const char* mge_gen_code = MGE_CUDA_GENCODE; +#else + static const char* mge_gen_code = "-1"; +#endif return mge_gen_code; }); diff --git a/src/core/impl/version.cpp b/src/core/impl/version.cpp index 30b9b32c..2a59f6a8 100644 --- a/src/core/impl/version.cpp +++ b/src/core/impl/version.cpp @@ -12,6 +12,10 @@ #include "megbrain/version.h" #include "megbrain/common.h" +#ifndef __IN_TEE_ENV__ +#include "git_full_hash_header.h" +#endif + using namespace mgb; //! some sdk do not call mgb::get_version explicitly, so we force show version for @@ -20,8 +24,8 @@ using namespace mgb; #ifndef __IN_TEE_ENV__ static __attribute__((constructor)) void show_version() { auto v = get_version(); - mgb_log("init Engine with version: %d.%d.%d(%d) at git commitid: %s", v.major, - v.minor, v.patch, v.is_dev, GIT_FULL_HASH); + mgb_log("init Engine with version: %d.%d.%d(%d) @(%s)", v.major, v.minor, v.patch, + v.is_dev, GIT_FULL_HASH); } #endif diff --git a/src/cuda_sm_gen.h.in b/src/cuda_sm_gen.h.in new file mode 100644 index 00000000..2c745ae8 --- /dev/null +++ b/src/cuda_sm_gen.h.in @@ -0,0 +1,6 @@ +#ifndef _HEADER_MGB_CUDA_SM_GEN_CONFIG +#define _HEADER_MGB_CUDA_SM_GEN_CONFIG + +#define MGE_CUDA_GENCODE "@MGE_CUDA_GENCODE@" + +#endif // _HEADER_MGB_CUDA_SM_GEN_CONFIG diff --git a/src/git_full_hash_header.h.in b/src/git_full_hash_header.h.in new file mode 100644 index 00000000..7d3d75e8 --- /dev/null +++ b/src/git_full_hash_header.h.in @@ -0,0 +1,6 @@ +#ifndef _HEADER_MGB_GIT_FULL_HASH_HEADER_CONFIG +#define _HEADER_MGB_GIT_FULL_HASH_HEADER_CONFIG + +#define GIT_FULL_HASH "commit id: @GIT_FULL_HASH@" + +#endif // _HEADER_MGB_GIT_FULL_HASH_HEADER_CONFIG diff --git a/src/megbrain_build_config.h.in b/src/megbrain_build_config.h.in index 0ffcadfb..802d316e 100644 --- a/src/megbrain_build_config.h.in +++ b/src/megbrain_build_config.h.in @@ -267,7 +267,4 @@ #define MGE_WIN_DECLSPEC_DATA #endif -#define GIT_FULL_HASH "@GIT_FULL_HASH@" -#define MGE_CUDA_GENCODE "@MGE_CUDA_GENCODE@" - #endif // _HEADER_MGB_BUILD_CONFIG