From 9fd9a1af71270e2eb8171cae6f215543020b1762 Mon Sep 17 00:00:00 2001 From: lianliguang Date: Wed, 29 Apr 2020 15:31:41 +0800 Subject: [PATCH] add warning info to statistics how much nodes using raise or reduce to selected kernel info --- .../ccsrc/device/ascend/kernel_select_ascend.cc | 7 +++++-- .../ccsrc/device/ascend/kernel_select_ascend.h | 2 +- mindspore/ccsrc/session/ascend_session.cc | 17 ++++++++++++++++- mindspore/ccsrc/utils/utils.h | 5 ++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/mindspore/ccsrc/device/ascend/kernel_select_ascend.cc b/mindspore/ccsrc/device/ascend/kernel_select_ascend.cc index d8779bc55..9e54adc63 100644 --- a/mindspore/ccsrc/device/ascend/kernel_select_ascend.cc +++ b/mindspore/ccsrc/device/ascend/kernel_select_ascend.cc @@ -342,7 +342,7 @@ void AddNodeAndKernelDataType(const CNodePtr &kernel_node, const kernel::KernelB std::vector *node_mix_precision_datatype_index) { MS_EXCEPTION_IF_NULL(node_mix_precision_datatype); bool add_node_datatype_flag = false; - if (node_mix_precision_datatype->size() == 0) { + if (node_mix_precision_datatype->empty()) { add_node_datatype_flag = true; } for (size_t input_index = 0; input_index < kernel_build_info.GetInputNum(); ++input_index) { @@ -464,8 +464,9 @@ std::vector> FilterRaisedOrReducePrecis } } // namespace -void SelectKernelInfo(const CNodePtr &kernel_node) { +int SelectKernelInfo(const CNodePtr &kernel_node) { std::vector> kernel_info_list; + int status = kStatusAllMatched; MS_EXCEPTION_IF_NULL(kernel_node); bool precision_reduce = false; std::shared_ptr selected_kernel_info = nullptr; @@ -486,11 +487,13 @@ void SelectKernelInfo(const CNodePtr &kernel_node) { << "] cannot find valid kernel info, not supported the type" << buffer.str(); } else { PrintRaiseOrReducePrecisionSelectedInfo(kernel_node, selected_kernel_info, precision_reduce); + status = precision_reduce ? kStatusReducePrecision : kStatusRaisePrecision; } } AnfAlgo::SetSelectKernelBuildInfo(selected_kernel_info, kernel_node.get()); // Set format and data type for input tensor. SetTensorDeviceInfo(*selected_kernel_info, kernel_node); + return status; } bool CheckKernelAccuracySupported(const CNodePtr &kernel_node, diff --git a/mindspore/ccsrc/device/ascend/kernel_select_ascend.h b/mindspore/ccsrc/device/ascend/kernel_select_ascend.h index 100cd8e1e..af353815b 100644 --- a/mindspore/ccsrc/device/ascend/kernel_select_ascend.h +++ b/mindspore/ccsrc/device/ascend/kernel_select_ascend.h @@ -21,7 +21,7 @@ namespace mindspore { namespace device { namespace ascend { -void SelectKernelInfo(const CNodePtr &kernel_node); +int SelectKernelInfo(const CNodePtr &kernel_node); bool CheckKernelAccuracySupported(const CNodePtr &kernel_node, const kernel::KernelBuildInfoPtr &new_kernel_build_info); } // namespace ascend } // namespace device diff --git a/mindspore/ccsrc/session/ascend_session.cc b/mindspore/ccsrc/session/ascend_session.cc index bd5fba6d4..8d6e3f906 100755 --- a/mindspore/ccsrc/session/ascend_session.cc +++ b/mindspore/ccsrc/session/ascend_session.cc @@ -312,10 +312,25 @@ py::tuple AscendSession::RunOp(const OpRunInfo &op_run_info, const GraphInfo &gr // compile graph steps void AscendSession::SelectKernel(const KernelGraph &kernel_graph) const { MS_LOG(INFO) << "Start!"; + size_t raise_precision_count = 0; + size_t reduce_precision_count = 0; for (const auto &cnode : kernel_graph.execution_order()) { - device::ascend::SelectKernelInfo(cnode); + auto status = device::ascend::SelectKernelInfo(cnode); + if (status == kStatusRaisePrecision) { + raise_precision_count++; + } else if (status == kStatusReducePrecision) { + reduce_precision_count++; + } MS_LOG(INFO) << "Select ApplyKernel: " << cnode->DebugString(); } + if (raise_precision_count > 0) { + MS_LOG(WARNING) << "There has " << raise_precision_count + << " node/nodes used raise precision to selected the kernel!"; + } + if (reduce_precision_count > 0) { + MS_LOG(WARNING) << "There has " << reduce_precision_count + << " node/nodes used reduce precision to selected the kernel!"; + } MS_LOG(INFO) << "Finish!"; } diff --git a/mindspore/ccsrc/utils/utils.h b/mindspore/ccsrc/utils/utils.h index 59d7f27c1..2624defce 100644 --- a/mindspore/ccsrc/utils/utils.h +++ b/mindspore/ccsrc/utils/utils.h @@ -184,7 +184,10 @@ constexpr auto kControlDependBehindIndex = 2; // index define of depend constexpr auto kRealInputIndexInDepend = 1; constexpr auto kDependAttachNodeIndex = 2; - +// status of kernel select result +const int kStatusReducePrecision = -1; +const int kStatusRaisePrecision = 1; +const int kStatusAllMatched = 0; // format constexpr auto kOpFormat_DEFAULT = "DefaultFormat"; constexpr auto kOpFormat_NC1KHKWHWC0 = "NC1KHKWHWC0"; -- GitLab