From b3049a3440faf221baf094fbd3aa8303b075b7d7 Mon Sep 17 00:00:00 2001 From: zhangzhaoju Date: Mon, 12 Dec 2022 10:57:31 +0800 Subject: [PATCH] Fix cordump problem while null input while has null input, xdivy return null too according to tensorflow --- mindspore/ccsrc/kernel/kernel.h | 8 ++++++++ .../plugin/device/cpu/kernel/xdivy_cpu_kernel.cc | 14 ++++++++++---- .../plugin/device/cpu/kernel/xdivy_cpu_kernel.h | 1 + .../plugin/device/gpu/hal/device/gpu_common.h | 13 ------------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/mindspore/ccsrc/kernel/kernel.h b/mindspore/ccsrc/kernel/kernel.h index 85eb9510d5f..ad4b0f1aa50 100644 --- a/mindspore/ccsrc/kernel/kernel.h +++ b/mindspore/ccsrc/kernel/kernel.h @@ -404,6 +404,14 @@ inline bool GetDynamicAttrIntValue(const std::vector &inputs, c *attr_value = res.value(); return true; } + +template +inline bool CheckNullInput(const std::vector &input_shape) { + // If input_shape.size() == 0, it means a scalar input; If input_shape.size() != 0 and input_shape contains 0, + // it means a null input. Just return a null output. + return input_shape.size() != 0 && std::any_of(input_shape.begin(), input_shape.end(), [](T i) { return i == 0; }); +} +#define CHECK_NULL_INPUT(input_shape) mindspore::kernel::CheckNullInput(input_shape) } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/xdivy_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/xdivy_cpu_kernel.cc index a5ebfd03dc3..568d8758cc0 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/xdivy_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/xdivy_cpu_kernel.cc @@ -99,6 +99,9 @@ bool XdivyCpuKernelMod::LaunchKernel(const std::vector &inpu const std::vector &outputs) { CHECK_KERNEL_INPUTS_NUM(inputs.size(), INPUT_NUM, kernel_name_); CHECK_KERNEL_OUTPUTS_NUM(outputs.size(), OUTPUT_NUM, kernel_name_); + if (has_null_input_) { + return true; + } auto x_addr = static_cast(inputs[0]->addr); auto y_addr = static_cast(inputs[1]->addr); auto output_addr = static_cast(outputs[0]->addr); @@ -136,10 +139,6 @@ bool XdivyCpuKernelMod::LaunchKernel(const std::vector &inpu bool XdivyCpuKernelMod::Launch(const std::vector &inputs, const std::vector &workspace, const std::vector &outputs) { - const size_t kInputsNum = 2; - const size_t kOutputsNum = 1; - CHECK_KERNEL_INPUTS_NUM(inputs.size(), kInputsNum, kernel_name_); - CHECK_KERNEL_OUTPUTS_NUM(outputs.size(), kOutputsNum, kernel_name_); return kernel_func_(this, inputs, workspace, outputs); } @@ -174,6 +173,13 @@ int XdivyCpuKernelMod::Resize(const BaseOperatorPtr &base_operator, const std::v auto x_shape = LongVecToSizeVec(inputs.at(kIndex0)->GetShapeVector()); auto y_shape = LongVecToSizeVec(inputs.at(kIndex1)->GetShapeVector()); + + // while has null input, xdivy result is null too + has_null_input_ = CheckNullInput(x_shape) || CheckNullInput(y_shape); + if (has_null_input_) { + return 0; + } + auto out_shape = LongVecToSizeVec(outputs.at(kIndex0)->GetShapeVector()); if (out_shape.size() > MAX_DIMS || out_shape.size() < x_shape.size() || out_shape.size() < y_shape.size()) { MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', the dimension of input cannot be greater than " << MAX_DIMS diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/xdivy_cpu_kernel.h b/mindspore/ccsrc/plugin/device/cpu/kernel/xdivy_cpu_kernel.h index ea197453969..32bb06dbd91 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/xdivy_cpu_kernel.h +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/xdivy_cpu_kernel.h @@ -58,6 +58,7 @@ class XdivyCpuKernelMod : public NativeCpuKernelMod, public MatchKernelHelper index_listx_{}; std::vector index_listy_{}; bool is_need_broadcast_{false}; + bool has_null_input_{false}; }; } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_common.h b/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_common.h index 2fc80e26d5d..90432257f8f 100644 --- a/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_common.h +++ b/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_common.h @@ -228,19 +228,6 @@ namespace gpu { #define VARIABLE_NOT_USED(var) \ { (void)(var); } -template -inline bool CheckNullInput(const std::vector &input_shape) { - // If input_shape.size() == 0, it means a scalar input; If input_shape.size() != 0 and input_shape contains 0, - // it means a null input. Just return a null output. - if (input_shape.size() != 0) { - if (std::any_of(input_shape.begin(), input_shape.end(), [](T i) { return i == 0; })) { - return true; - } - } - return false; -} -#define CHECK_NULL_INPUT(input_shape) mindspore::device::gpu::CheckNullInput(input_shape) - inline bool CheckShapePositive(const std::vector &input_shape) { if (input_shape.size() != 0) { if (std::all_of(input_shape.begin(), input_shape.end(), [](int64_t i) { return i > 0; })) {