From ef6c2e2bd3d6be1175e20c9902b801eeb8b8eb52 Mon Sep 17 00:00:00 2001 From: Shenghang Tsai <jackalcooper@gmail.com> Date: Fri, 16 Jul 2021 21:32:38 +0800 Subject: [PATCH] Add definition for CMAKE_BUILD_TYPE and print cmake_build_type in oneflow doctor (#5505) * check in changes * refine * refine Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com> --- CMakeLists.txt | 2 ++ oneflow/__main__.py | 1 + oneflow/api/python/flags.cpp | 12 ++++++++++++ oneflow/python/framework/sysconfig.py | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 149024a98..68b7fa17b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,8 @@ if(NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZ endif() message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +add_definitions(-DONEFLOW_CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "") option(THIRD_PARTY "Build third party" ON) diff --git a/oneflow/__main__.py b/oneflow/__main__.py index e93609569..7b575523a 100644 --- a/oneflow/__main__.py +++ b/oneflow/__main__.py @@ -48,6 +48,7 @@ def main(): print("path:", oneflow.__path__) print("version:", oneflow.__version__) + print("cmake_build_type:", oneflow.sysconfig.cmake_build_type()) if __name__ == "__main__": diff --git a/oneflow/api/python/flags.cpp b/oneflow/api/python/flags.cpp index 4f9cfd89a..32e53492e 100644 --- a/oneflow/api/python/flags.cpp +++ b/oneflow/api/python/flags.cpp @@ -57,6 +57,18 @@ ONEFLOW_API_PYBIND11_MODULE("flags", m) { return false; #endif // RPC_BACKEND_LOCAL }); + +#define STRINGIFY(x) STRINGIFY_(x) +#define STRINGIFY_(x) #x + m.def("cmake_build_type", []() { +#ifdef ONEFLOW_CMAKE_BUILD_TYPE + return std::string(STRINGIFY(ONEFLOW_CMAKE_BUILD_TYPE)); +#else + return std::string("Undefined"); +#endif // ONEFLOW_CMAKE_BUILD_TYPE + }); +#undef STRINGIFY +#undef STRINGIFY_ } } // namespace oneflow diff --git a/oneflow/python/framework/sysconfig.py b/oneflow/python/framework/sysconfig.py index f9985b7db..0f0e360d6 100644 --- a/oneflow/python/framework/sysconfig.py +++ b/oneflow/python/framework/sysconfig.py @@ -80,3 +80,8 @@ def has_rpc_backend_grpc() -> bool: @oneflow_export("sysconfig.has_rpc_backend_local") def has_rpc_backend_local() -> bool: return oneflow._oneflow_internal.flags.has_rpc_backend_local() + + +@oneflow_export("sysconfig.cmake_build_type") +def cmake_build_type() -> str: + return oneflow._oneflow_internal.flags.cmake_build_type() -- GitLab