forked from huawei/mindspore2022
!16579 fix CPU transpose with 1 axes unsupport problem
From: @fan-jibin Reviewed-by: @guoqi1024,@zhaizhiqiang Signed-off-by: @guoqi1024,@zhaizhiqiang
This commit is contained in:
commit
71b522ec09
|
|
@ -237,9 +237,6 @@
|
|||
const int *out_strides = transpose_param->out_strides_; \
|
||||
int data_size = transpose_param->data_size_; \
|
||||
int num_axes = transpose_param->num_axes_; \
|
||||
if (num_axes < 2) { \
|
||||
return NNACL_ERR; \
|
||||
} \
|
||||
bool needTranspose = false; \
|
||||
for (int i = 1; i < num_axes; ++i) { \
|
||||
if (perm[i] - perm[i - 1] != 1) { \
|
||||
|
|
|
|||
|
|
@ -206,10 +206,6 @@ int Fp16DoTranspose(const float16_t *in_data, float16_t *out_data, const int *ou
|
|||
int data_size = transpose_param->data_size_;
|
||||
int num_axes = transpose_param->num_axes_;
|
||||
|
||||
if (num_axes < 2) {
|
||||
return NNACL_ERR;
|
||||
}
|
||||
|
||||
// check if transpose is needed
|
||||
bool needTranspose = false;
|
||||
for (int i = 1; i < num_axes; ++i) {
|
||||
|
|
|
|||
|
|
@ -211,10 +211,6 @@ int DoTransposeFp32(const float *in_data, float *out_data, const int *output_sha
|
|||
int data_size = transpose_param->data_size_;
|
||||
int num_axes = transpose_param->num_axes_;
|
||||
|
||||
if (num_axes < 2) {
|
||||
return NNACL_ERR;
|
||||
}
|
||||
|
||||
// check if transpose is needed
|
||||
bool needTranspose = false;
|
||||
for (int i = 1; i < num_axes; ++i) {
|
||||
|
|
|
|||
|
|
@ -183,10 +183,6 @@ int DoTransposeInt8(const int8_t *in_data, int8_t *out_data, const int *output_s
|
|||
int *out_strides = transpose_param->out_strides_;
|
||||
int num_axes = transpose_param->num_axes_;
|
||||
|
||||
if (num_axes < 2) {
|
||||
return NNACL_ERR;
|
||||
}
|
||||
|
||||
// check if transpose is needed
|
||||
bool needTranspose = false;
|
||||
for (int i = 1; i < num_axes; i++) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include "common/thread_pool.h"
|
||||
#include "nnacl/fp32/transpose_fp32.h"
|
||||
#include "nnacl/int8/transpose_int8.h"
|
||||
#include "nnacl/errorcode.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
|
|
@ -90,26 +91,32 @@ void TransposeCPUFwdKernel::LaunchKernel(const std::vector<AddressPtr> &inputs,
|
|||
}
|
||||
|
||||
if (axes_.size() <= MAX_TRANSPOSE_DIM_SIZE) {
|
||||
int res = NNACL_OK;
|
||||
if constexpr (std::is_same_v<T, int8_t>) {
|
||||
DoTransposeInt8(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeInt8(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, int16_t>) {
|
||||
DoTransposeInt16(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeInt16(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, int32_t>) {
|
||||
DoTransposeInt32(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeInt32(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, int64_t>) {
|
||||
DoTransposeInt64(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeInt64(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, uint8_t>) {
|
||||
DoTransposeUInt8(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeUInt8(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, uint16_t>) {
|
||||
DoTransposeUInt16(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeUInt16(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, uint32_t>) {
|
||||
DoTransposeUInt32(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeUInt32(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, uint64_t>) {
|
||||
DoTransposeUInt64(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeUInt64(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, float>) {
|
||||
DoTransposeFp32(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeFp32(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
} else if constexpr (std::is_same_v<T, bool>) {
|
||||
DoTransposeBool(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
res = DoTransposeBool(input_addr, output_addr, output_shape, &transpose_param_);
|
||||
}
|
||||
if (res == NNACL_ERR) {
|
||||
MS_LOG(EXCEPTION) << "Transpose input addr or output addr is null";
|
||||
} else if (res == NNACL_PARAM_INVALID) {
|
||||
MS_LOG(EXCEPTION) << "Transpose parameters are invalid.";
|
||||
}
|
||||
} else {
|
||||
size_t data_count = (inputs[0]->size) / sizeof(T);
|
||||
|
|
|
|||
Loading…
Reference in New Issue