| @@ -23,12 +23,17 @@ | |||
| #endif | |||
| typedef struct TransposeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int perm_[8]; | |||
| bool conjugate_; | |||
| int num_axes_; | |||
| // shape correlative | |||
| int strides_[8]; | |||
| int out_strides_[8]; | |||
| // other parameter | |||
| int num_axes_; | |||
| int data_size_; | |||
| } TransposeParameter; | |||
| @@ -19,10 +19,15 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct ROIPoolingParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int pooledW_; | |||
| int pooledH_; | |||
| float scale_; | |||
| // shape correlative | |||
| int in_strides_[DIMENSION_4D]; | |||
| int out_strides_[DIMENSION_4D]; | |||
| float scale_; | |||
| int ndim_; | |||
| int input_w_; | |||
| int input_h_; | |||
| @@ -32,9 +37,9 @@ typedef struct ROIPoolingParameter { | |||
| int output_h_; | |||
| int output_n_; | |||
| int output_c_; | |||
| // other parameter | |||
| int thread_num_; | |||
| int pooledW_; | |||
| int pooledH_; | |||
| } ROIPoolingParameter; | |||
| #ifdef __cplusplus | |||
| @@ -19,11 +19,12 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct { | |||
| typedef struct SkipGramParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int ngram_size; | |||
| int max_skip_size; | |||
| bool include_all_ngrams; | |||
| int max_skip_size; | |||
| int ngram_size; | |||
| } SkipGramParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_FP32_SKIP_GRAM_H_ | |||
| @@ -18,13 +18,18 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct SpaceToBatchParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| bool need_paddings_; | |||
| int block_sizes_[4]; | |||
| int paddings_[4]; | |||
| // shape correlative | |||
| int input_shape_[4]; | |||
| int output_shape_[4]; | |||
| int padded_in_shape_[4]; | |||
| // other parameter | |||
| bool need_paddings_; | |||
| int padded_input_element_num; | |||
| } SpaceToBatchParameter; | |||
| #ifdef __cplusplus | |||
| @@ -18,6 +18,7 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct SpaceToDepthParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int32_t block_size_; | |||
| } SpaceToDepthParameter; | |||
| @@ -20,13 +20,18 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct TileParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int in_dim_; | |||
| int multiples_[5]; | |||
| // shape correlative | |||
| int in_shape_[5]; | |||
| int out_shape_[5]; | |||
| int multiples_[5]; | |||
| int in_strides_[5]; | |||
| int out_strides_[5]; | |||
| // other parameter | |||
| int in_dim_; | |||
| } TileParameter; | |||
| #ifdef __cplusplus | |||
| @@ -25,11 +25,14 @@ typedef struct TopkNode { | |||
| } TopkNode; | |||
| typedef struct TopkParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int last_dim_size_; | |||
| int loop_num_; | |||
| int k_; | |||
| bool sorted_; | |||
| // other parameter | |||
| int last_dim_size_; | |||
| int loop_num_; | |||
| void *topk_node_list_; | |||
| } TopkParameter; | |||
| @@ -20,6 +20,7 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct UniqueParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| } UniqueParameter; | |||
| @@ -22,8 +22,11 @@ | |||
| #define UNSQUEEZE_DIMS_MAX_SIZE 4 | |||
| typedef struct UnsqueezeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int dims_[UNSQUEEZE_DIMS_MAX_SIZE]; | |||
| // other parameter | |||
| int num_dim_; | |||
| } UnsqueezeParameter; | |||
| @@ -20,13 +20,16 @@ | |||
| #define REDUCE_MAX_AXES_NUM 8 | |||
| typedef struct ReduceParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int axes_[REDUCE_MAX_AXES_NUM]; | |||
| bool keep_dims_; | |||
| int mode_; | |||
| bool reduce_to_end_; | |||
| float coeff; | |||
| int axes_[REDUCE_MAX_AXES_NUM]; | |||
| // other parameter | |||
| int num_axes_; | |||
| int mode_; | |||
| } ReduceParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_REDUCE_PARAMETER_H_ | |||
| @@ -21,7 +21,10 @@ | |||
| #include "nnacl/quantization/quantize.h" | |||
| typedef struct ReshapeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| // other parameter | |||
| ReshapeQuantArg quant_para_; | |||
| int thread_count_; | |||
| } ReshapeParameter; | |||
| @@ -18,6 +18,7 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct ResizeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int method_; | |||
| int64_t new_height_; | |||
| @@ -20,14 +20,19 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct ReverseSequenceParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int ndim_; | |||
| int seq_axis_; | |||
| int batch_axis_; | |||
| // shape correlative | |||
| int input_shape0_[5]; | |||
| int output_shape_[5]; | |||
| int input_stride_[5]; | |||
| int output_stride_[5]; | |||
| int seq_axis_; | |||
| int batch_axis_; | |||
| // other parameter | |||
| int ndim_; | |||
| int outer_count_; | |||
| int outer_stride_; | |||
| int inner_count_; | |||
| @@ -20,11 +20,17 @@ | |||
| #include <mindspore/lite/nnacl/quantization/quantize.h> | |||
| #include "nnacl/op_base.h" | |||
| typedef struct ScaleParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int axis_; | |||
| int activation_type_; | |||
| // shape correlative | |||
| int outer_size_; | |||
| int axis_size_; | |||
| int inner_size_; | |||
| int axis_; | |||
| // other parameter | |||
| bool const_scale_; | |||
| bool const_offset_; | |||
| QuantMulArg scale_mul_arg_; | |||
| @@ -33,7 +39,6 @@ typedef struct ScaleParameter { | |||
| int scale_zp_; | |||
| int offset_zp_; | |||
| int output_zp_; | |||
| int activation_type_; | |||
| int output_activation_min_; | |||
| int output_activation_max_; | |||
| } ScaleParameter; | |||
| @@ -20,6 +20,7 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct ScatterNDParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| } ScatterNDParameter; | |||
| @@ -20,6 +20,7 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct ShapeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| } ShapeParameter; | |||
| @@ -21,15 +21,20 @@ | |||
| #define SIGMOID_OFFSET_MAX_SIZE 4 | |||
| typedef struct SigmoidParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| // shape correlative | |||
| const int *in_shape_; | |||
| const int *out_shape_; | |||
| // other parameter | |||
| SigmoidQuantArg quant_arg; | |||
| double alpha_; | |||
| int thread_count_; | |||
| int64_t offset_[PRELU_OFFSET_MAX_SIZE]; | |||
| int64_t in_offset_[PRELU_OFFSET_MAX_SIZE]; | |||
| int64_t axis_; | |||
| const int *in_shape_; | |||
| const int *out_shape_; | |||
| int input_dim_; | |||
| int element_num; | |||
| } SigmoidParameter; | |||
| @@ -23,12 +23,17 @@ | |||
| #define SLICE_SHAPE_MAX_SIZE 4 | |||
| typedef struct SliceParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| SliceQuantArg quant_arg_; | |||
| // shape correlative | |||
| int32_t shape_[SLICE_SHAPE_MAX_SIZE]; | |||
| int32_t begin_[SLICE_SHAPE_MAX_SIZE]; | |||
| int32_t end_[SLICE_SHAPE_MAX_SIZE]; | |||
| int32_t size_[SLICE_SHAPE_MAX_SIZE]; | |||
| int32_t shape_[SLICE_SHAPE_MAX_SIZE]; | |||
| // other parameter | |||
| SliceQuantArg quant_arg_; | |||
| int32_t param_length_; | |||
| } SliceParameter; | |||
| @@ -20,11 +20,16 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct SoftmaxParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int32_t axis_; | |||
| // shape correlative | |||
| int input_shape_[5]; | |||
| // other parameter | |||
| int element_size_; | |||
| int n_dim_; | |||
| int input_shape_[5]; | |||
| } SoftmaxParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_SOFTMAX_PARAMETER_H_ | |||
| @@ -20,8 +20,11 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct SparseToDenseParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| bool validate_indices_; | |||
| // other parameter | |||
| int thread_num_; | |||
| } SparseToDenseParameter; | |||
| @@ -21,12 +21,17 @@ | |||
| #include "nnacl/quantization/quantize.h" | |||
| #define SPLIT_STRIDES_SIZE 32 | |||
| typedef struct SplitParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| SplitQuantArg quant_arg_; | |||
| int num_split_; | |||
| int split_sizes_[SPLIT_STRIDES_SIZE]; | |||
| int strides_[SPLIT_STRIDES_SIZE]; | |||
| int split_dim_; | |||
| // shape correlative | |||
| int strides_[SPLIT_STRIDES_SIZE]; | |||
| // other parameter | |||
| SplitQuantArg quant_arg_; | |||
| int n_dims_; | |||
| int split_count_; | |||
| } SplitParameter; | |||
| @@ -20,6 +20,7 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct SqueezeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int axes_[8]; | |||
| } SqueezeParameter; | |||
| @@ -22,17 +22,22 @@ | |||
| #define SQUEEZE_OFFSET_MAX_SIZE 4 | |||
| typedef struct SqueezeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| SqueezeQuantArg quant_arg; | |||
| int thread_count_; | |||
| int thread_id_; | |||
| int offset_size_; | |||
| int64_t offset_[SQUEEZE_OFFSET_MAX_SIZE]; | |||
| int64_t in_offset_[SQUEEZE_OFFSET_MAX_SIZE]; | |||
| int64_t axis_; | |||
| // shape correlative | |||
| const int *in_shape_; | |||
| const int *out_shape_; | |||
| int offset_size_; | |||
| int64_t offset_[SQUEEZE_OFFSET_MAX_SIZE]; | |||
| int64_t in_offset_[SQUEEZE_OFFSET_MAX_SIZE]; | |||
| int input_dim_; | |||
| // other parameter | |||
| SqueezeQuantArg quant_arg; | |||
| int thread_count_; | |||
| int thread_id_; | |||
| } SqueezeParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_SQUEEZE_PARAMETER_H_ | |||
| @@ -19,6 +19,7 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct StackParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int32_t axis_; | |||
| } StackParameter; | |||
| @@ -19,14 +19,19 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct StridedSliceParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int begins_[8]; | |||
| int ends_[8]; | |||
| int strides_[8]; | |||
| int isScale; | |||
| int num_axes_; | |||
| // shape correlative | |||
| int in_shape_length_; | |||
| int in_shape_[8]; | |||
| // other parameter | |||
| int num_axes_; | |||
| LiteDataType data_type; | |||
| } StridedSliceParameter; | |||
| @@ -22,12 +22,17 @@ | |||
| #define MAX_TRANSPOSE_DIM_SIZE 5 | |||
| typedef struct TransposeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int perm_[8]; | |||
| bool conjugate_; | |||
| int num_axes_; | |||
| // shape correlative | |||
| int strides_[8]; | |||
| int out_strides_[8]; | |||
| // other parameter | |||
| int num_axes_; | |||
| int data_size_; | |||
| } TransposeParameter; | |||
| @@ -22,17 +22,22 @@ | |||
| #define UNSQUEEZE_OFFSET_MAX_SIZE 4 | |||
| typedef struct UnSqueezeParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| UnSqueezeQuantArg quant_arg; | |||
| int thread_count_; | |||
| int thread_id_; | |||
| int offset_size_; | |||
| int64_t offset_[UNSQUEEZE_OFFSET_MAX_SIZE]; | |||
| int64_t in_offset_[UNSQUEEZE_OFFSET_MAX_SIZE]; | |||
| int64_t axis_; | |||
| // shape correlative | |||
| const int *in_shape_; | |||
| const int *out_shape_; | |||
| int input_dim_; | |||
| int64_t offset_[UNSQUEEZE_OFFSET_MAX_SIZE]; | |||
| int64_t in_offset_[UNSQUEEZE_OFFSET_MAX_SIZE]; | |||
| // other parameter | |||
| UnSqueezeQuantArg quant_arg; | |||
| int thread_count_; | |||
| int thread_id_; | |||
| int offset_size_; | |||
| } UnSqueezeParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_UNSQUEEZE_PARAMETER_H_ | |||
| @@ -20,9 +20,12 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct UnstackParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int num_; | |||
| int axis_; | |||
| // other parameter | |||
| int pre_dims_; | |||
| int axis_dim_; | |||
| int after_dims_; | |||
| @@ -19,7 +19,10 @@ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct WhereParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| // other parameter | |||
| int num_; | |||
| int num1_; | |||
| int num2_; | |||
| @@ -41,8 +41,8 @@ OpParameter *PopulateSliceParameter(const mindspore::lite::PrimitiveC *primitive | |||
| } | |||
| slice_param->param_length_ = static_cast<int32_t>(param_begin.size()); | |||
| for (int32_t i = 0; i < slice_param->param_length_; ++i) { | |||
| slice_param->begin_[i] = param_begin[i]; | |||
| slice_param->size_[i] = param_size[i]; | |||
| slice_param->begin_[i] = param_begin.at(i); | |||
| slice_param->size_[i] = param_size.at(i); | |||
| } | |||
| return reinterpret_cast<OpParameter *>(slice_param); | |||
| } | |||
| @@ -31,8 +31,16 @@ OpParameter *PopulateSpaceToBatchNDParameter(const mindspore::lite::PrimitiveC * | |||
| space_batch_param_nd->op_parameter_.type_ = primitive->Type(); | |||
| auto block_sizes = ((mindspore::lite::SpaceToBatchND *)primitive)->GetBlockShape(); | |||
| if (block_sizes.size() > std::numeric_limits<size_t>::max() / sizeof(int)) { | |||
| MS_LOG(ERROR) << "The value of block_sizes.size() is too big"; | |||
| return nullptr; | |||
| } | |||
| memcpy(space_batch_param_nd->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int)); | |||
| auto paddings = ((mindspore::lite::SpaceToBatchND *)primitive)->GetPaddings(); | |||
| if (paddings.size() > std::numeric_limits<size_t>::max() / sizeof(int)) { | |||
| MS_LOG(ERROR) << "The value of paddings.size() is too big"; | |||
| return nullptr; | |||
| } | |||
| memcpy(space_batch_param_nd->paddings_, (paddings.data()), paddings.size() * sizeof(int)); | |||
| return reinterpret_cast<OpParameter *>(space_batch_param_nd); | |||
| } | |||
| @@ -33,8 +33,16 @@ OpParameter *PopulateSpaceToBatchParameter(const mindspore::lite::PrimitiveC *pr | |||
| memset(space_batch_param, 0, sizeof(SpaceToBatchParameter)); | |||
| space_batch_param->op_parameter_.type_ = primitive->Type(); | |||
| auto block_sizes = ((mindspore::lite::SpaceToBatch *)primitive)->BlockSizes(); | |||
| if (block_sizes.size() > std::numeric_limits<size_t>::max() / sizeof(int)) { | |||
| MS_LOG(ERROR) << "The value of block_sizes.size() is too big"; | |||
| return nullptr; | |||
| } | |||
| memcpy(space_batch_param->block_sizes_, (block_sizes.data()), block_sizes.size() * sizeof(int)); | |||
| auto paddings = ((mindspore::lite::SpaceToBatch *)primitive)->Paddings(); | |||
| if (paddings.size() > std::numeric_limits<size_t>::max() / sizeof(int)) { | |||
| MS_LOG(ERROR) << "The value of paddings.size() is too big"; | |||
| return nullptr; | |||
| } | |||
| memcpy(space_batch_param->paddings_, (paddings.data()), paddings.size() * sizeof(int)); | |||
| return reinterpret_cast<OpParameter *>(space_batch_param); | |||
| } | |||
| @@ -34,12 +34,28 @@ OpParameter *PopulateStridedSliceParameter(const mindspore::lite::PrimitiveC *pr | |||
| auto n_dims = ((lite::StridedSlice *)primitive)->NDims(); | |||
| strided_slice_param->num_axes_ = n_dims; | |||
| auto begin = ((lite::StridedSlice *)primitive)->GetBegins(); | |||
| if (begin.size() > std::numeric_limits<size_t>::max() / sizeof(int)) { | |||
| MS_LOG(ERROR) << "The value of begin.size() is too big"; | |||
| return nullptr; | |||
| } | |||
| memcpy(strided_slice_param->begins_, (begin.data()), begin.size() * sizeof(int)); | |||
| auto end = ((lite::StridedSlice *)primitive)->GetEnds(); | |||
| if (end.size() > std::numeric_limits<size_t>::max() / sizeof(int)) { | |||
| MS_LOG(ERROR) << "The value of end.size() is too big"; | |||
| return nullptr; | |||
| } | |||
| memcpy(strided_slice_param->ends_, (end.data()), end.size() * sizeof(int)); | |||
| auto stride = ((lite::StridedSlice *)primitive)->GetStrides(); | |||
| if (stride.size() > std::numeric_limits<size_t>::max() / sizeof(int)) { | |||
| MS_LOG(ERROR) << "The value of stride.size() is too big"; | |||
| return nullptr; | |||
| } | |||
| memcpy(strided_slice_param->strides_, (stride.data()), stride.size() * sizeof(int)); | |||
| auto in_shape = ((lite::StridedSlice *)primitive)->GetInShape(); | |||
| if (in_shape.size() > std::numeric_limits<size_t>::max() / sizeof(int)) { | |||
| MS_LOG(ERROR) << "The value of in_shape.size() is too big"; | |||
| return nullptr; | |||
| } | |||
| memcpy(strided_slice_param->in_shape_, (in_shape.data()), in_shape.size() * sizeof(int)); | |||
| return reinterpret_cast<OpParameter *>(strided_slice_param); | |||
| } | |||
| @@ -71,7 +71,7 @@ int Reduce::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inp | |||
| attr->keepDims = GetValue<bool>(prim.GetAttr("keep_dims")); | |||
| if (inputs.size() == kAnfPopulaterInputNumTwo) { | |||
| auto inputNode = inputs[kAnfPopulaterInputNumOne]; | |||
| auto inputNode = inputs.at(kAnfPopulaterInputNumOne); | |||
| MS_ASSERT(inputNode != nullptr); | |||
| if (inputNode->isa<ValueNode>()) { | |||
| auto valueNode = inputNode->cast<ValueNodePtr>(); | |||
| @@ -173,7 +173,7 @@ int Reduce::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outp | |||
| } | |||
| int begin_axis; | |||
| begin_axis = axes[0] < 0 ? axes[0] + rank : axes[0]; | |||
| begin_axis = axes.at(0) < 0 ? axes.at(0) + rank : axes.at(0); | |||
| for (auto i = begin_axis + 1; i < rank; ++i) { | |||
| actual_axes.emplace_back(i); | |||
| } | |||
| @@ -195,7 +195,8 @@ int Reduce::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outp | |||
| for (size_t i = 0; i < in_shape.size(); i++) { | |||
| bool reduce_axis = false; | |||
| for (size_t idx = 0; idx < num_axes; ++idx) { | |||
| if (static_cast<size_t>(actual_axes[idx]) == i || static_cast<size_t>(actual_axes[idx] + in_shape.size()) == i) { | |||
| if (static_cast<size_t>(actual_axes.at(idx)) == i || | |||
| static_cast<size_t>(actual_axes.at(idx) + in_shape.size()) == i) { | |||
| reduce_axis = true; | |||
| break; | |||
| } | |||
| @@ -205,7 +206,7 @@ int Reduce::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outp | |||
| out_shape.push_back(1); | |||
| } | |||
| } else { | |||
| out_shape.push_back(in_shape[i]); | |||
| out_shape.push_back(in_shape.at(i)); | |||
| } | |||
| } | |||
| output->set_shape(out_shape); | |||
| @@ -48,7 +48,7 @@ int Reshape::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &in | |||
| if (this->primitive_->value.value == nullptr) { | |||
| auto attr = new (std::nothrow) schema::ReshapeT(); | |||
| MS_ASSERT(inputs.size() == kAnfPopulaterInputNumThree - 1); | |||
| auto inputNode = inputs[kAnfPopulaterInputNumTwo - 1]; | |||
| auto inputNode = inputs.at(kAnfPopulaterInputNumTwo - 1); | |||
| if (inputNode->isa<ValueNode>()) { | |||
| auto valueNode = inputNode->cast<ValueNodePtr>(); | |||
| MS_ASSERT(valueNode != nullptr); | |||
| @@ -58,7 +58,7 @@ int Reshape::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &in | |||
| auto tuple = val->cast<ValueTuplePtr>(); | |||
| MS_ASSERT(tuple != nullptr); | |||
| for (size_t i = 0; i < tuple->size(); ++i) { | |||
| auto elem = tuple->value()[i]->cast<Int32ImmPtr>(); | |||
| auto elem = tuple->value().at(i)->cast<Int32ImmPtr>(); | |||
| MS_ASSERT(elem != nullptr); | |||
| attr->shape.emplace_back(static_cast<int>(elem->value())); | |||
| } | |||
| @@ -114,7 +114,7 @@ Registry ReshapeRegistry(schema::PrimitiveType_Reshape, ReshapeCreator); | |||
| int Reshape::CalNewShape(const Tensor *in_tensor, std::vector<int> *out_shape) const { | |||
| size_t in_shape_size = 1; | |||
| for (size_t i = 0; i < in_tensor->shape().size(); i++) { | |||
| in_shape_size *= in_tensor->shape()[i]; | |||
| in_shape_size *= in_tensor->shape().at(i); | |||
| } | |||
| int64_t inferIndex = -1; | |||
| size_t out_shapeSize = 1; | |||
| @@ -154,14 +154,14 @@ void CalShape(const T *data, const std::vector<Tensor *> &inputs, std::vector<in | |||
| if (static_cast<int>(data[i]) == -1) { | |||
| index = i; | |||
| } else if (static_cast<int>(data[i]) == 0) { | |||
| size *= inputs[0]->shape()[i]; | |||
| size *= inputs[0]->shape().at(i); | |||
| } else { | |||
| size *= data[i]; | |||
| } | |||
| out_shape->push_back(data[i]); | |||
| } | |||
| if (static_cast<int>(data[index]) == -1) { | |||
| (*out_shape)[index] = input_count / size; | |||
| (*out_shape).at(index) = input_count / size; | |||
| } | |||
| } | |||
| int Reshape::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outputs_) { | |||
| @@ -213,7 +213,7 @@ int Reshape::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> out | |||
| } | |||
| } else if (inputs_.size() == kSingleNum) { | |||
| for (size_t i = 0; i < GetShape().size(); ++i) { | |||
| out_shape.push_back(GetShape()[i]); | |||
| out_shape.push_back(GetShape().at(i)); | |||
| } | |||
| } else { | |||
| MS_LOG(ERROR) << "inputs tensor size invalid."; | |||
| @@ -68,8 +68,8 @@ int Resize::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inp | |||
| return RET_ERROR; | |||
| } | |||
| std::vector<int> targetSize = GetValue<std::vector<int>>(prim.GetAttr("size")); | |||
| attr->newHeight = targetSize[0]; | |||
| attr->newWidth = targetSize[1]; | |||
| attr->newHeight = targetSize.at(0); | |||
| attr->newWidth = targetSize.at(1); | |||
| attr->alignCorners = GetValue<bool>(prim.GetAttr("align_corners")); | |||
| this->primitive_->value.value = attr; | |||
| @@ -57,7 +57,7 @@ int Rfft::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> output | |||
| return RET_OK; | |||
| } | |||
| auto input_shape = input->shape(); | |||
| input_shape[input_shape.size() - 1] = GetFftLength() / 2 + 1; | |||
| input_shape.at(input_shape.size() - 1) = GetFftLength() / 2 + 1; | |||
| input_shape.push_back(2); | |||
| outputs_.front()->set_shape(input_shape); | |||
| return RET_OK; | |||
| @@ -86,16 +86,17 @@ int Sgd::InferShape(std::vector<lite::Tensor *> inputs, std::vector<lite::Tensor | |||
| return RET_ERROR; | |||
| } | |||
| if (inputs[0]->ElementsNum() != inputs[1]->ElementsNum() || inputs[0]->ElementsNum() != inputs[3]->ElementsNum() || | |||
| inputs[2]->ElementsNum() != 1 || inputs[4]->ElementsNum() != 1) { | |||
| if (inputs.at(0)->ElementsNum() != inputs.at(1)->ElementsNum() || | |||
| inputs.at(0)->ElementsNum() != inputs.at(3)->ElementsNum() || inputs.at(2)->ElementsNum() != 1 || | |||
| inputs.at(4)->ElementsNum() != 1) { | |||
| MS_LOG(ERROR) << "error input data size!"; | |||
| return RET_ERROR; | |||
| } | |||
| if (!outputs.empty()) { | |||
| auto *out = outputs.front(); | |||
| MS_ASSERT(out != nullptr); | |||
| out->set_data_type(inputs[0]->data_type()); | |||
| out->set_format(inputs[0]->format()); | |||
| out->set_data_type(inputs.at(0)->data_type()); | |||
| out->set_format(inputs.at(0)->format()); | |||
| out->set_shape({1}); | |||
| } | |||
| @@ -77,7 +77,7 @@ int Slice::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> &inpu | |||
| } | |||
| } | |||
| } | |||
| auto sizeNode = inputs[kAnfPopulaterInputNumTwo]; | |||
| auto sizeNode = inputs.at(kAnfPopulaterInputNumTwo); | |||
| MS_ASSERT(sizeNode != nullptr); | |||
| if (sizeNode->isa<ValueNode>()) { | |||
| auto valueNode = sizeNode->cast<ValueNodePtr>(); | |||
| @@ -172,8 +172,8 @@ int Slice::InferShape(std::vector<lite::Tensor *> inputs, std::vector<lite::Tens | |||
| return RET_PARAM_INVALID; | |||
| } | |||
| auto input = inputs.at(0); | |||
| outputs[0]->set_data_type(input->data_type()); | |||
| outputs[0]->set_format(input->format()); | |||
| outputs.at(0)->set_data_type(input->data_type()); | |||
| outputs.at(0)->set_format(input->format()); | |||
| if (!infer_flag()) { | |||
| return RET_OK; | |||
| } | |||
| @@ -191,7 +191,7 @@ int Slice::InferShape(std::vector<lite::Tensor *> inputs, std::vector<lite::Tens | |||
| if (slice_size.empty() && inputs.at(2)->data_c() != nullptr) { | |||
| for (int i = 0; i < inputs.at(2)->ElementsNum(); i++) { | |||
| auto end = static_cast<int *>(inputs.at(2)->data_c())[i]; | |||
| auto size = end < 0 ? end : (end == INT32_MAX ? -1 : end - slice_begin[i]); | |||
| auto size = end < 0 ? end : (end == INT32_MAX ? -1 : end - slice_begin.at(i)); | |||
| slice_size.emplace_back(size); | |||
| } | |||
| } | |||
| @@ -208,32 +208,32 @@ int Slice::InferShape(std::vector<lite::Tensor *> inputs, std::vector<lite::Tens | |||
| begin.assign(input_shape.size(), 0); | |||
| size.assign(input_shape.size(), -1); | |||
| for (size_t i = 0; i < slice_axes.size(); ++i) { | |||
| begin[slice_axes[i]] = slice_begin[i]; | |||
| size[slice_axes[i]] = slice_size[i]; | |||
| begin.at(slice_axes.at(i)) = slice_begin.at(i); | |||
| size.at(slice_axes.at(i)) = slice_size.at(i); | |||
| } | |||
| for (size_t i = 0; i < input_shape.size(); ++i) { | |||
| if (size[i] < 0 && size[i] != -1) { | |||
| MS_LOG(ERROR) << "Invalid size input!size[" << i << "]=" << size[i]; | |||
| if (size.at(i) < 0 && size.at(i) != -1) { | |||
| MS_LOG(ERROR) << "Invalid size input!size[" << i << "]=" << size.at(i); | |||
| return RET_PARAM_INVALID; | |||
| } | |||
| if (begin[i] < 0) { | |||
| MS_LOG(ERROR) << "Invalid begin input " << begin[i] << " which should be >= 0"; | |||
| if (begin.at(i) < 0) { | |||
| MS_LOG(ERROR) << "Invalid begin input " << begin.at(i) << " which should be >= 0"; | |||
| return RET_PARAM_INVALID; | |||
| } | |||
| if (input_shape[i] <= begin[i]) { | |||
| MS_LOG(ERROR) << "Invalid begin input!begin[" << i << "]=" << begin[i] | |||
| << " which should be <= " << input_shape[i]; | |||
| if (input_shape.at(i) <= begin.at(i)) { | |||
| MS_LOG(ERROR) << "Invalid begin input!begin[" << i << "]=" << begin.at(i) | |||
| << " which should be <= " << input_shape.at(i); | |||
| return RET_PARAM_INVALID; | |||
| } | |||
| if (size[i] > (input_shape[i] - begin[i])) { | |||
| MS_LOG(ERROR) << "Invalid size input " << size[i] << " which should be <= " << input_shape[i] - begin[i]; | |||
| if (size.at(i) > (input_shape.at(i) - begin.at(i))) { | |||
| MS_LOG(ERROR) << "Invalid size input " << size.at(i) << " which should be <= " << input_shape.at(i) - begin.at(i); | |||
| return RET_PARAM_INVALID; | |||
| } | |||
| output_shape[i] = size[i] < 0 ? input_shape[i] - begin[i] : size[i]; | |||
| output_shape.at(i) = size.at(i) < 0 ? input_shape.at(i) - begin.at(i) : size.at(i); | |||
| } | |||
| outputs[0]->set_shape(output_shape); | |||
| outputs.at(0)->set_shape(output_shape); | |||
| return RET_OK; | |||
| } | |||
| } // namespace lite | |||
| @@ -98,8 +98,8 @@ int SpaceToBatchND::InferShape(std::vector<lite::Tensor *> inputs, std::vector<l | |||
| MS_LOG(ERROR) << "space_to_batch_nd only support NHWC now!"; | |||
| return RET_ERROR; | |||
| } | |||
| outputs[0]->set_data_type(input->data_type()); | |||
| outputs[0]->set_format(input->format()); | |||
| outputs.at(0)->set_data_type(input->data_type()); | |||
| outputs.at(0)->set_format(input->format()); | |||
| if (!infer_flag()) { | |||
| return RET_OK; | |||
| } | |||
| @@ -120,11 +120,11 @@ int SpaceToBatchND::InferShape(std::vector<lite::Tensor *> inputs, std::vector<l | |||
| } | |||
| std::vector<int32_t> output_shape(input_shape.size()); | |||
| output_shape[NHWC_N] = input_shape[NHWC_N] * block_shape[0] * block_shape[1]; | |||
| output_shape[NHWC_H] = (input_shape[NHWC_H] + pedding[0] + pedding[1]) / block_shape[0]; | |||
| output_shape[NHWC_W] = (input_shape[NHWC_W] + pedding[2] + pedding[3]) / block_shape[1]; | |||
| output_shape[NHWC_C] = input_shape[NHWC_C]; | |||
| outputs[0]->set_shape(output_shape); | |||
| output_shape.at(NHWC_N) = input_shape.at(NHWC_N) * block_shape.at(0) * block_shape.at(1); | |||
| output_shape.at(NHWC_H) = (input_shape.at(NHWC_H) + pedding.at(0) + pedding.at(1)) / block_shape.at(0); | |||
| output_shape.at(NHWC_W) = (input_shape.at(NHWC_W) + pedding.at(2) + pedding.at(3)) / block_shape.at(1); | |||
| output_shape.at(NHWC_C) = input_shape.at(NHWC_C); | |||
| outputs.at(0)->set_shape(output_shape); | |||
| return RET_OK; | |||
| } | |||
| } // namespace lite | |||
| @@ -71,8 +71,8 @@ int SpaceToDepth::InferShape(std::vector<lite::Tensor *> inputs, std::vector<lit | |||
| MS_LOG(ERROR) << "space_to_depth only support NHWC now!"; | |||
| return 1; | |||
| } | |||
| outputs[0]->set_format(input->format()); | |||
| outputs[0]->set_data_type(input->data_type()); | |||
| outputs.at(0)->set_format(input->format()); | |||
| outputs.at(0)->set_data_type(input->data_type()); | |||
| if (!infer_flag()) { | |||
| return RET_OK; | |||
| } | |||
| @@ -83,17 +83,21 @@ int SpaceToDepth::InferShape(std::vector<lite::Tensor *> inputs, std::vector<lit | |||
| } | |||
| int32_t block_size = GetBlockSize(); | |||
| if (input_shape[NHWC_H] % block_size != 0 || input_shape[NHWC_H] == 0 || input_shape[NHWC_W] % block_size != 0 || | |||
| input_shape[NHWC_W] == 0) { | |||
| if (input_shape.at(NHWC_H) % block_size != 0 || input_shape.at(NHWC_H) == 0 || | |||
| input_shape.at(NHWC_W) % block_size != 0 || input_shape.at(NHWC_W) == 0) { | |||
| MS_LOG(ERROR) << "input dimension h or w size error!"; | |||
| return 1; | |||
| } | |||
| std::vector<int32_t> output_shape(input_shape.size()); | |||
| output_shape[NHWC_N] = input_shape[NHWC_N]; | |||
| output_shape[NHWC_H] = input_shape[NHWC_H] / block_size; | |||
| output_shape[NHWC_W] = input_shape[NHWC_W] / block_size; | |||
| output_shape[NHWC_C] = input_shape[NHWC_C] * (block_size * block_size); | |||
| outputs[0]->set_shape(output_shape); | |||
| output_shape.at(NHWC_N) = input_shape.at(NHWC_N); | |||
| output_shape.at(NHWC_H) = input_shape.at(NHWC_H) / block_size; | |||
| output_shape.at(NHWC_W) = input_shape.at(NHWC_W) / block_size; | |||
| if (block_size * block_size > std::numeric_limits<int32_t>::max() / input_shape.at(NHWC_C)) { | |||
| MS_LOG(ERROR) << "The value of block_size * block_size is too big"; | |||
| return RET_ERROR; | |||
| } | |||
| output_shape.at(NHWC_C) = input_shape.at(NHWC_C) * (block_size * block_size); | |||
| outputs.at(0)->set_shape(output_shape); | |||
| return RET_OK; | |||
| } | |||
| } // namespace lite | |||
| @@ -61,8 +61,8 @@ int SparseToDense::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor | |||
| return RET_ERROR; | |||
| } | |||
| auto input2 = inputs_.at(2); | |||
| outputs_[0]->set_data_type(input2->data_type()); | |||
| outputs_[0]->set_format(input2->format()); | |||
| outputs_.at(0)->set_data_type(input2->data_type()); | |||
| outputs_.at(0)->set_format(input2->format()); | |||
| if (!infer_flag()) { | |||
| return RET_OK; | |||
| @@ -77,7 +77,7 @@ int SparseToDense::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor | |||
| for (int i = 0; i < input1->ElementsNum(); i++) { | |||
| output_shape.push_back(input1_data[i]); | |||
| } | |||
| outputs_[0]->set_shape(output_shape); | |||
| outputs_.at(0)->set_shape(output_shape); | |||
| return RET_OK; | |||
| } | |||
| } // namespace lite | |||
| @@ -120,8 +120,8 @@ int Split::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outpu | |||
| return RET_ERROR; | |||
| } | |||
| for (int i = 0; i < number_split; ++i) { | |||
| outputs_[i]->set_data_type(input->data_type()); | |||
| outputs_[i]->set_format(input->format()); | |||
| outputs_.at(i)->set_data_type(input->data_type()); | |||
| outputs_.at(i)->set_format(input->format()); | |||
| } | |||
| if (!infer_flag()) { | |||
| return RET_OK; | |||
| @@ -130,26 +130,26 @@ int Split::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outpu | |||
| std::vector<int> input_shape = input->shape(); | |||
| std::vector<int> size_split; | |||
| for (size_t i = 0; i < GetSizeSplits().size(); ++i) { | |||
| size_split.push_back(GetSizeSplits()[i]); | |||
| size_split.push_back(GetSizeSplits().at(i)); | |||
| } | |||
| for (int i = 0; i < number_split; ++i) { | |||
| std::vector<int> output_shape; | |||
| output_shape.insert(output_shape.begin(), input_shape.begin(), input_shape.end()); | |||
| int split_dim_i = input_shape[split_dim]; | |||
| int split_dim_i = input_shape.at(split_dim); | |||
| // support split size is -1 in the end. | |||
| if (size_split.empty()) { | |||
| split_dim_i = input_shape[split_dim] / number_split; | |||
| } else if (i == number_split - 1 && size_split[i] == -1) { | |||
| split_dim_i = input_shape.at(split_dim) / number_split; | |||
| } else if (i == number_split - 1 && size_split.at(i) == -1) { | |||
| for (size_t j = 0; j < size_split.size() - 1; ++j) { | |||
| split_dim_i -= size_split[j]; | |||
| split_dim_i -= size_split.at(j); | |||
| } | |||
| } else { | |||
| split_dim_i = size_split[i]; | |||
| split_dim_i = size_split.at(i); | |||
| } | |||
| output_shape[split_dim] = split_dim_i; | |||
| outputs_[i]->set_shape(output_shape); | |||
| outputs_[i]->set_data_type(input->data_type()); | |||
| outputs_[i]->set_format(input->format()); | |||
| output_shape.at(split_dim) = split_dim_i; | |||
| outputs_.at(i)->set_shape(output_shape); | |||
| outputs_.at(i)->set_data_type(input->data_type()); | |||
| outputs_.at(i)->set_format(input->format()); | |||
| } | |||
| return RET_OK; | |||
| } | |||
| @@ -118,19 +118,19 @@ int Squeeze::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> out | |||
| } | |||
| if (axes_.size() == 0) { | |||
| for (size_t i = 0; i < in_shape.size(); i++) { | |||
| if (in_shape[i] != 1) { | |||
| out_shape.push_back(in_shape[i]); | |||
| if (in_shape.at(i) != 1) { | |||
| out_shape.push_back(in_shape.at(i)); | |||
| } | |||
| } | |||
| } else { | |||
| size_t axisIdx = 0; | |||
| for (size_t i = 0; i < in_shape.size(); i++) { | |||
| if (axisIdx < axes_.size() && axes_[axisIdx] == static_cast<int>(i)) { | |||
| MS_ASSERT(in_shape[i] == 1); | |||
| if (axisIdx < axes_.size() && axes_.at(axisIdx) == static_cast<int>(i)) { | |||
| MS_ASSERT(in_shape.at(i) == 1); | |||
| axisIdx++; | |||
| continue; | |||
| } else { | |||
| out_shape.push_back(in_shape[i]); | |||
| out_shape.push_back(in_shape.at(i)); | |||
| } | |||
| } | |||
| } | |||
| @@ -80,8 +80,8 @@ int Stack::InferShape(std::vector<Tensor *> inputs, std::vector<Tensor *> output | |||
| } | |||
| auto input = inputs.at(0); | |||
| auto input0_data_type = input->data_type(); | |||
| outputs[0]->set_data_type(input0_data_type); | |||
| outputs[0]->set_format(input->format()); | |||
| outputs.at(0)->set_data_type(input0_data_type); | |||
| outputs.at(0)->set_format(input->format()); | |||
| if (!infer_flag()) { | |||
| return RET_OK; | |||
| } | |||
| @@ -95,25 +95,25 @@ int Stack::InferShape(std::vector<Tensor *> inputs, std::vector<Tensor *> output | |||
| } | |||
| for (size_t i = 1; i < inputs.size(); ++i) { | |||
| auto input_shape_tmp = inputs[i]->shape(); | |||
| auto input_shape_tmp = inputs.at(i)->shape(); | |||
| if (input_shape_tmp.size() != input_shape.size()) { | |||
| MS_LOG(ERROR) << "All input shape size should be the same!"; | |||
| return RET_PARAM_INVALID; | |||
| } | |||
| for (size_t j = 0; j < input_shape.size(); ++j) { | |||
| if (input_shape_tmp[j] != input_shape[j]) { | |||
| if (input_shape_tmp.at(j) != input_shape.at(j)) { | |||
| MS_LOG(ERROR) << "All input shape should be the same!"; | |||
| return RET_PARAM_INVALID; | |||
| } | |||
| } | |||
| if (inputs[i]->data_type() != input0_data_type) { | |||
| if (inputs.at(i)->data_type() != input0_data_type) { | |||
| MS_LOG(ERROR) << "All input shuld have the same data type!input[" << i | |||
| << "] data type = " << inputs[i]->data_type(); | |||
| << "] data type = " << inputs.at(i)->data_type(); | |||
| return RET_PARAM_INVALID; | |||
| } | |||
| } | |||
| output_shape.insert(output_shape.begin() + axis, inputs.size()); | |||
| outputs[0]->set_shape(output_shape); | |||
| outputs.at(0)->set_shape(output_shape); | |||
| return RET_OK; | |||
| } | |||
| } // namespace lite | |||
| @@ -263,7 +263,7 @@ int StridedSlice::InferShape(std::vector<lite::Tensor *> inputs, std::vector<lit | |||
| } | |||
| auto input = inputs.at(0); | |||
| outputs.front()->set_data_type(input->data_type()); | |||
| outputs[0]->set_format(input->format()); | |||
| outputs.at(0)->set_format(input->format()); | |||
| MS_ASSERT(input != nullptr); | |||
| auto input_shape = input->shape(); | |||
| auto inferflag = infer_flag(); | |||
| @@ -275,9 +275,9 @@ int StridedSlice::InferShape(std::vector<lite::Tensor *> inputs, std::vector<lit | |||
| if (inferflag) { | |||
| in_shape_.emplace_back(input_shape.at(i)); | |||
| } | |||
| begins_.emplace_back((GetBegin())[i]); | |||
| ends_.emplace_back((GetEnd())[i]); | |||
| strides_.emplace_back((GetStride())[i]); | |||
| begins_.emplace_back((GetBegin()).at(i)); | |||
| ends_.emplace_back((GetEnd()).at(i)); | |||
| strides_.emplace_back((GetStride()).at(i)); | |||
| } | |||
| } else { | |||
| auto begin_tensor = inputs.at(1); | |||
| @@ -73,9 +73,9 @@ int TopK::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> output | |||
| } | |||
| MS_ASSERT(topk_prim != nullptr); | |||
| auto out_shape = input->shape(); | |||
| out_shape[out_shape.size() - 1] = GetK(); | |||
| out_shape.at(out_shape.size() - 1) = GetK(); | |||
| if (inputs_.size() == kDoubleNum && inputs_.at(1)->data_c() != nullptr) { | |||
| out_shape[out_shape.size() - 1] = reinterpret_cast<int *>(inputs_.at(1)->data_c())[0]; | |||
| out_shape.at(out_shape.size() - 1) = reinterpret_cast<int *>(inputs_.at(1)->data_c())[0]; | |||
| } | |||
| output0->set_shape(out_shape); | |||
| output1->set_shape(out_shape); | |||
| @@ -62,7 +62,7 @@ int Transpose::UnPackAttr(const Primitive &prim, const std::vector<AnfNodePtr> & | |||
| auto tuple = val->cast<ValueTuplePtr>(); | |||
| MS_ASSERT(tuple != nullptr); | |||
| for (size_t i = 0; i < tuple->size(); i++) { | |||
| auto elem = tuple->value()[i]->cast<Int32ImmPtr>(); | |||
| auto elem = tuple->value().at(i)->cast<Int32ImmPtr>(); | |||
| MS_ASSERT(elem != nullptr); | |||
| attr->perm.emplace_back(static_cast<int>(elem->value())); | |||
| } | |||
| @@ -134,13 +134,13 @@ int Transpose::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> o | |||
| } | |||
| std::vector<int> perm; | |||
| for (size_t i = 0; i < GetPerm().size(); i++) { | |||
| perm.push_back(GetPerm()[i]); | |||
| perm.push_back(GetPerm().at(i)); | |||
| } | |||
| std::vector<int> in_shape = input->shape(); | |||
| std::vector<int> out_shape; | |||
| out_shape.resize(perm.size()); | |||
| for (size_t i = 0; i < perm.size(); ++i) { | |||
| out_shape[i] = in_shape[perm[i]]; | |||
| out_shape.at(i) = in_shape.at(perm.at(i)); | |||
| } | |||
| output->set_shape(out_shape); | |||
| return RET_OK; | |||
| @@ -46,8 +46,8 @@ int UnsortedSegmentSum::UnPackAttr(const Primitive &prim, const std::vector<AnfN | |||
| } | |||
| if (this->primitive_->value.value == nullptr) { | |||
| std::unique_ptr<schema::UnsortedSegmentSumT> attr = std::make_unique<schema::UnsortedSegmentSumT>(); | |||
| if (inputs[2]->isa<ValueNode>()) { | |||
| ValuePtr value = inputs[2]->cast<ValueNodePtr>()->value(); | |||
| if (inputs.at(2)->isa<ValueNode>()) { | |||
| ValuePtr value = inputs.at(2)->cast<ValueNodePtr>()->value(); | |||
| attr->numSegments = GetValue<int>(value); | |||
| this->primitive_->value.value = attr.release(); | |||
| } | |||
| @@ -92,14 +92,14 @@ int UnsortedSegmentSum::InferShape(std::vector<Tensor *> inputs_, std::vector<Te | |||
| } | |||
| Tensor *out = outputs_.front(); | |||
| Tensor *x = inputs_.front(); | |||
| Tensor *segment_id = inputs_[1]; | |||
| Tensor *segment_id = inputs_.at(1); | |||
| std::vector<int> x_shape = x->shape(); | |||
| std::vector<int> segment_id_shape = segment_id->shape(); | |||
| int num_segments = GetNumSegments(); | |||
| std::vector<int> output_shape; | |||
| output_shape.push_back(num_segments); | |||
| for (int index = segment_id_shape.size(); index < static_cast<int>(x_shape.size()); index++) { | |||
| output_shape.push_back(x_shape[index]); | |||
| output_shape.push_back(x_shape.at(index)); | |||
| } | |||
| out->set_shape(output_shape); | |||
| out->set_format(x->format()); | |||
| @@ -97,14 +97,14 @@ int Unsqueeze::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> o | |||
| size_t in_itr = 0; | |||
| size_t ax_itr = 0; | |||
| for (size_t i = 0; i < sz; i++) { | |||
| if (ax_itr < dim_rank && dims[ax_itr] == static_cast<int>(i)) { | |||
| if (ax_itr < dim_rank && dims.at(ax_itr) == static_cast<int>(i)) { | |||
| out_shape.emplace_back(1); | |||
| ax_itr++; | |||
| } else if (ax_itr < dim_rank && dims[ax_itr] + sz == i) { | |||
| } else if (ax_itr < dim_rank && dims.at(ax_itr) + sz == i) { | |||
| out_shape.emplace_back(1); | |||
| ax_itr++; | |||
| } else { | |||
| out_shape.emplace_back(in_shape[in_itr]); | |||
| out_shape.emplace_back(in_shape.at(in_itr)); | |||
| in_itr++; | |||
| } | |||
| } | |||
| @@ -93,28 +93,28 @@ int Where::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outpu | |||
| int axisout = 0; | |||
| size_t temp = 0; | |||
| for (size_t j = 0; j < shape_tmp.size(); j++) { | |||
| if (shape_tmp[j] == shape_tmp1[j] && shape_tmp[j] != shape_tmp2[j]) { | |||
| if (shape_tmp.at(j) == shape_tmp1.at(j) && shape_tmp.at(j) != shape_tmp2.at(j)) { | |||
| axisout = j; | |||
| break; | |||
| } | |||
| if (shape_tmp[j] == shape_tmp2[j] && shape_tmp[j] != shape_tmp1[j]) { | |||
| if (shape_tmp.at(j) == shape_tmp2.at(j) && shape_tmp.at(j) != shape_tmp1.at(j)) { | |||
| axisout = j; | |||
| break; | |||
| } | |||
| if (shape_tmp1[j] == shape_tmp2[j] && shape_tmp[j] != shape_tmp1[j]) { | |||
| if (shape_tmp1.at(j) == shape_tmp2.at(j) && shape_tmp.at(j) != shape_tmp1.at(j)) { | |||
| axisout = j; | |||
| break; | |||
| } | |||
| temp += 1; | |||
| if (temp == shape_tmp.size()) { | |||
| outputs_[0]->set_shape(shape_tmp); | |||
| outputs_.at(0)->set_shape(shape_tmp); | |||
| output->set_data_type(input->data_type()); | |||
| return RET_OK; | |||
| } | |||
| } | |||
| auto output_shape = shape_tmp; | |||
| output_shape[axisout] = nummax; | |||
| outputs_[0]->set_shape(output_shape); | |||
| output_shape.at(axisout) = nummax; | |||
| outputs_.at(0)->set_shape(output_shape); | |||
| return RET_OK; | |||
| } | |||
| } // namespace lite | |||
| @@ -96,9 +96,9 @@ int While::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outpu | |||
| return RET_ERROR; | |||
| } | |||
| for (size_t i = 0; i < inputs_.size(); i++) { | |||
| outputs_[i]->set_data_type(inputs_[i]->data_type()); | |||
| outputs_[i]->set_format(inputs_[i]->format()); | |||
| outputs_[i]->set_shape(inputs_[i]->shape()); | |||
| outputs_.at(i)->set_data_type(inputs_.at(i)->data_type()); | |||
| outputs_.at(i)->set_format(inputs_.at(i)->format()); | |||
| outputs_.at(i)->set_shape(inputs_.at(i)->shape()); | |||
| } | |||
| return RET_OK; | |||
| @@ -131,16 +131,16 @@ void ReduceBaseCPUKernel::CalculateInnerOuterSize() { | |||
| int axis = axes_[i]; | |||
| auto outer_size = 1; | |||
| for (int j = 0; j < axis; j++) { | |||
| outer_size *= tmp_shape[j]; | |||
| outer_size *= tmp_shape.at(j); | |||
| } | |||
| outer_sizes_.emplace_back(outer_size); | |||
| auto inner_size = 1; | |||
| for (int k = axis + 1; k < static_cast<int>(tmp_shape.size()); k++) { | |||
| inner_size *= tmp_shape[k]; | |||
| inner_size *= tmp_shape.at(k); | |||
| } | |||
| inner_sizes_.emplace_back(inner_size); | |||
| axis_sizes_.emplace_back(tmp_shape[axis]); | |||
| tmp_shape[axis] = 1; | |||
| axis_sizes_.emplace_back(tmp_shape.at(axis)); | |||
| tmp_shape.at(axis) = 1; | |||
| } | |||
| } | |||
| @@ -152,12 +152,12 @@ void ReduceBaseCPUKernel::CalculateTmpBufferSize() { | |||
| size_t size = 1; | |||
| for (size_t j = 0; j < input_shape.size(); j++) { | |||
| if (axis != static_cast<int>(j)) { | |||
| size *= input_shape[j]; | |||
| size *= input_shape.at(j); | |||
| } | |||
| } | |||
| MS_ASSERT(context_->allocator != nullptr); | |||
| buffer_sizes_.emplace_back(size); | |||
| input_shape[axis] = 1; | |||
| input_shape.at(axis) = 1; | |||
| } | |||
| } | |||
| @@ -57,7 +57,7 @@ int ResizeBaseCPUKernel::CheckParameters() { | |||
| return RET_INVALID_OP_ATTR; | |||
| } | |||
| } else if (this->in_tensors_.size() == lite::kDoubleNum) { | |||
| auto out_shape = this->in_tensors_[1]->data_c(); | |||
| auto out_shape = this->in_tensors_.at(1)->data_c(); | |||
| if (out_shape == nullptr) { | |||
| MS_LOG(INFO) << "Out shape is not assigned"; | |||
| const_shape_ = false; | |||
| @@ -48,8 +48,8 @@ int SoftmaxBaseCPUKernel::ReSize() { | |||
| softmax_param_->axis_ += in_dims; | |||
| } | |||
| for (size_t i = 0; i < in_dims; i++) { | |||
| softmax_param_->input_shape_[i] = in_shape[i]; | |||
| ele_size *= in_shape[i]; | |||
| softmax_param_->input_shape_[i] = in_shape.at(i); | |||
| ele_size *= in_shape.at(i); | |||
| } | |||
| softmax_param_->element_size_ = ele_size; | |||
| return RET_OK; | |||
| @@ -41,21 +41,21 @@ int SplitBaseCPUKernel::ReSize() { | |||
| MS_ASSERT(input_shape.size() >= 2 && input_shape.size() <= SPLIT_STRIDES_SIZE); | |||
| param->strides_[input_shape.size() - 1] = 1; | |||
| for (int i = input_shape.size() - 2; i >= 0; i--) { | |||
| param->strides_[i] = param->strides_[i + 1] * input_shape[i + 1]; | |||
| param->strides_[i] = param->strides_[i + 1] * input_shape.at(i + 1); | |||
| } | |||
| MS_ASSERT(static_cast<size_t>(param->split_dim_) < input_shape.size()); | |||
| param->split_count_ = | |||
| param->strides_[0] * input_shape[0] / (input_shape[param->split_dim_] * param->strides_[param->split_dim_]); | |||
| param->strides_[0] * input_shape.at(0) / (input_shape.at(param->split_dim_) * param->strides_[param->split_dim_]); | |||
| param->n_dims_ = input_shape.size(); | |||
| if (param->split_sizes_[0] == 0) { | |||
| MS_ASSERT(param->num_split_ > 0 && static_cast<int>(param->num_split_) < input_shape.size()); | |||
| if (input_shape[param->split_dim_] % param->num_split_ != 0) { | |||
| if (input_shape.at(param->split_dim_) % param->num_split_ != 0) { | |||
| MS_LOG(ERROR) << "Default split size is not usable."; | |||
| return RET_ERROR; | |||
| } | |||
| int split_size = input_shape[param->split_dim_] / param->num_split_; | |||
| int split_size = input_shape.at(param->split_dim_) / param->num_split_; | |||
| for (int i = 0; i < param->num_split_; i++) { | |||
| param->split_sizes_[i] = split_size; | |||
| } | |||
| @@ -63,7 +63,7 @@ int SplitBaseCPUKernel::ReSize() { | |||
| MS_ASSERT(param->num_split_ >= 1 && param->num_split_ <= SPLIT_STRIDES_SIZE); | |||
| if (param->split_sizes_[param->num_split_ - 1] == -1) { | |||
| int split_shape_end = input_shape[param->split_dim_]; | |||
| int split_shape_end = input_shape.at(param->split_dim_); | |||
| for (int i = 0; i < param->num_split_ - 1; i++) { | |||
| split_shape_end -= param->split_sizes_[i]; | |||
| } | |||
| @@ -92,10 +92,10 @@ int ReduceFp16CPUKernel::Run() { | |||
| fp16_src_data_ = fp16_input_; | |||
| for (size_t i = 0; i < data_buffers_.size(); ++i) { | |||
| fp16_dst_data_ = data_buffers_[i]; | |||
| outer_size_ = outer_sizes_[i]; | |||
| inner_size_ = inner_sizes_[i]; | |||
| axis_size_ = axis_sizes_[i]; | |||
| fp16_dst_data_ = data_buffers_.at(i); | |||
| outer_size_ = outer_sizes_.at(i); | |||
| inner_size_ = inner_sizes_.at(i); | |||
| axis_size_ = axis_sizes_.at(i); | |||
| auto error_code = ParallelLaunch(this->context_->thread_pool_, ReduceFp16Impl, this, context_->thread_num_); | |||
| if (error_code != RET_OK) { | |||
| FreeTmpBuffer(); | |||
| @@ -39,7 +39,7 @@ int SplitFp16CPUKernel::Init() { | |||
| } | |||
| output_ptr_.resize(param->num_split_); | |||
| for (size_t i = 0; i < output_ptr_.size(); i++) { | |||
| output_ptr_[i] = nullptr; | |||
| output_ptr_.at(i) = nullptr; | |||
| } | |||
| if (!InferShapeDone()) { | |||
| return RET_OK; | |||
| @@ -82,8 +82,8 @@ int SplitFp16CPUKernel::Run() { | |||
| return RET_ERROR; | |||
| } | |||
| for (int i = 0; i < param->num_split_; i++) { | |||
| output_ptr_[i] = MallocOutputFp16(out_tensors_.at(i), context_); | |||
| if (output_ptr_[i] == nullptr) { | |||
| output_ptr_.at(i) = MallocOutputFp16(out_tensors_.at(i), context_); | |||
| if (output_ptr_.at(i) == nullptr) { | |||
| FreeInputAndOutput(); | |||
| MS_LOG(ERROR) << "input or output is nullptr"; | |||
| return RET_ERROR; | |||
| @@ -92,7 +92,7 @@ int SplitFp16CPUKernel::Run() { | |||
| auto ret = ParallelLaunch(this->context_->thread_pool_, SplitFp16Run, this, thread_n_num_); | |||
| for (int i = 0; i < param->num_split_; i++) { | |||
| if (out_tensors_.at(i)->data_type() == kNumberTypeFloat32) { | |||
| Float16ToFloat32(output_ptr_[i], reinterpret_cast<float *>(out_tensors_.at(i)->MutableData()), | |||
| Float16ToFloat32(output_ptr_.at(i), reinterpret_cast<float *>(out_tensors_.at(i)->MutableData()), | |||
| out_tensors_.at(i)->ElementsNum()); | |||
| } | |||
| } | |||
| @@ -110,8 +110,8 @@ void SplitFp16CPUKernel::FreeInputAndOutput() { | |||
| } | |||
| for (int i = 0; i < param->num_split_; i++) { | |||
| if (out_tensors_.at(i)->data_type() == kNumberTypeFloat32) { | |||
| context_->allocator->Free(output_ptr_[i]); | |||
| output_ptr_[i] = nullptr; | |||
| context_->allocator->Free(output_ptr_.at(i)); | |||
| output_ptr_.at(i) = nullptr; | |||
| } | |||
| } | |||
| } | |||
| @@ -40,22 +40,22 @@ int StackFp16CPUKernel::Init() { | |||
| void StackFp16CPUKernel::InitMallocFlags() { | |||
| malloc_buffers_.resize(in_tensors_.size()); | |||
| for (size_t i = 0; i < in_tensors_.size(); ++i) { | |||
| malloc_buffers_[i] = in_tensors_[i]->data_type() == kNumberTypeFloat32; | |||
| malloc_buffers_.at(i) = in_tensors_.at(i)->data_type() == kNumberTypeFloat32; | |||
| } | |||
| malloc_out = out_tensors_[0]->data_type() == kNumberTypeFloat32; | |||
| malloc_out = out_tensors_.at(0)->data_type() == kNumberTypeFloat32; | |||
| } | |||
| int StackFp16CPUKernel::MallocAssignBuffer() { | |||
| buffers_.resize(in_tensors_.size(), nullptr); | |||
| for (size_t i = 0; i < in_tensors_.size(); ++i) { | |||
| buffers_[i] = ConvertInputFp32toFp16(in_tensors_[i], context_); | |||
| if (buffers_[i] == nullptr) { | |||
| buffers_.at(i) = ConvertInputFp32toFp16(in_tensors_.at(i), context_); | |||
| if (buffers_.at(i) == nullptr) { | |||
| return RET_ERROR; | |||
| } | |||
| } | |||
| out_buffer_ = nullptr; | |||
| out_buffer_ = MallocOutputFp16(out_tensors_[0], context_); | |||
| out_buffer_ = MallocOutputFp16(out_tensors_.at(0), context_); | |||
| if (out_buffer_ == nullptr) { | |||
| return RET_ERROR; | |||
| } | |||
| @@ -64,9 +64,9 @@ int StackFp16CPUKernel::MallocAssignBuffer() { | |||
| void StackFp16CPUKernel::FreeBuffer() { | |||
| for (size_t i = 0; i < buffers_.size(); ++i) { | |||
| if (malloc_buffers_[i] && buffers_[i] != nullptr) { | |||
| context_->allocator->Free(buffers_[i]); | |||
| buffers_[i] = nullptr; | |||
| if (malloc_buffers_.at(i) && buffers_.at(i) != nullptr) { | |||
| context_->allocator->Free(buffers_.at(i)); | |||
| buffers_.at(i) = nullptr; | |||
| } | |||
| } | |||
| if (malloc_out && out_buffer_ != nullptr) { | |||
| @@ -77,9 +77,9 @@ void StackFp16CPUKernel::FreeBuffer() { | |||
| int StackFp16CPUKernel::Run() { | |||
| size_t inputs_num = in_tensors_.size(); | |||
| auto input0 = in_tensors_[0]; | |||
| auto input0 = in_tensors_.at(0); | |||
| if (inputs_num == 1) { | |||
| memcpy(out_tensors_[0]->MutableData(), input0->MutableData(), input0->Size()); | |||
| memcpy(out_tensors_.at(0)->MutableData(), input0->MutableData(), input0->Size()); | |||
| return RET_OK; | |||
| } | |||
| InitMallocFlags(); | |||
| @@ -39,7 +39,7 @@ int TransposeFp16CPUKernel::Init() { | |||
| int TransposeFp16CPUKernel::ReSize() { | |||
| TransposeParameter *param = reinterpret_cast<TransposeParameter *>(this->op_parameter_); | |||
| num_unit_ = static_cast<int>(in_tensors_[kInputIndex]->shape().at(param->perm_[kNHWC_H])); | |||
| num_unit_ = static_cast<int>(in_tensors_.at(kInputIndex)->shape().at(param->perm_[kNHWC_H])); | |||
| thread_h_num_ = MSMIN(thread_num_, num_unit_); | |||
| thread_h_stride_ = UP_DIV(num_unit_, thread_h_num_); | |||
| auto &in_tensor = in_tensors_.front(); | |||
| @@ -50,8 +50,8 @@ int TransposeFp16CPUKernel::ReSize() { | |||
| param->out_strides_[param->num_axes_ - 1] = 1; | |||
| param->data_size_ = in_tensor->Size(); | |||
| for (int i = param->num_axes_ - 2; i >= 0; i--) { | |||
| param->strides_[i] = in_shape[i + 1] * param->strides_[i + 1]; | |||
| param->out_strides_[i] = out_shape[i + 1] * param->out_strides_[i + 1]; | |||
| param->strides_[i] = in_shape.at(i + 1) * param->strides_[i + 1]; | |||
| param->out_strides_[i] = out_shape.at(i + 1) * param->out_strides_[i + 1]; | |||
| } | |||
| return RET_OK; | |||
| @@ -130,13 +130,13 @@ int ReduceCPUKernel::Run() { | |||
| HandleASumAndSumSquare(); | |||
| for (size_t i = 0; i < static_cast<size_t>(num_axes_); ++i) { | |||
| if (i != static_cast<size_t>(num_axes_ - 1)) { | |||
| dst_data_ = data_buffers_[i]; | |||
| dst_data_ = data_buffers_.at(i); | |||
| } else { | |||
| dst_data_ = out_tensors_.at(0)->MutableData(); | |||
| } | |||
| outer_size_ = outer_sizes_[i]; | |||
| inner_size_ = inner_sizes_[i]; | |||
| axis_size_ = axis_sizes_[i]; | |||
| outer_size_ = outer_sizes_.at(i); | |||
| inner_size_ = inner_sizes_.at(i); | |||
| axis_size_ = axis_sizes_.at(i); | |||
| auto error_code = ParallelLaunch(this->context_->thread_pool_, ReduceImpl, this, context_->thread_num_); | |||
| if (error_code != RET_OK) { | |||
| MS_LOG(ERROR) << "Reduce run error, error_code[" << error_code << "]"; | |||
| @@ -51,7 +51,7 @@ int ResizeCPUKernel::ReSize() { | |||
| auto input = in_tensors_.at(0); | |||
| auto input_shape = input->shape(); | |||
| ret = PrepareResizeBilinear(input_shape.data(), out_tensors_[0]->shape().data(), align_corners_, y_bottoms_, | |||
| ret = PrepareResizeBilinear(input_shape.data(), out_tensors_.at(0)->shape().data(), align_corners_, y_bottoms_, | |||
| y_tops_, x_lefts_, x_rights_, y_bottom_weights_, x_left_weights_); | |||
| if (ret != RET_OK) { | |||
| FreeTmpBuffer(); | |||
| @@ -164,15 +164,15 @@ int ResizeCPUKernel::RunImpl(int task_id) { | |||
| switch (method_) { | |||
| case static_cast<int>(schema::ResizeMethod_LINEAR): { | |||
| int n_h_begin, n_h_end; | |||
| int n = out_tensors_.at(0)->shape()[0]; | |||
| int n = out_tensors_.at(0)->shape().at(0); | |||
| int h = new_height_; | |||
| int unit = UP_DIV(n * h, context_->thread_num_); | |||
| n_h_begin = unit * task_id; | |||
| n_h_end = std::min(n_h_begin + unit, n * h); | |||
| int c = in_tensors_.at(0)->shape()[3]; | |||
| int c = in_tensors_.at(0)->shape().at(3); | |||
| float *line0 = line_buffer_ + new_width_ * c * 2 * task_id; | |||
| float *line1 = line0 + new_width_ * c; | |||
| ret = ResizeBilinear2(input_data, output_data, input_shape.data(), out_tensors_[0]->shape().data(), y_bottoms_, | |||
| ret = ResizeBilinear2(input_data, output_data, input_shape.data(), out_tensors_.at(0)->shape().data(), y_bottoms_, | |||
| y_tops_, x_lefts_, x_rights_, y_bottom_weights_, x_left_weights_, line0, line1, n_h_begin, | |||
| n_h_end); | |||
| @@ -186,8 +186,8 @@ int ResizeCPUKernel::RunImpl(int task_id) { | |||
| MS_LOG(ERROR) << "The out shape data is nullptr."; | |||
| return RET_NULL_PTR; | |||
| } else { | |||
| out_tensors_[0]->shape()[1] = static_cast<int64_t>(data[0]); | |||
| out_tensors_[0]->shape()[2] = static_cast<int64_t>(data[1]); | |||
| out_tensors_.at(0)->shape().at(1) = static_cast<int64_t>(data[0]); | |||
| out_tensors_.at(0)->shape().at(2) = static_cast<int64_t>(data[1]); | |||
| } | |||
| } | |||
| ret = ResizeNearestNeighbor(input_data, output_data, input_shape.data(), out_tensors_[0]->shape().data(), | |||
| @@ -31,8 +31,8 @@ namespace mindspore::kernel { | |||
| int ReverseCPUKernel::Stride(int index) { | |||
| int stride = 1; | |||
| for (size_t i = index + 1; i < in_tensors_[0]->shape().size(); ++i) { | |||
| stride *= in_tensors_[0]->shape()[i]; | |||
| for (size_t i = index + 1; i < in_tensors_.at(0)->shape().size(); ++i) { | |||
| stride *= in_tensors_.at(0)->shape().at(i); | |||
| } | |||
| return stride; | |||
| } | |||
| @@ -43,7 +43,7 @@ int ReverseCPUKernel::ReSize() { | |||
| thread_sz_stride_ = UP_DIV(data_size_, thread_sz_count_); | |||
| auto *param = reinterpret_cast<ReverseParameter *>(op_parameter_); | |||
| auto input_shape = in_tensors_[0]->shape(); | |||
| auto input_shape = in_tensors_.at(0)->shape(); | |||
| if (param->num_axis_ > static_cast<int>(input_shape.size())) { | |||
| MS_LOG(ERROR) << "Reverse dims : " << param->num_axis_ | |||
| << "is greater than input shape size :" << input_shape.size(); | |||
| @@ -72,7 +72,7 @@ int ReverseCPUKernel::ReSize() { | |||
| inCount_[i] = input_shape[axis]; | |||
| outCount_[i] = 1; | |||
| for (int j = 0; j < axis; j++) { | |||
| outCount_[i] *= input_shape[j]; | |||
| outCount_[i] *= input_shape.at(j); | |||
| } | |||
| } | |||
| @@ -39,14 +39,14 @@ void ReverseSequenceCPUKernel::ConvertAxisToPositive(const std::vector<int> shap | |||
| int ReverseSequenceCPUKernel::CalcCountPreAxis(const std::vector<int> shape, int axis) { | |||
| int count = 1; | |||
| for (int i = 0; i < axis; ++i) { | |||
| count *= shape[i]; | |||
| count *= shape.at(i); | |||
| } | |||
| return count; | |||
| } | |||
| int ReverseSequenceCPUKernel::CalcCountAfterAxis(const std::vector<int> shape, int axis) { | |||
| int count = 1; | |||
| for (size_t i = axis + 1; i < shape.size(); ++i) { | |||
| count *= shape[i]; | |||
| count *= shape.at(i); | |||
| } | |||
| return count; | |||
| } | |||
| @@ -50,21 +50,21 @@ int ROIPoolingCPUKernel::ReSize() { | |||
| return RET_ERROR; | |||
| } | |||
| param_->ndim_ = ndims; | |||
| param_->input_n_ = in_shape[0]; | |||
| param_->input_h_ = in_shape[1]; | |||
| param_->input_w_ = in_shape[2]; | |||
| param_->input_c_ = in_shape[3]; | |||
| param_->output_n_ = out_shape[0]; | |||
| param_->output_h_ = out_shape[1]; | |||
| param_->output_w_ = out_shape[2]; | |||
| param_->output_c_ = out_shape[3]; | |||
| param_->input_n_ = in_shape.at(0); | |||
| param_->input_h_ = in_shape.at(1); | |||
| param_->input_w_ = in_shape.at(2); | |||
| param_->input_c_ = in_shape.at(3); | |||
| param_->output_n_ = out_shape.at(0); | |||
| param_->output_h_ = out_shape.at(1); | |||
| param_->output_w_ = out_shape.at(2); | |||
| param_->output_c_ = out_shape.at(3); | |||
| param_->in_strides_[ndims - 1] = 1; | |||
| param_->out_strides_[ndims - 1] = 1; | |||
| for (int i = ndims - 2; i >= 0; --i) { | |||
| param_->in_strides_[i] = in_shape[i + 1] * param_->in_strides_[i + 1]; | |||
| param_->out_strides_[i] = out_shape[i + 1] * param_->out_strides_[i + 1]; | |||
| param_->in_strides_[i] = in_shape.at(i + 1) * param_->in_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[0]); | |||
| param_->thread_num_ = MSMIN(param_->op_parameter_.thread_num_, out_shape.at(0)); | |||
| max_c_ = reinterpret_cast<float *>(malloc(param_->input_c_ * sizeof(float))); | |||
| if (max_c_ == nullptr) { | |||
| MS_LOG(ERROR) << "malloc max_c failed."; | |||
| @@ -101,17 +101,17 @@ int ScaleCPUKernel::CalculateParameter() { | |||
| scale_param_->axis_size_ = 1; | |||
| scale_param_->inner_size_ = 1; | |||
| for (int i = 0; i < scale_param_->axis_; i++) { | |||
| scale_param_->outer_size_ *= in_shape[i]; | |||
| scale_param_->outer_size_ *= in_shape.at(i); | |||
| } | |||
| for (size_t i = 0; i < scale_shape.size(); i++) { | |||
| if (in_shape[i + scale_param_->axis_] != scale_shape[i]) { | |||
| if (in_shape.at(i + scale_param_->axis_) != scale_shape.at(i)) { | |||
| MS_LOG(ERROR) << "Scale tensor shape is incorrect."; | |||
| return RET_ERROR; | |||
| } | |||
| scale_param_->axis_size_ *= in_shape[i + scale_param_->axis_]; | |||
| scale_param_->axis_size_ *= in_shape.at(i + scale_param_->axis_); | |||
| } | |||
| for (size_t i = scale_param_->axis_ + scale_shape.size(); i < in_shape.size(); i++) { | |||
| scale_param_->inner_size_ *= in_shape[i]; | |||
| scale_param_->inner_size_ *= in_shape.at(i); | |||
| } | |||
| scale_param_->op_parameter_.thread_num_ = MSMIN(scale_param_->op_parameter_.thread_num_, scale_param_->outer_size_); | |||
| return RET_OK; | |||
| @@ -177,7 +177,7 @@ int ScaleCPUKernel::Run() { | |||
| auto in_tensor = in_tensors_.front(); | |||
| input_ptr_ = reinterpret_cast<float *>(in_tensor->data_c()); | |||
| if (!scale_param_->const_scale_) { | |||
| auto scale_tensor = in_tensors_[1]; | |||
| auto scale_tensor = in_tensors_.at(1); | |||
| scale_ = reinterpret_cast<float *>(scale_tensor->data_c()); | |||
| } | |||
| if (!scale_param_->const_offset_) { | |||
| @@ -73,13 +73,13 @@ int ScatterNDCPUKernel::ReSize() { | |||
| // check update shape | |||
| auto update_shape = update->shape(); | |||
| for (size_t i = 0; i < indices_shape.size() - 1; i++) { | |||
| if (update_shape[i] != indices_shape[i]) { | |||
| if (update_shape.at(i) != indices_shape.at(i)) { | |||
| MS_LOG(ERROR) << "Value of " << i << " th dimension of indices is not equal to that of update."; | |||
| return RET_ERROR; | |||
| } | |||
| } | |||
| for (size_t i = 0; i < shape->ElementsNum() - (indices_shape.size() - 1); i++) { | |||
| if (update_shape[i + indices_shape.size() - 1] != shape_data[i + indices_shape.size() - 1]) { | |||
| if (update_shape.at(i + indices_shape.size() - 1) != shape_data[i + indices_shape.size() - 1]) { | |||
| MS_LOG(ERROR) << "Value of " << i + indices_shape.size() - 1 | |||
| << " th dimension of indices is not equal to the corresbonding dimension of shape."; | |||
| return RET_ERROR; | |||
| @@ -90,7 +90,7 @@ int ScatterNDCPUKernel::ReSize() { | |||
| // calculate unit_size_ | |||
| unit_size_ = 1; | |||
| for (int i = indices_shape.size() - 1; i < update_rank; i++) { | |||
| unit_size_ *= update_shape[i]; | |||
| unit_size_ *= update_shape.at(i); | |||
| } | |||
| // calculate offsets | |||
| @@ -102,9 +102,9 @@ int ScatterNDCPUKernel::ReSize() { | |||
| } | |||
| num_unit_ = 1; | |||
| num_unit_ *= update_shape[indices_shape.size() - 2]; | |||
| num_unit_ *= update_shape.at(indices_shape.size() - 2); | |||
| for (int i = indices_shape.size() - 3; i >= 0; i--) { | |||
| num_unit_ *= update_shape[i]; | |||
| num_unit_ *= update_shape.at(i); | |||
| } | |||
| int *indices_ptr = reinterpret_cast<int *>(indices->MutableData()); | |||
| @@ -112,7 +112,7 @@ int ScatterNDCPUKernel::ReSize() { | |||
| for (int i = 0; i < num_unit_; i++) { | |||
| int tmp_stride = 0; | |||
| for (int j = 0; j < indice_unit_rank; j++) { | |||
| tmp_stride += indices_ptr[i * indice_unit_rank + j] * out_strides_[j] * unit_size_; | |||
| tmp_stride += indices_ptr[i * indice_unit_rank + j] * out_strides_.at(j) * unit_size_; | |||
| } | |||
| output_unit_offsets_.push_back(tmp_stride); | |||
| } | |||
| @@ -43,7 +43,7 @@ int ShapeCPUKernel::Run() { | |||
| } | |||
| for (size_t i = 0; i < in_tensor->shape().size(); i++) { | |||
| reinterpret_cast<int *>(out_tensor->MutableData())[i] = in_tensor->shape()[i]; | |||
| reinterpret_cast<int *>(out_tensor->MutableData())[i] = in_tensor->shape().at(i); | |||
| } | |||
| return RET_OK; | |||
| @@ -68,7 +68,7 @@ int SkipGramCPUKernel::Run() { | |||
| return RET_ERROR; | |||
| } | |||
| StringPack sentence = mindspore::lite::ParseTensorBuffer(in_tensors_[0]).at(0); | |||
| StringPack sentence = mindspore::lite::ParseTensorBuffer(in_tensors_.at(0)).at(0); | |||
| std::vector<StringPack> words; | |||
| ParseSentenceToWords(sentence, &words); | |||
| @@ -78,12 +78,12 @@ int SkipGramCPUKernel::Run() { | |||
| int index = 1; | |||
| int size = words.size(); | |||
| while (index >= 0) { | |||
| if (index < skip_gram_parameter_->ngram_size && stack[index] + 1 < size && | |||
| (index == 0 || stack[index] - stack[index - 1] <= skip_gram_parameter_->max_skip_size)) { | |||
| stack[index]++; | |||
| if (index < skip_gram_parameter_->ngram_size && stack.at(index) + 1 < size && | |||
| (index == 0 || stack.at(index) - stack.at(index - 1) <= skip_gram_parameter_->max_skip_size)) { | |||
| stack.at(index)++; | |||
| index++; | |||
| if (index < skip_gram_parameter_->ngram_size) { | |||
| stack[index] = stack[index - 1]; | |||
| stack.at(index) = stack.at(index - 1); | |||
| } | |||
| } else { | |||
| if (index > 0 && ((skip_gram_parameter_->include_all_ngrams && index <= skip_gram_parameter_->ngram_size) || | |||
| @@ -92,16 +92,16 @@ int SkipGramCPUKernel::Run() { | |||
| char blank[1] = {' '}; | |||
| StringPack blank_str = {1, blank}; | |||
| for (int i = 0; i < 2 * index - 2; i += 2) { | |||
| gram[i] = words[stack[i / 2]]; | |||
| gram[i + 1] = blank_str; | |||
| gram.at(i) = words.at(stack.at(i / 2)); | |||
| gram.at(i + 1) = blank_str; | |||
| } | |||
| gram[2 * index - 2] = words[stack[index - 1]]; | |||
| gram.at(2 * index - 2) = words.at(stack.at(index - 1)); | |||
| result.push_back(gram); | |||
| } | |||
| index--; | |||
| } | |||
| } | |||
| auto ret = mindspore::lite::WriteSeperatedStringsToTensor(out_tensors_[0], result); | |||
| auto ret = mindspore::lite::WriteSeperatedStringsToTensor(out_tensors_.at(0), result); | |||
| return ret; | |||
| } | |||
| @@ -45,8 +45,8 @@ int SliceCPUKernel::ReSize() { | |||
| } | |||
| for (int i = 0; i < param_->param_length_; ++i) { | |||
| param_->shape_[i] = in_tensors_.at(0)->DimensionSize(i); | |||
| param_->begin_[i] = begin[i]; | |||
| param_->size_[i] = size[i] < 0 ? param_->shape_[i] - param_->begin_[i] : size[i]; | |||
| param_->begin_[i] = begin.at(i); | |||
| param_->size_[i] = size.at(i) < 0 ? param_->shape_[i] - param_->begin_[i] : size.at(i); | |||
| param_->end_[i] = param_->begin_[i] + param_->size_[i]; | |||
| } | |||
| if (param_->param_length_ < DIMENSION_4D) { | |||
| @@ -63,8 +63,8 @@ int SliceCPUKernel::Init() { | |||
| } | |||
| int SliceCPUKernel::SliceParallelRun(int thread_id) { | |||
| const float *input_data = reinterpret_cast<const float *>(in_tensors_[0]->MutableData()); | |||
| float *output_data = reinterpret_cast<float *>(out_tensors_[0]->MutableData()); | |||
| const float *input_data = reinterpret_cast<const float *>(in_tensors_.at(0)->MutableData()); | |||
| float *output_data = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData()); | |||
| MS_ASSERT(input_data); | |||
| MS_ASSERT(output_data); | |||
| DoSlice(input_data, output_data, param_, thread_id); | |||
| @@ -77,8 +77,8 @@ int SliceCPUKernel::Run() { | |||
| MS_LOG(ERROR) << "PreProcess fail!ret: " << ret; | |||
| return ret; | |||
| } | |||
| const float *input_data = reinterpret_cast<const float *>(in_tensors_[0]->MutableData()); | |||
| float *output_data = reinterpret_cast<float *>(out_tensors_[0]->MutableData()); | |||
| const float *input_data = reinterpret_cast<const float *>(in_tensors_.at(0)->MutableData()); | |||
| float *output_data = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData()); | |||
| if (param_->size_[1] < op_parameter_->thread_num_) { | |||
| DoSliceNoParallel(input_data, output_data, param_); | |||
| return RET_OK; | |||
| @@ -51,11 +51,11 @@ int SoftmaxCPUKernel::ReSize() { | |||
| auto in_shape = in_tensors_.front()->shape(); | |||
| int out_plane_size = 1; | |||
| for (int i = 0; i < axis; ++i) { | |||
| out_plane_size *= in_shape[i]; | |||
| out_plane_size *= in_shape.at(i); | |||
| } | |||
| int in_plane_size = 1; | |||
| for (int i = axis + 1; i < n_dim; i++) { | |||
| in_plane_size *= in_shape[i]; | |||
| in_plane_size *= in_shape.at(i); | |||
| } | |||
| in_plane_size_ = in_plane_size; | |||
| out_plane_size_ = out_plane_size; | |||
| @@ -45,12 +45,12 @@ int SpaceToDepthCPUKernel::Init() { | |||
| } | |||
| int SpaceToDepthCPUKernel::ReSize() { | |||
| if (in_tensors_[0]->format() != schema::Format::Format_NHWC) { | |||
| if (in_tensors_.at(0)->format() != schema::Format::Format_NHWC) { | |||
| MS_LOG(ERROR) << "space_to_depth only support NHWC now!"; | |||
| return RET_FORMAT_ERR; | |||
| } | |||
| num_unit_ = static_cast<int>(out_tensors_[0]->shape().at(kNHWC_H)); | |||
| num_unit_ = static_cast<int>(out_tensors_.at(0)->shape().at(kNHWC_H)); | |||
| thread_h_num_ = MSMIN(op_parameter_->thread_num_, num_unit_); | |||
| thread_h_stride_ = UP_DIV(num_unit_, thread_h_num_); | |||
| return RET_OK; | |||
| @@ -62,8 +62,8 @@ int SpaceToDepthCPUKernel::SpaceToDepth(int task_id) { | |||
| return RET_OK; | |||
| } | |||
| int thread_offset = task_id * thread_h_stride_; | |||
| auto in_shape = in_tensors_[0]->shape(); | |||
| auto out_shape = out_tensors_[0]->shape(); | |||
| auto in_shape = in_tensors_.at(0)->shape(); | |||
| auto out_shape = out_tensors_.at(0)->shape(); | |||
| SpaceToDepthParameter *param = reinterpret_cast<SpaceToDepthParameter *>(op_parameter_); | |||
| MS_ASSERT(param); | |||
| MS_ASSERT(input_ptr_); | |||
| @@ -88,9 +88,9 @@ int SpaceToDepthRun(void *cdata, int task_id) { | |||
| } | |||
| int SpaceToDepthCPUKernel::Run() { | |||
| input_ptr_ = reinterpret_cast<float *>(in_tensors_[0]->MutableData()); | |||
| output_ptr_ = reinterpret_cast<float *>(out_tensors_[0]->MutableData()); | |||
| if (in_tensors_[0]->format() == schema::Format::Format_NHWC) { | |||
| input_ptr_ = reinterpret_cast<float *>(in_tensors_.at(0)->MutableData()); | |||
| output_ptr_ = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData()); | |||
| if (in_tensors_.at(0)->format() == schema::Format::Format_NHWC) { | |||
| auto ret = ParallelLaunch(this->context_->thread_pool_, SpaceToDepthRun, this, thread_h_num_); | |||
| if (ret != RET_OK) { | |||
| MS_LOG(ERROR) << "SpaceToDepth error error_code[" << ret << "]"; | |||
| @@ -91,7 +91,7 @@ int SparseToDenseRun(void *cdata, int task_id) { | |||
| int SparseToDenseCPUKernel::GenerateIndices() { | |||
| auto input0 = in_tensors_.at(0); | |||
| index_num = input0->shape()[0]; | |||
| index_num = input0->shape().at(0); | |||
| if (index_num >= std::numeric_limits<int>::max() / static_cast<int>(sizeof(int *))) { | |||
| MS_LOG(ERROR) << "Input dim is invalid, dim: " << index_num; | |||
| return RET_ERROR; | |||
| @@ -120,7 +120,7 @@ int SparseToDenseCPUKernel::GenerateIndices() { | |||
| break; | |||
| } | |||
| case 2: { | |||
| int true_dims = input0->shape()[1]; | |||
| int true_dims = input0->shape().at(1); | |||
| MS_ASSERT(true_dims <= DIMENSION_4D); | |||
| for (int i = 0; i < index_num; i++) { | |||
| sparse_indices_vect[i] = new int[DIMENSION_4D]; | |||
| @@ -77,7 +77,7 @@ int SplitCPUKernel::Run() { | |||
| auto in_tensor = in_tensors_.front(); | |||
| input_ptr_ = reinterpret_cast<float *>(in_tensor->MutableData()); | |||
| for (int i = 0; i < param->num_split_; i++) { | |||
| output_ptr_[i] = reinterpret_cast<float *>(out_tensors_.at(i)->MutableData()); | |||
| output_ptr_.at(i) = reinterpret_cast<float *>(out_tensors_.at(i)->MutableData()); | |||
| } | |||
| auto ret = ParallelLaunch(this->context_->thread_pool_, SplitRun, this, thread_n_num_); | |||
| if (ret != RET_OK) { | |||
| @@ -29,7 +29,7 @@ using mindspore::schema::PrimitiveType_Stack; | |||
| namespace mindspore::kernel { | |||
| int StackCPUKernel::ReSize() { | |||
| StackParameter *param = reinterpret_cast<StackParameter *>(op_parameter_); | |||
| auto input0_shape = in_tensors_[0]->shape(); | |||
| auto input0_shape = in_tensors_.at(0)->shape(); | |||
| axis_ = param->axis_ < 0 ? param->axis_ + input0_shape.size() + 1 : param->axis_; | |||
| return RET_OK; | |||
| } | |||
| @@ -44,31 +44,31 @@ int StackCPUKernel::Init() { | |||
| int StackCPUKernel::Run() { | |||
| size_t inputs_num = in_tensors_.size(); | |||
| auto input0 = in_tensors_[0]; | |||
| auto input0 = in_tensors_.at(0); | |||
| if (inputs_num == 1) { | |||
| auto *output_data = reinterpret_cast<int8_t *>(out_tensors_[0]->MutableData()); | |||
| auto *output_data = reinterpret_cast<int8_t *>(out_tensors_.at(0)->MutableData()); | |||
| MS_ASSERT(output_data); | |||
| auto *input_data = reinterpret_cast<const int8_t *>(input0->MutableData()); | |||
| MS_ASSERT(input_data); | |||
| DoStackOneInput(input_data, output_data, input0->Size()); | |||
| return RET_OK; | |||
| } | |||
| auto input0_shape = in_tensors_[0]->shape(); | |||
| if (in_tensors_[0]->data_type() == kNumberTypeFloat32 || in_tensors_[0]->data_type() == kNumberTypeFloat) { | |||
| auto *output_data = reinterpret_cast<float *>(out_tensors_[0]->MutableData()); | |||
| auto input0_shape = in_tensors_.at(0)->shape(); | |||
| if (in_tensors_.at(0)->data_type() == kNumberTypeFloat32 || in_tensors_.at(0)->data_type() == kNumberTypeFloat) { | |||
| auto *output_data = reinterpret_cast<float *>(out_tensors_.at(0)->MutableData()); | |||
| MS_ASSERT(output_data); | |||
| float *inputs[inputs_num]; | |||
| for (size_t i = 0; i < inputs_num; ++i) { | |||
| inputs[i] = reinterpret_cast<float *>(in_tensors_[i]->MutableData()); | |||
| inputs[i] = reinterpret_cast<float *>(in_tensors_.at(i)->MutableData()); | |||
| MS_ASSERT(inputs[i]); | |||
| } | |||
| DoStack(inputs, inputs_num, input0_shape.data(), input0_shape.size(), axis_, output_data); | |||
| } else { | |||
| auto *output_data = reinterpret_cast<int32_t *>(out_tensors_[0]->MutableData()); | |||
| auto *output_data = reinterpret_cast<int32_t *>(out_tensors_.at(0)->MutableData()); | |||
| MS_ASSERT(output_data); | |||
| int32_t *inputs[inputs_num]; | |||
| for (size_t i = 0; i < inputs_num; ++i) { | |||
| inputs[i] = reinterpret_cast<int32_t *>(in_tensors_[i]->MutableData()); | |||
| inputs[i] = reinterpret_cast<int32_t *>(in_tensors_.at(i)->MutableData()); | |||
| MS_ASSERT(inputs[i]); | |||
| } | |||
| DoStackInt32(inputs, inputs_num, input0_shape.data(), input0_shape.size(), axis_, output_data); | |||
| @@ -43,8 +43,8 @@ int TileCPUKernel::ReSize() { | |||
| auto tile_parameter_ = reinterpret_cast<TileParameter *>(op_parameter_); | |||
| MS_ASSERT(tile_parameter_); | |||
| for (int i = 0; i < tile_parameter_->in_dim_; ++i) { | |||
| tile_parameter_->in_shape_[i] = in_tensors_[0]->shape()[i]; | |||
| tile_parameter_->out_shape_[i] = out_tensors_[0]->shape()[i]; | |||
| tile_parameter_->in_shape_[i] = in_tensors_.at(0)->shape().at(i); | |||
| tile_parameter_->out_shape_[i] = out_tensors_.at(0)->shape().at(i); | |||
| } | |||
| ComputeStrides(tile_parameter_->in_shape_, tile_parameter_->in_strides_, tile_parameter_->in_dim_); | |||
| ComputeStrides(tile_parameter_->out_shape_, tile_parameter_->out_strides_, tile_parameter_->in_dim_); | |||
| @@ -37,10 +37,10 @@ int TopKCPUKernel::Init() { | |||
| int TopKCPUKernel::ReSize() { | |||
| lite::Tensor *input = in_tensors_.at(0); | |||
| TopkParameter *parameter = reinterpret_cast<TopkParameter *>(op_parameter_); | |||
| parameter->last_dim_size_ = input->shape()[input->shape().size() - 1]; | |||
| parameter->last_dim_size_ = input->shape().at(input->shape().size() - 1); | |||
| parameter->loop_num_ = 1; | |||
| for (size_t i = 0; i < input->shape().size() - 1; ++i) { | |||
| parameter->loop_num_ *= input->shape()[i]; | |||
| parameter->loop_num_ *= input->shape().at(i); | |||
| } | |||
| return RET_OK; | |||
| } | |||
| @@ -36,7 +36,7 @@ int TransposeCPUKernel::Init() { | |||
| int TransposeCPUKernel::ReSize() { | |||
| TransposeParameter *param = reinterpret_cast<TransposeParameter *>(op_parameter_); | |||
| num_unit_ = static_cast<int>(in_tensors_[kInputIndex]->shape().at(param->perm_[kNHWC_H])); | |||
| num_unit_ = static_cast<int>(in_tensors_.at(kInputIndex)->shape().at(param->perm_[kNHWC_H])); | |||
| thread_h_num_ = MSMIN(thread_num_, num_unit_); | |||
| thread_h_stride_ = UP_DIV(num_unit_, thread_h_num_); | |||
| @@ -48,8 +48,8 @@ int TransposeCPUKernel::ReSize() { | |||
| param->out_strides_[param->num_axes_ - 1] = 1; | |||
| param->data_size_ = inTensor->Size(); | |||
| for (int i = param->num_axes_ - 2; i >= 0; i--) { | |||
| param->strides_[i] = in_shape[i + 1] * param->strides_[i + 1]; | |||
| param->out_strides_[i] = out_shape[i + 1] * param->out_strides_[i + 1]; | |||
| param->strides_[i] = in_shape.at(i + 1) * param->strides_[i + 1]; | |||
| param->out_strides_[i] = out_shape.at(i + 1) * param->out_strides_[i + 1]; | |||
| } | |||
| if (this->in_shape_ != nullptr) { | |||
| free(this->in_shape_); | |||
| @@ -39,7 +39,7 @@ int UniqueCPUKernel::Run() { | |||
| Unique(input, in_tensors_.at(0)->ElementsNum(), output0, &output0_len, output1); | |||
| std::vector<int> out_shape = out_tensors_.at(0)->shape(); | |||
| out_shape[out_shape.size() - 1] = output0_len; | |||
| out_shape.at(out_shape.size() - 1) = output0_len; | |||
| out_tensors_.at(0)->set_shape(out_shape); | |||
| return RET_OK; | |||
| } | |||
| @@ -141,10 +141,10 @@ int ScaleInt8CPUKernel::InitParameter() { | |||
| second_in_shape_.resize(len); | |||
| size_t i = 0; | |||
| for (; i < input1_size; ++i) { | |||
| second_in_shape_[i] = input1_shape[i]; | |||
| second_in_shape_.at(i) = input1_shape.at(i); | |||
| } | |||
| for (; i < len; ++i) { | |||
| second_in_shape_[i] = 1; | |||
| second_in_shape_.at(i) = 1; | |||
| } | |||
| input1_size = len; | |||
| } | |||
| @@ -164,7 +164,7 @@ int ScaleInt8CPUKernel::InitParameter() { | |||
| if (i < fill_dim_num) { | |||
| tile_para->in_shape1_[i] = 1; | |||
| } else { | |||
| tile_para->in_shape1_[i] = second_in_shape_[j++]; | |||
| tile_para->in_shape1_[i] = second_in_shape_.at(j++); | |||
| } | |||
| tile_para->out_shape_[i] = out_tensors_.at(0)->DimensionSize(i); | |||
| } | |||
| @@ -51,9 +51,9 @@ int SliceInt8CPUKernel::Init() { | |||
| } | |||
| int SliceInt8CPUKernel::DoSlice(int task_id) { | |||
| const int8_t *input_data = reinterpret_cast<const int8_t *>(in_tensors_[0]->MutableData()); | |||
| const int8_t *input_data = reinterpret_cast<const int8_t *>(in_tensors_.at(0)->MutableData()); | |||
| MS_ASSERT(input_data); | |||
| int8_t *output_data = reinterpret_cast<int8_t *>(out_tensors_[0]->MutableData()); | |||
| int8_t *output_data = reinterpret_cast<int8_t *>(out_tensors_.at(0)->MutableData()); | |||
| MS_ASSERT(output_data); | |||
| auto ret = SliceInt8(input_data, output_data, param_, task_id); | |||
| @@ -73,9 +73,9 @@ int SliceInt8Run(void *cdata, int task_id) { | |||
| } | |||
| int SliceInt8CPUKernel::Run() { | |||
| const int8_t *input_data = reinterpret_cast<const int8_t *>(in_tensors_[0]->MutableData()); | |||
| const int8_t *input_data = reinterpret_cast<const int8_t *>(in_tensors_.at(0)->MutableData()); | |||
| MS_ASSERT(input_data); | |||
| int8_t *output_data = reinterpret_cast<int8_t *>(out_tensors_[0]->MutableData()); | |||
| int8_t *output_data = reinterpret_cast<int8_t *>(out_tensors_.at(0)->MutableData()); | |||
| MS_ASSERT(output_data); | |||
| mindspore::lite::STATUS ret = RET_ERROR; | |||
| if (param_->size_[1] < param_->op_parameter_.thread_num_) { | |||
| @@ -36,10 +36,10 @@ int TopKInt8CPUKernel::ReSize() { | |||
| MS_ASSERT(parameter); | |||
| lite::Tensor *input = in_tensors_.at(0); | |||
| MS_ASSERT(input); | |||
| parameter->last_dim_size_ = input->shape()[input->shape().size() - 1]; | |||
| parameter->last_dim_size_ = input->shape().at(input->shape().size() - 1); | |||
| parameter->loop_num_ = 1; | |||
| for (size_t i = 0; i < input->shape().size() - 1; ++i) { | |||
| parameter->loop_num_ *= input->shape()[i]; | |||
| parameter->loop_num_ *= input->shape().at(i); | |||
| } | |||
| return RET_OK; | |||
| } | |||
| @@ -90,8 +90,8 @@ int TransposeInt8CPUKernel::ReSize() { | |||
| transpose_param_->strides_[transpose_param_->num_axes_ - 1] = 1; | |||
| transpose_param_->out_strides_[transpose_param_->num_axes_ - 1] = 1; | |||
| for (int i = transpose_param_->num_axes_ - 2; i >= 0; i--) { | |||
| transpose_param_->strides_[i] = in_shape[i + 1] * transpose_param_->strides_[i + 1]; | |||
| transpose_param_->out_strides_[i] = out_shape[i + 1] * transpose_param_->out_strides_[i + 1]; | |||
| transpose_param_->strides_[i] = in_shape.at(i + 1) * transpose_param_->strides_[i + 1]; | |||
| transpose_param_->out_strides_[i] = out_shape.at(i + 1) * transpose_param_->out_strides_[i + 1]; | |||
| } | |||
| extra_dims_ = out_shape.size() > MAX_TRANSPOSE_DIM_SIZE; | |||
| @@ -30,6 +30,7 @@ TEST_F(TestTopKFp32, TopK) { | |||
| lite::Tensor in_tensor(kNumberTypeFloat32, {2, 2, 3}); | |||
| lite::Tensor out_tensor0(kNumberTypeFloat32, {2, 2, 2}); | |||
| lite::Tensor out_tensor1(kNumberTypeInt32, {2, 2, 2}); | |||
| float input_data[] = {1, 2, 3, 6, 5, 4, 9, 8, 7, 10, 12, 11}; | |||
| float output_data0[8] = {0}; | |||
| int32_t output_data1[8] = {0}; | |||
| @@ -39,7 +40,7 @@ TEST_F(TestTopKFp32, TopK) { | |||
| std::vector<lite::Tensor *> inputs = {&in_tensor}; | |||
| std::vector<lite::Tensor *> outputs = {&out_tensor0, &out_tensor1}; | |||
| TopkParameter parameter = {{}, 3, 4, 2, true}; | |||
| TopkParameter parameter = {{}, 2, true, 3, 4}; | |||
| kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_TopK}; | |||
| auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); | |||
| @@ -34,7 +34,7 @@ TEST_F(SpaceToBatchTestInt8, test1) { | |||
| std::vector<lite::Tensor *> inputs = {&in_tensor}; | |||
| std::vector<lite::Tensor *> outputs = {&out_tensor}; | |||
| SpaceToBatchParameter parameter = {{}, false, {2, 2}, {1, 1, 1, 1}}; | |||
| SpaceToBatchParameter parameter = {{}, {2, 2}, {1, 1, 1, 1}, 2, {}, {}, false}; | |||
| kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_SpaceToBatchND}; | |||
| auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); | |||
| @@ -40,7 +40,7 @@ TEST_F(TestTopKInt8, TopK) { | |||
| std::vector<lite::Tensor *> inputs = {&in_tensor}; | |||
| std::vector<lite::Tensor *> outputs = {&out_tensor0, &out_tensor1}; | |||
| TopkParameter parameter = {{}, 3, 4, 2, true}; | |||
| TopkParameter parameter = {{}, 2, true, 3, 4}; | |||
| kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_TopK}; | |||
| auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); | |||