Skip to content

Commit

Permalink
Fix import oneflow segmentation fault
Browse files Browse the repository at this point in the history
Do not include env.h header file.
  • Loading branch information
xiacijie authored Apr 25, 2022
1 parent 0a244fc commit 4dc08d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
12 changes: 0 additions & 12 deletions oneflow/api/python/env/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ inline Maybe<void> SetGraphLRVerbose(bool verbose) {
return Maybe<void>::Ok();
}
inline bool GetGraphLRVerbose() { return IsOpenGraphVerboseStepLr(); }

inline Maybe<void> SetGraphDebugMaxPyStackDepth(int32_t depth) {
*GetGraphDebugMaxPyStackDepthVar() = depth;
return Maybe<void>::Ok();
}
inline int32_t GetGraphDebugMaxPyStackDepth() { return *GetGraphDebugMaxPyStackDepthVar(); }

inline Maybe<void> SetGraphDebugMode(bool mode) {
*GetGraphDebugModeFlag() = mode;
return Maybe<void>::Ok();
}
inline bool GetGraphDebugMode() { return *GetGraphDebugModeFlag(); }
} // namespace oneflow

#endif // ONEFLOW_API_PYTHON_ENV_ENV_H_
2 changes: 1 addition & 1 deletion oneflow/api/python/functional/python_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ limitations under the License.

#include <Python.h>

#include "oneflow/api/python/env/env.h"
#include "oneflow/api/python/functional/common.h"
#include "oneflow/core/framework/op_interpreter/dispatch_frame.h"
#include "oneflow/core/job/graph_scope_vars.h"

namespace oneflow {
namespace one {
Expand Down
26 changes: 16 additions & 10 deletions oneflow/core/job/graph_scope_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@ namespace oneflow {

namespace {

std::atomic<bool>* GetGraphVerboseStepLr() {
static std::atomic<bool> graph_verbose_step_lr{false};
bool* GetGraphVerboseStepLr() {
static thread_local bool graph_verbose_step_lr = false;
return &graph_verbose_step_lr;
}

int32_t* GetGraphDebugMaxPyStackDepthVar() {
static thread_local int32_t graph_debug_max_py_stack_depth = 2;
return &graph_debug_max_py_stack_depth;
}

bool* GetGraphDebugModeFlag() {
static thread_local bool graph_debug_mode_flag = false;
return &graph_debug_mode_flag;
}
} // namespace

bool IsOpenGraphVerboseStepLr() {
Expand All @@ -36,13 +46,9 @@ void SetGraphVerboseStepLr(bool verbose) {
*graph_verbose_step_lr = verbose;
}

std::atomic<int32_t>* GetGraphDebugMaxPyStackDepthVar() {
static std::atomic<int32_t> graph_debug_max_py_stack_depth{2};
return &graph_debug_max_py_stack_depth;
}
void SetGraphDebugMaxPyStackDepth(int32_t depth) { *GetGraphDebugMaxPyStackDepthVar() = depth; }
int32_t GetGraphDebugMaxPyStackDepth() { return *GetGraphDebugMaxPyStackDepthVar(); }

std::atomic<bool>* GetGraphDebugModeFlag() {
static std::atomic<bool> graph_debug_mode_flag{false};
return &graph_debug_mode_flag;
}
void SetGraphDebugMode(bool mode) { *GetGraphDebugModeFlag() = mode; }
bool GetGraphDebugMode() { return *GetGraphDebugModeFlag(); }
} // namespace oneflow
9 changes: 5 additions & 4 deletions oneflow/core/job/graph_scope_vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ limitations under the License.
#ifndef ONEFLOW_CORE_JOB_GRAPH_SCOPE_VARS_H_
#define ONEFLOW_CORE_JOB_GRAPH_SCOPE_VARS_H_

#include "oneflow/core/common/maybe.h"

#include <cstdint>
namespace oneflow {

bool IsOpenGraphVerboseStepLr();
void SetGraphVerboseStepLr(bool verbose);

std::atomic<int32_t>* GetGraphDebugMaxPyStackDepthVar();
std::atomic<bool>* GetGraphDebugModeFlag();
void SetGraphDebugMaxPyStackDepth(int32_t depth);
int32_t GetGraphDebugMaxPyStackDepth();
void SetGraphDebugMode(bool mode);
bool GetGraphDebugMode();
} // namespace oneflow

#endif // ONEFLOW_CORE_JOB_GRAPH_SCOPE_VARS_H_

0 comments on commit 4dc08d6

Please sign in to comment.