From 0c281008256cff34aa489514355505a7579fc76a Mon Sep 17 00:00:00 2001 From: z00512249 Date: Thu, 24 Feb 2022 20:36:01 +0800 Subject: [PATCH] fix cpu lu kernel codex && pclint-plus --- .../device/cpu/kernel/eigen/lu_cpu_kernel.cc | 20 +++++++++---------- .../device/cpu/kernel/eigen/lu_cpu_kernel.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/eigen/lu_cpu_kernel.cc b/mindspore/ccsrc/plugin/device/cpu/kernel/eigen/lu_cpu_kernel.cc index b1ed073c4a7..ac27fe59506 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/eigen/lu_cpu_kernel.cc +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/eigen/lu_cpu_kernel.cc @@ -98,10 +98,10 @@ T LUCpuKernelMod::GetPermutatedValue(const T *lu_value, const std::vector -bool LUCpuKernelMod::UpdateMajorPermutation(T *lu_value, std::vector *const per_value, int *pivots, size_t k, +bool LUCpuKernelMod::UpdateMajorPermutation(T *lu_value, std::vector *per_value, int *pivots, size_t k, size_t rows) { T max_major_value = static_cast(kZeroThreshold); - int max_major_index = 0; + size_t max_major_index = 0; for (size_t i = k; i < rows; ++i) { T value = GetPermutatedValue(lu_value, *per_value, i, k); T abs_value = std::abs(value); @@ -113,7 +113,7 @@ bool LUCpuKernelMod::UpdateMajorPermutation(T *lu_value, std::vector *co int per_k = per_value->at(k); (*per_value)[k] = per_value->at(max_major_index); (*per_value)[max_major_index] = per_k; - pivots[k] = max_major_index; + pivots[k] = SizeToInt(max_major_index); return max_major_value != static_cast(kZeroThreshold); } @@ -145,14 +145,14 @@ bool LUCpuKernelMod::Launch(const std::vector &inputs, // init pivots std::vector per_value(pivots_col_, 0); for (size_t i = 0; i < pivots_col_; ++i) { - per_value[i] = i; + per_value[i] = SizeToInt(i); } // 1. memcpy input to output, do full lu inplace. (void)memcpy_s(lu_value, lu_row_ * lu_col_ * sizeof(T), a_value, a_row_ * a_col_ * sizeof(T)); - int s = std::min(a_row_, a_col_); + size_t s = std::min(a_row_, a_col_); // 2. do lu decompose inplace - for (int k = 0; k < s; ++k) { + for (size_t k = 0; k < s; ++k) { // 2.1 choose major element of current col if return false means current col elements are all zero, just continue. if (!UpdateMajorPermutation(lu_value, &per_value, pivots, k, lu_row_)) { continue; @@ -179,8 +179,8 @@ bool LUCpuKernelMod::Launch(const std::vector &inputs, // 3. calculate final lu by permutation list std::unordered_map> pivots_map; - for (int i = 0; i < static_cast(lu_row_); ++i) { - pivots_map[per_value[i]] = {i, false}; + for (size_t i = 0; i < lu_row_; ++i) { + pivots_map[per_value[i]] = {SizeToInt(i), false}; } int pivots_count = 0; for (const auto &pivot : pivots_map) { @@ -192,8 +192,8 @@ bool LUCpuKernelMod::Launch(const std::vector &inputs, continue; } - T *lu_ori_row = lu_value + index * lu_col_; - T *lu_trans_row = lu_value + key * lu_col_; + T *lu_ori_row = lu_value + index * SizeToInt(lu_col_); + T *lu_trans_row = lu_value + key * SizeToInt(lu_col_); // copy ori data to trans lu (void)memcpy_s(lu_trans_wk, lu_col_ * sizeof(T), lu_ori_row, lu_col_ * sizeof(T)); // copy new data to ori data ptr diff --git a/mindspore/ccsrc/plugin/device/cpu/kernel/eigen/lu_cpu_kernel.h b/mindspore/ccsrc/plugin/device/cpu/kernel/eigen/lu_cpu_kernel.h index 5e59e78ad51..565b9f602fd 100644 --- a/mindspore/ccsrc/plugin/device/cpu/kernel/eigen/lu_cpu_kernel.h +++ b/mindspore/ccsrc/plugin/device/cpu/kernel/eigen/lu_cpu_kernel.h @@ -37,7 +37,7 @@ class LUCpuKernelMod : public NativeCpuKernelMod { void InitPivotVecInfo(const std::vector &shape, size_t *row, size_t *col); void InitInputOutputSize(const CNodePtr &kernel_node) override; T GetPermutatedValue(const T *lu_value, const std::vector &per_value, size_t i, size_t j); - bool UpdateMajorPermutation(T *lu_value, std::vector *const per_value, int *pivots, size_t k, size_t rows); + bool UpdateMajorPermutation(T *lu_value, std::vector *per_value, int *pivots, size_t k, size_t rows); void SetPermutatedValue(T *lu_value, const std::vector &per_value, size_t i, size_t j, const T &value); size_t batch_size_{1}; size_t a_row_{1};