forked from mindspore-Ecosystem/mindspore
check code
This commit is contained in:
parent
111d1a9a61
commit
1920828739
|
@ -36,6 +36,7 @@ void Concat(void **input, int input_num, int axis, int **inputs_output_shape, si
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int input_stride = after_axis_size * inputs_output_shape[i][axis];
|
int input_stride = after_axis_size * inputs_output_shape[i][axis];
|
||||||
|
NNACL_CHECK_ZERO_RETURN(thread_num);
|
||||||
int offset = UP_DIV(input_stride, thread_num);
|
int offset = UP_DIV(input_stride, thread_num);
|
||||||
int count = input_stride - offset * task_id;
|
int count = input_stride - offset * task_id;
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ int AvgPoolingFp16(const float16_t *input_ptr, float16_t *output_ptr, const Pool
|
||||||
MS_FLOAT16X8 max_value = MS_MOVQ_F16(max);
|
MS_FLOAT16X8 max_value = MS_MOVQ_F16(max);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
NNACL_CHECK_ZERO_RETURN_ERR(output_w);
|
||||||
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
|
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
|
||||||
const float16_t *src_b_ptr = input_ptr + batch * in_h * in_w * channel;
|
const float16_t *src_b_ptr = input_ptr + batch * in_h * in_w * channel;
|
||||||
float16_t *dst_b_ptr = output_ptr + batch * output_h * output_w * channel;
|
float16_t *dst_b_ptr = output_ptr + batch * output_h * output_w * channel;
|
||||||
|
@ -268,6 +269,7 @@ void MaxPoolingFp16(const float16_t *input_ptr, float16_t *output_ptr, const Poo
|
||||||
int thread_num = pooling_param->thread_num_;
|
int thread_num = pooling_param->thread_num_;
|
||||||
|
|
||||||
// input channel is equal to output channel
|
// input channel is equal to output channel
|
||||||
|
NNACL_CHECK_ZERO_RETURN(output_w);
|
||||||
for (int batch = 0; batch < output_batch; batch++) {
|
for (int batch = 0; batch < output_batch; batch++) {
|
||||||
int in_batch_offset = batch * in_h * in_w * channel;
|
int in_batch_offset = batch * in_h * in_w * channel;
|
||||||
int out_batch_offset = batch * output_h * output_w * channel;
|
int out_batch_offset = batch * output_h * output_w * channel;
|
||||||
|
|
|
@ -23,7 +23,7 @@ int InstanceNorm(const float *src_data, float *dst_data, const float *gamma_data
|
||||||
const InstanceNormParameter *param, size_t task_id) {
|
const InstanceNormParameter *param, size_t task_id) {
|
||||||
NNACL_CHECK_NULL_RETURN_ERR(src_data);
|
NNACL_CHECK_NULL_RETURN_ERR(src_data);
|
||||||
NNACL_CHECK_NULL_RETURN_ERR(dst_data);
|
NNACL_CHECK_NULL_RETURN_ERR(dst_data);
|
||||||
NNACL_CHECK_ZERO_RETURN_ERR(param->op_parameter_.thread_num_)
|
NNACL_CHECK_ZERO_RETURN_ERR(param->op_parameter_.thread_num_);
|
||||||
int channel_step = UP_DIV(param->channel_, param->op_parameter_.thread_num_);
|
int channel_step = UP_DIV(param->channel_, param->op_parameter_.thread_num_);
|
||||||
int channel_begin = (int)(task_id)*channel_step;
|
int channel_begin = (int)(task_id)*channel_step;
|
||||||
int channel_end = MSMIN(channel_begin + channel_step, param->channel_);
|
int channel_end = MSMIN(channel_begin + channel_step, param->channel_);
|
||||||
|
|
|
@ -65,7 +65,7 @@ int GetInputFlattenIndex(int out_flatten_index, const int *input_shape, const Pa
|
||||||
int in_flatten_index = 0;
|
int in_flatten_index = 0;
|
||||||
for (int i = 0; i < DEFAULT_PAD_NDIMS; ++i) {
|
for (int i = 0; i < DEFAULT_PAD_NDIMS; ++i) {
|
||||||
int left_pad = pad_param->paddings_[i * 2];
|
int left_pad = pad_param->paddings_[i * 2];
|
||||||
NNACL_CHECK_ZERO_RETURN_ERR(pad_param->out_strides[i])
|
NNACL_CHECK_ZERO_RETURN_ERR(pad_param->out_strides[i]);
|
||||||
int out_dim_index = out_flatten_index / pad_param->out_strides[i];
|
int out_dim_index = out_flatten_index / pad_param->out_strides[i];
|
||||||
out_flatten_index %= pad_param->out_strides[i];
|
out_flatten_index %= pad_param->out_strides[i];
|
||||||
int in_dim_index = TransOut2InputDimIndex(out_dim_index, left_pad, input_shape[i], pad_param->mirror_offset_);
|
int in_dim_index = TransOut2InputDimIndex(out_dim_index, left_pad, input_shape[i], pad_param->mirror_offset_);
|
||||||
|
|
|
@ -54,6 +54,7 @@ int GetInputFlattenIndexInt8(int out_flatten_index, const int *input_shape, cons
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < COMM_SHAPE_SIZE; ++i) {
|
for (i = 0; i < COMM_SHAPE_SIZE; ++i) {
|
||||||
int left_pad = pad_param->paddings_[i * 2];
|
int left_pad = pad_param->paddings_[i * 2];
|
||||||
|
NNACL_CHECK_ZERO_RETURN_ERR(pad_param->out_strides[i]);
|
||||||
int out_dim_index = out_flatten_index / pad_param->out_strides[i];
|
int out_dim_index = out_flatten_index / pad_param->out_strides[i];
|
||||||
out_flatten_index %= pad_param->out_strides[i];
|
out_flatten_index %= pad_param->out_strides[i];
|
||||||
int in_dim_index = TransOut2InputDimIndexInt8(out_dim_index, left_pad, input_shape[i], pad_param->mirror_offset_);
|
int in_dim_index = TransOut2InputDimIndexInt8(out_dim_index, left_pad, input_shape[i], pad_param->mirror_offset_);
|
||||||
|
|
|
@ -94,7 +94,7 @@ int AvgPoolingOptInt8(const int8_t *input_ptr, int8_t *output_ptr, PoolingParame
|
||||||
double real_multiplier = pooling_param->quant_args_[0][0].scale_ / pooling_param->quant_args_[1][0].scale_;
|
double real_multiplier = pooling_param->quant_args_[0][0].scale_ / pooling_param->quant_args_[1][0].scale_;
|
||||||
const int8_t out_min = INT8_MIN;
|
const int8_t out_min = INT8_MIN;
|
||||||
const int8_t out_max = INT8_MAX;
|
const int8_t out_max = INT8_MAX;
|
||||||
|
NNACL_CHECK_ZERO_RETURN_ERR(output_w);
|
||||||
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
|
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
|
||||||
int in_batch_offset = batch * pooling_param->input_h_ * in_w * channel;
|
int in_batch_offset = batch * pooling_param->input_h_ * in_w * channel;
|
||||||
int out_batch_offset = batch * pooling_param->output_h_ * output_w * channel;
|
int out_batch_offset = batch * pooling_param->output_h_ * output_w * channel;
|
||||||
|
@ -341,6 +341,7 @@ void MaxPoolingWithQuantInt8(const int8_t *input_ptr, int8_t *output_ptr, Poolin
|
||||||
int output_zp = pooling_param->quant_args_[1][0].zp_;
|
int output_zp = pooling_param->quant_args_[1][0].zp_;
|
||||||
double real_multiplier = input_scale / output_scale;
|
double real_multiplier = input_scale / output_scale;
|
||||||
|
|
||||||
|
NNACL_CHECK_ZERO_RETURN(output_w);
|
||||||
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
|
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
|
||||||
int in_batch_offset = batch * in_h * in_w * channel;
|
int in_batch_offset = batch * in_h * in_w * channel;
|
||||||
int out_batch_offset = batch * pooling_param->output_h_ * output_w * channel;
|
int out_batch_offset = batch * pooling_param->output_h_ * output_w * channel;
|
||||||
|
@ -428,6 +429,7 @@ void MaxPoolingOptInt8(const int8_t *input_ptr, int8_t *output_ptr, PoolingParam
|
||||||
int thread_num = MSMIN(out_tile_count, pooling_param->thread_num_);
|
int thread_num = MSMIN(out_tile_count, pooling_param->thread_num_);
|
||||||
int8_t out_array[MAX_MAXPOOL_SIZE];
|
int8_t out_array[MAX_MAXPOOL_SIZE];
|
||||||
|
|
||||||
|
NNACL_CHECK_ZERO_RETURN(output_w);
|
||||||
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
|
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
|
||||||
int in_batch_offset = batch * pooling_param->input_h_ * in_w * channel;
|
int in_batch_offset = batch * pooling_param->input_h_ * in_w * channel;
|
||||||
int out_batch_offset = batch * pooling_param->output_h_ * output_w * channel;
|
int out_batch_offset = batch * pooling_param->output_h_ * output_w * channel;
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#define DOWN_ROUND(x, y) ((x) / (y) * (y))
|
#define DOWN_ROUND(x, y) ((x) / (y) * (y))
|
||||||
|
|
||||||
#define MSVALID(left, x, right) (MSMIN((MSMAX(left, x)), right))
|
#define MSVALID(left, x, right) (MSMIN((MSMAX(left, x)), right))
|
||||||
|
#define SIZE_MUL_OVERFLOW(x, y) (((x) == 0) ? false : (SIZE_MAX / (x)) < (y))
|
||||||
#define INT_MUL_OVERFLOW(x, y) \
|
#define INT_MUL_OVERFLOW(x, y) \
|
||||||
((x == 0) ? false \
|
((x == 0) ? false \
|
||||||
: ((x) > 0 ? ((y >= 0) ? (INT_MAX / (x)) < (y) : (INT_MAX / (x)) < (-1 * (y))) \
|
: ((x) > 0 ? ((y >= 0) ? (INT_MAX / (x)) < (y) : (INT_MAX / (x)) < (-1 * (y))) \
|
||||||
|
@ -156,21 +157,21 @@
|
||||||
if ((val) == 0) { \
|
if ((val) == 0) { \
|
||||||
return NNACL_ERR; \
|
return NNACL_ERR; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#define NNACL_CHECK_ZERO_RETURN(val) \
|
#define NNACL_CHECK_ZERO_RETURN(val) \
|
||||||
do { \
|
do { \
|
||||||
if ((val) == 0) { \
|
if ((val) == 0) { \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#define NNACL_CHECK_NULL_RETURN_ERR(ptr) \
|
#define NNACL_CHECK_NULL_RETURN_ERR(ptr) \
|
||||||
do { \
|
do { \
|
||||||
if ((ptr) == NULL) { \
|
if ((ptr) == NULL) { \
|
||||||
return NNACL_NULL_PTR; \
|
return NNACL_NULL_PTR; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
|
@ -107,29 +107,29 @@ int ResizeFP32Coder::MallocTmpBuffer() {
|
||||||
// malloc memory for x, y coordinates
|
// malloc memory for x, y coordinates
|
||||||
{
|
{
|
||||||
coordinate_.x_lefts_ = reinterpret_cast<int *>(malloc(sizeof(int) * x_len_));
|
coordinate_.x_lefts_ = reinterpret_cast<int *>(malloc(sizeof(int) * x_len_));
|
||||||
CHECK_MALLOC_RES(coordinate_.x_lefts_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(coordinate_.x_lefts_, RET_NULL_PTR);
|
||||||
coordinate_.y_tops_ = reinterpret_cast<int *>(malloc(sizeof(int) * y_len_));
|
coordinate_.y_tops_ = reinterpret_cast<int *>(malloc(sizeof(int) * y_len_));
|
||||||
CHECK_MALLOC_RES(coordinate_.y_tops_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(coordinate_.y_tops_, RET_NULL_PTR);
|
||||||
if (method_ == static_cast<int>(schema::ResizeMethod_LINEAR)) {
|
if (method_ == static_cast<int>(schema::ResizeMethod_LINEAR)) {
|
||||||
coordinate_.x_rights_ = reinterpret_cast<int *>(malloc(sizeof(int) * x_len_));
|
coordinate_.x_rights_ = reinterpret_cast<int *>(malloc(sizeof(int) * x_len_));
|
||||||
CHECK_MALLOC_RES(coordinate_.x_rights_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(coordinate_.x_rights_, RET_NULL_PTR);
|
||||||
coordinate_.y_bottoms_ = reinterpret_cast<int *>(malloc(sizeof(int) * y_len_));
|
coordinate_.y_bottoms_ = reinterpret_cast<int *>(malloc(sizeof(int) * y_len_));
|
||||||
CHECK_MALLOC_RES(coordinate_.y_bottoms_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(coordinate_.y_bottoms_, RET_NULL_PTR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// malloc memory for weights of x, y axes
|
// malloc memory for weights of x, y axes
|
||||||
{
|
{
|
||||||
x_weights_ = reinterpret_cast<float *>(malloc(sizeof(float) * x_weight_len_));
|
x_weights_ = reinterpret_cast<float *>(malloc(sizeof(float) * x_weight_len_));
|
||||||
CHECK_MALLOC_RES(x_weights_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(x_weights_, RET_NULL_PTR);
|
||||||
y_weights_ = reinterpret_cast<float *>(malloc(sizeof(float) * y_weight_len_));
|
y_weights_ = reinterpret_cast<float *>(malloc(sizeof(float) * y_weight_len_));
|
||||||
CHECK_MALLOC_RES(y_weights_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(y_weights_, RET_NULL_PTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
size_t line_buffer_size = sizeof(float) * x_len_ * input_tensor_->Channel() * 2 * kMaxThreadNumSupported;
|
size_t line_buffer_size = sizeof(float) * x_len_ * input_tensor_->Channel() * 2 * kMaxThreadNumSupported;
|
||||||
line_buffer_ = reinterpret_cast<float *>(allocator_->Malloc(kNumberTypeFloat32, line_buffer_size, kWorkspace));
|
line_buffer_ = reinterpret_cast<float *>(allocator_->Malloc(kNumberTypeFloat32, line_buffer_size, kWorkspace));
|
||||||
CHECK_MALLOC_RES(line_buffer_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(line_buffer_, RET_NULL_PTR);
|
||||||
}
|
}
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
MS_LOG(ERROR) << "malloc data failed."; \
|
MS_LOG(ERROR) << "malloc data failed."; \
|
||||||
return errcode; \
|
return errcode; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#ifndef ENABLE_HIGH_PERFORMANCE
|
#ifndef ENABLE_HIGH_PERFORMANCE
|
||||||
#define CHECK_NULL_RETURN(ptr) \
|
#define CHECK_NULL_RETURN(ptr) \
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
MS_LOG(ERROR) << #ptr << " must not be null!"; \
|
MS_LOG(ERROR) << #ptr << " must not be null!"; \
|
||||||
return mindspore::lite::RET_NULL_PTR; \
|
return mindspore::lite::RET_NULL_PTR; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#define CHECK_LESS_RETURN(size1, size2) \
|
#define CHECK_LESS_RETURN(size1, size2) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -51,7 +51,8 @@
|
||||||
MS_LOG(ERROR) << #size1 << " must not less than " << #size2; \
|
MS_LOG(ERROR) << #size1 << " must not less than " << #size2; \
|
||||||
return mindspore::lite::RET_ERROR; \
|
return mindspore::lite::RET_ERROR; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define CHECK_NULL_RETURN(ptr)
|
#define CHECK_NULL_RETURN(ptr)
|
||||||
#define CHECK_LESS_RETURN(size1, size2)
|
#define CHECK_LESS_RETURN(size1, size2)
|
||||||
|
|
|
@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_Concat;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateConcatParameter(const void *prim) {
|
OpParameter *PopulateConcatParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto *primitive = static_cast<const schema::Primitive *>(prim);
|
auto *primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto value = primitive->value_as_Concat();
|
auto value = primitive->value_as_Concat();
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
MS_LOG(ERROR) << "param is nullptr";
|
MS_LOG(ERROR) << "param is nullptr";
|
||||||
|
|
|
@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_NonMaxSuppression;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateNonMaxSuppressionParameter(const void *prim) {
|
OpParameter *PopulateNonMaxSuppressionParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto value = primitive->value_as_NonMaxSuppression();
|
auto value = primitive->value_as_NonMaxSuppression();
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
MS_LOG(ERROR) << "value is nullptr";
|
MS_LOG(ERROR) << "value is nullptr";
|
||||||
|
|
|
@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_PadFusion;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulatePadParameter(const void *prim) {
|
OpParameter *PopulatePadParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto value = primitive->value_as_PadFusion();
|
auto value = primitive->value_as_PadFusion();
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
MS_LOG(ERROR) << "value is nullptr";
|
MS_LOG(ERROR) << "value is nullptr";
|
||||||
|
|
|
@ -21,8 +21,8 @@ using mindspore::schema::PrimitiveType_MaxPoolFusion;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateAvgPoolParameter(const void *primitive) {
|
OpParameter *PopulateAvgPoolParameter(const void *primitive) {
|
||||||
|
MS_CHECK_TRUE_RET(primitive != nullptr, nullptr);
|
||||||
auto pooling_prim = static_cast<const schema::Primitive *>(primitive);
|
auto pooling_prim = static_cast<const schema::Primitive *>(primitive);
|
||||||
MS_ASSERT(pooling_prim != nullptr);
|
|
||||||
auto value = pooling_prim->value_as_AvgPoolFusion();
|
auto value = pooling_prim->value_as_AvgPoolFusion();
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
MS_LOG(ERROR) << "value is nullptr";
|
MS_LOG(ERROR) << "value is nullptr";
|
||||||
|
|
|
@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_ReverseSequence;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateReverseSequenceParameter(const void *prim) {
|
OpParameter *PopulateReverseSequenceParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto value = primitive->value_as_ReverseSequence();
|
auto value = primitive->value_as_ReverseSequence();
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
MS_LOG(ERROR) << "value is nullptr";
|
MS_LOG(ERROR) << "value is nullptr";
|
||||||
|
|
|
@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_ROIPooling;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateROIPoolingParameter(const void *prim) {
|
OpParameter *PopulateROIPoolingParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto value = primitive->value_as_ROIPooling();
|
auto value = primitive->value_as_ROIPooling();
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
MS_LOG(ERROR) << "value is nullptr";
|
MS_LOG(ERROR) << "value is nullptr";
|
||||||
|
|
|
@ -21,8 +21,8 @@ using mindspore::schema::PrimitiveType_Shape;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateShapeParameter(const void *prim) {
|
OpParameter *PopulateShapeParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
|
|
||||||
auto *param = reinterpret_cast<OpParameter *>(malloc(sizeof(OpParameter)));
|
auto *param = reinterpret_cast<OpParameter *>(malloc(sizeof(OpParameter)));
|
||||||
if (param == nullptr) {
|
if (param == nullptr) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_SparseToDense;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateSparseToDenseParameter(const void *prim) {
|
OpParameter *PopulateSparseToDenseParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
|
|
||||||
auto *param = reinterpret_cast<SparseToDenseParameter *>(malloc(sizeof(SparseToDenseParameter)));
|
auto *param = reinterpret_cast<SparseToDenseParameter *>(malloc(sizeof(SparseToDenseParameter)));
|
||||||
if (param == nullptr) {
|
if (param == nullptr) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_Unstack;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateUnstackParameter(const void *prim) {
|
OpParameter *PopulateUnstackParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto value = primitive->value_as_Unstack();
|
auto value = primitive->value_as_Unstack();
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
MS_LOG(ERROR) << "value is nullptr";
|
MS_LOG(ERROR) << "value is nullptr";
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
namespace {
|
namespace {
|
||||||
OpParameter *PopulateConcatParameter(const void *prim) {
|
OpParameter *PopulateConcatParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto concat_prim = primitive->value_as_Concat();
|
auto concat_prim = primitive->value_as_Concat();
|
||||||
if (concat_prim == nullptr) {
|
if (concat_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "concat_prim is nullptr";
|
MS_LOG(ERROR) << "concat_prim is nullptr";
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
namespace {
|
namespace {
|
||||||
OpParameter *PopulateNonMaxSuppressionParameter(const void *prim) {
|
OpParameter *PopulateNonMaxSuppressionParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto non_max_suppression_prim = primitive->value_as_NonMaxSuppression();
|
auto non_max_suppression_prim = primitive->value_as_NonMaxSuppression();
|
||||||
if (non_max_suppression_prim == nullptr) {
|
if (non_max_suppression_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "non_max_suppression_prim is nullptr";
|
MS_LOG(ERROR) << "non_max_suppression_prim is nullptr";
|
||||||
|
|
|
@ -22,8 +22,9 @@ namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
namespace {
|
namespace {
|
||||||
OpParameter *PopulatePadParameter(const void *prim) {
|
OpParameter *PopulatePadParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
|
|
||||||
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto pad_prim = primitive->value_as_Pad();
|
auto pad_prim = primitive->value_as_Pad();
|
||||||
if (pad_prim == nullptr) {
|
if (pad_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "pad_prim is nullptr";
|
MS_LOG(ERROR) << "pad_prim is nullptr";
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
namespace {
|
namespace {
|
||||||
OpParameter *PopulatePoolingParameter(const void *prim) {
|
OpParameter *PopulatePoolingParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto pooling_prim = primitive->value_as_Pooling();
|
auto pooling_prim = primitive->value_as_Pooling();
|
||||||
if (pooling_prim == nullptr) {
|
if (pooling_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "pooling_prim is nullptr";
|
MS_LOG(ERROR) << "pooling_prim is nullptr";
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
namespace {
|
namespace {
|
||||||
OpParameter *PopulateReverseSequenceParameter(const void *prim) {
|
OpParameter *PopulateReverseSequenceParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto reverse_sequence_prim = primitive->value_as_ReverseSequence();
|
auto reverse_sequence_prim = primitive->value_as_ReverseSequence();
|
||||||
if (reverse_sequence_prim == nullptr) {
|
if (reverse_sequence_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "reverse_sequence_prim is nullptr";
|
MS_LOG(ERROR) << "reverse_sequence_prim is nullptr";
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
namespace {
|
namespace {
|
||||||
OpParameter *PopulateROIPoolingParameter(const void *prim) {
|
OpParameter *PopulateROIPoolingParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto roi_pooling_prim = primitive->value_as_ROIPooling();
|
auto roi_pooling_prim = primitive->value_as_ROIPooling();
|
||||||
if (roi_pooling_prim == nullptr) {
|
if (roi_pooling_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "roi_pooling_prim is nullptr";
|
MS_LOG(ERROR) << "roi_pooling_prim is nullptr";
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
namespace {
|
namespace {
|
||||||
OpParameter *PopulateUnstackParameter(const void *prim) {
|
OpParameter *PopulateUnstackParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
auto unstack_prim = primitive->value_as_Unstack();
|
auto unstack_prim = primitive->value_as_Unstack();
|
||||||
if (unstack_prim == nullptr) {
|
if (unstack_prim == nullptr) {
|
||||||
MS_LOG(ERROR) << "unstack_prim is nullptr";
|
MS_LOG(ERROR) << "unstack_prim is nullptr";
|
||||||
|
|
|
@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_Where;
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
namespace lite {
|
namespace lite {
|
||||||
OpParameter *PopulateWhereParameter(const void *prim) {
|
OpParameter *PopulateWhereParameter(const void *prim) {
|
||||||
|
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||||
auto primitive = static_cast<const schema::Primitive *>(prim);
|
auto primitive = static_cast<const schema::Primitive *>(prim);
|
||||||
MS_ASSERT(primitive != nullptr);
|
|
||||||
|
|
||||||
auto *param = reinterpret_cast<WhereParameter *>(malloc(sizeof(WhereParameter)));
|
auto *param = reinterpret_cast<WhereParameter *>(malloc(sizeof(WhereParameter)));
|
||||||
if (param == nullptr) {
|
if (param == nullptr) {
|
||||||
|
|
|
@ -83,10 +83,10 @@ void PoolingBaseCPUKernel::FreeQuantParam() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolingBaseCPUKernel::Init() {
|
int PoolingBaseCPUKernel::Init() {
|
||||||
MS_ASSERT(in_tensors_.size() == 1);
|
CHECK_LESS_RETURN(in_tensors_.size(), 1);
|
||||||
MS_ASSERT(out_tensors_.size() == 1);
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
pooling_param_->thread_num_ = thread_count_;
|
pooling_param_->thread_num_ = thread_count_;
|
||||||
MS_ASSERT(this->op_parameter_ != nullptr);
|
CHECK_NULL_RETURN(op_parameter_);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,21 +101,27 @@ int ConcatFp16CPUKernel::Run() {
|
||||||
if (in_tensor->data_type() == kNumberTypeFloat || in_tensor->data_type() == kNumberTypeFloat32) {
|
if (in_tensor->data_type() == kNumberTypeFloat || in_tensor->data_type() == kNumberTypeFloat32) {
|
||||||
auto in_tensor_data = reinterpret_cast<float *>(in_tensor->data_c());
|
auto in_tensor_data = reinterpret_cast<float *>(in_tensor->data_c());
|
||||||
MS_ASSERT(in_tensor_data != nullptr);
|
MS_ASSERT(in_tensor_data != nullptr);
|
||||||
|
CHECK_NULL_RETURN(in_tensor_data);
|
||||||
Float32ToFloat16(in_tensor_data, fp16_inputs_[i], in_tensor->ElementsNum());
|
Float32ToFloat16(in_tensor_data, fp16_inputs_[i], in_tensor->ElementsNum());
|
||||||
} else {
|
} else {
|
||||||
fp16_inputs_[i] = reinterpret_cast<float16_t *>(in_tensor->data_c());
|
fp16_inputs_[i] = reinterpret_cast<float16_t *>(in_tensor->data_c());
|
||||||
MS_ASSERT(fp16_inputs_[i] != nullptr);
|
MS_ASSERT(fp16_inputs_[i] != nullptr);
|
||||||
|
CHECK_NULL_RETURN(fp16_inputs_[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
shapes.push_back(in_tensors_[i]->shape());
|
shapes.push_back(in_tensors_[i]->shape());
|
||||||
|
MS_CHECK_LT(concat_param_->axis_, static_cast<int>(in_tensors_[i]->shape().size()), RET_ERROR);
|
||||||
inputs_output_shape[i] = shapes[i].data();
|
inputs_output_shape[i] = shapes[i].data();
|
||||||
}
|
}
|
||||||
auto output_shape = out_tensors_.at(0)->shape();
|
auto output_shape = out_tensors_.at(0)->shape();
|
||||||
|
MS_CHECK_LT(concat_param_->axis_, static_cast<int>(output_shape.size()), RET_ERROR);
|
||||||
inputs_output_shape[input_num] = output_shape.data();
|
inputs_output_shape[input_num] = output_shape.data();
|
||||||
auto output_addr = out_tensors_.at(0)->MutableData();
|
auto output_addr = out_tensors_.at(0)->MutableData();
|
||||||
|
CHECK_NULL_RETURN(output_addr);
|
||||||
if (out_tensors_.at(0)->data_type() == kNumberTypeFloat16) {
|
if (out_tensors_.at(0)->data_type() == kNumberTypeFloat16) {
|
||||||
fp16_output_ = reinterpret_cast<float16_t *>(out_tensors_.at(0)->data_c());
|
fp16_output_ = reinterpret_cast<float16_t *>(out_tensors_.at(0)->data_c());
|
||||||
MS_ASSERT(fp16_output_ != nullptr);
|
MS_ASSERT(fp16_output_ != nullptr);
|
||||||
|
CHECK_NULL_RETURN(fp16_output_);
|
||||||
}
|
}
|
||||||
int dtype_len = in_tensors_.at(0)->data_type() == kNumberTypeInt32 ? sizeof(int32_t) : sizeof(float16_t);
|
int dtype_len = in_tensors_.at(0)->data_type() == kNumberTypeInt32 ? sizeof(int32_t) : sizeof(float16_t);
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,13 @@ int PadFp16CPUKernel::RunImpl(int task_id) {
|
||||||
|
|
||||||
int PadFp16CPUKernel::RunMirrorPadImpl(int task_id) {
|
int PadFp16CPUKernel::RunMirrorPadImpl(int task_id) {
|
||||||
auto input = in_tensors_.at(0);
|
auto input = in_tensors_.at(0);
|
||||||
|
CHECK_NULL_RETURN(input);
|
||||||
auto output = out_tensors_.at(0);
|
auto output = out_tensors_.at(0);
|
||||||
|
CHECK_NULL_RETURN(output);
|
||||||
auto input_data = reinterpret_cast<float16_t *>(input->data_c());
|
auto input_data = reinterpret_cast<float16_t *>(input->data_c());
|
||||||
|
CHECK_NULL_RETURN(input_data);
|
||||||
auto output_data = reinterpret_cast<float16_t *>(output->data_c());
|
auto output_data = reinterpret_cast<float16_t *>(output->data_c());
|
||||||
|
CHECK_NULL_RETURN(output_data);
|
||||||
|
|
||||||
/* Fast Mirror pad */
|
/* Fast Mirror pad */
|
||||||
if (mirror_pad_block_.size() != 0) {
|
if (mirror_pad_block_.size() != 0) {
|
||||||
|
@ -67,7 +71,7 @@ int PadFp16CPUKernel::RunMirrorPadImpl(int task_id) {
|
||||||
}
|
}
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
MS_CHECK_FALSE(op_parameter_->thread_num_ == 0, RET_ERROR);
|
||||||
int unit = UP_DIV(out_tensors_.at(0)->ElementsNum(), op_parameter_->thread_num_);
|
int unit = UP_DIV(out_tensors_.at(0)->ElementsNum(), op_parameter_->thread_num_);
|
||||||
int begin = unit * task_id;
|
int begin = unit * task_id;
|
||||||
int end = MSMIN(begin + unit, out_tensors_.at(0)->ElementsNum());
|
int end = MSMIN(begin + unit, out_tensors_.at(0)->ElementsNum());
|
||||||
|
@ -83,6 +87,7 @@ int PadFp16CPUKernel::Run() {
|
||||||
MS_LOG(ERROR) << "The number of padding value should be only one, but got " << value_num;
|
MS_LOG(ERROR) << "The number of padding value should be only one, but got " << value_num;
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
CHECK_NULL_RETURN(pad_value->data_c());
|
||||||
pad_param_->constant_value_ = *(reinterpret_cast<float16_t *>(pad_value->data_c()));
|
pad_param_->constant_value_ = *(reinterpret_cast<float16_t *>(pad_value->data_c()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,9 @@ int PoolingFp16CPUKernel::RunImpl(int task_id) {
|
||||||
minf = 0.f;
|
minf = 0.f;
|
||||||
maxf = 6.f;
|
maxf = 6.f;
|
||||||
}
|
}
|
||||||
|
CHECK_NULL_RETURN(fp16_input_);
|
||||||
|
CHECK_NULL_RETURN(fp16_output_);
|
||||||
|
CHECK_NULL_RETURN(pooling_param_);
|
||||||
if (pooling_param_->pool_mode_ == PoolMode_MaxPool) {
|
if (pooling_param_->pool_mode_ == PoolMode_MaxPool) {
|
||||||
MaxPoolingFp16(fp16_input_, fp16_output_, pooling_param_, task_id, minf, maxf);
|
MaxPoolingFp16(fp16_input_, fp16_output_, pooling_param_, task_id, minf, maxf);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -51,8 +51,8 @@ int BroadcastToCPUKernel::ReSize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int BroadcastToCPUKernel::Init() {
|
int BroadcastToCPUKernel::Init() {
|
||||||
CHECK_LESS_RETURN(in_tensors_.size(), 1)
|
CHECK_LESS_RETURN(in_tensors_.size(), 1);
|
||||||
CHECK_LESS_RETURN(out_tensors_.size(), 1)
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
shape_info_ = reinterpret_cast<BroadcastShapeInfo *>(malloc(sizeof(BroadcastShapeInfo)));
|
shape_info_ = reinterpret_cast<BroadcastShapeInfo *>(malloc(sizeof(BroadcastShapeInfo)));
|
||||||
if (shape_info_ == nullptr) {
|
if (shape_info_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Malloc BroadcastShapeInfo failed!";
|
MS_LOG(ERROR) << "Malloc BroadcastShapeInfo failed!";
|
||||||
|
|
|
@ -47,12 +47,16 @@ int ConcatCPUKernel::DoConcat(int task_id) {
|
||||||
std::vector<std::vector<int>> shapes;
|
std::vector<std::vector<int>> shapes;
|
||||||
for (size_t i = 0; i < input_num; ++i) {
|
for (size_t i = 0; i < input_num; ++i) {
|
||||||
inputs_addr[i] = in_tensors_[i]->data_c();
|
inputs_addr[i] = in_tensors_[i]->data_c();
|
||||||
|
CHECK_NULL_RETURN(inputs_addr[i]);
|
||||||
shapes.push_back(in_tensors_[i]->shape());
|
shapes.push_back(in_tensors_[i]->shape());
|
||||||
|
MS_CHECK_LT(concat_param_->axis_, static_cast<int>(in_tensors_[i]->shape().size()), RET_ERROR);
|
||||||
inputs_output_shape[i] = shapes[i].data();
|
inputs_output_shape[i] = shapes[i].data();
|
||||||
}
|
}
|
||||||
auto output_shape = out_tensors_.at(0)->shape();
|
auto output_shape = out_tensors_.at(0)->shape();
|
||||||
|
MS_CHECK_LT(concat_param_->axis_, static_cast<int>(output_shape.size()), RET_ERROR);
|
||||||
inputs_output_shape[input_num] = output_shape.data();
|
inputs_output_shape[input_num] = output_shape.data();
|
||||||
auto output_addr = out_tensors_.at(0)->data_c();
|
auto output_addr = out_tensors_.at(0)->data_c();
|
||||||
|
CHECK_NULL_RETURN(output_addr);
|
||||||
|
|
||||||
Concat(inputs_addr.data(), input_num, concat_param_->axis_, inputs_output_shape.data(), output_shape.size(),
|
Concat(inputs_addr.data(), input_num, concat_param_->axis_, inputs_output_shape.data(), output_shape.size(),
|
||||||
output_addr, task_id, op_parameter_->thread_num_, sizeof(float));
|
output_addr, task_id, op_parameter_->thread_num_, sizeof(float));
|
||||||
|
|
|
@ -39,6 +39,8 @@ constexpr size_t kScoreTensorIndex = 1;
|
||||||
constexpr size_t kMaxOutputNumTensorIndex = 2;
|
constexpr size_t kMaxOutputNumTensorIndex = 2;
|
||||||
constexpr size_t kIoUThresholdTensorIndex = 3;
|
constexpr size_t kIoUThresholdTensorIndex = 3;
|
||||||
constexpr size_t kScoreThresholdTensorIndex = 4;
|
constexpr size_t kScoreThresholdTensorIndex = 4;
|
||||||
|
constexpr size_t kScoreDimsBoxNumIndex = 2;
|
||||||
|
constexpr size_t kBoxDimsBoxNumIndex = 1;
|
||||||
constexpr size_t kYIndexA = 0;
|
constexpr size_t kYIndexA = 0;
|
||||||
constexpr size_t kYIndexB = 2;
|
constexpr size_t kYIndexB = 2;
|
||||||
constexpr size_t kXIndexA = 1;
|
constexpr size_t kXIndexA = 1;
|
||||||
|
@ -47,8 +49,6 @@ constexpr int kBoxPointNum = 4;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int NonMaxSuppressionCPUKernel::Init() {
|
int NonMaxSuppressionCPUKernel::Init() {
|
||||||
CHECK_LESS_RETURN(in_tensors_.size(), C2NUM);
|
|
||||||
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
|
||||||
// boxes, scores, max_output_boxes, iou_threshold, score_threshold
|
// boxes, scores, max_output_boxes, iou_threshold, score_threshold
|
||||||
if (in_tensors_.size() < kMinInputsSize || in_tensors_.size() > kMaxInputsSize || out_tensors_.size() != kOutputNum) {
|
if (in_tensors_.size() < kMinInputsSize || in_tensors_.size() > kMaxInputsSize || out_tensors_.size() != kOutputNum) {
|
||||||
MS_LOG(ERROR) << "NonMaxSuppression input size should be in [" << kMinInputsSize << ", " << kMaxInputsSize << "]"
|
MS_LOG(ERROR) << "NonMaxSuppression input size should be in [" << kMinInputsSize << ", " << kMaxInputsSize << "]"
|
||||||
|
@ -166,7 +166,7 @@ int NonMaxSuppressionCPUKernel::Run_Selecte(bool simple_out, int box_num, int ba
|
||||||
if (!simple_out) {
|
if (!simple_out) {
|
||||||
const int output_last_dim = 3;
|
const int output_last_dim = 3;
|
||||||
output->set_shape({selected_num, output_last_dim});
|
output->set_shape({selected_num, output_last_dim});
|
||||||
MS_ASSERT(output_last_dim * sizeof(int32_t) == sizeof(NMSIndex));
|
MS_CHECK_TRUE_RET(output_last_dim * sizeof(int32_t) == sizeof(NMSIndex), RET_ERROR);
|
||||||
auto *out_data = reinterpret_cast<int32_t *>(output->ReallocData());
|
auto *out_data = reinterpret_cast<int32_t *>(output->ReallocData());
|
||||||
if (out_data == nullptr) {
|
if (out_data == nullptr) {
|
||||||
MS_LOG(ERROR) << "out_data is nullptr.";
|
MS_LOG(ERROR) << "out_data is nullptr.";
|
||||||
|
@ -220,8 +220,7 @@ int NonMaxSuppressionCPUKernel::Run() {
|
||||||
MS_LOG(ERROR) << "Boxes tensor batch num should be equal to scores tensor's batch num.";
|
MS_LOG(ERROR) << "Boxes tensor batch num should be equal to scores tensor's batch num.";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
constexpr size_t kScoreDimsBoxNumIndex = 2;
|
|
||||||
constexpr size_t kBoxDimsBoxNumIndex = 1;
|
|
||||||
if (score_dims.at(kScoreDimsBoxNumIndex) != box_dims.at(kBoxDimsBoxNumIndex)) {
|
if (score_dims.at(kScoreDimsBoxNumIndex) != box_dims.at(kBoxDimsBoxNumIndex)) {
|
||||||
MS_LOG(ERROR) << "Boxes tensor spatial dimension should be equal to scores tensor's spatial dimension.";
|
MS_LOG(ERROR) << "Boxes tensor spatial dimension should be equal to scores tensor's spatial dimension.";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
|
|
|
@ -31,7 +31,7 @@ constexpr size_t kMirrorPadInputSize = 2;
|
||||||
constexpr size_t kPadCommonInputSize = 2;
|
constexpr size_t kPadCommonInputSize = 2;
|
||||||
} // namespace
|
} // namespace
|
||||||
int PadCPUKernel::Init() {
|
int PadCPUKernel::Init() {
|
||||||
CHECK_LESS_RETURN(in_tensors_.size(), 1);
|
CHECK_LESS_RETURN(in_tensors_.size(), kPadCommonInputSize);
|
||||||
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
if (!InferShapeDone()) {
|
if (!InferShapeDone()) {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
|
@ -118,30 +118,30 @@ int ResizeCPUKernel::MallocTmpBuffer() {
|
||||||
// malloc memory for x, y coordinates
|
// malloc memory for x, y coordinates
|
||||||
{
|
{
|
||||||
coordinate_.x_lefts_ = reinterpret_cast<int *>(malloc(static_cast<int>(sizeof(int)) * x_len));
|
coordinate_.x_lefts_ = reinterpret_cast<int *>(malloc(static_cast<int>(sizeof(int)) * x_len));
|
||||||
CHECK_MALLOC_RES(coordinate_.x_lefts_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(coordinate_.x_lefts_, RET_NULL_PTR);
|
||||||
coordinate_.y_tops_ = reinterpret_cast<int *>(malloc(static_cast<int>(sizeof(int)) * y_len));
|
coordinate_.y_tops_ = reinterpret_cast<int *>(malloc(static_cast<int>(sizeof(int)) * y_len));
|
||||||
CHECK_MALLOC_RES(coordinate_.y_tops_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(coordinate_.y_tops_, RET_NULL_PTR);
|
||||||
if (method_ == static_cast<int>(schema::ResizeMethod_LINEAR)) {
|
if (method_ == static_cast<int>(schema::ResizeMethod_LINEAR)) {
|
||||||
coordinate_.x_rights_ = reinterpret_cast<int *>(malloc(static_cast<int>(sizeof(int)) * x_len));
|
coordinate_.x_rights_ = reinterpret_cast<int *>(malloc(static_cast<int>(sizeof(int)) * x_len));
|
||||||
CHECK_MALLOC_RES(coordinate_.x_rights_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(coordinate_.x_rights_, RET_NULL_PTR);
|
||||||
coordinate_.y_bottoms_ = reinterpret_cast<int *>(malloc(static_cast<int>(sizeof(int)) * y_len));
|
coordinate_.y_bottoms_ = reinterpret_cast<int *>(malloc(static_cast<int>(sizeof(int)) * y_len));
|
||||||
CHECK_MALLOC_RES(coordinate_.y_bottoms_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(coordinate_.y_bottoms_, RET_NULL_PTR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// malloc memory for weights of x, y axes
|
// malloc memory for weights of x, y axes
|
||||||
{
|
{
|
||||||
x_weights_ = reinterpret_cast<float *>(malloc(static_cast<int>(sizeof(float)) * x_weight_len));
|
x_weights_ = reinterpret_cast<float *>(malloc(static_cast<int>(sizeof(float)) * x_weight_len));
|
||||||
CHECK_MALLOC_RES(x_weights_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(x_weights_, RET_NULL_PTR);
|
||||||
y_weights_ = reinterpret_cast<float *>(malloc(static_cast<int>(sizeof(float)) * y_weight_len));
|
y_weights_ = reinterpret_cast<float *>(malloc(static_cast<int>(sizeof(float)) * y_weight_len));
|
||||||
CHECK_MALLOC_RES(y_weights_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(y_weights_, RET_NULL_PTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
line_buffer_ =
|
line_buffer_ =
|
||||||
reinterpret_cast<float *>(malloc(static_cast<int>(sizeof(float)) * x_len * in_tensors_.at(0)->Channel() *
|
reinterpret_cast<float *>(malloc(static_cast<int>(sizeof(float)) * x_len * in_tensors_.at(0)->Channel() *
|
||||||
kResizeSizeDouble * op_parameter_->thread_num_));
|
kResizeSizeDouble * op_parameter_->thread_num_));
|
||||||
CHECK_MALLOC_RES(line_buffer_, RET_NULL_PTR)
|
CHECK_MALLOC_RES(line_buffer_, RET_NULL_PTR);
|
||||||
}
|
}
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ using mindspore::schema::PrimitiveType_ReverseSequence;
|
||||||
|
|
||||||
namespace mindspore::kernel {
|
namespace mindspore::kernel {
|
||||||
int ReverseSequenceCPUKernel::Init() {
|
int ReverseSequenceCPUKernel::Init() {
|
||||||
CHECK_LESS_RETURN(in_tensors_.size(), C2NUM);
|
CHECK_LESS_RETURN(in_tensors_.size(), kInputSize1);
|
||||||
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
if (!InferShapeDone()) {
|
if (!InferShapeDone()) {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
@ -94,11 +94,11 @@ int ReverseSequenceCPUKernel::Run() {
|
||||||
void *input1 = in_tensors_.at(1)->MutableData();
|
void *input1 = in_tensors_.at(1)->MutableData();
|
||||||
float *output = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData());
|
float *output = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData());
|
||||||
ReverseSequenceParameter *param = reinterpret_cast<ReverseSequenceParameter *>(op_parameter_);
|
ReverseSequenceParameter *param = reinterpret_cast<ReverseSequenceParameter *>(op_parameter_);
|
||||||
MS_ASSERT(param);
|
CHECK_NULL_RETURN(param);
|
||||||
param->is_seq_length_int32_ = in_tensors_.at(1)->data_type() == kNumberTypeInt32;
|
param->is_seq_length_int32_ = in_tensors_.at(1)->data_type() == kNumberTypeInt32;
|
||||||
MS_ASSERT(input0);
|
CHECK_NULL_RETURN(input0);
|
||||||
MS_ASSERT(input1);
|
CHECK_NULL_RETURN(input1);
|
||||||
MS_ASSERT(output);
|
CHECK_NULL_RETURN(output);
|
||||||
ReverseSequence(input0, input1, output, param);
|
ReverseSequence(input0, input1, output, param);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ using mindspore::schema::PrimitiveType_ROIPooling;
|
||||||
|
|
||||||
namespace mindspore::kernel {
|
namespace mindspore::kernel {
|
||||||
int ROIPoolingCPUKernel::Init() {
|
int ROIPoolingCPUKernel::Init() {
|
||||||
CHECK_LESS_RETURN(in_tensors_.size(), C2NUM);
|
CHECK_LESS_RETURN(in_tensors_.size(), kInputSize1);
|
||||||
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
if (!InferShapeDone()) {
|
if (!InferShapeDone()) {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
@ -69,6 +69,10 @@ int ROIPoolingCPUKernel::ReSize() {
|
||||||
param_->out_strides_[i] = out_shape.at(i + 1) * param_->out_strides_[i + 1];
|
param_->out_strides_[i] = out_shape.at(i + 1) * param_->out_strides_[i + 1];
|
||||||
}
|
}
|
||||||
param_->thread_num_ = MSMIN(param_->op_parameter_.thread_num_, out_shape.at(0));
|
param_->thread_num_ = MSMIN(param_->op_parameter_.thread_num_, out_shape.at(0));
|
||||||
|
if (INT_MUL_OVERFLOW(param_->input_c_, static_cast<int>(sizeof(float)))) {
|
||||||
|
MS_LOG(ERROR) << "int mul overflow";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
max_c_ = reinterpret_cast<float *>(malloc(param_->input_c_ * static_cast<int>(sizeof(float))));
|
max_c_ = reinterpret_cast<float *>(malloc(param_->input_c_ * static_cast<int>(sizeof(float))));
|
||||||
if (max_c_ == nullptr) {
|
if (max_c_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "malloc max_c failed.";
|
MS_LOG(ERROR) << "malloc max_c failed.";
|
||||||
|
@ -78,11 +82,11 @@ int ROIPoolingCPUKernel::ReSize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ROIPoolingCPUKernel::DoExecute(int task_id) {
|
int ROIPoolingCPUKernel::DoExecute(int task_id) {
|
||||||
MS_ASSERT(in_ptr_);
|
CHECK_NULL_RETURN(in_ptr_);
|
||||||
MS_ASSERT(out_ptr_);
|
CHECK_NULL_RETURN(out_ptr_);
|
||||||
MS_ASSERT(roi_ptr_);
|
CHECK_NULL_RETURN(roi_ptr_);
|
||||||
MS_ASSERT(max_c_);
|
CHECK_NULL_RETURN(max_c_);
|
||||||
MS_ASSERT(param_);
|
CHECK_NULL_RETURN(param_);
|
||||||
auto ret = ROIPooling(in_ptr_, out_ptr_, roi_ptr_, max_c_, task_id, param_);
|
auto ret = ROIPooling(in_ptr_, out_ptr_, roi_ptr_, max_c_, task_id, param_);
|
||||||
if (ret != RET_OK) {
|
if (ret != RET_OK) {
|
||||||
MS_LOG(ERROR) << "ROIPooling Execute error task_id[" << task_id << "] error_code[" << ret << "]";
|
MS_LOG(ERROR) << "ROIPooling Execute error task_id[" << task_id << "] error_code[" << ret << "]";
|
||||||
|
|
|
@ -34,8 +34,8 @@ constexpr int kScatterIndicesIndex = 1;
|
||||||
constexpr int kScatterUpdateIndex = 2;
|
constexpr int kScatterUpdateIndex = 2;
|
||||||
} // namespace
|
} // namespace
|
||||||
int ScatterNDCPUKernel::Init() {
|
int ScatterNDCPUKernel::Init() {
|
||||||
CHECK_LESS_RETURN(in_tensors_.size(), DIMENSION_3D)
|
CHECK_LESS_RETURN(in_tensors_.size(), DIMENSION_3D);
|
||||||
CHECK_LESS_RETURN(out_tensors_.size(), 1)
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
if (!InferShapeDone()) {
|
if (!InferShapeDone()) {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,8 @@ constexpr int kScatterUpdateIndex = 2;
|
||||||
constexpr size_t kScatterIndicesDims = 2;
|
constexpr size_t kScatterIndicesDims = 2;
|
||||||
} // namespace
|
} // namespace
|
||||||
int ScatterNdUpdateCPUKernel::Init() {
|
int ScatterNdUpdateCPUKernel::Init() {
|
||||||
CHECK_LESS_RETURN(in_tensors_.size(), DIMENSION_3D)
|
CHECK_LESS_RETURN(in_tensors_.size(), DIMENSION_3D);
|
||||||
CHECK_LESS_RETURN(out_tensors_.size(), 1)
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
if (!InferShapeDone()) {
|
if (!InferShapeDone()) {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ int SparseToDenseCPUKernel::Init() {
|
||||||
auto input3 = in_tensors_.at(3);
|
auto input3 = in_tensors_.at(3);
|
||||||
MS_ASSERT(input3);
|
MS_ASSERT(input3);
|
||||||
sparse_values = reinterpret_cast<float *>(input2->MutableData());
|
sparse_values = reinterpret_cast<float *>(input2->MutableData());
|
||||||
|
CHECK_NULL_RETURN(sparse_values);
|
||||||
|
CHECK_NULL_RETURN(input3->MutableData());
|
||||||
default_value = reinterpret_cast<float *>(input3->MutableData())[0];
|
default_value = reinterpret_cast<float *>(input3->MutableData())[0];
|
||||||
if (input2->ElementsNum() == 1) {
|
if (input2->ElementsNum() == 1) {
|
||||||
isScalar = true;
|
isScalar = true;
|
||||||
|
@ -74,10 +76,10 @@ int SparseToDenseCPUKernel::DoExcute(int task_id) {
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
int out_width = output_num / index_num;
|
int out_width = output_num / index_num;
|
||||||
MS_ASSERT(sparse_indices_vect);
|
CHECK_NULL_RETURN(sparse_indices_vect);
|
||||||
MS_ASSERT(output_shape);
|
CHECK_NULL_RETURN(output_shape);
|
||||||
MS_ASSERT(sparse_values);
|
CHECK_NULL_RETURN(sparse_values);
|
||||||
MS_ASSERT(output_data);
|
CHECK_NULL_RETURN(output_data);
|
||||||
SparseToDense(sparse_indices_vect, output_shape, sparse_values, default_value, output_data, isScalar, index_start,
|
SparseToDense(sparse_indices_vect, output_shape, sparse_values, default_value, output_data, isScalar, index_start,
|
||||||
index_end, out_width);
|
index_end, out_width);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
@ -108,6 +110,7 @@ int SparseToDenseCPUKernel::GenerateIndices() {
|
||||||
}
|
}
|
||||||
index_dim = static_cast<int>(input0->shape().size());
|
index_dim = static_cast<int>(input0->shape().size());
|
||||||
int *sparse_indices = reinterpret_cast<int *>(input0->MutableData());
|
int *sparse_indices = reinterpret_cast<int *>(input0->MutableData());
|
||||||
|
CHECK_NULL_RETURN(sparse_indices);
|
||||||
switch (index_dim) {
|
switch (index_dim) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1: {
|
case 1: {
|
||||||
|
@ -180,7 +183,7 @@ int SparseToDenseCPUKernel::Run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output_data = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData());
|
output_data = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData());
|
||||||
MS_ASSERT(output_data != nullptr);
|
CHECK_NULL_RETURN(output_data);
|
||||||
count_unit_ = thread_count_ > 1 ? UP_DIV(index_num, thread_count_) : index_num;
|
count_unit_ = thread_count_ > 1 ? UP_DIV(index_num, thread_count_) : index_num;
|
||||||
ret = ParallelLaunch(this->ms_context_, SparseToDenseRun, this, s2d_param->thread_num_);
|
ret = ParallelLaunch(this->ms_context_, SparseToDenseRun, this, s2d_param->thread_num_);
|
||||||
if (ret != RET_OK) {
|
if (ret != RET_OK) {
|
||||||
|
@ -191,7 +194,7 @@ int SparseToDenseCPUKernel::Run() {
|
||||||
if (sparse_indices_vect != nullptr) {
|
if (sparse_indices_vect != nullptr) {
|
||||||
for (int i = 0; i < index_num; i++) {
|
for (int i = 0; i < index_num; i++) {
|
||||||
if (sparse_indices_vect[i] != nullptr) {
|
if (sparse_indices_vect[i] != nullptr) {
|
||||||
delete sparse_indices_vect[i];
|
delete[] sparse_indices_vect[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx_->allocator->Free(sparse_indices_vect);
|
ctx_->allocator->Free(sparse_indices_vect);
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace mindspore::kernel {
|
||||||
int UnstackCPUKernel::Init() {
|
int UnstackCPUKernel::Init() {
|
||||||
CHECK_LESS_RETURN(in_tensors_.size(), 1);
|
CHECK_LESS_RETURN(in_tensors_.size(), 1);
|
||||||
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
|
CHECK_NULL_RETURN(op_parameter_);
|
||||||
if (!InferShapeDone()) {
|
if (!InferShapeDone()) {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
@ -59,6 +60,10 @@ int UnstackCPUKernel::ReSize() {
|
||||||
free(output_addr_array_);
|
free(output_addr_array_);
|
||||||
output_addr_array_ = nullptr;
|
output_addr_array_ = nullptr;
|
||||||
}
|
}
|
||||||
|
if (SIZE_MUL_OVERFLOW(sizeof(void *), out_tensors_.size())) {
|
||||||
|
MS_LOG(ERROR) << "mul overflow";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
output_addr_array_ = reinterpret_cast<void **>(malloc(sizeof(void *) * out_tensors_.size()));
|
output_addr_array_ = reinterpret_cast<void **>(malloc(sizeof(void *) * out_tensors_.size()));
|
||||||
if (output_addr_array_ == nullptr) {
|
if (output_addr_array_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Failed to malloc memory";
|
MS_LOG(ERROR) << "Failed to malloc memory";
|
||||||
|
@ -69,12 +74,12 @@ int UnstackCPUKernel::ReSize() {
|
||||||
|
|
||||||
int UnstackCPUKernel::Run() {
|
int UnstackCPUKernel::Run() {
|
||||||
float *input = reinterpret_cast<float *>(in_tensors_.at(0)->MutableData());
|
float *input = reinterpret_cast<float *>(in_tensors_.at(0)->MutableData());
|
||||||
MS_ASSERT(input);
|
CHECK_NULL_RETURN(input);
|
||||||
size_t out_num = out_tensors_.size();
|
size_t out_num = out_tensors_.size();
|
||||||
for (size_t i = 0; i < out_num; i++) {
|
for (size_t i = 0; i < out_num; i++) {
|
||||||
output_addr_array_[i] = out_tensors_.at(i)->data_c();
|
output_addr_array_[i] = out_tensors_.at(i)->data_c();
|
||||||
|
CHECK_NULL_RETURN(output_addr_array_[i]);
|
||||||
}
|
}
|
||||||
MS_ASSERT(output_addr_array_);
|
|
||||||
auto para = reinterpret_cast<UnstackParameter *>(op_parameter_);
|
auto para = reinterpret_cast<UnstackParameter *>(op_parameter_);
|
||||||
para->num_ = static_cast<int>(out_num);
|
para->num_ = static_cast<int>(out_num);
|
||||||
Unstack(input, output_addr_array_, para, sizeof(float));
|
Unstack(input, output_addr_array_, para, sizeof(float));
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
#include "src/runtime/kernel/arm/fp32/where_fp32.h"
|
#include "src/runtime/kernel/arm/fp32/where_fp32.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
|
||||||
#include "schema/model_generated.h"
|
#include "schema/model_generated.h"
|
||||||
#include "nnacl/fp32/where_fp32.h"
|
#include "nnacl/fp32/where_fp32.h"
|
||||||
#include "src/kernel_registry.h"
|
#include "src/kernel_registry.h"
|
||||||
|
@ -47,11 +46,11 @@ int WhereCPUKernel::PreProcess() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int WhereCPUKernel::DoExcute(int task_id) {
|
int WhereCPUKernel::DoExcute(int task_id) {
|
||||||
MS_ASSERT(condition_);
|
CHECK_NULL_RETURN(condition_);
|
||||||
MS_ASSERT(x_);
|
CHECK_NULL_RETURN(x_);
|
||||||
MS_ASSERT(y_);
|
CHECK_NULL_RETURN(y_);
|
||||||
MS_ASSERT(output_data_);
|
CHECK_NULL_RETURN(output_data_);
|
||||||
MS_ASSERT(where_param_);
|
CHECK_NULL_RETURN(where_param_);
|
||||||
WhereWithTripleInputs(condition_, x_, y_, output_data_, where_param_, task_id);
|
WhereWithTripleInputs(condition_, x_, y_, output_data_, where_param_, task_id);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
@ -70,15 +69,15 @@ int WhereCPUKernel::RunWithSingleInput() {
|
||||||
auto input = in_tensors_.at(0);
|
auto input = in_tensors_.at(0);
|
||||||
MS_ASSERT(input);
|
MS_ASSERT(input);
|
||||||
condition_ = reinterpret_cast<bool *>(input->data_c());
|
condition_ = reinterpret_cast<bool *>(input->data_c());
|
||||||
|
CHECK_NULL_RETURN(condition_);
|
||||||
where_param_->condition_num_ = input->ElementsNum();
|
where_param_->condition_num_ = input->ElementsNum();
|
||||||
where_param_->rank_ = static_cast<int>(input->shape().size());
|
where_param_->rank_ = static_cast<int>(input->shape().size());
|
||||||
int strides[8];
|
int strides[8];
|
||||||
ComputeStrides(in_tensors_.at(0)->shape().data(), strides, where_param_->rank_);
|
ComputeStrides(in_tensors_.at(0)->shape().data(), strides, where_param_->rank_);
|
||||||
|
|
||||||
auto data = ms_context_->allocator->Malloc(where_param_->condition_num_ * where_param_->rank_ *
|
auto data = ms_context_->allocator->Malloc(where_param_->condition_num_ * where_param_->rank_ *
|
||||||
static_cast<int>(sizeof(int32_t)));
|
static_cast<int>(sizeof(int32_t)));
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
MS_LOG(ERROR) << "macllov data is error!";
|
MS_LOG(ERROR) << "malloc data is error!";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
int *result = reinterpret_cast<int *>(data);
|
int *result = reinterpret_cast<int *>(data);
|
||||||
|
@ -107,6 +106,7 @@ int WhereCPUKernel::RunWithSingleInput() {
|
||||||
MS_LOG(ERROR) << "malloc out tensor failed.";
|
MS_LOG(ERROR) << "malloc out tensor failed.";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
MS_CHECK_GE(where_param_->condition_num_, true_num, RET_ERROR);
|
||||||
memcpy(out_data, result, true_num * where_param_->rank_ * static_cast<int>(sizeof(int32_t)));
|
memcpy(out_data, result, true_num * where_param_->rank_ * static_cast<int>(sizeof(int32_t)));
|
||||||
ms_context_->allocator->Free(data);
|
ms_context_->allocator->Free(data);
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
|
|
|
@ -28,11 +28,21 @@ namespace mindspore::kernel {
|
||||||
int ConcatInt8CPUKernel::Init() {
|
int ConcatInt8CPUKernel::Init() {
|
||||||
concat_param_->input_shapes_ = nullptr;
|
concat_param_->input_shapes_ = nullptr;
|
||||||
auto input_num = in_tensors_.size();
|
auto input_num = in_tensors_.size();
|
||||||
|
MS_CHECK_FALSE(input_num == 0, RET_ERROR);
|
||||||
|
if (SIZE_MUL_OVERFLOW(sizeof(int8_t *), input_num)) {
|
||||||
|
MS_LOG(ERROR) << "mul overflow";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
input_data_ = reinterpret_cast<int8_t **>(malloc(sizeof(int8_t *) * input_num));
|
input_data_ = reinterpret_cast<int8_t **>(malloc(sizeof(int8_t *) * input_num));
|
||||||
if (input_data_ == nullptr) {
|
if (input_data_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Null pointer reference: inputs_array.";
|
MS_LOG(ERROR) << "Null pointer reference: inputs_array.";
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SIZE_MUL_OVERFLOW(sizeof(QuantArg), input_num)) {
|
||||||
|
MS_LOG(ERROR) << "mul overflow";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
concat_param_->quant_arg_.in_args_ = reinterpret_cast<QuantArg *>(malloc(sizeof(QuantArg) * input_num));
|
concat_param_->quant_arg_.in_args_ = reinterpret_cast<QuantArg *>(malloc(sizeof(QuantArg) * input_num));
|
||||||
if (concat_param_->quant_arg_.in_args_ == nullptr) {
|
if (concat_param_->quant_arg_.in_args_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "Null pointer reference: quant_concat_parm_->in_quant_args_.";
|
MS_LOG(ERROR) << "Null pointer reference: quant_concat_parm_->in_quant_args_.";
|
||||||
|
@ -65,6 +75,10 @@ int ConcatInt8CPUKernel::ReSize() {
|
||||||
|
|
||||||
auto input_num = in_tensors_.size();
|
auto input_num = in_tensors_.size();
|
||||||
concat_param_->input_num_ = static_cast<int>(input_num);
|
concat_param_->input_num_ = static_cast<int>(input_num);
|
||||||
|
if (SIZE_MUL_OVERFLOW(sizeof(int *), input_num)) {
|
||||||
|
MS_LOG(ERROR) << "mul overflow";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
concat_param_->input_shapes_ = reinterpret_cast<int **>(malloc(sizeof(int *) * input_num));
|
concat_param_->input_shapes_ = reinterpret_cast<int **>(malloc(sizeof(int *) * input_num));
|
||||||
if (concat_param_->input_shapes_ == nullptr) {
|
if (concat_param_->input_shapes_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "malloc concat_param_->input_shapes_ failed.";
|
MS_LOG(ERROR) << "malloc concat_param_->input_shapes_ failed.";
|
||||||
|
@ -72,6 +86,10 @@ int ConcatInt8CPUKernel::ReSize() {
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < input_num; i++) {
|
for (size_t i = 0; i < input_num; i++) {
|
||||||
auto in_shape = in_tensors_.at(i)->shape();
|
auto in_shape = in_tensors_.at(i)->shape();
|
||||||
|
if (SIZE_MUL_OVERFLOW(in_shape.size(), sizeof(int))) {
|
||||||
|
MS_LOG(ERROR) << "mul overflow";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
concat_param_->input_shapes_[i] = reinterpret_cast<int *>(malloc(in_shape.size() * sizeof(int)));
|
concat_param_->input_shapes_[i] = reinterpret_cast<int *>(malloc(in_shape.size() * sizeof(int)));
|
||||||
if (concat_param_->input_shapes_[i] == nullptr) {
|
if (concat_param_->input_shapes_[i] == nullptr) {
|
||||||
MS_LOG(ERROR) << "malloc concat_param_->input_shapes_[" << i << "]"
|
MS_LOG(ERROR) << "malloc concat_param_->input_shapes_[" << i << "]"
|
||||||
|
@ -90,6 +108,10 @@ int ConcatInt8CPUKernel::ReSize() {
|
||||||
auto output_tensor = out_tensors_.at(kOutputIndex);
|
auto output_tensor = out_tensors_.at(kOutputIndex);
|
||||||
auto out_shape = output_tensor->shape();
|
auto out_shape = output_tensor->shape();
|
||||||
size_t output_dim = out_shape.size();
|
size_t output_dim = out_shape.size();
|
||||||
|
if (SIZE_MUL_OVERFLOW(output_dim, sizeof(int))) {
|
||||||
|
MS_LOG(ERROR) << "mul overflow";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
concat_param_->output_shapes_ = reinterpret_cast<int *>(malloc(output_dim * sizeof(int)));
|
concat_param_->output_shapes_ = reinterpret_cast<int *>(malloc(output_dim * sizeof(int)));
|
||||||
if (concat_param_->output_shapes_ == nullptr) {
|
if (concat_param_->output_shapes_ == nullptr) {
|
||||||
MS_LOG(ERROR) << "malloc concat_param_->output_shapes_ failed.";
|
MS_LOG(ERROR) << "malloc concat_param_->output_shapes_ failed.";
|
||||||
|
@ -107,15 +129,17 @@ int ConcatInt8CPUKernel::ReSize() {
|
||||||
|
|
||||||
int ConcatInt8CPUKernel::Run() {
|
int ConcatInt8CPUKernel::Run() {
|
||||||
auto input_num = concat_param_->input_num_;
|
auto input_num = concat_param_->input_num_;
|
||||||
|
MS_CHECK_FALSE(op_parameter_->thread_num_ == 0, RET_ERROR);
|
||||||
count_unit_ =
|
count_unit_ =
|
||||||
op_parameter_->thread_num_ > 1 ? UP_DIV(before_axis_size, op_parameter_->thread_num_) : before_axis_size;
|
op_parameter_->thread_num_ > 1 ? UP_DIV(before_axis_size, op_parameter_->thread_num_) : before_axis_size;
|
||||||
concat_param_->count_unit_ = count_unit_;
|
concat_param_->count_unit_ = count_unit_;
|
||||||
|
|
||||||
for (int i = 0; i < input_num; i++) {
|
for (int i = 0; i < input_num; i++) {
|
||||||
input_data_[i] = static_cast<int8_t *>(in_tensors_.at(i)->MutableData());
|
input_data_[i] = static_cast<int8_t *>(in_tensors_.at(i)->MutableData());
|
||||||
|
CHECK_NULL_RETURN(input_data_[i]);
|
||||||
}
|
}
|
||||||
output_data_ = reinterpret_cast<int8_t *>(out_tensors_.at(0)->MutableData());
|
output_data_ = reinterpret_cast<int8_t *>(out_tensors_.at(0)->MutableData());
|
||||||
|
CHECK_NULL_RETURN(output_data_);
|
||||||
auto ret = ParallelLaunch(this->ms_context_, ConcatInt8Run, this, op_parameter_->thread_num_);
|
auto ret = ParallelLaunch(this->ms_context_, ConcatInt8Run, this, op_parameter_->thread_num_);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "src/kernel_registry.h"
|
#include "src/kernel_registry.h"
|
||||||
|
#include "nnacl/op_base.h"
|
||||||
|
|
||||||
using mindspore::lite::RET_ERROR;
|
using mindspore::lite::RET_ERROR;
|
||||||
using mindspore::lite::RET_MEMORY_FAILED;
|
using mindspore::lite::RET_MEMORY_FAILED;
|
||||||
|
@ -112,6 +113,9 @@ int PadInt8CPUKernel::ReSize() {
|
||||||
|
|
||||||
int PadInt8CPUKernel::Init() {
|
int PadInt8CPUKernel::Init() {
|
||||||
MS_ASSERT(pad_param_);
|
MS_ASSERT(pad_param_);
|
||||||
|
CHECK_LESS_RETURN(in_tensors_.size(), kInputSize1);
|
||||||
|
CHECK_LESS_RETURN(out_tensors_.size(), 1);
|
||||||
|
CHECK_NULL_RETURN(op_parameter_);
|
||||||
auto error_code = SetQuantParam();
|
auto error_code = SetQuantParam();
|
||||||
if (error_code != RET_OK) {
|
if (error_code != RET_OK) {
|
||||||
MS_LOG(ERROR) << "SetQuantParam failed. errorcode: " << error_code;
|
MS_LOG(ERROR) << "SetQuantParam failed. errorcode: " << error_code;
|
||||||
|
@ -124,10 +128,10 @@ int PadInt8CPUKernel::Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int PadInt8CPUKernel::RunImpl(int task_id) {
|
int PadInt8CPUKernel::RunImpl(int task_id) {
|
||||||
MS_ASSERT(in_data_);
|
CHECK_NULL_RETURN(in_data_);
|
||||||
MS_ASSERT(out_data_);
|
CHECK_NULL_RETURN(out_data_);
|
||||||
MS_ASSERT(in_dims_);
|
CHECK_NULL_RETURN(in_dims_);
|
||||||
MS_ASSERT(out_dims_);
|
CHECK_NULL_RETURN(out_dims_);
|
||||||
return PadConstant4D(in_data_, out_data_, in_dims_, out_dims_, pad_param_->paddings_, task_id,
|
return PadConstant4D(in_data_, out_data_, in_dims_, out_dims_, pad_param_->paddings_, task_id,
|
||||||
op_parameter_->thread_num_);
|
op_parameter_->thread_num_);
|
||||||
}
|
}
|
||||||
|
@ -159,6 +163,9 @@ int PadInt8CPUKernel::HandleMirrorPad() {
|
||||||
void PadInt8CPUKernel::CalculateStrides() {
|
void PadInt8CPUKernel::CalculateStrides() {
|
||||||
pad_param_->in_strides[COMM_SHAPE_SIZE - 1] = 1;
|
pad_param_->in_strides[COMM_SHAPE_SIZE - 1] = 1;
|
||||||
for (auto i = COMM_SHAPE_SIZE - 2; i >= 0; --i) {
|
for (auto i = COMM_SHAPE_SIZE - 2; i >= 0; --i) {
|
||||||
|
if (INT_MUL_OVERFLOW(in_dims_[i + 1], pad_param_->in_strides[i + 1])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pad_param_->in_strides[i] = in_dims_[i + 1] * pad_param_->in_strides[i + 1];
|
pad_param_->in_strides[i] = in_dims_[i + 1] * pad_param_->in_strides[i + 1];
|
||||||
}
|
}
|
||||||
for (auto i = 0; i < COMM_SHAPE_SIZE; ++i) {
|
for (auto i = 0; i < COMM_SHAPE_SIZE; ++i) {
|
||||||
|
@ -166,6 +173,9 @@ void PadInt8CPUKernel::CalculateStrides() {
|
||||||
}
|
}
|
||||||
pad_param_->out_strides[COMM_SHAPE_SIZE - 1] = 1;
|
pad_param_->out_strides[COMM_SHAPE_SIZE - 1] = 1;
|
||||||
for (auto i = COMM_SHAPE_SIZE - 2; i >= 0; --i) {
|
for (auto i = COMM_SHAPE_SIZE - 2; i >= 0; --i) {
|
||||||
|
if (INT_MUL_OVERFLOW(out_dims_[i + 1], pad_param_->out_strides[i + 1])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pad_param_->out_strides[i] = out_dims_[i + 1] * pad_param_->out_strides[i + 1];
|
pad_param_->out_strides[i] = out_dims_[i + 1] * pad_param_->out_strides[i + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,10 +199,10 @@ int PadInt8CPUKernel::RunMirrorPadImpl(int task_id) {
|
||||||
auto output = out_tensors_.at(0);
|
auto output = out_tensors_.at(0);
|
||||||
MS_ASSERT(output);
|
MS_ASSERT(output);
|
||||||
auto input_data = reinterpret_cast<int8_t *>(input->MutableData());
|
auto input_data = reinterpret_cast<int8_t *>(input->MutableData());
|
||||||
MS_ASSERT(input_data);
|
CHECK_NULL_RETURN(input_data);
|
||||||
auto output_data = reinterpret_cast<int8_t *>(output->MutableData());
|
auto output_data = reinterpret_cast<int8_t *>(output->MutableData());
|
||||||
MS_ASSERT(output_data);
|
CHECK_NULL_RETURN(output_data);
|
||||||
|
MS_CHECK_FALSE(op_parameter_->thread_num_ == 0, RET_ERROR);
|
||||||
int unit = UP_DIV(output->ElementsNum(), op_parameter_->thread_num_);
|
int unit = UP_DIV(output->ElementsNum(), op_parameter_->thread_num_);
|
||||||
int begin = unit * task_id;
|
int begin = unit * task_id;
|
||||||
int end = MSMIN(begin + unit, output->ElementsNum());
|
int end = MSMIN(begin + unit, output->ElementsNum());
|
||||||
|
@ -263,8 +273,9 @@ int PadInt8CPUKernel::CopyPaddingFromInput() {
|
||||||
|
|
||||||
int PadInt8CPUKernel::Run() {
|
int PadInt8CPUKernel::Run() {
|
||||||
in_data_ = reinterpret_cast<int8_t *>(in_tensors_.at(0)->MutableData());
|
in_data_ = reinterpret_cast<int8_t *>(in_tensors_.at(0)->MutableData());
|
||||||
|
CHECK_NULL_RETURN(in_data_);
|
||||||
out_data_ = reinterpret_cast<int8_t *>(out_tensors_.at(0)->MutableData());
|
out_data_ = reinterpret_cast<int8_t *>(out_tensors_.at(0)->MutableData());
|
||||||
|
CHECK_NULL_RETURN(out_data_);
|
||||||
int error_code;
|
int error_code;
|
||||||
if (pad_param_->pad_mode_ == static_cast<int>(schema::PaddingMode_CONSTANT)) {
|
if (pad_param_->pad_mode_ == static_cast<int>(schema::PaddingMode_CONSTANT)) {
|
||||||
memset(out_data_, pad_param_->pad_quant_arg_.constant_value_[0],
|
memset(out_data_, pad_param_->pad_quant_arg_.constant_value_[0],
|
||||||
|
|
|
@ -64,10 +64,10 @@ int PoolingInt8CPUKernel::ReSize() {
|
||||||
|
|
||||||
int PoolingInt8CPUKernel::RunImpl(int task_id) {
|
int PoolingInt8CPUKernel::RunImpl(int task_id) {
|
||||||
auto input_data = reinterpret_cast<int8_t *>(in_tensors_.at(kInputIndex)->MutableData());
|
auto input_data = reinterpret_cast<int8_t *>(in_tensors_.at(kInputIndex)->MutableData());
|
||||||
MS_ASSERT(input_data);
|
CHECK_NULL_RETURN(input_data);
|
||||||
auto output_data = reinterpret_cast<int8_t *>(out_tensors_.at(kOutputIndex)->MutableData());
|
auto output_data = reinterpret_cast<int8_t *>(out_tensors_.at(kOutputIndex)->MutableData());
|
||||||
MS_ASSERT(output_data);
|
CHECK_NULL_RETURN(output_data);
|
||||||
MS_ASSERT(pooling_param_);
|
CHECK_NULL_RETURN(pooling_param_);
|
||||||
if (pooling_param_->pool_mode_ == PoolMode_MaxPool) {
|
if (pooling_param_->pool_mode_ == PoolMode_MaxPool) {
|
||||||
if (pooling_param_->quantize_) {
|
if (pooling_param_->quantize_) {
|
||||||
MaxPoolingWithQuantInt8(input_data, output_data, pooling_param_, task_id);
|
MaxPoolingWithQuantInt8(input_data, output_data, pooling_param_, task_id);
|
||||||
|
|
|
@ -59,8 +59,14 @@ void ConcatGetWorkGroup(const std::vector<size_t> &global, std::vector<size_t> *
|
||||||
const int max_divider = 8;
|
const int max_divider = 8;
|
||||||
const int max_x = 2, max_y = 8;
|
const int max_x = 2, max_y = 8;
|
||||||
int x = std::min(GetMaxDivisorStrategy1(global[0], max_divider), max_x);
|
int x = std::min(GetMaxDivisorStrategy1(global[0], max_divider), max_x);
|
||||||
|
if (x == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int yz = max_size / x;
|
int yz = max_size / x;
|
||||||
int y = std::min(std::min(GetMaxDivisorStrategy1(global[1], max_divider), yz), max_y);
|
int y = std::min(std::min(GetMaxDivisorStrategy1(global[1], max_divider), yz), max_y);
|
||||||
|
if (y == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int z = std::min(yz / y, static_cast<int>(UP_DIV(global[2], 2)));
|
int z = std::min(yz / y, static_cast<int>(UP_DIV(global[2], 2)));
|
||||||
|
|
||||||
local->clear();
|
local->clear();
|
||||||
|
|
|
@ -55,6 +55,7 @@ int SparseToDenseOpenCLKernel::InitOutputToDefault() {
|
||||||
|
|
||||||
int SparseToDenseOpenCLKernel::InitWeights() {
|
int SparseToDenseOpenCLKernel::InitWeights() {
|
||||||
auto allocator = ocl_runtime_->GetAllocator();
|
auto allocator = ocl_runtime_->GetAllocator();
|
||||||
|
MS_CHECK_GE(in_tensors_.size(), 3, RET_ERROR);
|
||||||
auto weight_tensor = in_tensors_[2];
|
auto weight_tensor = in_tensors_[2];
|
||||||
size_t size = 1;
|
size_t size = 1;
|
||||||
for (int i = 0; i < weight_tensor->shape().size(); ++i) {
|
for (int i = 0; i < weight_tensor->shape().size(); ++i) {
|
||||||
|
@ -177,6 +178,7 @@ void SparseToDenseOpenCLKernel::SetGlobalLocal() {
|
||||||
int SparseToDenseOpenCLKernel::Prepare() {
|
int SparseToDenseOpenCLKernel::Prepare() {
|
||||||
enable_fp16_ = ocl_runtime_->GetFp16Enable();
|
enable_fp16_ = ocl_runtime_->GetFp16Enable();
|
||||||
input_dim_ = in_tensors_[0]->shape().size();
|
input_dim_ = in_tensors_[0]->shape().size();
|
||||||
|
MS_CHECK_GE(input_dim_, 2, RET_ERROR);
|
||||||
inshapeindex1_dim = in_tensors_[0]->shape()[1];
|
inshapeindex1_dim = in_tensors_[0]->shape()[1];
|
||||||
weight_scalar_ = in_tensors_[2]->IsScalar();
|
weight_scalar_ = in_tensors_[2]->IsScalar();
|
||||||
const std::string kernel_name = "SparseToDense" + std::string(weight_scalar_ ? "Scalar" : "Vector");
|
const std::string kernel_name = "SparseToDense" + std::string(weight_scalar_ ? "Scalar" : "Vector");
|
||||||
|
|
Loading…
Reference in New Issue