!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"
typedef struct FlattenParameter {
// Primitive parameter
OpParameter op_parameter_;
// other parameter
int size;
} FlattenParameter;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,9 +20,12 @@
#include "nnacl/op_base.h"
typedef struct LshProjectionParameter {
// Primitive parameter
OpParameter op_parameter_;
int lsh_type_;
// shape correlative
int hash_shape_[2];
// other parameter
int lsh_type_;
int feature_num_;
char **hash_buffs_;
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 struct MatMulParameter {
// Primitive parameter
OpParameter op_parameter_;
// other parameter
int row_;
int col_;
int row_4_;

View File

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

View File

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

View File

@ -23,15 +23,18 @@
#define DEFAULT_PAD_NDIMS 4
typedef struct PadParameter {
// Primitive parameter
OpParameter op_parameter_;
PadQuantArg pad_quant_arg_;
int paddings_[MAX_PAD_SIZE];
int padding_length;
int pad_mode_;
float constant_value_;
int mirror_offset_;
// shape correlative
int padding_length;
// other parameter
int in_strides[DEFAULT_PAD_NDIMS];
int out_strides[DEFAULT_PAD_NDIMS];
int mirror_offset_;
PadQuantArg pad_quant_arg_;
} PadParameter;
#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 struct PoolingParameter {
// Primitive parameter
OpParameter op_parameter_;
PoolMode pool_mode_;
RoundMode round_mode_;
ActType act_type_;
QuantArg **quant_args_;
int avg_mode_;
bool global_;
int window_w_;
int window_h_;
int stride_w_;
int stride_h_;
// shape correlative
int input_w_;
int input_h_;
int input_batch_;
@ -43,11 +48,9 @@ typedef struct PoolingParameter {
int pad_d_;
int pad_l_;
int pad_r_;
int stride_w_;
int stride_h_;
// other parameter
int thread_num_;
int avg_mode_;
bool global_;
QuantArg **quant_args_;
bool quantize_;
} PoolingParameter;

View File

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

View File

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

View File

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

View File

@ -24,6 +24,7 @@
#define PRIOR_BOX_MAX_NUM 8
#define PRIOR_BOX_VAR_NUM 4
typedef struct PriorBoxParameter {
// Primitive parameter
OpParameter op_parameter_;
int32_t min_sizes_size;
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));
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->batchDims_ = gather_attr->GetBatchDims();
return reinterpret_cast<OpParameter *>(gather_param);

View File

@ -15,6 +15,7 @@
*/
#include "src/ops/l2_norm.h"
#include <cstdint>
#include "src/ops/primitive_c.h"
#include "src/ops/populate/populate_register.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));
l2_norm_parameter->op_parameter_.type_ = primitive->Type();
auto param = reinterpret_cast<mindspore::lite::L2Norm *>(const_cast<mindspore::lite::PrimitiveC *>(primitive));
MS_ASSERT(param);
auto axis_vec = param->GetAxis();
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)));
if (l2_norm_parameter->axis_ == nullptr) {
MS_LOG(ERROR) << "malloc axis_ data failed";

View File

@ -15,6 +15,7 @@
*/
#include "nnacl/layer_norm_parameter.h"
#include <cstdint>
#include "src/ops/layer_norm.h"
#include "src/ops/primitive_c.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 normalized_shape = param->GetNormalizedShape();
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)));
if (layer_norm_parameter->normalized_shape_ == nullptr) {
MS_LOG(ERROR) << "malloc layer_norm_parameter->normalized_shape_ failed.";
free(layer_norm_parameter);
layer_norm_parameter = nullptr;
return nullptr;
}
for (size_t i = 0; i < normalized_shape.size(); i++) {