diff --git a/mindspore/ccsrc/backend/session/gpu_session.cc b/mindspore/ccsrc/backend/session/gpu_session.cc index 42d47445e8..cf2508216b 100644 --- a/mindspore/ccsrc/backend/session/gpu_session.cc +++ b/mindspore/ccsrc/backend/session/gpu_session.cc @@ -65,6 +65,8 @@ void GPUSession::StartKernelRT() const { void GPUSession::Optimize(const std::shared_ptr &kernel_graph) { MS_EXCEPTION_IF_NULL(kernel_graph); + auto context_ptr = MsContext::GetInstance(); + MS_EXCEPTION_IF_NULL(context_ptr); auto optimizer = std::make_shared(); auto pm = std::make_shared(); pm->AddPass(std::make_shared()); @@ -73,9 +75,11 @@ void GPUSession::Optimize(const std::shared_ptr &kernel_graph) { pm->AddPass(std::make_shared()); pm->AddPass(std::make_shared()); pm->AddPass(std::make_shared()); - pm->AddPass(std::make_shared()); - pm->AddPass(std::make_shared()); - pm->AddPass(std::make_shared()); + if (context_ptr->execution_mode() != kPynativeMode) { + pm->AddPass(std::make_shared()); + pm->AddPass(std::make_shared()); + pm->AddPass(std::make_shared()); + } optimizer->AddPassManager(pm); (void)optimizer->Optimize(kernel_graph); kernel_graph->SetExecOrderByDefault(); diff --git a/mindspore/ccsrc/runtime/device/gpu/gpu_device_address.cc b/mindspore/ccsrc/runtime/device/gpu/gpu_device_address.cc index f8664875e8..521e280f90 100644 --- a/mindspore/ccsrc/runtime/device/gpu/gpu_device_address.cc +++ b/mindspore/ccsrc/runtime/device/gpu/gpu_device_address.cc @@ -32,6 +32,10 @@ namespace device { namespace gpu { bool GPUDeviceAddress::SyncDeviceToHost(const std::vector &, size_t size, TypeId, void *host_ptr) const { MS_EXCEPTION_IF_NULL(host_ptr); + bool need_sync = (size != 0) && (size_ != 0); + if (!need_sync) { + return true; + } auto &stream = GPUDeviceManager::GetInstance().default_stream(); MS_EXCEPTION_IF_NULL(stream); auto ret = GPUDeviceManager::GetInstance().SyncStream(stream); @@ -48,6 +52,10 @@ bool GPUDeviceAddress::SyncDeviceToHost(const std::vector &, size_t size, T bool GPUDeviceAddress::SyncHostToDevice(const std::vector &, size_t size, TypeId, const void *host_ptr) const { MS_EXCEPTION_IF_NULL(host_ptr); + bool need_sync = (size != 0) && (size_ != 0); + if (!need_sync) { + return true; + } auto &stream = GPUDeviceManager::GetInstance().default_stream(); MS_EXCEPTION_IF_NULL(stream); if (size != size_) {