diff --git a/impl/camb/CMakeLists.txt b/impl/camb/CMakeLists.txt index 8cbe3a7d8..591d911fd 100644 --- a/impl/camb/CMakeLists.txt +++ b/impl/camb/CMakeLists.txt @@ -32,7 +32,7 @@ endif() file(GLOB_RECURSE IMPL_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} functions/*.cpp common/*.cpp) file(GLOB_RECURSE IMPL_SRC_MMCV RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} functions_mmcv/*.cpp functions/*.mlu ) file(GLOB_RECURSE IMPL_SRC_MMCV_MLU RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} functions_mmcv/*.mlu) -list(APPEND IMPL_SRC mlu_ops_helper.cpp cnnl_helper.cpp diopi_helper.cpp init.cpp) +list(APPEND IMPL_SRC mlu_ops_helper.cpp cnnl_helper.cpp diopi_helper.cpp env_vars.cpp) list(APPEND IMPL_SRC ${IMPL_SRC_MMCV}) list(APPEND IMPL_SRC ${IMPL_SRC_MMCV_MLU}) diff --git a/impl/camb/cnnl_helper.hpp b/impl/camb/cnnl_helper.hpp index d640f65aa..bece5beec 100644 --- a/impl/camb/cnnl_helper.hpp +++ b/impl/camb/cnnl_helper.hpp @@ -19,16 +19,14 @@ #include "diopi_helper.hpp" -extern bool isRecordOn; - #define DIOPI_CALLCNNL(Expr) \ do { \ void* record = nullptr; \ - if (isRecordOn) { \ + if (isRecordOn()) { \ DIOPI_RECORD_START(Expr); \ } \ ::cnnlStatus_t ret = Expr; \ - if (isRecordOn) { \ + if (isRecordOn()) { \ DIOPI_RECORD_END; \ } \ if (ret != ::CNNL_STATUS_SUCCESS) { \ diff --git a/impl/camb/diopi_helper.hpp b/impl/camb/diopi_helper.hpp index b0e00b8b4..647226047 100644 --- a/impl/camb/diopi_helper.hpp +++ b/impl/camb/diopi_helper.hpp @@ -19,6 +19,7 @@ #include #include +#include "env_vars.hpp" #include "error.hpp" #include "impl_functions.hpp" @@ -66,16 +67,14 @@ void getFuncName(const char* expr, char* name); // cant' use this macro DIOPI_RECORD_END alone, but use it in pairs with DIOPI_RECORD_START #define DIOPI_RECORD_END diopiRecordEnd(&record); -extern bool isRecordOn; - #define DIOPI_CALL(Expr) \ do { \ void* record = nullptr; \ - if (isRecordOn) { \ + if (isRecordOn()) { \ DIOPI_RECORD_START(Expr); \ } \ diopiError_t ret = Expr; \ - if (isRecordOn) { \ + if (isRecordOn()) { \ DIOPI_RECORD_END; \ } \ if (diopiSuccess != ret) { \ diff --git a/impl/camb/init.cpp b/impl/camb/env_vars.cpp similarity index 59% rename from impl/camb/init.cpp rename to impl/camb/env_vars.cpp index 908d3f59c..b8b948290 100644 --- a/impl/camb/init.cpp +++ b/impl/camb/env_vars.cpp @@ -3,6 +3,8 @@ * @author DeepLink * @copyright (c) 2023, DeepLink. */ +#include "env_vars.hpp" + #include #include @@ -15,15 +17,7 @@ bool isEnvStateOn(const char* envName) { return true; } -bool isRecordOnFunc() { return isEnvStateOn("DIOPI_RECORD_ENV"); } - -// global vars are listed bellow -bool isRecordOn = false; - -static int initFunc() { - // init func is called here; - isRecordOn = isRecordOnFunc(); - return 0; +bool isRecordOn() { + static bool isRecord = isEnvStateOn("DIOPI_RECORD_ENV"); + return isRecord; } - -static int initGlobalVal = initFunc(); diff --git a/impl/camb/env_vars.hpp b/impl/camb/env_vars.hpp new file mode 100644 index 000000000..c22e864a4 --- /dev/null +++ b/impl/camb/env_vars.hpp @@ -0,0 +1,12 @@ +/** + * @file + * @author DeepLink + * @copyright (c) 2023, DeepLink. + */ + +#ifndef IMPL_CAMB_ENV_VARS_HPP_ +#define IMPL_CAMB_ENV_VARS_HPP_ + +bool isRecordOn(); + +#endif // IMPL_CAMB_ENV_VARS_HPP_