Browse Source

!21610 [MS][LITE]tile gather broad_cast infer bug

Merge pull request !21610 from mengyuanli/bugfix
tags/v1.5.0-rc1
i-robot Gitee 4 years ago
parent
commit
4884736d19
4 changed files with 25 additions and 19 deletions
  1. +6
    -4
      mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/base/gather_base.c
  2. +15
    -11
      mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/broadcast_to_infer.c
  3. +4
    -3
      mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/tile_infer.c
  4. +0
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/where_infer.c

+ 6
- 4
mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/base/gather_base.c View File

@@ -29,12 +29,14 @@ int Gather(const void *input, int outer_size, int inner_size, int limit, const i
int8_t *int8_out_m = int8_out + inner_size * m * indices_element_size * data_size;

for (int i = 0; i < indices_element_size; ++i) {
if (indices[i] < 0 || indices[i] >= limit) {
printf("[ERROR] [%s:%d] %s] indices[%d]:%d is out of range [%d, %d)\n", __FILE__, __LINE__, __func__, i,
indices[i], 0, limit);
int index = indices[i];
if (index < -limit || indices[i] >= limit) {
return NNACL_ERR;
}
memcpy(int8_out_m + i * inner_size * data_size, int8_in_m + indices[i] * inner_size * data_size,
if (indices[i] < 0) {
index = limit + indices[i];
}
memcpy(int8_out_m + i * inner_size * data_size, int8_in_m + index * inner_size * data_size,
data_size * inner_size);
}
}


+ 15
- 11
mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/broadcast_to_infer.c View File

@@ -62,6 +62,19 @@ int GetShapeByType(const TensorC *shape_tensor, size_t shape_size, int32_t *dst_
return NNACL_OK;
}

int CheckShape(const int *input_shape, const int *dst_shape, const int input_shape_index, const int dst_shape_index) {
if (dst_shape[dst_shape_index] < 0) {
return NNACL_ERR;
}
if (input_shape_index >= 0) {
int input_shape_i = input_shape[input_shape_index];
if (input_shape_i != dst_shape[dst_shape_index] && input_shape_i != 1 && dst_shape[dst_shape_index] != 1) {
return NNACL_ERR;
}
}
return NNACL_OK;
}

int BroadcastToInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
OpParameter *parameter) {
int ret = CheckAugmentNull(inputs, inputs_size, outputs, outputs_size, parameter);
@@ -112,21 +125,12 @@ int BroadcastToInferShape(const TensorC *const *inputs, size_t inputs_size, Tens
size_t input_shape_size = input->shape_size_;
int shape[MAX_SHAPE_SIZE];
int input_shape_index = (int)(input_shape_size)-1;
if (input_shape_size > dst_shape_size) {
return NNACL_ERR;
}

for (int i = (int)(dst_shape_size)-1; i >= 0; --i) {
if (dst_shape[i] < 0) {
if (CheckShape(input_shape, dst_shape, input_shape_index, i) != NNACL_OK) {
return NNACL_ERR;
}
if (input_shape_index >= 0) {
int dim = input_shape[input_shape_index];
if (dim != dst_shape[i] && dim != 1) {
return NNACL_ERR;
}
}
shape[i] = dst_shape[i];
shape[i] = dst_shape[i] == 1 ? input_shape[input_shape_index] : dst_shape[i];
--input_shape_index;
}
SetShapeArray(outputs[0], shape, dst_shape_size);


+ 4
- 3
mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/tile_infer.c View File

@@ -56,13 +56,14 @@ int TileInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **o
TileParameter *param = (TileParameter *)parameter;

size_t multiples_size = 0;
int data_num = GetElementNum(inputs[1]);
if (data_num > (int)(input->shape_size_) || input->shape_size_ > MAX_SHAPE_SIZE) {
int input1_shape_size = inputs[1]->shape_size_;
if (input1_shape_size > (int)(input->shape_size_) || input->shape_size_ > MAX_SHAPE_SIZE) {
return NNACL_INPUT_TENSOR_ERROR;
}
if (data_num > MAX_TILE_DIM_SIZE) {
if (input1_shape_size > MAX_TILE_DIM_SIZE) {
return NNACL_ERR;
}
int data_num = GetElementNum(inputs[1]);
multiples_size = (size_t)(data_num);
if (inputs[1]->data_type_ != kNumberTypeInt && inputs[1]->data_type_ != kNumberTypeInt32) {
return NNACL_INPUT_TENSOR_ERROR;


+ 0
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/infer/where_infer.c View File

@@ -71,7 +71,6 @@ int WhereInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **
temp += 1;
if (temp == input0->shape_size_) {
SetShapeTensor(output, input);
output->data_type_ = input->data_type_;
return NNACL_OK;
}
}


Loading…
Cancel
Save