forked from mindspore-Ecosystem/mindspore
!30562 fix cpu matrix_set_diag && matrix_band_part kernel codex && pclint-plus
Merge pull request !30562 from zhuzhongrui/pub_master2
This commit is contained in:
commit
1de823f1eb
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -36,16 +36,15 @@ void MatrixBandPartCpuKernelMod<T>::InitKernel(const CNodePtr &kernel_node) {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool MatrixBandPartCpuKernelMod<T>::Launch(const std::vector<AddressPtr> &inputs,
|
||||
const std::vector<AddressPtr> &workspace,
|
||||
bool MatrixBandPartCpuKernelMod<T>::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &,
|
||||
const std::vector<AddressPtr> &outputs) {
|
||||
T *in_value = reinterpret_cast<T *>(inputs[0]->addr);
|
||||
const int64_t *lower = reinterpret_cast<int64_t *>(inputs[1]->addr);
|
||||
const int64_t *upper = reinterpret_cast<int64_t *>(inputs[2]->addr);
|
||||
T *out_value = reinterpret_cast<T *>(outputs[0]->addr);
|
||||
|
||||
const size_t l = (*lower < 0 || *lower > static_cast<int64_t>(m_)) ? m_ : *lower;
|
||||
const size_t u = (*upper < 0 || *upper > static_cast<int64_t>(n_)) ? n_ : *upper;
|
||||
const size_t l = (*lower < 0 || *lower > static_cast<int64_t>(m_)) ? m_ : static_cast<size_t>(*lower);
|
||||
const size_t u = (*upper < 0 || *upper > static_cast<int64_t>(n_)) ? n_ : static_cast<size_t>(*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;
|
||||
|
|
|
@ -38,37 +38,35 @@ void MatrixSetDiagCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
// invalid alignment will throw an exception.
|
||||
auto alignment = AnfAlgo::GetNodeAttr<std::string>(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<kernel::AddressPtr> &in
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void MatrixSetDiagCpuKernelMod::LaunchKernel(const std::vector<AddressPtr> &inputs,
|
||||
const std::vector<AddressPtr> &workspaces,
|
||||
void MatrixSetDiagCpuKernelMod::LaunchKernel(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &,
|
||||
const std::vector<AddressPtr> &outputs) {
|
||||
auto input = inputs.at(kDim0);
|
||||
auto diag = inputs.at(kDim1);
|
||||
|
|
Loading…
Reference in New Issue