print trace info when init/run kernel failed

pull/9455/head
kswang 4 years ago
parent c03f6d8b66
commit 25f97679fd

@ -17,6 +17,7 @@
#include "backend/session/cpu_session.h" #include "backend/session/cpu_session.h"
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#include <exception>
#include "ir/anf.h" #include "ir/anf.h"
#include "utils/ms_utils.h" #include "utils/ms_utils.h"
#include "utils/trace_base.h" #include "utils/trace_base.h"
@ -262,7 +263,11 @@ void CPUSession::BuildKernel(const KernelGraph *kernel_graph) {
if (cpu_kernel == nullptr) { if (cpu_kernel == nullptr) {
KernelNotSupportException(kernel_node); KernelNotSupportException(kernel_node);
} }
cpu_kernel->Init(kernel_node); try {
cpu_kernel->Init(kernel_node);
} catch (std::exception &e) {
MS_LOG(EXCEPTION) << e.what() << "\nTrace: " << trace::DumpSourceLines(kernel_node);
}
AnfAlgo::SetKernelMod(cpu_kernel, kernel_node.get()); AnfAlgo::SetKernelMod(cpu_kernel, kernel_node.get());
MS_LOG(INFO) << "Cpu build success operator[" << kernel_name << "]."; MS_LOG(INFO) << "Cpu build success operator[" << kernel_name << "].";
} }

@ -21,6 +21,7 @@
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <exception>
#include "backend/kernel_compiler/kernel.h" #include "backend/kernel_compiler/kernel.h"
#include "runtime/device/cpu/cpu_device_address.h" #include "runtime/device/cpu/cpu_device_address.h"
#include "utils/ms_context.h" #include "utils/ms_context.h"
@ -370,11 +371,16 @@ bool CPUKernelRuntime::Run(session::KernelGraph *kernel_graph, bool is_task_sink
MS_EXCEPTION_IF_NULL(device_address); MS_EXCEPTION_IF_NULL(device_address);
AddRuntimeAddress(device_address, &kernel_workspaces); AddRuntimeAddress(device_address, &kernel_workspaces);
} }
auto ret = kernel_mod->Launch(kernel_inputs, kernel_workspaces, kernel_outputs, 0); bool ret = true;
resource_manager_.DecreaseAddressRefCount(kernel); try {
ret = kernel_mod->Launch(kernel_inputs, kernel_workspaces, kernel_outputs, 0);
} catch (std::exception &e) {
MS_LOG(EXCEPTION) << e.what() << "\nTrace:" << trace::DumpSourceLines(kernel);
}
if (!ret) { if (!ret) {
MS_LOG(EXCEPTION) << "Launch kernel failed. Trace:" << trace::DumpSourceLines(kernel); MS_LOG(EXCEPTION) << "Launch kernel failed. Trace:" << trace::DumpSourceLines(kernel);
} }
resource_manager_.DecreaseAddressRefCount(kernel);
#ifdef ENABLE_PROFILE #ifdef ENABLE_PROFILE
double cost_time = GetTime() - start_time; double cost_time = GetTime() - start_time;
MS_LOG(INFO) << "cpu kernel: " << kernel->fullname_with_scope() << " costs " << cost_time * 1e6 << " us"; MS_LOG(INFO) << "cpu kernel: " << kernel->fullname_with_scope() << " costs " << cost_time * 1e6 << " us";

Loading…
Cancel
Save