-
Notifications
You must be signed in to change notification settings - Fork 825
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
fix registry may segment #5336
fix registry may segment #5336
Conversation
c8143f0
to
0390102
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common/registry_error.h
Maybe<void> CheckRegistryError();
void CatchRegistryError(const std::function<Maybe<void>()>&);
usage:
CatchRegistryError([&]()->Maybe<void>{
JUST();
return Maybe<void>::Ok();
});
cf440e5
to
b6440be
Compare
@@ -0,0 +1,25 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api/python/registry/registry.cpp
|
||
namespace oneflow { | ||
|
||
static std::shared_ptr<Maybe<void>> registry_error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::shared_ptrcfg::ErrorProto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe只做函数的返回值。做成某个成员或者变量得有非常无奈的理由。
namespace py = pybind11; | ||
|
||
ONEFLOW_API_PYBIND11_MODULE("", m) { | ||
m.def("CheckRegistryError", []() { return oneflow::CheckRegistryError().GetOrThrow(); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckAndClearRegistryError
namespace oneflow { | ||
|
||
static std::shared_ptr<Maybe<void>> registry_error; | ||
Maybe<void> CheckRegistryError() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckAndClearRegisterError
|
||
static std::shared_ptr<Maybe<void>> registry_error; | ||
Maybe<void> CheckRegistryError() { | ||
return registry_error == nullptr ? Maybe<void>::Ok() : *registry_error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加clear逻辑。
} | ||
|
||
void CatchRegistryError(const std::function<Maybe<void>()>& handler) { | ||
const auto& maybe_error = handler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TRY(handler());
const auto& maybe_error = handler(); | ||
if (!maybe_error.IsOk()) { | ||
if (registry_error == nullptr) { | ||
registry_error = std::make_shared<Maybe<void>>(maybe_error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registry_error = maybe_error.error()
// register python op kernel | ||
auto reg = user_op::UserOpRegistryMgr::Get() | ||
.CheckAndGetOpKernelRegistry(op_module_name + "_forward") | ||
.SetCreateFn<PyForwardKernel>() | ||
.SetIsMatchedHob( | ||
((user_op::HobDeviceTag() == "cpu") & (user_op::HobDeviceSubTag() == "py"))); | ||
user_op::UserOpRegistryMgr::Get().Register(reg.Finish().GetResult()); | ||
user_op::UserOpRegistryMgr::Get().Register(JUST(reg.Finish()).GetResult()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUST
// register python grad op kernel | ||
auto grad_reg = user_op::UserOpRegistryMgr::Get() | ||
.CheckAndGetOpKernelRegistry(op_module_name + "_backward") | ||
.SetCreateFn<PyBackwardKernel>() | ||
.SetIsMatchedHob(((user_op::HobDeviceTag() == "cpu") | ||
& (user_op::HobDeviceSubTag() == "py"))); | ||
user_op::UserOpRegistryMgr::Get().Register(grad_reg.Finish().GetResult()); | ||
user_op::UserOpRegistryMgr::Get().Register(JUST(grad_reg.Finish()).GetResult()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUST
735f8ac
to
7834e75
Compare
3e04917
to
2ee7096
Compare
|
||
namespace oneflow { | ||
|
||
static std::shared_ptr<cfg::ErrorProto> registry_error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::shared_ptr<cfg::ErrorProto>* MutRegistryError() {
static std::shared_ptr<cfg::ErrorProto> registry_error;
return registry_error;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放在匿名空间里
std::shared_ptr<cfg::ErrorProto> registry_error_inner = nullptr; | ||
registry_error_inner.swap(registry_error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::shared_ptr<cfg::ErrorProto> old_value = MutRegistryError();
void CatchRegistryError(const std::function<Maybe<void>()>& handler) { | ||
const auto& maybe_error = TRY(handler()); | ||
if (!maybe_error.IsOk()) { | ||
if (registry_error == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!*MutRegistryError())
@@ -24,6 +24,7 @@ limitations under the License. | |||
|
|||
namespace oneflow { | |||
|
|||
std::shared_ptr<Error> registry_error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉
f51226d
to
c7e5822
Compare
return Maybe<void>::Ok(); | ||
} | ||
std::shared_ptr<cfg::ErrorProto> registry_error_old = *MutRegistryError(); | ||
*MutRegistryError() = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MutRegistryError()->reset();
c7e5822
to
5073bd2
Compare
11d86a9
to
634f5aa
Compare
No description provided.