check code

This commit is contained in:
zhaozhenlong 2021-08-27 09:57:16 +08:00
parent 111d1a9a61
commit 1920828739
47 changed files with 176 additions and 95 deletions

View File

@ -36,6 +36,7 @@ void Concat(void **input, int input_num, int axis, int **inputs_output_shape, si
continue;
}
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 count = input_stride - offset * task_id;
if (count <= 0) {

View File

@ -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);
#endif
NNACL_CHECK_ZERO_RETURN_ERR(output_w);
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
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;
@ -268,6 +269,7 @@ void MaxPoolingFp16(const float16_t *input_ptr, float16_t *output_ptr, const Poo
int thread_num = pooling_param->thread_num_;
// input channel is equal to output channel
NNACL_CHECK_ZERO_RETURN(output_w);
for (int batch = 0; batch < output_batch; batch++) {
int in_batch_offset = batch * in_h * in_w * channel;
int out_batch_offset = batch * output_h * output_w * channel;

View File

@ -23,7 +23,7 @@ int InstanceNorm(const float *src_data, float *dst_data, const float *gamma_data
const InstanceNormParameter *param, size_t task_id) {
NNACL_CHECK_NULL_RETURN_ERR(src_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_begin = (int)(task_id)*channel_step;
int channel_end = MSMIN(channel_begin + channel_step, param->channel_);

View File

@ -65,7 +65,7 @@ int GetInputFlattenIndex(int out_flatten_index, const int *input_shape, const Pa
int in_flatten_index = 0;
for (int i = 0; i < DEFAULT_PAD_NDIMS; ++i) {
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];
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_);

View File

@ -54,6 +54,7 @@ int GetInputFlattenIndexInt8(int out_flatten_index, const int *input_shape, cons
int i;
for (i = 0; i < COMM_SHAPE_SIZE; ++i) {
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];
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_);

View File

@ -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_;
const int8_t out_min = INT8_MIN;
const int8_t out_max = INT8_MAX;
NNACL_CHECK_ZERO_RETURN_ERR(output_w);
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
int in_batch_offset = batch * pooling_param->input_h_ * in_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_;
double real_multiplier = input_scale / output_scale;
NNACL_CHECK_ZERO_RETURN(output_w);
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
int in_batch_offset = batch * in_h * in_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_);
int8_t out_array[MAX_MAXPOOL_SIZE];
NNACL_CHECK_ZERO_RETURN(output_w);
for (int batch = 0; batch < pooling_param->output_batch_; batch++) {
int in_batch_offset = batch * pooling_param->input_h_ * in_w * channel;
int out_batch_offset = batch * pooling_param->output_h_ * output_w * channel;

View File

@ -49,6 +49,7 @@
#define DOWN_ROUND(x, y) ((x) / (y) * (y))
#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) \
((x == 0) ? false \
: ((x) > 0 ? ((y >= 0) ? (INT_MAX / (x)) < (y) : (INT_MAX / (x)) < (-1 * (y))) \
@ -156,21 +157,21 @@
if ((val) == 0) { \
return NNACL_ERR; \
} \
} while (0);
} while (0)
#define NNACL_CHECK_ZERO_RETURN(val) \
do { \
if ((val) == 0) { \
return; \
} \
} while (0);
} while (0)
#define NNACL_CHECK_NULL_RETURN_ERR(ptr) \
do { \
if ((ptr) == NULL) { \
return NNACL_NULL_PTR; \
} \
} while (0);
} while (0)
#else

View File

@ -107,29 +107,29 @@ int ResizeFP32Coder::MallocTmpBuffer() {
// malloc memory for x, y coordinates
{
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_));
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)) {
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_));
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
{
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_));
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;
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;
}

View File

@ -34,7 +34,7 @@
MS_LOG(ERROR) << "malloc data failed."; \
return errcode; \
} \
} while (0);
} while (0)
#ifndef ENABLE_HIGH_PERFORMANCE
#define CHECK_NULL_RETURN(ptr) \
@ -43,7 +43,7 @@
MS_LOG(ERROR) << #ptr << " must not be null!"; \
return mindspore::lite::RET_NULL_PTR; \
} \
} while (0);
} while (0)
#define CHECK_LESS_RETURN(size1, size2) \
do { \
@ -51,7 +51,8 @@
MS_LOG(ERROR) << #size1 << " must not less than " << #size2; \
return mindspore::lite::RET_ERROR; \
} \
} while (0);
} while (0)
#else
#define CHECK_NULL_RETURN(ptr)
#define CHECK_LESS_RETURN(size1, size2)

View File

@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_Concat;
namespace mindspore {
namespace lite {
OpParameter *PopulateConcatParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto *primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto value = primitive->value_as_Concat();
if (value == nullptr) {
MS_LOG(ERROR) << "param is nullptr";

View File

@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_NonMaxSuppression;
namespace mindspore {
namespace lite {
OpParameter *PopulateNonMaxSuppressionParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto value = primitive->value_as_NonMaxSuppression();
if (value == nullptr) {
MS_LOG(ERROR) << "value is nullptr";

View File

@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_PadFusion;
namespace mindspore {
namespace lite {
OpParameter *PopulatePadParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto value = primitive->value_as_PadFusion();
if (value == nullptr) {
MS_LOG(ERROR) << "value is nullptr";

View File

@ -21,8 +21,8 @@ using mindspore::schema::PrimitiveType_MaxPoolFusion;
namespace mindspore {
namespace lite {
OpParameter *PopulateAvgPoolParameter(const void *primitive) {
MS_CHECK_TRUE_RET(primitive != nullptr, nullptr);
auto pooling_prim = static_cast<const schema::Primitive *>(primitive);
MS_ASSERT(pooling_prim != nullptr);
auto value = pooling_prim->value_as_AvgPoolFusion();
if (value == nullptr) {
MS_LOG(ERROR) << "value is nullptr";

View File

@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_ReverseSequence;
namespace mindspore {
namespace lite {
OpParameter *PopulateReverseSequenceParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto value = primitive->value_as_ReverseSequence();
if (value == nullptr) {
MS_LOG(ERROR) << "value is nullptr";

View File

@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_ROIPooling;
namespace mindspore {
namespace lite {
OpParameter *PopulateROIPoolingParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto value = primitive->value_as_ROIPooling();
if (value == nullptr) {
MS_LOG(ERROR) << "value is nullptr";

View File

@ -21,8 +21,8 @@ using mindspore::schema::PrimitiveType_Shape;
namespace mindspore {
namespace lite {
OpParameter *PopulateShapeParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto *param = reinterpret_cast<OpParameter *>(malloc(sizeof(OpParameter)));
if (param == nullptr) {

View File

@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_SparseToDense;
namespace mindspore {
namespace lite {
OpParameter *PopulateSparseToDenseParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto *param = reinterpret_cast<SparseToDenseParameter *>(malloc(sizeof(SparseToDenseParameter)));
if (param == nullptr) {

View File

@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_Unstack;
namespace mindspore {
namespace lite {
OpParameter *PopulateUnstackParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto value = primitive->value_as_Unstack();
if (value == nullptr) {
MS_LOG(ERROR) << "value is nullptr";

View File

@ -22,8 +22,8 @@ namespace mindspore {
namespace lite {
namespace {
OpParameter *PopulateConcatParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto concat_prim = primitive->value_as_Concat();
if (concat_prim == nullptr) {
MS_LOG(ERROR) << "concat_prim is nullptr";

View File

@ -22,8 +22,8 @@ namespace mindspore {
namespace lite {
namespace {
OpParameter *PopulateNonMaxSuppressionParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto non_max_suppression_prim = primitive->value_as_NonMaxSuppression();
if (non_max_suppression_prim == nullptr) {
MS_LOG(ERROR) << "non_max_suppression_prim is nullptr";

View File

@ -22,8 +22,9 @@ namespace mindspore {
namespace lite {
namespace {
OpParameter *PopulatePadParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto pad_prim = primitive->value_as_Pad();
if (pad_prim == nullptr) {
MS_LOG(ERROR) << "pad_prim is nullptr";

View File

@ -22,8 +22,8 @@ namespace mindspore {
namespace lite {
namespace {
OpParameter *PopulatePoolingParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto pooling_prim = primitive->value_as_Pooling();
if (pooling_prim == nullptr) {
MS_LOG(ERROR) << "pooling_prim is nullptr";

View File

@ -22,8 +22,8 @@ namespace mindspore {
namespace lite {
namespace {
OpParameter *PopulateReverseSequenceParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto reverse_sequence_prim = primitive->value_as_ReverseSequence();
if (reverse_sequence_prim == nullptr) {
MS_LOG(ERROR) << "reverse_sequence_prim is nullptr";

View File

@ -22,8 +22,8 @@ namespace mindspore {
namespace lite {
namespace {
OpParameter *PopulateROIPoolingParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto roi_pooling_prim = primitive->value_as_ROIPooling();
if (roi_pooling_prim == nullptr) {
MS_LOG(ERROR) << "roi_pooling_prim is nullptr";

View File

@ -22,8 +22,8 @@ namespace mindspore {
namespace lite {
namespace {
OpParameter *PopulateUnstackParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto *primitive = static_cast<const schema::v0::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto unstack_prim = primitive->value_as_Unstack();
if (unstack_prim == nullptr) {
MS_LOG(ERROR) << "unstack_prim is nullptr";

View File

@ -20,8 +20,8 @@ using mindspore::schema::PrimitiveType_Where;
namespace mindspore {
namespace lite {
OpParameter *PopulateWhereParameter(const void *prim) {
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
auto primitive = static_cast<const schema::Primitive *>(prim);
MS_ASSERT(primitive != nullptr);
auto *param = reinterpret_cast<WhereParameter *>(malloc(sizeof(WhereParameter)));
if (param == nullptr) {

View File

@ -83,10 +83,10 @@ void PoolingBaseCPUKernel::FreeQuantParam() {
}
int PoolingBaseCPUKernel::Init() {
MS_ASSERT(in_tensors_.size() == 1);
MS_ASSERT(out_tensors_.size() == 1);
CHECK_LESS_RETURN(in_tensors_.size(), 1);
CHECK_LESS_RETURN(out_tensors_.size(), 1);
pooling_param_->thread_num_ = thread_count_;
MS_ASSERT(this->op_parameter_ != nullptr);
CHECK_NULL_RETURN(op_parameter_);
return RET_OK;
}

View File

@ -101,21 +101,27 @@ int ConcatFp16CPUKernel::Run() {
if (in_tensor->data_type() == kNumberTypeFloat || in_tensor->data_type() == kNumberTypeFloat32) {
auto in_tensor_data = reinterpret_cast<float *>(in_tensor->data_c());
MS_ASSERT(in_tensor_data != nullptr);
CHECK_NULL_RETURN(in_tensor_data);
Float32ToFloat16(in_tensor_data, fp16_inputs_[i], in_tensor->ElementsNum());
} else {
fp16_inputs_[i] = reinterpret_cast<float16_t *>(in_tensor->data_c());
MS_ASSERT(fp16_inputs_[i] != nullptr);
CHECK_NULL_RETURN(fp16_inputs_[i]);
}
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();
}
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();
auto output_addr = out_tensors_.at(0)->MutableData();
CHECK_NULL_RETURN(output_addr);
if (out_tensors_.at(0)->data_type() == kNumberTypeFloat16) {
fp16_output_ = reinterpret_cast<float16_t *>(out_tensors_.at(0)->data_c());
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);

View File

@ -35,9 +35,13 @@ int PadFp16CPUKernel::RunImpl(int task_id) {
int PadFp16CPUKernel::RunMirrorPadImpl(int task_id) {
auto input = in_tensors_.at(0);
CHECK_NULL_RETURN(input);
auto output = out_tensors_.at(0);
CHECK_NULL_RETURN(output);
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());
CHECK_NULL_RETURN(output_data);
/* Fast Mirror pad */
if (mirror_pad_block_.size() != 0) {
@ -67,7 +71,7 @@ int PadFp16CPUKernel::RunMirrorPadImpl(int task_id) {
}
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 begin = unit * task_id;
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;
return RET_ERROR;
}
CHECK_NULL_RETURN(pad_value->data_c());
pad_param_->constant_value_ = *(reinterpret_cast<float16_t *>(pad_value->data_c()));
}

View File

@ -60,6 +60,9 @@ int PoolingFp16CPUKernel::RunImpl(int task_id) {
minf = 0.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) {
MaxPoolingFp16(fp16_input_, fp16_output_, pooling_param_, task_id, minf, maxf);
} else {

View File

@ -51,8 +51,8 @@ int BroadcastToCPUKernel::ReSize() {
}
int BroadcastToCPUKernel::Init() {
CHECK_LESS_RETURN(in_tensors_.size(), 1)
CHECK_LESS_RETURN(out_tensors_.size(), 1)
CHECK_LESS_RETURN(in_tensors_.size(), 1);
CHECK_LESS_RETURN(out_tensors_.size(), 1);
shape_info_ = reinterpret_cast<BroadcastShapeInfo *>(malloc(sizeof(BroadcastShapeInfo)));
if (shape_info_ == nullptr) {
MS_LOG(ERROR) << "Malloc BroadcastShapeInfo failed!";

View File

@ -47,12 +47,16 @@ int ConcatCPUKernel::DoConcat(int task_id) {
std::vector<std::vector<int>> shapes;
for (size_t i = 0; i < input_num; ++i) {
inputs_addr[i] = in_tensors_[i]->data_c();
CHECK_NULL_RETURN(inputs_addr[i]);
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();
}
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();
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(),
output_addr, task_id, op_parameter_->thread_num_, sizeof(float));

View File

@ -39,6 +39,8 @@ constexpr size_t kScoreTensorIndex = 1;
constexpr size_t kMaxOutputNumTensorIndex = 2;
constexpr size_t kIoUThresholdTensorIndex = 3;
constexpr size_t kScoreThresholdTensorIndex = 4;
constexpr size_t kScoreDimsBoxNumIndex = 2;
constexpr size_t kBoxDimsBoxNumIndex = 1;
constexpr size_t kYIndexA = 0;
constexpr size_t kYIndexB = 2;
constexpr size_t kXIndexA = 1;
@ -47,8 +49,6 @@ constexpr int kBoxPointNum = 4;
} // namespace
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
if (in_tensors_.size() < kMinInputsSize || in_tensors_.size() > kMaxInputsSize || out_tensors_.size() != kOutputNum) {
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) {
const int output_last_dim = 3;
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());
if (out_data == 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.";
return RET_ERROR;
}
constexpr size_t kScoreDimsBoxNumIndex = 2;
constexpr size_t kBoxDimsBoxNumIndex = 1;
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.";
return RET_ERROR;

View File

@ -31,7 +31,7 @@ constexpr size_t kMirrorPadInputSize = 2;
constexpr size_t kPadCommonInputSize = 2;
} // namespace
int PadCPUKernel::Init() {
CHECK_LESS_RETURN(in_tensors_.size(), 1);
CHECK_LESS_RETURN(in_tensors_.size(), kPadCommonInputSize);
CHECK_LESS_RETURN(out_tensors_.size(), 1);
if (!InferShapeDone()) {
return RET_OK;

View File

@ -118,30 +118,30 @@ int ResizeCPUKernel::MallocTmpBuffer() {
// malloc memory for x, y coordinates
{
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));
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)) {
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));
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
{
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));
CHECK_MALLOC_RES(y_weights_, RET_NULL_PTR)
CHECK_MALLOC_RES(y_weights_, RET_NULL_PTR);
}
{
line_buffer_ =
reinterpret_cast<float *>(malloc(static_cast<int>(sizeof(float)) * x_len * in_tensors_.at(0)->Channel() *
kResizeSizeDouble * op_parameter_->thread_num_));
CHECK_MALLOC_RES(line_buffer_, RET_NULL_PTR)
CHECK_MALLOC_RES(line_buffer_, RET_NULL_PTR);
}
return RET_OK;
}

View File

@ -25,7 +25,7 @@ using mindspore::schema::PrimitiveType_ReverseSequence;
namespace mindspore::kernel {
int ReverseSequenceCPUKernel::Init() {
CHECK_LESS_RETURN(in_tensors_.size(), C2NUM);
CHECK_LESS_RETURN(in_tensors_.size(), kInputSize1);
CHECK_LESS_RETURN(out_tensors_.size(), 1);
if (!InferShapeDone()) {
return RET_OK;
@ -94,11 +94,11 @@ int ReverseSequenceCPUKernel::Run() {
void *input1 = in_tensors_.at(1)->MutableData();
float *output = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData());
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;
MS_ASSERT(input0);
MS_ASSERT(input1);
MS_ASSERT(output);
CHECK_NULL_RETURN(input0);
CHECK_NULL_RETURN(input1);
CHECK_NULL_RETURN(output);
ReverseSequence(input0, input1, output, param);
return RET_OK;
}

View File

@ -29,7 +29,7 @@ using mindspore::schema::PrimitiveType_ROIPooling;
namespace mindspore::kernel {
int ROIPoolingCPUKernel::Init() {
CHECK_LESS_RETURN(in_tensors_.size(), C2NUM);
CHECK_LESS_RETURN(in_tensors_.size(), kInputSize1);
CHECK_LESS_RETURN(out_tensors_.size(), 1);
if (!InferShapeDone()) {
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_->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))));
if (max_c_ == nullptr) {
MS_LOG(ERROR) << "malloc max_c failed.";
@ -78,11 +82,11 @@ int ROIPoolingCPUKernel::ReSize() {
}
int ROIPoolingCPUKernel::DoExecute(int task_id) {
MS_ASSERT(in_ptr_);
MS_ASSERT(out_ptr_);
MS_ASSERT(roi_ptr_);
MS_ASSERT(max_c_);
MS_ASSERT(param_);
CHECK_NULL_RETURN(in_ptr_);
CHECK_NULL_RETURN(out_ptr_);
CHECK_NULL_RETURN(roi_ptr_);
CHECK_NULL_RETURN(max_c_);
CHECK_NULL_RETURN(param_);
auto ret = ROIPooling(in_ptr_, out_ptr_, roi_ptr_, max_c_, task_id, param_);
if (ret != RET_OK) {
MS_LOG(ERROR) << "ROIPooling Execute error task_id[" << task_id << "] error_code[" << ret << "]";

View File

@ -34,8 +34,8 @@ constexpr int kScatterIndicesIndex = 1;
constexpr int kScatterUpdateIndex = 2;
} // namespace
int ScatterNDCPUKernel::Init() {
CHECK_LESS_RETURN(in_tensors_.size(), DIMENSION_3D)
CHECK_LESS_RETURN(out_tensors_.size(), 1)
CHECK_LESS_RETURN(in_tensors_.size(), DIMENSION_3D);
CHECK_LESS_RETURN(out_tensors_.size(), 1);
if (!InferShapeDone()) {
return RET_OK;
}

View File

@ -35,8 +35,8 @@ constexpr int kScatterUpdateIndex = 2;
constexpr size_t kScatterIndicesDims = 2;
} // namespace
int ScatterNdUpdateCPUKernel::Init() {
CHECK_LESS_RETURN(in_tensors_.size(), DIMENSION_3D)
CHECK_LESS_RETURN(out_tensors_.size(), 1)
CHECK_LESS_RETURN(in_tensors_.size(), DIMENSION_3D);
CHECK_LESS_RETURN(out_tensors_.size(), 1);
if (!InferShapeDone()) {
return RET_OK;
}

View File

@ -37,6 +37,8 @@ int SparseToDenseCPUKernel::Init() {
auto input3 = in_tensors_.at(3);
MS_ASSERT(input3);
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];
if (input2->ElementsNum() == 1) {
isScalar = true;
@ -74,10 +76,10 @@ int SparseToDenseCPUKernel::DoExcute(int task_id) {
return RET_ERROR;
}
int out_width = output_num / index_num;
MS_ASSERT(sparse_indices_vect);
MS_ASSERT(output_shape);
MS_ASSERT(sparse_values);
MS_ASSERT(output_data);
CHECK_NULL_RETURN(sparse_indices_vect);
CHECK_NULL_RETURN(output_shape);
CHECK_NULL_RETURN(sparse_values);
CHECK_NULL_RETURN(output_data);
SparseToDense(sparse_indices_vect, output_shape, sparse_values, default_value, output_data, isScalar, index_start,
index_end, out_width);
return RET_OK;
@ -108,6 +110,7 @@ int SparseToDenseCPUKernel::GenerateIndices() {
}
index_dim = static_cast<int>(input0->shape().size());
int *sparse_indices = reinterpret_cast<int *>(input0->MutableData());
CHECK_NULL_RETURN(sparse_indices);
switch (index_dim) {
case 0:
case 1: {
@ -180,7 +183,7 @@ int SparseToDenseCPUKernel::Run() {
}
}
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;
ret = ParallelLaunch(this->ms_context_, SparseToDenseRun, this, s2d_param->thread_num_);
if (ret != RET_OK) {
@ -191,7 +194,7 @@ int SparseToDenseCPUKernel::Run() {
if (sparse_indices_vect != nullptr) {
for (int i = 0; i < index_num; i++) {
if (sparse_indices_vect[i] != nullptr) {
delete sparse_indices_vect[i];
delete[] sparse_indices_vect[i];
}
}
ctx_->allocator->Free(sparse_indices_vect);

View File

@ -27,6 +27,7 @@ namespace mindspore::kernel {
int UnstackCPUKernel::Init() {
CHECK_LESS_RETURN(in_tensors_.size(), 1);
CHECK_LESS_RETURN(out_tensors_.size(), 1);
CHECK_NULL_RETURN(op_parameter_);
if (!InferShapeDone()) {
return RET_OK;
}
@ -59,6 +60,10 @@ int UnstackCPUKernel::ReSize() {
free(output_addr_array_);
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()));
if (output_addr_array_ == nullptr) {
MS_LOG(ERROR) << "Failed to malloc memory";
@ -69,12 +74,12 @@ int UnstackCPUKernel::ReSize() {
int UnstackCPUKernel::Run() {
float *input = reinterpret_cast<float *>(in_tensors_.at(0)->MutableData());
MS_ASSERT(input);
CHECK_NULL_RETURN(input);
size_t out_num = out_tensors_.size();
for (size_t i = 0; i < out_num; i++) {
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_);
para->num_ = static_cast<int>(out_num);
Unstack(input, output_addr_array_, para, sizeof(float));

View File

@ -15,7 +15,6 @@
*/
#include "src/runtime/kernel/arm/fp32/where_fp32.h"
#include <vector>
#include <algorithm>
#include "schema/model_generated.h"
#include "nnacl/fp32/where_fp32.h"
#include "src/kernel_registry.h"
@ -47,11 +46,11 @@ int WhereCPUKernel::PreProcess() {
}
int WhereCPUKernel::DoExcute(int task_id) {
MS_ASSERT(condition_);
MS_ASSERT(x_);
MS_ASSERT(y_);
MS_ASSERT(output_data_);
MS_ASSERT(where_param_);
CHECK_NULL_RETURN(condition_);
CHECK_NULL_RETURN(x_);
CHECK_NULL_RETURN(y_);
CHECK_NULL_RETURN(output_data_);
CHECK_NULL_RETURN(where_param_);
WhereWithTripleInputs(condition_, x_, y_, output_data_, where_param_, task_id);
return RET_OK;
}
@ -70,15 +69,15 @@ int WhereCPUKernel::RunWithSingleInput() {
auto input = in_tensors_.at(0);
MS_ASSERT(input);
condition_ = reinterpret_cast<bool *>(input->data_c());
CHECK_NULL_RETURN(condition_);
where_param_->condition_num_ = input->ElementsNum();
where_param_->rank_ = static_cast<int>(input->shape().size());
int strides[8];
ComputeStrides(in_tensors_.at(0)->shape().data(), strides, where_param_->rank_);
auto data = ms_context_->allocator->Malloc(where_param_->condition_num_ * where_param_->rank_ *
static_cast<int>(sizeof(int32_t)));
if (data == nullptr) {
MS_LOG(ERROR) << "macllov data is error!";
MS_LOG(ERROR) << "malloc data is error!";
return RET_ERROR;
}
int *result = reinterpret_cast<int *>(data);
@ -107,6 +106,7 @@ int WhereCPUKernel::RunWithSingleInput() {
MS_LOG(ERROR) << "malloc out tensor failed.";
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)));
ms_context_->allocator->Free(data);
return RET_OK;

View File

@ -28,11 +28,21 @@ namespace mindspore::kernel {
int ConcatInt8CPUKernel::Init() {
concat_param_->input_shapes_ = nullptr;
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));
if (input_data_ == nullptr) {
MS_LOG(ERROR) << "Null pointer reference: inputs_array.";
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));
if (concat_param_->quant_arg_.in_args_ == nullptr) {
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();
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));
if (concat_param_->input_shapes_ == nullptr) {
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++) {
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)));
if (concat_param_->input_shapes_[i] == nullptr) {
MS_LOG(ERROR) << "malloc concat_param_->input_shapes_[" << i << "]"
@ -90,6 +108,10 @@ int ConcatInt8CPUKernel::ReSize() {
auto output_tensor = out_tensors_.at(kOutputIndex);
auto out_shape = output_tensor->shape();
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)));
if (concat_param_->output_shapes_ == nullptr) {
MS_LOG(ERROR) << "malloc concat_param_->output_shapes_ failed.";
@ -107,15 +129,17 @@ int ConcatInt8CPUKernel::ReSize() {
int ConcatInt8CPUKernel::Run() {
auto input_num = concat_param_->input_num_;
MS_CHECK_FALSE(op_parameter_->thread_num_ == 0, RET_ERROR);
count_unit_ =
op_parameter_->thread_num_ > 1 ? UP_DIV(before_axis_size, op_parameter_->thread_num_) : before_axis_size;
concat_param_->count_unit_ = count_unit_;
for (int i = 0; i < input_num; i++) {
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());
CHECK_NULL_RETURN(output_data_);
auto ret = ParallelLaunch(this->ms_context_, ConcatInt8Run, this, op_parameter_->thread_num_);
return ret;

View File

@ -18,6 +18,7 @@
#include <cfloat>
#include <cmath>
#include "src/kernel_registry.h"
#include "nnacl/op_base.h"
using mindspore::lite::RET_ERROR;
using mindspore::lite::RET_MEMORY_FAILED;
@ -112,6 +113,9 @@ int PadInt8CPUKernel::ReSize() {
int PadInt8CPUKernel::Init() {
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();
if (error_code != RET_OK) {
MS_LOG(ERROR) << "SetQuantParam failed. errorcode: " << error_code;
@ -124,10 +128,10 @@ int PadInt8CPUKernel::Init() {
}
int PadInt8CPUKernel::RunImpl(int task_id) {
MS_ASSERT(in_data_);
MS_ASSERT(out_data_);
MS_ASSERT(in_dims_);
MS_ASSERT(out_dims_);
CHECK_NULL_RETURN(in_data_);
CHECK_NULL_RETURN(out_data_);
CHECK_NULL_RETURN(in_dims_);
CHECK_NULL_RETURN(out_dims_);
return PadConstant4D(in_data_, out_data_, in_dims_, out_dims_, pad_param_->paddings_, task_id,
op_parameter_->thread_num_);
}
@ -159,6 +163,9 @@ int PadInt8CPUKernel::HandleMirrorPad() {
void PadInt8CPUKernel::CalculateStrides() {
pad_param_->in_strides[COMM_SHAPE_SIZE - 1] = 1;
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];
}
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;
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];
}
}
@ -189,10 +199,10 @@ int PadInt8CPUKernel::RunMirrorPadImpl(int task_id) {
auto output = out_tensors_.at(0);
MS_ASSERT(output);
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());
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 begin = unit * task_id;
int end = MSMIN(begin + unit, output->ElementsNum());
@ -263,8 +273,9 @@ int PadInt8CPUKernel::CopyPaddingFromInput() {
int PadInt8CPUKernel::Run() {
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());
CHECK_NULL_RETURN(out_data_);
int error_code;
if (pad_param_->pad_mode_ == static_cast<int>(schema::PaddingMode_CONSTANT)) {
memset(out_data_, pad_param_->pad_quant_arg_.constant_value_[0],

View File

@ -64,10 +64,10 @@ int PoolingInt8CPUKernel::ReSize() {
int PoolingInt8CPUKernel::RunImpl(int task_id) {
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());
MS_ASSERT(output_data);
MS_ASSERT(pooling_param_);
CHECK_NULL_RETURN(output_data);
CHECK_NULL_RETURN(pooling_param_);
if (pooling_param_->pool_mode_ == PoolMode_MaxPool) {
if (pooling_param_->quantize_) {
MaxPoolingWithQuantInt8(input_data, output_data, pooling_param_, task_id);

View File

@ -59,8 +59,14 @@ void ConcatGetWorkGroup(const std::vector<size_t> &global, std::vector<size_t> *
const int max_divider = 8;
const int max_x = 2, max_y = 8;
int x = std::min(GetMaxDivisorStrategy1(global[0], max_divider), max_x);
if (x == 0) {
return;
}
int yz = max_size / x;
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)));
local->clear();

View File

@ -55,6 +55,7 @@ int SparseToDenseOpenCLKernel::InitOutputToDefault() {
int SparseToDenseOpenCLKernel::InitWeights() {
auto allocator = ocl_runtime_->GetAllocator();
MS_CHECK_GE(in_tensors_.size(), 3, RET_ERROR);
auto weight_tensor = in_tensors_[2];
size_t size = 1;
for (int i = 0; i < weight_tensor->shape().size(); ++i) {
@ -177,6 +178,7 @@ void SparseToDenseOpenCLKernel::SetGlobalLocal() {
int SparseToDenseOpenCLKernel::Prepare() {
enable_fp16_ = ocl_runtime_->GetFp16Enable();
input_dim_ = in_tensors_[0]->shape().size();
MS_CHECK_GE(input_dim_, 2, RET_ERROR);
inshapeindex1_dim = in_tensors_[0]->shape()[1];
weight_scalar_ = in_tensors_[2]->IsScalar();
const std::string kernel_name = "SparseToDense" + std::string(weight_scalar_ ? "Scalar" : "Vector");