From ca79f7de6acb2f19cc2228ed0d1b1264bfe4437b Mon Sep 17 00:00:00 2001 From: baihuawei Date: Fri, 9 Dec 2022 09:47:19 +0800 Subject: [PATCH] fix LockRuntime stream nullptr --- .../ascend/hal/device/ascend_kernel_runtime.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_kernel_runtime.cc b/mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_kernel_runtime.cc index 38e811cee05..61be7e62bdf 100644 --- a/mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_kernel_runtime.cc +++ b/mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_kernel_runtime.cc @@ -1102,19 +1102,21 @@ bool AscendKernelRuntime::RunTask(const session::KernelGraph &graph) { bool AscendKernelRuntime::SyncStream() { SetCurrentContext(); - { + if (stream_ != nullptr) { // cppcheck-suppress unreadVariable auto lock = device::KernelRuntime::LockRuntime(stream_); - if (stream_ != nullptr && !AscendStreamMng::GetInstance().SyncStream(stream_)) { + if (!AscendStreamMng::GetInstance().SyncStream(stream_)) { MS_LOG(ERROR) << "Sync default stream failed."; return false; } } - // cppcheck-suppress unreadVariable - auto lock = device::KernelRuntime::LockRuntime(communication_stream_); - if (communication_stream_ != nullptr && !AscendStreamMng::GetInstance().SyncStream(communication_stream_)) { - MS_LOG(ERROR) << "Sync default stream failed."; - return false; + if (communication_stream_ != nullptr) { + // cppcheck-suppress unreadVariable + auto lock = device::KernelRuntime::LockRuntime(communication_stream_); + if (!AscendStreamMng::GetInstance().SyncStream(communication_stream_)) { + MS_LOG(ERROR) << "Sync default stream failed."; + return false; + } } return true; }