forked from mindspore-Ecosystem/mindspore
!43362 fixing static code warnings
Merge pull request !43362 from 古木/warn-r1.9
This commit is contained in:
commit
03b2d4f18a
|
@ -80,7 +80,7 @@ int CTCLossV2CpuKernelMod::Resize(const BaseOperatorPtr &base_operator, const st
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename S, typename T>
|
template <typename S, typename T>
|
||||||
void CTCLossV2CpuKernelMod::LossCompute(S *log_probs_p, S *log_alpha_p, T *tar_p, SoftParam params) {
|
void CTCLossV2CpuKernelMod::LossCompute(const S *log_probs_p, S *log_alpha_p, const T *tar_p, SoftParam params) const {
|
||||||
constexpr S neg_inf = -std::numeric_limits<S>::infinity();
|
constexpr S neg_inf = -std::numeric_limits<S>::infinity();
|
||||||
int64_t input_length = params.input_length;
|
int64_t input_length = params.input_length;
|
||||||
int64_t target_length = params.target_length;
|
int64_t target_length = params.target_length;
|
||||||
|
@ -112,7 +112,7 @@ void CTCLossV2CpuKernelMod::LossCompute(S *log_probs_p, S *log_alpha_p, T *tar_p
|
||||||
} else {
|
} else {
|
||||||
log_a3 = neg_inf;
|
log_a3 = neg_inf;
|
||||||
}
|
}
|
||||||
if (log_max == neg_inf) {
|
if (std::isinf(log_max) && std::signbit(log_max)) {
|
||||||
log_max = 0;
|
log_max = 0;
|
||||||
}
|
}
|
||||||
S log_three_sum = std::log(std::exp(log_a1 - log_max) + std::exp(log_a2 - log_max) + std::exp(log_a3 - log_max)) +
|
S log_three_sum = std::log(std::exp(log_a1 - log_max) + std::exp(log_a2 - log_max) + std::exp(log_a3 - log_max)) +
|
||||||
|
@ -124,7 +124,8 @@ void CTCLossV2CpuKernelMod::LossCompute(S *log_probs_p, S *log_alpha_p, T *tar_p
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool CTCLossV2CpuKernelMod::IndexProcessing(T *in_len_p, T *tar_len_p, std::vector<int64_t> *target_offsets) {
|
bool CTCLossV2CpuKernelMod::IndexProcessing(const T *in_len_p, const T *tar_len_p,
|
||||||
|
std::vector<int64_t> *target_offsets) {
|
||||||
const int64_t target_stride = max_target_length_;
|
const int64_t target_stride = max_target_length_;
|
||||||
for (size_t i = 0; i < LongToSize(batch_sizes_); ++i) {
|
for (size_t i = 0; i < LongToSize(batch_sizes_); ++i) {
|
||||||
if (tar_len_p[i] < 0 || tar_len_p[i] > target_stride) {
|
if (tar_len_p[i] < 0 || tar_len_p[i] > target_stride) {
|
||||||
|
@ -155,12 +156,12 @@ template <typename S, typename T>
|
||||||
bool CTCLossV2CpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &inputs,
|
bool CTCLossV2CpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &inputs,
|
||||||
const std::vector<kernel::AddressPtr> &,
|
const std::vector<kernel::AddressPtr> &,
|
||||||
const std::vector<kernel::AddressPtr> &outputs) {
|
const std::vector<kernel::AddressPtr> &outputs) {
|
||||||
auto log_probs_p = reinterpret_cast<S *>(inputs[kIndex0]->addr);
|
auto log_probs_p = static_cast<S *>(inputs[kIndex0]->addr);
|
||||||
auto tar_p = reinterpret_cast<T *>(inputs[kIndex1]->addr);
|
auto tar_p = static_cast<T *>(inputs[kIndex1]->addr);
|
||||||
auto in_len_p = reinterpret_cast<T *>(inputs[kIndex2]->addr);
|
auto in_len_p = static_cast<T *>(inputs[kIndex2]->addr);
|
||||||
auto tar_len_p = reinterpret_cast<T *>(inputs[kIndex3]->addr);
|
auto tar_len_p = static_cast<T *>(inputs[kIndex3]->addr);
|
||||||
auto neg_log_p = reinterpret_cast<S *>(outputs[kIndex0]->addr);
|
auto neg_log_p = static_cast<S *>(outputs[kIndex0]->addr);
|
||||||
auto log_alpha_p = reinterpret_cast<S *>(outputs[kIndex1]->addr);
|
auto log_alpha_p = static_cast<S *>(outputs[kIndex1]->addr);
|
||||||
std::vector<int64_t> target_offsets(LongToSize(batch_sizes_));
|
std::vector<int64_t> target_offsets(LongToSize(batch_sizes_));
|
||||||
if (!IndexProcessing<T>(in_len_p, tar_len_p, &target_offsets)) {
|
if (!IndexProcessing<T>(in_len_p, tar_len_p, &target_offsets)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -184,7 +185,7 @@ bool CTCLossV2CpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &
|
||||||
S l1 = log_alpha_p[log_alpha_it(b, in_len - 1, tar_len * target_mul)];
|
S l1 = log_alpha_p[log_alpha_it(b, in_len - 1, tar_len * target_mul)];
|
||||||
S l2 = log_alpha_p[log_alpha_it(b, in_len - 1, tar_len * target_mul - 1)];
|
S l2 = log_alpha_p[log_alpha_it(b, in_len - 1, tar_len * target_mul - 1)];
|
||||||
S m = std::max(l1, l2);
|
S m = std::max(l1, l2);
|
||||||
m = ((m == -std::numeric_limits<S>::infinity()) ? 0 : m);
|
m = ((std::isinf(m) && std::signbit(m)) ? 0 : m);
|
||||||
S log_likelihood = std::log(std::exp(l1 - m) + std::exp(l2 - m)) + m;
|
S log_likelihood = std::log(std::exp(l1 - m) + std::exp(l2 - m)) + m;
|
||||||
neg_log_p[b] = -log_likelihood;
|
neg_log_p[b] = -log_likelihood;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_CTCLOSS_V2_CPU_KERNEL_H_
|
#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_CTCLOSS_V2_CPU_KERNEL_H_
|
||||||
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_CTCLOSS_V2_CPU_KERNEL_H_
|
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_CTCLOSS_V2_CPU_KERNEL_H_
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -55,7 +56,7 @@ class CTCLossV2CpuKernelMod : public NativeCpuKernelMod, public MatchKernelHelpe
|
||||||
int64_t batch;
|
int64_t batch;
|
||||||
};
|
};
|
||||||
template <typename target_t>
|
template <typename target_t>
|
||||||
inline int64_t GetBlankPaddedTarget(const target_t *target, int64_t offset, int64_t idx) {
|
inline int64_t GetBlankPaddedTarget(const target_t *target, int64_t offset, int64_t idx) const {
|
||||||
constexpr int64_t interval = 2;
|
constexpr int64_t interval = 2;
|
||||||
if (idx % interval == 0) {
|
if (idx % interval == 0) {
|
||||||
return blank_;
|
return blank_;
|
||||||
|
@ -64,9 +65,9 @@ class CTCLossV2CpuKernelMod : public NativeCpuKernelMod, public MatchKernelHelpe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename S, typename T>
|
template <typename S, typename T>
|
||||||
void LossCompute(S *log_probs_p, S *log_alpha_p, T *tar_p, SoftParam params);
|
void LossCompute(const S *log_probs_p, S *log_alpha_p, const T *tar_p, SoftParam params) const;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool IndexProcessing(T *in_len_p, T *tar_len_p, std::vector<int64_t> *target_offsets);
|
bool IndexProcessing(const T *in_len_p, const T *tar_len_p, std::vector<int64_t> *target_offsets);
|
||||||
// Variables for the operator itself
|
// Variables for the operator itself
|
||||||
int64_t blank_{0};
|
int64_t blank_{0};
|
||||||
// Stands for T
|
// Stands for T
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <cmath>
|
||||||
#include "abstract/utils.h"
|
#include "abstract/utils.h"
|
||||||
#include "mindspore/core/ops/ctc_loss_v2_grad.h"
|
#include "mindspore/core/ops/ctc_loss_v2_grad.h"
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
|
@ -37,7 +37,7 @@ struct SoftParam {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename target_t>
|
template <typename target_t>
|
||||||
static inline int64_t get_target_prime(target_t *target, int64_t offset, int64_t idx, int64_t BLANK) {
|
static inline int64_t get_target_prime(const target_t *target, int64_t offset, int64_t idx, int64_t BLANK) {
|
||||||
constexpr int64_t even = 2;
|
constexpr int64_t even = 2;
|
||||||
if (idx % even == 0) {
|
if (idx % even == 0) {
|
||||||
return BLANK;
|
return BLANK;
|
||||||
|
@ -88,8 +88,8 @@ int CTCLossV2GradCpuKernelMod::Resize(const BaseOperatorPtr &base_operator, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename scalar_t, typename target_t>
|
template <typename scalar_t, typename target_t>
|
||||||
void ComputeGrad(scalar_t *log_probs, const NdTensorIterator<kDim3> &log_probs_it, SoftParam params,
|
void ComputeGrad(const scalar_t *log_probs, const NdTensorIterator<kDim3> &log_probs_it, SoftParam params,
|
||||||
scalar_t *log_alpha, const NdTensorIterator<kDim3> &log_alpha_it, scalar_t *log_beta,
|
const scalar_t *log_alpha, const NdTensorIterator<kDim3> &log_alpha_it, scalar_t *log_beta,
|
||||||
const NdTensorIterator<kDim3> &log_beta_it, scalar_t *grad, const NdTensorIterator<kDim3> &grad_it) {
|
const NdTensorIterator<kDim3> &log_beta_it, scalar_t *grad, const NdTensorIterator<kDim3> &grad_it) {
|
||||||
int64_t blank_ = params.blank_;
|
int64_t blank_ = params.blank_;
|
||||||
int64_t input_length = params.input_length;
|
int64_t input_length = params.input_length;
|
||||||
|
@ -121,14 +121,14 @@ void ComputeGrad(scalar_t *log_probs, const NdTensorIterator<kDim3> &log_probs_i
|
||||||
} else {
|
} else {
|
||||||
lb3 = neginf;
|
lb3 = neginf;
|
||||||
}
|
}
|
||||||
if (lbmax == neginf) {
|
if (std::isinf(lbmax) && std::signbit(lbmax)) {
|
||||||
lbmax = 0;
|
lbmax = 0;
|
||||||
}
|
}
|
||||||
log_beta[log_beta_it(b, t, s)] = std::log(std::exp(lb1 - lbmax) + std::exp(lb2 - lbmax) + std::exp(lb3 - lbmax)) +
|
log_beta[log_beta_it(b, t, s)] = std::log(std::exp(lb1 - lbmax) + std::exp(lb2 - lbmax) + std::exp(lb3 - lbmax)) +
|
||||||
lbmax + log_probs[log_probs_it(t, b, current_target_prime)];
|
lbmax + log_probs[log_probs_it(t, b, current_target_prime)];
|
||||||
scalar_t log_alpha_beta = log_alpha[log_alpha_it(b, t, s)] + log_beta[log_beta_it(b, t, s)];
|
scalar_t log_alpha_beta = log_alpha[log_alpha_it(b, t, s)] + log_beta[log_beta_it(b, t, s)];
|
||||||
scalar_t &lcab = grad[grad_it(t, b, current_target_prime)];
|
scalar_t &lcab = grad[grad_it(t, b, current_target_prime)];
|
||||||
if (lcab == neginf) {
|
if (std::isinf(lcab) && std::signbit(lcab)) {
|
||||||
lcab = log_alpha_beta;
|
lcab = log_alpha_beta;
|
||||||
} else {
|
} else {
|
||||||
scalar_t max = std::max(lcab, log_alpha_beta);
|
scalar_t max = std::max(lcab, log_alpha_beta);
|
||||||
|
@ -140,16 +140,16 @@ void ComputeGrad(scalar_t *log_probs, const NdTensorIterator<kDim3> &log_probs_i
|
||||||
template <typename scalar_t, typename target_t>
|
template <typename scalar_t, typename target_t>
|
||||||
bool CTCLossV2GradCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &inputs,
|
bool CTCLossV2GradCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &inputs,
|
||||||
const std::vector<kernel::AddressPtr> &workspace,
|
const std::vector<kernel::AddressPtr> &workspace,
|
||||||
const std::vector<kernel::AddressPtr> &outputs) {
|
const std::vector<kernel::AddressPtr> &outputs) const {
|
||||||
auto grad_out = reinterpret_cast<scalar_t *>(inputs[kIndex0]->addr);
|
auto grad_out = static_cast<scalar_t *>(inputs[kIndex0]->addr);
|
||||||
auto log_probs = reinterpret_cast<scalar_t *>(inputs[kIndex1]->addr);
|
auto log_probs = static_cast<scalar_t *>(inputs[kIndex1]->addr);
|
||||||
auto targets = reinterpret_cast<target_t *>(inputs[kIndex2]->addr);
|
auto targets = static_cast<target_t *>(inputs[kIndex2]->addr);
|
||||||
auto input_lengths = reinterpret_cast<target_t *>(inputs[kIndex3]->addr);
|
auto input_lengths = static_cast<target_t *>(inputs[kIndex3]->addr);
|
||||||
auto target_lengths = reinterpret_cast<target_t *>(inputs[kIndex4]->addr);
|
auto target_lengths = static_cast<target_t *>(inputs[kIndex4]->addr);
|
||||||
auto neg_log_likelihood = reinterpret_cast<scalar_t *>(inputs[kIndex5]->addr);
|
auto neg_log_likelihood = static_cast<scalar_t *>(inputs[kIndex5]->addr);
|
||||||
auto log_alpha = reinterpret_cast<scalar_t *>(inputs[kIndex6]->addr);
|
auto log_alpha = static_cast<scalar_t *>(inputs[kIndex6]->addr);
|
||||||
auto log_beta = reinterpret_cast<scalar_t *>(workspace[kIndex0]->addr);
|
auto log_beta = static_cast<scalar_t *>(workspace[kIndex0]->addr);
|
||||||
auto grad = reinterpret_cast<scalar_t *>(outputs[kIndex0]->addr);
|
auto grad = static_cast<scalar_t *>(outputs[kIndex0]->addr);
|
||||||
|
|
||||||
constexpr scalar_t neginf = -std::numeric_limits<scalar_t>::infinity();
|
constexpr scalar_t neginf = -std::numeric_limits<scalar_t>::infinity();
|
||||||
std::fill(grad, grad + (T_ * batch_size_ * num_labels_), neginf);
|
std::fill(grad, grad + (T_ * batch_size_ * num_labels_), neginf);
|
||||||
|
@ -160,7 +160,7 @@ bool CTCLossV2GradCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPt
|
||||||
NdTensorIterator<kDim3> log_beta_it(batch_size_, T_, target_mul * max_target_length_ + 1);
|
NdTensorIterator<kDim3> log_beta_it(batch_size_, T_, target_mul * max_target_length_ + 1);
|
||||||
for (int64_t b = 0; b < batch_size_; b++) {
|
for (int64_t b = 0; b < batch_size_; b++) {
|
||||||
scalar_t nll = neg_log_likelihood[b];
|
scalar_t nll = neg_log_likelihood[b];
|
||||||
if (zero_infinity_ && nll == std::numeric_limits<scalar_t>::infinity()) {
|
if (zero_infinity_ && std::isinf(nll) && !std::signbit(nll)) {
|
||||||
for (int t = 0; t < T_; t++) {
|
for (int t = 0; t < T_; t++) {
|
||||||
for (int c = 0; c < num_labels_; c++) {
|
for (int c = 0; c < num_labels_; c++) {
|
||||||
grad[grad_it(t, b, c)] = 0;
|
grad[grad_it(t, b, c)] = 0;
|
||||||
|
@ -189,7 +189,7 @@ bool CTCLossV2GradCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPt
|
||||||
log_beta[log_beta_it(b, input_length - 1, target_mul * target_length - 1)];
|
log_beta[log_beta_it(b, input_length - 1, target_mul * target_length - 1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SoftParam param = {blank_, input_length, target_length, tg_batch_offset, b, reinterpret_cast<void *>(targets)};
|
SoftParam param = {blank_, input_length, target_length, tg_batch_offset, b, static_cast<void *>(targets)};
|
||||||
ComputeGrad<scalar_t, target_t>(log_probs, log_probs_it, param, log_alpha, log_alpha_it, log_beta, log_beta_it,
|
ComputeGrad<scalar_t, target_t>(log_probs, log_probs_it, param, log_alpha, log_alpha_it, log_beta, log_beta_it,
|
||||||
grad, grad_it);
|
grad, grad_it);
|
||||||
scalar_t gr = grad_out[b];
|
scalar_t gr = grad_out[b];
|
||||||
|
|
|
@ -58,7 +58,7 @@ class CTCLossV2GradCpuKernelMod : public NativeCpuKernelMod, public MatchKernelH
|
||||||
// Dealing with multiple types
|
// Dealing with multiple types
|
||||||
template <typename scalar_t, typename target_t>
|
template <typename scalar_t, typename target_t>
|
||||||
bool LaunchKernel(const std::vector<kernel::AddressPtr> &inputs, const std::vector<kernel::AddressPtr> &workspace,
|
bool LaunchKernel(const std::vector<kernel::AddressPtr> &inputs, const std::vector<kernel::AddressPtr> &workspace,
|
||||||
const std::vector<kernel::AddressPtr> &outputs);
|
const std::vector<kernel::AddressPtr> &outputs) const;
|
||||||
};
|
};
|
||||||
} // namespace kernel
|
} // namespace kernel
|
||||||
} // namespace mindspore
|
} // namespace mindspore
|
||||||
|
|
|
@ -121,7 +121,7 @@ void GetGroupSet(const kernel::AddressPtr input, const size_t last_dim, const st
|
||||||
<< "but got " << group_indices.size() << " and " << input_strides.size() << ".";
|
<< "but got " << group_indices.size() << " and " << input_strides.size() << ".";
|
||||||
}
|
}
|
||||||
result->clear();
|
result->clear();
|
||||||
auto data_ptr = reinterpret_cast<T *>(input->addr);
|
auto data_ptr = static_cast<T *>(input->addr);
|
||||||
const auto start = std::inner_product(group_indices.begin(), group_indices.end(), input_strides.begin(), 0UL);
|
const auto start = std::inner_product(group_indices.begin(), group_indices.end(), input_strides.begin(), 0UL);
|
||||||
const auto end = start + last_dim;
|
const auto end = start + last_dim;
|
||||||
for (size_t i = start; i < end; ++i) {
|
for (size_t i = start; i < end; ++i) {
|
||||||
|
@ -199,9 +199,9 @@ bool DenseToDenseSetOperationCpuKernelMod::PopulateOutput(const std::vector<kern
|
||||||
const std::vector<kernel::AddressPtr> &outputs,
|
const std::vector<kernel::AddressPtr> &outputs,
|
||||||
const ShapeVector &output_shape, const size_t num_values,
|
const ShapeVector &output_shape, const size_t num_values,
|
||||||
const std::map<std::vector<size_t>, std::set<T>> *sets) {
|
const std::map<std::vector<size_t>, std::set<T>> *sets) {
|
||||||
auto out_indices_ptr = reinterpret_cast<int64_t *>(outputs[kOutput1]->addr);
|
auto out_indices_ptr = static_cast<int64_t *>(outputs[kOutput1]->addr);
|
||||||
auto out_values_ptr = reinterpret_cast<T *>(outputs[kOutput2]->addr);
|
auto out_values_ptr = static_cast<T *>(outputs[kOutput2]->addr);
|
||||||
auto out_shape_ptr = reinterpret_cast<int64_t *>(outputs[kOutput3]->addr);
|
auto out_shape_ptr = static_cast<int64_t *>(outputs[kOutput3]->addr);
|
||||||
size_t output_shape_size = output_shape.size();
|
size_t output_shape_size = output_shape.size();
|
||||||
auto num_values_signed = SizeToLong(num_values);
|
auto num_values_signed = SizeToLong(num_values);
|
||||||
auto output_shape_size_signed = SizeToLong(output_shape_size);
|
auto output_shape_size_signed = SizeToLong(output_shape_size);
|
||||||
|
@ -230,14 +230,14 @@ bool DenseToDenseSetOperationCpuKernelMod::PopulateOutput(const std::vector<kern
|
||||||
int64_t group_idx = 0;
|
int64_t group_idx = 0;
|
||||||
for (auto val = set.begin(); val != set.end(); ++val, ++val_idx, ++group_idx) {
|
for (auto val = set.begin(); val != set.end(); ++val, ++val_idx, ++group_idx) {
|
||||||
for (size_t i = 0; i < group_indices.size(); ++i) {
|
for (size_t i = 0; i < group_indices.size(); ++i) {
|
||||||
out_indices_mat(val_idx, i) = group_indices[i];
|
out_indices_mat(val_idx, i) = SizeToLong(group_indices[i]);
|
||||||
}
|
}
|
||||||
out_indices_mat(val_idx, group_indices.size()) = group_idx;
|
out_indices_mat(val_idx, group_indices.size()) = SizeToLong(group_idx);
|
||||||
out_values_flat(val_idx) = *val;
|
out_values_flat(val_idx) = *val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < output_shape_size; ++i) {
|
for (size_t i = 0; i < output_shape_size; ++i) {
|
||||||
out_shape_flat(i) = output_shape[i];
|
out_shape_flat(i) = SizeToLong(output_shape[i]);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,9 +132,9 @@ bool SparseConcatCpuKernelMod::SparseConcat(const std::vector<kernel::AddressPtr
|
||||||
const std::vector<kernel::AddressPtr> &,
|
const std::vector<kernel::AddressPtr> &,
|
||||||
const std::vector<kernel::AddressPtr> &outputs, const size_t shape_size,
|
const std::vector<kernel::AddressPtr> &outputs, const size_t shape_size,
|
||||||
const int size) {
|
const int size) {
|
||||||
auto output_indices = reinterpret_cast<int64_t *>(outputs[kOutputIndicesStart]->addr);
|
auto output_indices = static_cast<int64_t *>(outputs[kOutputIndicesStart]->addr);
|
||||||
auto output_values = reinterpret_cast<S *>(outputs[kOutputValuesStart]->addr);
|
auto output_values = static_cast<S *>(outputs[kOutputValuesStart]->addr);
|
||||||
auto output_shape = reinterpret_cast<int64_t *>(outputs[kOutputShapesStart]->addr);
|
auto output_shape = static_cast<int64_t *>(outputs[kOutputShapesStart]->addr);
|
||||||
auto input_coo_num = input_num_ / kCOOTensorNum;
|
auto input_coo_num = input_num_ / kCOOTensorNum;
|
||||||
const auto &first_shape_ptr = reinterpret_cast<T *>(inputs[kSpInputShapesStart * input_coo_num]->addr);
|
const auto &first_shape_ptr = reinterpret_cast<T *>(inputs[kSpInputShapesStart * input_coo_num]->addr);
|
||||||
std::map<size_t, int64_t> dim_position_map = {};
|
std::map<size_t, int64_t> dim_position_map = {};
|
||||||
|
@ -147,9 +147,9 @@ bool SparseConcatCpuKernelMod::SparseConcat(const std::vector<kernel::AddressPtr
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < input_coo_num; i++) {
|
for (unsigned int i = 0; i < input_coo_num; i++) {
|
||||||
const auto &indices_ptr = reinterpret_cast<int64_t *>(inputs[kSpInputIndicesStart * input_coo_num + i]->addr);
|
const auto &indices_ptr = static_cast<int64_t *>(inputs[kSpInputIndicesStart * input_coo_num + i]->addr);
|
||||||
const auto &values_ptr = reinterpret_cast<S *>(inputs[kSpInputValuesStart * input_coo_num + i]->addr);
|
const auto &values_ptr = static_cast<S *>(inputs[kSpInputValuesStart * input_coo_num + i]->addr);
|
||||||
const auto &shape_ptr = reinterpret_cast<T *>(inputs[kOutputShapesStart * input_coo_num + i]->addr);
|
const auto &shape_ptr = static_cast<T *>(inputs[kOutputShapesStart * input_coo_num + i]->addr);
|
||||||
auto cur_axis_shape = *(shape_ptr + concat_dim_);
|
auto cur_axis_shape = *(shape_ptr + concat_dim_);
|
||||||
for (unsigned int j = 0; j < inputs[kSpInputIndicesStart * input_coo_num + i]->size / sizeof(int64_t); j++) {
|
for (unsigned int j = 0; j < inputs[kSpInputIndicesStart * input_coo_num + i]->size / sizeof(int64_t); j++) {
|
||||||
if (static_cast<int>(j % shape_size) == concat_dim_) {
|
if (static_cast<int>(j % shape_size) == concat_dim_) {
|
||||||
|
@ -227,7 +227,7 @@ bool SparseConcatCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SparseConcat<S, T>(inputs, workspace, outputs, shape_size, size);
|
(void)SparseConcat<S, T>(inputs, workspace, outputs, shape_size, size);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,8 +91,9 @@ std::vector<TypePtr> SparseConcatInferType(const PrimitivePtr &primitive,
|
||||||
auto ind_type = inputs_indices[i]->BuildType();
|
auto ind_type = inputs_indices[i]->BuildType();
|
||||||
auto sha_type = inputs_shapes[i]->BuildType();
|
auto sha_type = inputs_shapes[i]->BuildType();
|
||||||
(void)values_types.emplace(elementi, inputs_values[i]->BuildType());
|
(void)values_types.emplace(elementi, inputs_values[i]->BuildType());
|
||||||
CheckAndConvertUtils::CheckTensorTypeValid("indices" + std::to_string(i), ind_type, {kInt64}, prim_name);
|
(void)CheckAndConvertUtils::CheckTensorTypeValid("indices" + std::to_string(i), ind_type, {kInt64}, prim_name);
|
||||||
CheckAndConvertUtils::CheckTensorTypeValid("shapes" + std::to_string(i), sha_type, {kInt64, kInt32}, prim_name);
|
(void)CheckAndConvertUtils::CheckTensorTypeValid("shapes" + std::to_string(i), sha_type, {kInt64, kInt32},
|
||||||
|
prim_name);
|
||||||
}
|
}
|
||||||
(void)CheckAndConvertUtils::CheckTensorTypeSame(values_types, common_valid_types_with_complex_and_bool, prim_name);
|
(void)CheckAndConvertUtils::CheckTensorTypeSame(values_types, common_valid_types_with_complex_and_bool, prim_name);
|
||||||
std::vector<TypePtr> out_type = {};
|
std::vector<TypePtr> out_type = {};
|
||||||
|
@ -139,7 +140,7 @@ std::vector<abstract::ShapePtr> SparseConcatInferShape(const PrimitivePtr &primi
|
||||||
<< indices_element0_shape[0] << ", but the value element number is "
|
<< indices_element0_shape[0] << ", but the value element number is "
|
||||||
<< values_element0_shape[0] << ".";
|
<< values_element0_shape[0] << ".";
|
||||||
}
|
}
|
||||||
primitive->AddAttr("N", MakeValue(SizeToLong(inputs_indices.size())));
|
(void)primitive->AddAttr("N", MakeValue(SizeToLong(inputs_indices.size())));
|
||||||
std::vector<int64_t> out_indices_shape = {};
|
std::vector<int64_t> out_indices_shape = {};
|
||||||
out_indices_shape.push_back(0);
|
out_indices_shape.push_back(0);
|
||||||
out_indices_shape.push_back(indices_element0_shape[1]);
|
out_indices_shape.push_back(indices_element0_shape[1]);
|
||||||
|
|
Loading…
Reference in New Issue