!19951 Refine unify runtime context
Merge pull request !19951 from zyli2020/r1.3_debug
This commit is contained in:
commit
d50df065d5
|
@ -398,6 +398,20 @@ void PrimitivePyAdapter::AddPyAttr(const py::str &name, const py::object &obj) {
|
|||
if (prim != nullptr) {
|
||||
prim->AddAttr(attr_name, converted_ret);
|
||||
}
|
||||
|
||||
if (attr_name == "primitive_target") {
|
||||
MS_EXCEPTION_IF_NULL(converted_ret);
|
||||
if (!converted_ret->isa<StringImm>()) {
|
||||
MS_LOG(EXCEPTION) << "Only support string CPU|GPU|Ascend for primitive_target";
|
||||
}
|
||||
|
||||
auto target = GetValue<std::string>(converted_ret);
|
||||
if (target != kCPUDevice && target != kGPUDevice) {
|
||||
auto context_ptr = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context_ptr);
|
||||
context_ptr->set_param<bool>(MS_CTX_ALREADY_SET_ENABLE_MINDRT, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PrimitivePyAdapter::DelPyAttr(const py::str &name) {
|
||||
|
|
|
@ -566,6 +566,10 @@ BackendPtr CreateBackend() {
|
|||
void SetMindRTEnable() {
|
||||
auto context_ptr = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context_ptr);
|
||||
if (context_ptr->get_param<bool>(MS_CTX_ALREADY_SET_ENABLE_MINDRT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string target = context_ptr->get_param<std::string>(MS_CTX_DEVICE_TARGET);
|
||||
if ((target != kGPUDevice) && (target != kCPUDevice)) {
|
||||
return;
|
||||
|
|
|
@ -87,6 +87,7 @@ MsContext::MsContext(const std::string &policy, const std::string &target) {
|
|||
set_param<bool>(MS_CTX_SAVE_COMPILE_CACHE, false);
|
||||
set_param<bool>(MS_CTX_LOAD_COMPILE_CACHE, false);
|
||||
set_param<bool>(MS_CTX_ENABLE_MINDRT, false);
|
||||
set_param<bool>(MS_CTX_ALREADY_SET_ENABLE_MINDRT, false);
|
||||
|
||||
backend_policy_ = policy_map_[policy];
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ enum MsCtxParam : unsigned {
|
|||
MS_CTX_SAVE_COMPILE_CACHE,
|
||||
MS_CTX_LOAD_COMPILE_CACHE,
|
||||
MS_CTX_ENABLE_MINDRT,
|
||||
MS_CTX_ALREADY_SET_ENABLE_MINDRT,
|
||||
MS_CTX_TYPE_BOOL_END,
|
||||
|
||||
// parameter of type int
|
||||
|
|
Loading…
Reference in New Issue