forked from mindspore-Ecosystem/mindspore
!49575 Fix cordump problem while null input
Merge pull request !49575 from zhangzhaoju/r1.10
This commit is contained in:
commit
ea8aae4ebb
|
@ -412,6 +412,14 @@ inline bool GetDynamicAttrIntValue(const std::vector<KernelTensorPtr> &inputs, c
|
|||
*attr_value = res.value();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool CheckNullInput(const std::vector<T> &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
|
||||
|
||||
|
|
|
@ -99,6 +99,9 @@ bool XdivyCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &inpu
|
|||
const std::vector<kernel::AddressPtr> &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<T *>(inputs[0]->addr);
|
||||
auto y_addr = static_cast<T *>(inputs[1]->addr);
|
||||
auto output_addr = static_cast<T *>(outputs[0]->addr);
|
||||
|
@ -136,10 +139,6 @@ bool XdivyCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &inpu
|
|||
|
||||
bool XdivyCpuKernelMod::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
|
||||
const std::vector<AddressPtr> &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
|
||||
|
|
|
@ -58,6 +58,7 @@ class XdivyCpuKernelMod : public NativeCpuKernelMod, public MatchKernelHelper<Xd
|
|||
std::vector<size_t> index_listx_{};
|
||||
std::vector<size_t> index_listy_{};
|
||||
bool is_need_broadcast_{false};
|
||||
bool has_null_input_{false};
|
||||
};
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -228,19 +228,6 @@ namespace gpu {
|
|||
#define VARIABLE_NOT_USED(var) \
|
||||
{ (void)(var); }
|
||||
|
||||
template <typename T>
|
||||
inline bool CheckNullInput(const std::vector<T> &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<int64_t> &input_shape) {
|
||||
if (input_shape.size() != 0) {
|
||||
if (std::all_of(input_shape.begin(), input_shape.end(), [](int64_t i) { return i > 0; })) {
|
||||
|
|
Loading…
Reference in New Issue