Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/graph del by ref #7857

Merged
merged 92 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
0bae07a
remove IsMultiClient() and single client logic
daquexian Mar 3, 2022
959346b
rename eager.multi_client to eager
daquexian Mar 3, 2022
9a03edb
auto format by CI
oneflow-ci-bot Mar 3, 2022
c59716f
add py ref
strint Mar 5, 2022
d531d43
refine new session
strint Mar 5, 2022
ade9d9c
clean code
strint Mar 5, 2022
e0d7dbb
make scope api inner use
strint Mar 5, 2022
ba9e31d
use session with ref cnt
strint Mar 6, 2022
b8f7f89
run barrier callback in BarrierPhyInstrOperand::~BarrierPhyInstrOperand
lixinqi Mar 6, 2022
af55be9
Merge branch 'master' into fix_barrier_instruction
lixinqi Mar 6, 2022
5f1324f
test pass
strint Mar 6, 2022
1eaefa8
Merge branch 'master' into remove_single_client
daquexian Mar 7, 2022
1b3c3df
Merge branch 'master' into fix_barrier_instruction
lixinqi Mar 7, 2022
516c691
Merge branch 'master' into fix_barrier_instruction
lixinqi Mar 7, 2022
9095397
lock gil in vm Callback thread
lixinqi Mar 7, 2022
c3846cd
Merge branch 'fix_barrier_instruction' of github.com:Oneflow-Inc/onef…
lixinqi Mar 7, 2022
e32f10d
Merge branch 'master' into remove_single_client
daquexian Mar 7, 2022
a517fb7
Merge branch 'master' into remove_single_client
mergify[bot] Mar 7, 2022
c944d61
Merge branch 'master' into remove_single_client
mergify[bot] Mar 8, 2022
969ba8c
more comments for VirtualMachineEngine::Callback()
lixinqi Mar 8, 2022
10e5f7e
merge master and fix conflict
strint Mar 8, 2022
69e3680
merge rm of single client
strint Mar 8, 2022
3b85239
merge
strint Mar 8, 2022
d406a30
Merge branch 'master' into fix_barrier_instruction
Flowingsun007 Mar 8, 2022
c7c6c67
Merge branch 'master' into fix_barrier_instruction
Flowingsun007 Mar 8, 2022
21f49ba
merge rm single client
strint Mar 8, 2022
65db196
Merge branch 'master' into fix_barrier_instruction
Flowingsun007 Mar 8, 2022
fca7b8d
Merge branch 'master' into fix_barrier_instruction
Flowingsun007 Mar 9, 2022
b049dfc
Merge branch 'master' into fix_barrier_instruction
Flowingsun007 Mar 9, 2022
d0e4c8f
rm initenv
strint Mar 9, 2022
c5bbf35
merge master
strint Mar 9, 2022
c1e664b
merge and fix master
strint Mar 9, 2022
760d131
refactor env c api
strint Mar 9, 2022
7ed5d66
Merge branch 'master' into fix_barrier_instruction
Flowingsun007 Mar 10, 2022
30d4cc0
add debug code
strint Mar 11, 2022
3bc7fe0
Merge branch 'fix_barrier_instruction' of https://github.com/Oneflow-…
strint Mar 11, 2022
24f02ea
fix and serving test pass
strint Mar 11, 2022
9d7617b
test passed
strint Mar 12, 2022
26abf82
rm useless
strint Mar 12, 2022
19be109
rm useless code
strint Mar 12, 2022
669dc9c
format
strint Mar 12, 2022
b0dbcdb
rm useless include
strint Mar 12, 2022
3281975
rm sync in py
strint Mar 12, 2022
29ccd30
the Env is never destroyed.
lixinqi Mar 13, 2022
8509484
export Env into python
lixinqi Mar 14, 2022
434b7af
more unittests
lixinqi Mar 14, 2022
d497049
merge env exit and vm gil fix
strint Mar 14, 2022
a64a552
fix and pass tests
strint Mar 14, 2022
b19c3fb
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow into …
strint Mar 14, 2022
cf4241f
Merge branch 'feat/graph_del_with_ref' into feat/graph_del_with_ref_m…
strint Mar 14, 2022
60b59e5
revert virtual_machine.cpp
lixinqi Mar 15, 2022
d9609c6
revert core/vm
lixinqi Mar 15, 2022
62540a4
remove outdated python class oneflow.unittest.TestCase
lixinqi Mar 15, 2022
78f2708
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow into …
strint Mar 15, 2022
1f82f5e
Merge branch 'export_env_to_python' of https://github.com/Oneflow-Inc…
strint Mar 15, 2022
ad0be01
graph test passed
strint Mar 15, 2022
3925eb4
wait shared_ptr.use_count() == 0
lixinqi Mar 16, 2022
86296cb
export unittest.TestCase in framework/unittest.py
lixinqi Mar 16, 2022
454f5e7
SwitchToShuttingDownPhase
lixinqi Mar 16, 2022
d1d9ad7
optional is_normal_exit
lixinqi Mar 16, 2022
a58348d
VirtualMachine::CloseVMThreads
lixinqi Mar 17, 2022
8bb83a1
merge master
lixinqi Mar 18, 2022
fe64379
Delete env_api.h
lixinqi Mar 18, 2022
9b5cecc
Merge branch 'master' into export_env_to_python
lixinqi Mar 22, 2022
f7f1fdf
merge branch export_env_to_python
lixinqi Mar 22, 2022
72426fc
address pr comments
lixinqi Mar 22, 2022
2300408
all test passed
strint Mar 22, 2022
174bc3d
rm is env init
strint Mar 22, 2022
3e8585e
Clear empty thread when graph destroy (#7633)
chengtbf Mar 22, 2022
46c9d97
Revert "Clear empty thread when graph destroy (#7633)" (#7860)
chengtbf Mar 22, 2022
3be6f81
fix a ref-cnt bug in TryRunBarrierInstruction.
chengtbf Mar 23, 2022
9f10675
Merge branch 'export_env_to_python' into fix_barrier_instruction
lixinqi Mar 23, 2022
da8b44d
Merge branch 'master' of github.com:Oneflow-Inc/oneflow into export_e…
chengtbf Mar 23, 2022
c52bc90
Merge branch 'export_env_to_python' of github.com:Oneflow-Inc/oneflow…
chengtbf Mar 23, 2022
b23869c
merge and fix conflict
chengtbf Mar 23, 2022
a80aea6
rm env_api
chengtbf Mar 23, 2022
ec04de3
fix clang-tidy error
chengtbf Mar 23, 2022
fde02a6
fix clang-tidy in env_imp
chengtbf Mar 23, 2022
7547134
merge master and fix conflict
strint Apr 8, 2022
b7774c1
refine env api
strint Apr 8, 2022
8d45134
format
strint Apr 8, 2022
2104348
refine graph del and sync at shuttingdown
strint Apr 8, 2022
809b483
fix typo
strint Apr 8, 2022
b642cc5
Merge branch 'master' into feat/graph_del_by_ref
strint Apr 9, 2022
6199229
add comment
strint Apr 9, 2022
e4e95ff
Merge branch 'master' into feat/graph_del_by_ref
lixinqi Apr 9, 2022
d11a7f8
Merge branch 'master' into feat/graph_del_by_ref
mergify[bot] Apr 9, 2022
ba1c68a
Merge branch 'master' into feat/graph_del_by_ref
strint Apr 10, 2022
2ec0e0f
Merge branch 'master' into feat/graph_del_by_ref
mergify[bot] Apr 10, 2022
310a9fd
Merge branch 'master' into feat/graph_del_by_ref
mergify[bot] Apr 10, 2022
da54f36
rm useless
strint Apr 10, 2022
5166fe7
rm useless
strint Apr 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 3 additions & 120 deletions oneflow/api/cpp/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,136 +15,19 @@ limitations under the License.
*/

#include <glog/logging.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <random>
#include <type_traits>
#include "oneflow/api/cpp/env.h"
#include "oneflow/core/common/global.h"
#include "oneflow/core/common/just.h"
#include "oneflow/core/common/optional.h"
#include "oneflow/core/framework/multi_client_session_context.h"
#include "oneflow/core/framework/session_util.h"
#include "oneflow/api/cpp/env_impl.h"
#include "oneflow/core/framework/shut_down_util.h"
#include "oneflow/core/job/cluster_instruction.h"
#include "oneflow/core/job/env.pb.h"
#include "oneflow/core/job/env_global_objects_scope.h"
#include "oneflow/core/control/ctrl_bootstrap.h"
#include "oneflow/core/job/session.h"
#include "oneflow/core/rpc/include/base.h"
#include "oneflow/core/vm/vm_util.h"
#include "oneflow/core/thread/thread_consistent_id.h"

namespace oneflow_api {

namespace of = oneflow;

namespace { // for inltialize

inline bool IsEnvInited() { return of::Global<of::EnvGlobalObjectsScope>::Get() != nullptr; }

bool HasEnvVar(const std::string& key) {
const char* value = getenv(key.c_str());
return value != nullptr;
}

std::string GetEnvVar(const std::string& key, const std::string& default_value) {
const char* value = getenv(key.c_str());
if (value == nullptr) { return default_value; }
return std::string(value);
}

int64_t GetEnvVar(const std::string& key, int64_t default_value) {
const char* value = getenv(key.c_str());
if (value == nullptr) { return default_value; }
return std::atoll(value);
}

int32_t FindFreePort(const std::string& addr) {
#ifdef __linux__
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
CHECK_GE(sock, 0) << "fail to find a free port.";
int optval = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));

std::mt19937 rng;
rng.seed(std::random_device()());
std::uniform_int_distribution<std::mt19937::result_type> dist(1, 1000);

int count = 0;
int num_attempts = 200;
do {
int port = 5000 + dist(rng);
struct sockaddr_in sockaddr {};
memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons(port);
sockaddr.sin_addr.s_addr = inet_addr(addr.c_str());
int error = bind(sock, (struct sockaddr*)&sockaddr, sizeof(sockaddr));
if (error == 0) { return port; }
++count;
} while (count < num_attempts);
CHECK_NE(count, num_attempts) << "fail to find a free port.";
#endif // __linux__
return -1;
}

void CompleteEnvProto(of::EnvProto& env_proto) {
auto bootstrap_conf = env_proto.mutable_ctrl_bootstrap_conf();
auto master_addr = bootstrap_conf->mutable_master_addr();
const std::string addr = GetEnvVar("MASTER_ADDR", "127.0.0.1");
master_addr->set_host(addr);
master_addr->set_port(GetEnvVar("MASTER_PORT", FindFreePort(addr)));
bootstrap_conf->set_world_size(GetEnvVar("WORLD_SIZE", 1));
bootstrap_conf->set_rank(GetEnvVar("RANK", 0));

auto cpp_logging_conf = env_proto.mutable_cpp_logging_conf();
if (HasEnvVar("GLOG_log_dir")) { cpp_logging_conf->set_log_dir(GetEnvVar("GLOG_log_dir", "")); }
if (HasEnvVar("GLOG_logtostderr")) {
cpp_logging_conf->set_logtostderr(GetEnvVar("GLOG_logtostderr", -1));
}
if (HasEnvVar("GLOG_logbuflevel")) {
cpp_logging_conf->set_logbuflevel(GetEnvVar("GLOG_logbuflevel", -1));
}
}

of::Maybe<void> initEnv() {
of::EnvProto env_proto;
CompleteEnvProto(env_proto);
of::Global<of::EnvGlobalObjectsScope>::SetAllocated(new of::EnvGlobalObjectsScope());
JUST(of::Global<of::EnvGlobalObjectsScope>::Get()->Init(env_proto));

of::ConfigProto config_proto;
config_proto.mutable_resource()->set_cpu_device_num(1); // useless, will be set in TryInit
const int64_t session_id = of::NewSessionId();
JUST(of::RegsiterSession(session_id));
config_proto.set_session_id(session_id);
of::Global<of::MultiClientSessionContext>::New();
of::Global<of::MultiClientSessionContext>::Get()->TryInit(config_proto).GetOrThrow();
return of::Maybe<void>::Ok();
}

} // namespace

void initialize() {
if (!IsEnvInited()) { initEnv().GetOrThrow(); }
if (of::Global<OneFlowEnv>::Get() == nullptr) { of::Global<OneFlowEnv>::New(); }
of::SetShuttingDown(false);
}

void release() {
if (IsEnvInited()) {
// sync multi_client
of::vm::ClusterSync().GetOrThrow();
of::Global<of::MultiClientSessionContext>::Get()->TryClose().GetOrThrow();
of::Global<of::MultiClientSessionContext>::Delete();
// destory env
OF_ENV_BARRIER();
of::Global<of::EnvGlobalObjectsScope>::Delete();
}
if (of::Global<OneFlowEnv>::Get() != nullptr) { of::Global<OneFlowEnv>::Delete(); }
of::SetShuttingDown();
of::ResetThisThreadUniqueConsistentId().GetOrThrow();
}
Expand Down
134 changes: 134 additions & 0 deletions oneflow/api/cpp/env_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
Copyright 2020 The OneFlow Authors. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <glog/logging.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <random>
#include <type_traits>
#include "oneflow/api/cpp/env_impl.h"
#include "oneflow/core/common/global.h"
#include "oneflow/core/common/just.h"
#include "oneflow/core/common/optional.h"
#include "oneflow/core/common/util.h"
#include "oneflow/core/framework/session_util.h"
#include "oneflow/core/job/env.pb.h"
#include "oneflow/core/job/cluster_instruction.h"
#include "oneflow/core/control/ctrl_bootstrap.h"
#include "oneflow/core/job/session.h"
#include "oneflow/core/rpc/include/base.h"
#include "oneflow/core/vm/vm_util.h"

namespace oneflow_api {

namespace of = oneflow;

namespace { // for inltialize

inline bool IsEnvInited() { return of::Global<of::EnvGlobalObjectsScope>::Get() != nullptr; }

bool HasEnvVar(const std::string& key) {
const char* value = getenv(key.c_str());
return value != nullptr;
}

std::string GetEnvVar(const std::string& key, const std::string& default_value) {
const char* value = getenv(key.c_str());
if (value == nullptr) { return default_value; }
return std::string(value);
}

int64_t GetEnvVar(const std::string& key, int64_t default_value) {
const char* value = getenv(key.c_str());
if (value == nullptr) { return default_value; }
return std::atoll(value);
}

int32_t FindFreePort(const std::string& addr) {
#ifdef __linux__
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
CHECK_GE(sock, 0) << "fail to find a free port.";
int optval = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));

std::mt19937 rng;
rng.seed(std::random_device()());
std::uniform_int_distribution<std::mt19937::result_type> dist(1, 1000);

int count = 0;
int num_attempts = 200;
do {
int port = 5000 + dist(rng);
struct sockaddr_in sockaddr {};
memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons(port);
sockaddr.sin_addr.s_addr = inet_addr(addr.c_str());
int error = bind(sock, (struct sockaddr*)&sockaddr, sizeof(sockaddr));
if (error == 0) { return port; }
++count;
} while (count < num_attempts);
CHECK_NE(count, num_attempts) << "fail to find a free port.";
#endif // __linux__
return -1;
}

void CompleteEnvProto(of::EnvProto& env_proto) {
auto bootstrap_conf = env_proto.mutable_ctrl_bootstrap_conf();
auto master_addr = bootstrap_conf->mutable_master_addr();
const std::string addr = GetEnvVar("MASTER_ADDR", "127.0.0.1");
master_addr->set_host(addr);
master_addr->set_port(GetEnvVar("MASTER_PORT", FindFreePort(addr)));
bootstrap_conf->set_world_size(GetEnvVar("WORLD_SIZE", 1));
bootstrap_conf->set_rank(GetEnvVar("RANK", 0));

auto cpp_logging_conf = env_proto.mutable_cpp_logging_conf();
if (HasEnvVar("GLOG_log_dir")) { cpp_logging_conf->set_log_dir(GetEnvVar("GLOG_log_dir", "")); }
if (HasEnvVar("GLOG_logtostderr")) {
cpp_logging_conf->set_logtostderr(GetEnvVar("GLOG_logtostderr", -1));
}
if (HasEnvVar("GLOG_logbuflevel")) {
cpp_logging_conf->set_logbuflevel(GetEnvVar("GLOG_logbuflevel", -1));
}
}
} // namespace

OneFlowEnv::OneFlowEnv() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Env for serving c++ api

of::EnvProto env_proto;
CompleteEnvProto(env_proto);

env_ctx_ = std::make_shared<of::EnvGlobalObjectsScope>(env_proto);

of::ConfigProto config_proto;
config_proto.mutable_resource()->set_cpu_device_num(1); // useless, will be set in TryInit
const int64_t session_id = of::NewSessionId();
CHECK_JUST(of::RegsiterSession(session_id));
config_proto.set_session_id(session_id);

session_ctx_ = std::make_shared<of::MultiClientSessionContext>(env_ctx_);
CHECK_JUST(session_ctx_->TryInit(config_proto));
}

OneFlowEnv::~OneFlowEnv() {
session_ctx_.reset();
env_ctx_.reset();
}

} // namespace oneflow_api
38 changes: 38 additions & 0 deletions oneflow/api/cpp/env_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2020 The OneFlow Authors. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <memory>
#include "oneflow/core/framework/multi_client_session_context.h"
#include "oneflow/core/job/env_global_objects_scope.h"

#ifndef ONEFLOW_API_CPP_ENV_IMPL_H_
#define ONEFLOW_API_CPP_ENV_IMPL_H_

namespace oneflow_api {
namespace of = oneflow;
class OneFlowEnv {
public:
OF_DISALLOW_COPY(OneFlowEnv);
OneFlowEnv();
~OneFlowEnv();
std::shared_ptr<of::MultiClientSessionContext> GetSessionCtx() { return session_ctx_; }

private:
std::shared_ptr<of::EnvGlobalObjectsScope> env_ctx_;
std::shared_ptr<of::MultiClientSessionContext> session_ctx_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个session_ctx一旦初始化就不会被修改是吗?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里稍稍有点反直觉。我一直以为是session_ctx持有oneflow_env。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,这里是 serving的用法,看起来serving那里目前是这么设定的。

session_ctx_会持有env_ctx_;oneflow_env包括了env和session,是导出给serving做oneflow总体启动和关闭的,之前的命名直接是env,这里沿袭了一下,叫oneflow env。

};
} // namespace oneflow_api

#endif // ONEFLOW_API_CPP_ENV_IMPL_H_
11 changes: 8 additions & 3 deletions oneflow/api/cpp/framework/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

#include "oneflow/api/common/ofblob.h"
#include "oneflow/api/cpp/env_impl.h"
#include "oneflow/api/cpp/framework/device.h"
#include "oneflow/api/cpp/framework/dtype.h"
#include "oneflow/api/cpp/framework/graph.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ limitations under the License.
#include "oneflow/core/operator/interface_blob_conf.pb.h"
#include "oneflow/core/operator/op_conf.pb.h"
#include "oneflow/core/register/logical_blob_id.pb.h"
#include "oneflow/core/vm/vm_util.h"

namespace oneflow_api {

Expand Down Expand Up @@ -134,7 +136,7 @@ class Graph::GraphImpl final {
GraphImpl(const GraphImpl& graph) = delete;
GraphImpl(GraphImpl&& graph) = default;

~GraphImpl() = default;
~GraphImpl();

GraphImpl& operator=(const GraphImpl& graph) = delete;
GraphImpl& operator=(GraphImpl&& graph) = default;
Expand Down Expand Up @@ -228,8 +230,9 @@ Graph::GraphImpl::GraphImpl(const std::string& model_path, const Device& device)
if (of::ParseBooleanFromEnv("ONEFLOW_SERVING_DEBUG", false)) { LOG(ERROR) << job_.DebugString(); }
job_.mutable_job_conf()->mutable_predict_conf();
job_.mutable_job_conf()->set_job_name(job_.mutable_job_conf()->job_name() + of::NewUniqueId());
graph_ = std::make_shared<of::NNGraph>(job_.job_conf().job_name());
of::Global<of::MultiClientSessionContext>::Get()->AddCGraph(graph_).GetOrThrow();
CHECK(of::Global<OneFlowEnv>::Get() != nullptr);
graph_ = std::make_shared<of::NNGraph>(job_.job_conf().job_name(),
of::Global<OneFlowEnv>::Get()->GetSessionCtx());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果直接是Global<std::shared_ptr<SessionCtx>>会好点吗?我还是在说让session_ctx依赖oneflow env的事情。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在也在尽量避免用Global来读写session,而是用引用计数,生命周期、依赖关系比较明确。

Global这种全局指针,在链式资源依赖 + 多线程里面,释放时很难做对,所以这里没有把session导出到Global。

这里下个PR再尝试把serving这里的接口也改成更彻底的依赖注入(oneflow graph那里已经改好了),可以避免使用Global这种跳线的写法了。

}

InputOutputInfos Graph::GraphImpl::GetInputInfos() { return input_infos_; }
Expand Down Expand Up @@ -403,4 +406,6 @@ of::Maybe<void> Graph::GraphImpl::RegisterTensors(const std::vector<Tensor>& inp
return of::Maybe<void>::Ok();
}

Graph::GraphImpl::~GraphImpl() { of::vm::ClusterSync().GetOrThrow(); }

} // namespace oneflow_api
8 changes: 4 additions & 4 deletions oneflow/api/python/env/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
#include <pybind11/pybind11.h>
#include "oneflow/api/python/env/env.h"
#include "oneflow/api/python/of_api_registry.h"
#include "oneflow/core/job/env_global_objects_scope.h"
#include "oneflow/core/common/global.h"
#include "oneflow/core/vm/vm_util.h"
#include "oneflow/core/vm/virtual_machine.h"
Expand All @@ -42,10 +43,9 @@ ONEFLOW_API_PYBIND11_MODULE("", m) {
m.def("EnvResource", &EnvResource);
m.def("EnableEagerEnvironment", &EnableEagerEnvironment);

py::class_<EnvGlobalObjectsScope, std::shared_ptr<EnvGlobalObjectsScope>>(m, "Env")
.def(py::init([](const std::string& env_proto_str) {
return CreateEnv(env_proto_str).GetPtrOrThrow();
}))
py::class_<oneflow::EnvGlobalObjectsScope, std::shared_ptr<oneflow::EnvGlobalObjectsScope>>(
m, "EnvContext")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

统一命名为context

.def(py::init<const std::string&>())
.def("SwitchToShuttingDownPhase", &SwitchToShuttingDownPhase,
py::call_guard<py::gil_scoped_release>());

Expand Down
9 changes: 0 additions & 9 deletions oneflow/api/python/env/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ inline Maybe<void> EnableEagerEnvironment(bool enable_eager_execution) {
return Maybe<void>::Ok();
}

inline Maybe<EnvGlobalObjectsScope> CreateEnv(const std::string& env_proto_str) {
EnvProto env_proto;
CHECK_OR_RETURN(TxtString2PbMessage(env_proto_str, &env_proto))
<< "failed to parse env_proto" << env_proto_str;
auto env = std::make_shared<EnvGlobalObjectsScope>();
JUST(env->Init(env_proto));
return env;
}

inline Maybe<long long> CurrentMachineId() { return GlobalProcessCtx::Rank(); }

inline Maybe<int64_t> GetRank() { return GlobalProcessCtx::Rank(); }
Expand Down
Loading