From 0de0e0cd4b0bb0576839c1b5b1f2cf25d9b00b5b Mon Sep 17 00:00:00 2001 From: z00512249 Date: Fri, 25 Feb 2022 10:36:21 +0800 Subject: [PATCH] fix cpu matrix_set_diag && matrix_band_part kernel codex && pclint-plus --- mindspore/ccsrc/kernel/common_utils.h | 5 ++-- .../cpu/kernel/matrix_band_part_cpu_kernel.cc | 7 +++-- .../cpu/kernel/matrix_set_diag_cpu_kernel.cc | 27 +++++++++---------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/mindspore/ccsrc/kernel/common_utils.h b/mindspore/ccsrc/kernel/common_utils.h index 2182779b9aa..9531a82194f 100644 --- a/mindspore/ccsrc/kernel/common_utils.h +++ b/mindspore/ccsrc/kernel/common_utils.h @@ -98,8 +98,9 @@ class MatrixInfo { // initial current indexes. int last_rank = SizeToInt(current_indexes_.size()) - 1; for (int i = last_rank; start != 0 && i >= 0; --i) { - current_indexes_[i] = start % shapes_.at(i); - start = start / shapes_.at(i); + size_t position = IntToSize(i); + current_indexes_[position] = start % shapes_.at(position); + start = start / shapes_.at(position); } return true; } diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/matrix_band_part_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/matrix_band_part_cpu_kernel.cc index cb5b8b10ede..04ed371f2c8 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/matrix_band_part_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/matrix_band_part_cpu_kernel.cc @@ -36,16 +36,15 @@ void MatrixBandPartCpuKernelMod::InitKernel(const CNodePtr &kernel_node) { } template -bool MatrixBandPartCpuKernelMod::Launch(const std::vector &inputs, - const std::vector &workspace, +bool MatrixBandPartCpuKernelMod::Launch(const std::vector &inputs, const std::vector &, const std::vector &outputs) { T *in_value = reinterpret_cast(inputs[0]->addr); const int64_t *lower = reinterpret_cast(inputs[1]->addr); const int64_t *upper = reinterpret_cast(inputs[2]->addr); T *out_value = reinterpret_cast(outputs[0]->addr); - const size_t l = (*lower < 0 || *lower > static_cast(m_)) ? m_ : *lower; - const size_t u = (*upper < 0 || *upper > static_cast(n_)) ? n_ : *upper; + const size_t l = (*lower < 0 || *lower > static_cast(m_)) ? m_ : static_cast(*lower); + const size_t u = (*upper < 0 || *upper > static_cast(n_)) ? n_ : static_cast(*upper); auto ret_s1 = memset_s(out_value, matrix_size_ * sizeof(T), 0, matrix_size_ * sizeof(T)); if (ret_s1 != EOK) { MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', memset output to 0 failed. Error no: " << ret_s1; diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/matrix_set_diag_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/matrix_set_diag_cpu_kernel.cc index 9dd9835047d..33d490362e9 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/matrix_set_diag_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/matrix_set_diag_cpu_kernel.cc @@ -38,37 +38,35 @@ void MatrixSetDiagCpuKernelMod::InitKernel(const CNodePtr &kernel_node) { // invalid alignment will throw an exception. auto alignment = AnfAlgo::GetNodeAttr(kernel_node, ALIGNMENT); alignment_ = GetAlignments(alignment); - constexpr int input_index = 0; - constexpr int diag_index = 1; - constexpr int diag_k_index = 2; - constexpr int output_index = 0; + constexpr size_t input_index = 0; + constexpr size_t diag_index = 1; + constexpr size_t diag_k_index = 2; + constexpr size_t output_index = 0; auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, input_index); auto diag_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, diag_index); auto diag_k_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, diag_k_index); auto output_shape = AnfAlgo::GetOutputInferShape(kernel_node, output_index); - constexpr int temporary_2d_dim = 2; - constexpr int temporary_1d_dim = 1; - if (SizeToInt(input_shape.size()) < temporary_2d_dim || SizeToInt(diag_shape.size()) < temporary_1d_dim || - input_shape != output_shape) { + constexpr size_t temporary_2d_dim = 2; + constexpr size_t temporary_1d_dim = 1; + if (input_shape.size() < temporary_2d_dim || diag_shape.size() < temporary_1d_dim || input_shape != output_shape) { MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', the dimension of input is invalid for input shape greater than 2D, diag shape " "greater than 1D, input shape should equal to output shape."; } - if (SizeToInt(diag_k_shape.size()) != temporary_1d_dim) { + if (diag_k_shape.size() != temporary_1d_dim) { MS_LOG(EXCEPTION) << "For '" << kernel_name_ << "', the dimension of diag_region's dim should be limited to range (k[0],k[1])."; } - int input_rank = SizeToInt(input_shape.size()); - for (int i = 0; i < input_rank - temporary_2d_dim; ++i) { + size_t input_rank = input_shape.size(); + for (size_t i = 0; i < input_rank - temporary_2d_dim; ++i) { outer_batch_ *= SizeToInt(input_shape.at(i)); } input_shape_ = input_shape; inner_rows_ = SizeToInt(input_shape.at(input_rank - temporary_2d_dim)); inner_cols_ = SizeToInt(input_shape.at(input_rank - temporary_1d_dim)); - expected_num_diags_ = - SizeToInt(diag_shape.size()) == input_rank ? SizeToInt(diag_shape.at(input_rank - temporary_2d_dim)) : 1; + expected_num_diags_ = diag_shape.size() == input_rank ? SizeToInt(diag_shape.at(input_rank - temporary_2d_dim)) : 1; data_type_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0); } @@ -94,8 +92,7 @@ bool MatrixSetDiagCpuKernelMod::Launch(const std::vector &in } template -void MatrixSetDiagCpuKernelMod::LaunchKernel(const std::vector &inputs, - const std::vector &workspaces, +void MatrixSetDiagCpuKernelMod::LaunchKernel(const std::vector &inputs, const std::vector &, const std::vector &outputs) { auto input = inputs.at(kDim0); auto diag = inputs.at(kDim1);