From dbaa1b462f86f1803d7f7e0747bffdd56ce6f6fa Mon Sep 17 00:00:00 2001 From: yujianfeng Date: Thu, 28 Jul 2022 10:36:30 +0800 Subject: [PATCH] Clean code for ops --- .../kernel/deformable_offsets_cpu_kernel.cc | 4 +-- .../kernel/deformable_offsets_cpu_kernel.h | 27 +++++++++---------- mindspore/core/ops/argmax_with_value.cc | 3 +-- mindspore/core/ops/deformable_offsets.cc | 16 ++++++----- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/deformable_offsets_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/deformable_offsets_cpu_kernel.cc index 1ab2883655c..af4c1615d13 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/deformable_offsets_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/deformable_offsets_cpu_kernel.cc @@ -180,7 +180,7 @@ int DeformableOffsetsCpuKernelMod::Resize(const BaseOperatorPtr &base_operator, output_h_ = output_shape[h_axis_]; output_w_ = output_shape[w_axis_]; position_grid_size_ = output_h_ * output_w_; - (void)workspace_size_list_.emplace_back(sizeof(int64_t) * position_grid_size_ * kKernelSizeSize); + (void)workspace_size_list_.emplace_back(sizeof(int64_t) * LongToSize(position_grid_size_) * kKernelSizeSize); return KRET_OK; } @@ -214,7 +214,7 @@ void DeformableOffsetsCpuKernelMod::DeformableOffsets(const T *input_addr, const int64_t offset_kh_dim = offset_kw_dim * kernel_size_[kKernelSizeWIndex]; int64_t offset_group_dim = offset_kh_dim * kernel_size_[kKernelSizeHIndex]; int64_t offset_mask_dim = offset_group_dim * deformable_groups_; - int64_t offset_n_dim = offset_mask_dim * kOffsetsSize; + int64_t offset_n_dim = offset_mask_dim * SizeToLong(kOffsetsSize); int64_t input_c_dim = input_h_ * input_w_; int64_t input_n_dim = input_c_dim * c_; diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/deformable_offsets_cpu_kernel.h b/mindspore/ccsrc/plugin/device/cpu/kernel/deformable_offsets_cpu_kernel.h index 6e5200f3eb7..a3eff400833 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/deformable_offsets_cpu_kernel.h +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/deformable_offsets_cpu_kernel.h @@ -44,7 +44,6 @@ class DeformableOffsetsCpuKernelMod : public NativeCpuKernelMod, const std::vector> &GetFuncList() const override; - protected: std::vector GetOpSupport() override { return OpSupport(); } private: @@ -63,20 +62,20 @@ class DeformableOffsetsCpuKernelMod : public NativeCpuKernelMod, std::vector pads_; std::vector kernel_size_; std::vector dilations_; - int64_t deformable_groups_; - bool modulated_; + int64_t deformable_groups_{1}; + bool modulated_{true}; - int64_t n_axis_; - int64_t c_axis_; - int64_t h_axis_; - int64_t w_axis_; - int64_t n_; - int64_t c_; - int64_t input_h_; - int64_t input_w_; - int64_t output_h_; - int64_t output_w_; - int64_t position_grid_size_; + size_t n_axis_{kIndex0}; + size_t c_axis_{kIndex1}; + size_t h_axis_{kIndex2}; + size_t w_axis_{kIndex3}; + int64_t n_{0}; + int64_t c_{0}; + int64_t input_h_{0}; + int64_t input_w_{0}; + int64_t output_h_{0}; + int64_t output_w_{0}; + int64_t position_grid_size_{0}; }; } // namespace kernel } // namespace mindspore diff --git a/mindspore/core/ops/argmax_with_value.cc b/mindspore/core/ops/argmax_with_value.cc index e3245d18334..8e117b7c778 100644 --- a/mindspore/core/ops/argmax_with_value.cc +++ b/mindspore/core/ops/argmax_with_value.cc @@ -40,7 +40,6 @@ bool ArgMaxWithValue::keep_dims() const { namespace { abstract::TupleShapePtr ArgMaxWithValueInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - auto prim_name = primitive->name(); auto x_shape_ptr = input_args[0]->BuildShape(); auto x_shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(x_shape_ptr); auto x_shape = x_shape_map[kShape]; @@ -67,7 +66,7 @@ abstract::TupleShapePtr ArgMaxWithValueInferShape(const PrimitivePtr &primitive, auto cal_shape = [axis, keep_dims](ShapeVector &shape, const ShapeVector &x_shape) -> void { (void)shape.insert(shape.end(), x_shape.begin(), x_shape.end()); if (keep_dims) { - shape[axis] = 1; + shape[LongToSize(axis)] = 1; } else { (void)shape.erase(shape.begin() + axis); } diff --git a/mindspore/core/ops/deformable_offsets.cc b/mindspore/core/ops/deformable_offsets.cc index 27395108eca..f9a7afce38c 100644 --- a/mindspore/core/ops/deformable_offsets.cc +++ b/mindspore/core/ops/deformable_offsets.cc @@ -64,7 +64,7 @@ std::vector CheckAttrTuple(const PrimitivePtr &prim, const std::string } std::vector CheckAttrTupleAndNCDimensions(const PrimitivePtr &primitive, const std::string &attr_name, - size_t num, int n_axis, int c_axis) { + size_t num, uint64_t n_axis, uint64_t c_axis) { std::vector tuple = CheckAttrTuple(primitive, attr_name, num); if (tuple[n_axis] != 1 || tuple[c_axis] != 1) { MS_EXCEPTION(ValueError) @@ -86,17 +86,19 @@ void DeformableOffsetsPadFunction(std::vector *output_hw, const std::ve constexpr size_t left_index = 2; constexpr size_t right_index = 3; if (x_h != abstract::Shape::SHP_ANY) { - out_h = static_cast(std::floor(1 + ((x_h * 1.0) + pads[top_index] + pads[bottom_index] - kernel_size[0] - - static_cast((kernel_size[0] - 1) * (dilations[h_axis] - 1))) / - strides[h_axis])); + out_h = static_cast( + std::floor(1 + ((x_h * 1.0) + pads[top_index] + pads[bottom_index] - kernel_size[0] - + static_cast((int64_t)LongToInt(kernel_size[0] - 1) * LongToInt(dilations[h_axis] - 1))) / + strides[h_axis])); if (is_min_shape && out_h < 1) { out_h = 1L; } } if (x_w != abstract::Shape::SHP_ANY) { - out_w = static_cast(std::floor(1 + ((x_w * 1.0) + pads[left_index] + pads[right_index] - kernel_size[1] - - static_cast((kernel_size[1] - 1) * (dilations[w_axis] - 1))) / - strides[w_axis])); + out_w = static_cast( + std::floor(1 + ((x_w * 1.0) + pads[left_index] + pads[right_index] - kernel_size[1] - + static_cast((int64_t)LongToInt(kernel_size[1] - 1) * LongToInt(dilations[w_axis] - 1))) / + strides[w_axis])); if (is_min_shape && out_w < 1) { out_w = 1L; }