Skip to content

Commit

Permalink
Yb/refactor_record (DeepLink-org#468)
Browse files Browse the repository at this point in the history
*refactor record in camb
  • Loading branch information
yangbofun authored Oct 13, 2023
1 parent a88d345 commit 9a1a48d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion impl/camb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
6 changes: 2 additions & 4 deletions impl/camb/cnnl_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand Down
7 changes: 3 additions & 4 deletions impl/camb/diopi_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <utility>
#include <vector>

#include "env_vars.hpp"
#include "error.hpp"
#include "impl_functions.hpp"

Expand Down Expand Up @@ -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) { \
Expand Down
16 changes: 5 additions & 11 deletions impl/camb/init.cpp → impl/camb/env_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @author DeepLink
* @copyright (c) 2023, DeepLink.
*/
#include "env_vars.hpp"

#include <cstdlib>
#include <cstring>

Expand All @@ -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();
12 changes: 12 additions & 0 deletions impl/camb/env_vars.hpp
Original file line number Diff line number Diff line change
@@ -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_

0 comments on commit 9a1a48d

Please sign in to comment.