!9305 paramter mem save check and add comments

From: @zhaozhenlong
Reviewed-by: @zhanghaibo5,@hangangqiang
Signed-off-by: @hangangqiang
This commit is contained in:
mindspore-ci-bot 2020-12-02 10:00:25 +08:00 committed by Gitee
commit cd9c7e5b03
26 changed files with 77 additions and 16 deletions

View File

@ -18,7 +18,9 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct FlattenParameter { typedef struct FlattenParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
// other parameter
int size; int size;
} FlattenParameter; } FlattenParameter;

View File

@ -20,11 +20,13 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct ExpParameter { typedef struct ExpParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int thread_num_;
float base_; float base_;
float scale_; float scale_;
float shift_; float shift_;
// other parameter
int thread_num_;
float in_scale_; float in_scale_;
float out_scale_; float out_scale_;
int element_num_; int element_num_;

View File

@ -20,6 +20,7 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct ExpandDimsParameter { typedef struct ExpandDimsParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int dim_; int dim_;
} ExpandDimsParameter; } ExpandDimsParameter;

View File

@ -25,6 +25,7 @@
#define FILL_DIMS_MAX_SIZE 4 #define FILL_DIMS_MAX_SIZE 4
typedef struct FillParameter { typedef struct FillParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int dims_[FILL_DIMS_MAX_SIZE]; int dims_[FILL_DIMS_MAX_SIZE];
int num_dims_; int num_dims_;

View File

@ -20,6 +20,7 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct GatherNdParameter { typedef struct GatherNdParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
} GatherNdParameter; } GatherNdParameter;

View File

@ -20,6 +20,7 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct LocalResponseNormParameter { typedef struct LocalResponseNormParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int depth_radius_; int depth_radius_;
float bias_; float bias_;

View File

@ -20,11 +20,14 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct LstmParameter { typedef struct LstmParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
// shape correlative
int input_size_; int input_size_;
int hidden_size_; // output_size int hidden_size_; // output_size
int seq_len_; int seq_len_;
int batch_; int batch_;
// other parameter
int input_step_; int input_step_;
int output_step_; int output_step_;
bool bidirectional_; bool bidirectional_;

View File

@ -23,8 +23,10 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct OneHotParameter { typedef struct OneHotParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int axis_; int axis_;
// other parameter
int depth_; int depth_;
float on_value_; float on_value_;
float off_value_; float off_value_;

View File

@ -20,6 +20,7 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct RangeParameter { typedef struct RangeParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int dType_; int dType_;
int start_; int start_;

View File

@ -20,6 +20,7 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct GatherParameter { typedef struct GatherParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int axis_; int axis_;
int batchDims_; int batchDims_;

View File

@ -20,9 +20,11 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct InstanceNormParameter { typedef struct InstanceNormParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
float epsilon_; float epsilon_;
float momentum_; float momentum_;
// shape correlative
int channel_; int channel_;
} InstanceNormParameter; } InstanceNormParameter;

View File

@ -20,13 +20,16 @@
#include "nnacl/quantization/quantize.h" #include "nnacl/quantization/quantize.h"
typedef struct L2NormParameter { typedef struct L2NormParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int *axis_;
size_t axis_num_;
float epsilon_; float epsilon_;
int *axis_;
// shape correlative
size_t axis_num_;
int data_num_; int data_num_;
int *shape_; int *shape_;
size_t shape_num_; size_t shape_num_;
// other parameter
ActType act_type_; ActType act_type_;
} L2NormParameter; } L2NormParameter;

View File

@ -20,11 +20,14 @@
#include "nnacl/quantization/quantize.h" #include "nnacl/quantization/quantize.h"
typedef struct LayerNormParameter { typedef struct LayerNormParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int *normalized_shape_;
int normalized_dims_;
float epsilon_; float epsilon_;
bool elementwise_affine_; bool elementwise_affine_;
// shape correlative
int *normalized_shape_;
int normalized_dims_;
// other parameter
int thread_count_; int thread_count_;
int thread_outsize_; int thread_outsize_;
} LayerNormParameter; } LayerNormParameter;

View File

@ -20,9 +20,12 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct LshProjectionParameter { typedef struct LshProjectionParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int lsh_type_; // shape correlative
int hash_shape_[2]; int hash_shape_[2];
// other parameter
int lsh_type_;
int feature_num_; int feature_num_;
char **hash_buffs_; char **hash_buffs_;
size_t hash_buff_size_; size_t hash_buff_size_;

View File

@ -36,7 +36,9 @@ typedef void (*MATMUL_OPT_DP_FUNC)(const int8_t *a, const int8_t *b, int8_t *dst
typedef enum OutType { OutType_C8 = 0, OutType_Nhwc = 1, OutType_TileC8 = 2 } OutType; typedef enum OutType { OutType_C8 = 0, OutType_Nhwc = 1, OutType_TileC8 = 2 } OutType;
typedef struct MatMulParameter { typedef struct MatMulParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
// other parameter
int row_; int row_;
int col_; int col_;
int row_4_; int row_4_;

View File

@ -21,7 +21,9 @@
#include "nnacl/quantization/quantize.h" #include "nnacl/quantization/quantize.h"
typedef struct MulParameter { typedef struct MulParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
// other parameter
int thread_count_; int thread_count_;
MulQuantArg mul_quant_arg_; MulQuantArg mul_quant_arg_;
} MulParameter; } MulParameter;

View File

@ -20,6 +20,7 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct NMSParameter { typedef struct NMSParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int center_point_box_; int center_point_box_;
} NMSParameter; } NMSParameter;

View File

@ -23,15 +23,18 @@
#define DEFAULT_PAD_NDIMS 4 #define DEFAULT_PAD_NDIMS 4
typedef struct PadParameter { typedef struct PadParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
PadQuantArg pad_quant_arg_;
int paddings_[MAX_PAD_SIZE]; int paddings_[MAX_PAD_SIZE];
int padding_length;
int pad_mode_; int pad_mode_;
float constant_value_; float constant_value_;
int mirror_offset_; // shape correlative
int padding_length;
// other parameter
int in_strides[DEFAULT_PAD_NDIMS]; int in_strides[DEFAULT_PAD_NDIMS];
int out_strides[DEFAULT_PAD_NDIMS]; int out_strides[DEFAULT_PAD_NDIMS];
int mirror_offset_;
PadQuantArg pad_quant_arg_;
} PadParameter; } PadParameter;
#endif // MINDSPORE_LITE_NNACL_PAD_PARAMETER_H_ #endif // MINDSPORE_LITE_NNACL_PAD_PARAMETER_H_

View File

@ -24,13 +24,18 @@ typedef enum PoolMode { PoolMode_No, PoolMode_MaxPool, PoolMode_AvgPool } PoolMo
typedef enum RoundMode { RoundMode_No, RoundMode_Ceil, RoundMode_Floor } RoundMode; typedef enum RoundMode { RoundMode_No, RoundMode_Ceil, RoundMode_Floor } RoundMode;
typedef struct PoolingParameter { typedef struct PoolingParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
PoolMode pool_mode_; PoolMode pool_mode_;
RoundMode round_mode_; RoundMode round_mode_;
ActType act_type_; ActType act_type_;
QuantArg **quant_args_; int avg_mode_;
bool global_;
int window_w_; int window_w_;
int window_h_; int window_h_;
int stride_w_;
int stride_h_;
// shape correlative
int input_w_; int input_w_;
int input_h_; int input_h_;
int input_batch_; int input_batch_;
@ -43,11 +48,9 @@ typedef struct PoolingParameter {
int pad_d_; int pad_d_;
int pad_l_; int pad_l_;
int pad_r_; int pad_r_;
int stride_w_; // other parameter
int stride_h_;
int thread_num_; int thread_num_;
int avg_mode_; QuantArg **quant_args_;
bool global_;
bool quantize_; bool quantize_;
} PoolingParameter; } PoolingParameter;

View File

@ -21,11 +21,13 @@
#include "nnacl/quantization/quantize.h" #include "nnacl/quantization/quantize.h"
typedef struct PowerParameter { typedef struct PowerParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
PowerQuantArg quant_arg_;
float power_; float power_;
float scale_; float scale_;
float shift_; float shift_;
// other parameter
PowerQuantArg quant_arg_;
bool broadcast_; bool broadcast_;
} PowerParameter; } PowerParameter;

View File

@ -18,7 +18,9 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct { typedef struct {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
// other parameter
int output_num; int output_num;
float weight_threshold; float weight_threshold;
} PredictParameter; } PredictParameter;

View File

@ -19,7 +19,9 @@
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
typedef struct PReluParameter { typedef struct PReluParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
// other parameter
float *slope_; float *slope_;
bool channelShared; bool channelShared;
int tile_block_; int tile_block_;

View File

@ -24,6 +24,7 @@
#define PRIOR_BOX_MAX_NUM 8 #define PRIOR_BOX_MAX_NUM 8
#define PRIOR_BOX_VAR_NUM 4 #define PRIOR_BOX_VAR_NUM 4
typedef struct PriorBoxParameter { typedef struct PriorBoxParameter {
// Primitive parameter
OpParameter op_parameter_; OpParameter op_parameter_;
int32_t min_sizes_size; int32_t min_sizes_size;
int32_t min_sizes[PRIOR_BOX_MAX_NUM]; int32_t min_sizes[PRIOR_BOX_MAX_NUM];

View File

@ -33,6 +33,11 @@ OpParameter *PopulateGatherParameter(const mindspore::lite::PrimitiveC *primitiv
} }
memset(gather_param, 0, sizeof(GatherParameter)); memset(gather_param, 0, sizeof(GatherParameter));
gather_param->op_parameter_.type_ = primitive->Type(); gather_param->op_parameter_.type_ = primitive->Type();
if (gather_attr->GetAxis() < 0) {
MS_LOG(ERROR) << "axis should be >= 0.";
free(gather_param);
return nullptr;
}
gather_param->axis_ = gather_attr->GetAxis(); gather_param->axis_ = gather_attr->GetAxis();
gather_param->batchDims_ = gather_attr->GetBatchDims(); gather_param->batchDims_ = gather_attr->GetBatchDims();
return reinterpret_cast<OpParameter *>(gather_param); return reinterpret_cast<OpParameter *>(gather_param);

View File

@ -15,6 +15,7 @@
*/ */
#include "src/ops/l2_norm.h" #include "src/ops/l2_norm.h"
#include <cstdint>
#include "src/ops/primitive_c.h" #include "src/ops/primitive_c.h"
#include "src/ops/populate/populate_register.h" #include "src/ops/populate/populate_register.h"
#include "nnacl/l2_norm_parameter.h" #include "nnacl/l2_norm_parameter.h"
@ -31,8 +32,14 @@ OpParameter *PopulateL2NormParameter(const mindspore::lite::PrimitiveC *primitiv
memset(l2_norm_parameter, 0, sizeof(L2NormParameter)); memset(l2_norm_parameter, 0, sizeof(L2NormParameter));
l2_norm_parameter->op_parameter_.type_ = primitive->Type(); l2_norm_parameter->op_parameter_.type_ = primitive->Type();
auto param = reinterpret_cast<mindspore::lite::L2Norm *>(const_cast<mindspore::lite::PrimitiveC *>(primitive)); auto param = reinterpret_cast<mindspore::lite::L2Norm *>(const_cast<mindspore::lite::PrimitiveC *>(primitive));
MS_ASSERT(param);
auto axis_vec = param->GetAxis(); auto axis_vec = param->GetAxis();
l2_norm_parameter->axis_num_ = axis_vec.size(); l2_norm_parameter->axis_num_ = axis_vec.size();
if (axis_vec.size() > SIZE_MAX / sizeof(int)) {
MS_LOG(ERROR) << "axis_vec size too big";
free(l2_norm_parameter);
return nullptr;
}
l2_norm_parameter->axis_ = reinterpret_cast<int *>(malloc(axis_vec.size() * sizeof(int))); l2_norm_parameter->axis_ = reinterpret_cast<int *>(malloc(axis_vec.size() * sizeof(int)));
if (l2_norm_parameter->axis_ == nullptr) { if (l2_norm_parameter->axis_ == nullptr) {
MS_LOG(ERROR) << "malloc axis_ data failed"; MS_LOG(ERROR) << "malloc axis_ data failed";

View File

@ -15,6 +15,7 @@
*/ */
#include "nnacl/layer_norm_parameter.h" #include "nnacl/layer_norm_parameter.h"
#include <cstdint>
#include "src/ops/layer_norm.h" #include "src/ops/layer_norm.h"
#include "src/ops/primitive_c.h" #include "src/ops/primitive_c.h"
#include "src/ops/populate/populate_register.h" #include "src/ops/populate/populate_register.h"
@ -32,11 +33,15 @@ OpParameter *PopulateLayerNormParameter(const mindspore::lite::PrimitiveC *primi
auto param = reinterpret_cast<mindspore::lite::LayerNorm *>(const_cast<mindspore::lite::PrimitiveC *>(primitive)); auto param = reinterpret_cast<mindspore::lite::LayerNorm *>(const_cast<mindspore::lite::PrimitiveC *>(primitive));
auto normalized_shape = param->GetNormalizedShape(); auto normalized_shape = param->GetNormalizedShape();
layer_norm_parameter->normalized_dims_ = normalized_shape.size(); layer_norm_parameter->normalized_dims_ = normalized_shape.size();
if (normalized_shape.size() > SIZE_MAX / sizeof(int)) {
MS_LOG(ERROR) << "normalized_shape size too big";
free(layer_norm_parameter);
return nullptr;
}
layer_norm_parameter->normalized_shape_ = reinterpret_cast<int *>(malloc(normalized_shape.size() * sizeof(int))); layer_norm_parameter->normalized_shape_ = reinterpret_cast<int *>(malloc(normalized_shape.size() * sizeof(int)));
if (layer_norm_parameter->normalized_shape_ == nullptr) { if (layer_norm_parameter->normalized_shape_ == nullptr) {
MS_LOG(ERROR) << "malloc layer_norm_parameter->normalized_shape_ failed."; MS_LOG(ERROR) << "malloc layer_norm_parameter->normalized_shape_ failed.";
free(layer_norm_parameter); free(layer_norm_parameter);
layer_norm_parameter = nullptr;
return nullptr; return nullptr;
} }
for (size_t i = 0; i < normalized_shape.size(); i++) { for (size_t i = 0; i < normalized_shape.size(); i++) {