From 40cb67b26e8dbee1faab7b670c65c97638f112ec Mon Sep 17 00:00:00 2001 From: yoni Date: Wed, 16 Jun 2021 18:17:40 +0300 Subject: [PATCH] change internal API to camel --- mindspore/lite/src/inner_kernel.h | 4 ++-- mindspore/lite/src/lite_kernel.h | 8 ++++---- .../runtime/kernel/arm/base/convolution_base.h | 2 +- .../runtime/kernel/arm/fp16/biasadd_fp16.cc | 4 ++-- .../src/runtime/kernel/arm/fp16/biasadd_fp16.h | 2 +- .../kernel/arm/fp16/convolution_1x1_fp16.cc | 8 ++++---- .../arm/fp16/convolution_delegate_fp16.h | 6 +++--- .../arm/fp16/convolution_depthwise_fp16.cc | 4 ++-- .../convolution_depthwise_slidewindow_fp16.cc | 4 ++-- .../kernel/arm/fp16/convolution_fp16.cc | 8 ++++---- .../arm/fp16/convolution_winograd_fp16.cc | 8 ++++---- .../kernel/arm/fp16/fused_batchnorm_fp16.cc | 4 ++-- .../kernel/arm/fp16/matmul_base_fp16.cc | 4 ++-- .../runtime/kernel/arm/fp16/matmul_base_fp16.h | 2 +- .../src/runtime/kernel/arm/fp16/matmul_fp16.cc | 4 ++-- .../runtime/kernel/arm/fp32/arithmetic_fp32.cc | 3 +++ .../kernel/arm/fp32/convolution_1x1_fp32.cc | 4 ++-- .../arm/fp32/convolution_delegate_fp32.h | 6 +++--- .../arm/fp32/convolution_depthwise_3x3_fp32.cc | 4 ++-- .../arm/fp32/convolution_depthwise_fp32.cc | 4 ++-- .../convolution_depthwise_indirect_fp32.cc | 4 ++-- .../convolution_depthwise_slidewindow_fp32.cc | 4 ++-- ...nvolution_depthwise_slidewindow_x86_fp32.cc | 4 ++-- .../kernel/arm/fp32/convolution_fp32.cc | 4 ++-- .../arm/fp32/convolution_winograd_fp32.cc | 4 ++-- .../kernel/arm/fp32/fused_batchnorm_fp32.cc | 2 +- mindspore/lite/src/scheduler.cc | 3 ++- mindspore/lite/src/train/train_session.cc | 18 +++++++++--------- mindspore/lite/test/config/models_ms_train.cfg | 10 +++++----- .../lite/test/st/scripts/run_benchmark_arm.sh | 12 ++++++++++-- .../lite/test/st/scripts/run_benchmark_x86.sh | 2 ++ .../kernel/arm/fp32_grad/bn_grad_fp32_test.cc | 2 +- 32 files changed, 88 insertions(+), 74 deletions(-) diff --git a/mindspore/lite/src/inner_kernel.h b/mindspore/lite/src/inner_kernel.h index 1a061d6087b..d6060524146 100644 --- a/mindspore/lite/src/inner_kernel.h +++ b/mindspore/lite/src/inner_kernel.h @@ -183,9 +183,9 @@ class InnerKernel : public Kernel { virtual bool IsEval() const { return !this->train_mode_; } - virtual void set_trainable(bool trainable = true) { this->trainable_ = trainable; } + virtual void SetTrainable(bool trainable = true) { this->trainable_ = trainable; } - virtual bool is_trainable() const { return this->trainable_; } + virtual bool IsTrainable() const { return this->trainable_; } TypeId registry_data_type(void) { return registry_data_type_; } diff --git a/mindspore/lite/src/lite_kernel.h b/mindspore/lite/src/lite_kernel.h index cb6cc54cb8d..ca804f778d6 100644 --- a/mindspore/lite/src/lite_kernel.h +++ b/mindspore/lite/src/lite_kernel.h @@ -192,17 +192,17 @@ class LiteKernel { return false; } - virtual void set_trainable(bool trainable = true) { + virtual void SetTrainable(bool trainable = true) { MS_ASSERT(kernel_ != nullptr); if (desc_.provider == kBuiltin) { - std::static_pointer_cast(kernel_)->set_trainable(trainable); + std::static_pointer_cast(kernel_)->SetTrainable(trainable); } } - virtual bool is_trainable() const { + virtual bool IsTrainable() const { MS_ASSERT(kernel_ != nullptr); if (desc_.provider == kBuiltin) { - return std::static_pointer_cast(kernel_)->is_trainable(); + return std::static_pointer_cast(kernel_)->IsTrainable(); } return false; } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/convolution_base.h b/mindspore/lite/src/runtime/kernel/arm/base/convolution_base.h index 977e09b36b4..c1908f1d39b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/convolution_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/convolution_base.h @@ -61,8 +61,8 @@ class ConvolutionBaseCPUKernel : public InnerKernel { void FreeAlignedData(void **ptr); protected: + bool IsRepack() { return is_repack_; } std::unordered_map addr_map; - bool is_repack() { return is_repack_; } void *bias_data_ = nullptr; const InnerContext *ctx_ = nullptr; ConvParameter *conv_param_ = nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/biasadd_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/biasadd_fp16.cc index 66d558ef2bd..b94255097e5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/biasadd_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/biasadd_fp16.cc @@ -53,7 +53,7 @@ int BiasAddCPUFp16Kernel::Run() { } } if (op_parameter_->is_train_session_) { - if ((is_trainable() && (IsTrain() || is_repack())) || (bias_data_type_ == kNumberTypeFloat16)) { + if ((IsTrainable() && (IsTrain() || IsRepack())) || (bias_data_type_ == kNumberTypeFloat16)) { PackWeight(); is_repack_ = false; } @@ -133,7 +133,7 @@ void BiasAddCPUFp16Kernel::PackWeight() { int BiasAddCPUFp16Kernel::Eval() { InnerKernel::Eval(); - if (is_trainable()) { + if (IsTrainable()) { is_repack_ = true; } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/biasadd_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/biasadd_fp16.h index 23725f5a04a..964f2cea768 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/biasadd_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/biasadd_fp16.h @@ -38,7 +38,7 @@ class BiasAddCPUFp16Kernel : public InnerKernel { private: int GetBiasData(); void PackWeight(); - bool is_repack() { return is_repack_; } + bool IsRepack() { return is_repack_; } ArithmeticParameter *bias_param_ = nullptr; float16_t *bias_data_ = nullptr; lite::Tensor *bias_tensor_ = nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc index 605482cadf1..b1eb2f65c6e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_1x1_fp16.cc @@ -97,7 +97,7 @@ int Convolution1x1FP16CPUKernel::InitWeightBias() { return RET_ERROR; } } - void *bias_origin_tmp = is_trainable() ? in_tensors_.at(2)->data_c() : origin_bias_; + void *bias_origin_tmp = IsTrainable() ? in_tensors_.at(2)->data_c() : origin_bias_; memcpy(bias_data_, bias_origin_tmp, output_channel * sizeof(float16_t)); memset(reinterpret_cast(bias_data_) + bias_size, 0, size - bias_size); } @@ -111,7 +111,7 @@ int Convolution1x1FP16CPUKernel::InitWeightBias() { return RET_ERROR; } } - void *weight_origin_tmp = is_trainable() ? weight_tensor->data_c() : origin_weight_; + void *weight_origin_tmp = IsTrainable() ? weight_tensor->data_c() : origin_weight_; memset(reinterpret_cast(weight_ptr_) + down_size, 0, size - down_size); ColMajor2Row8MajorFp16(weight_origin_tmp, weight_ptr_, input_channel, output_channel, true); @@ -240,7 +240,7 @@ int Convolution1x1FP16CPUKernel::Run() { return RET_MEMORY_FAILED; } - if (is_trainable() && (IsTrain() || is_repack())) { + if (IsTrainable() && (IsTrain() || IsRepack())) { auto ret = InitWeightBias(); if (ret != 0) { MS_LOG(ERROR) << "Convolution 1x1 fp16 repack weight failure"; @@ -283,7 +283,7 @@ int Convolution1x1FP16CPUKernel::Run() { } int Convolution1x1FP16CPUKernel::Eval() { - if (is_trainable()) { + if (IsTrainable()) { is_repack_ = true; } return InnerKernel::Eval(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h index af9c9b7ef07..503b76288c9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h @@ -55,9 +55,9 @@ class ConvolutionDelegateFP16CPUKernel : public InnerKernel { InnerKernel::Train(); return fp16_conv_kernel_->Train(); } - void set_trainable(bool trainable) override { - InnerKernel::set_trainable(trainable); - return fp16_conv_kernel_->set_trainable(trainable); + void SetTrainable(bool trainable) override { + InnerKernel::SetTrainable(trainable); + return fp16_conv_kernel_->SetTrainable(trainable); } void set_in_tensor(lite::Tensor *in_tensor, int index) override { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc index 1754f3ec4dd..576dbe3eacd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc @@ -109,7 +109,7 @@ static int ConvDwFp16Run(void *cdata, int task_id, float lhs_scale, float rhs_sc } int ConvolutionDepthwiseFp16CPUKernel::Run() { - if (is_trainable() && (IsTrain() || is_repack())) { + if (IsTrainable() && (IsTrain() || IsRepack())) { auto ret = InitWeightBias(); if (ret != 0) { MS_LOG(ERROR) << "Convolution depthwise fp16 repack weight failure"; @@ -125,7 +125,7 @@ int ConvolutionDepthwiseFp16CPUKernel::Run() { } int ConvolutionDepthwiseFp16CPUKernel::Eval() { - if (is_trainable()) { + if (IsTrainable()) { is_repack_ = true; } return InnerKernel::Eval(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc index a71ea54f331..ece2d46a072 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_slidewindow_fp16.cc @@ -161,7 +161,7 @@ int ConvolutionDepthwiseSWFp16CPUKernel::Run() { packed_output_ = output_ptr; } - if (is_trainable() && (IsTrain() || is_repack())) { + if (IsTrainable() && (IsTrain() || IsRepack())) { ret = InitWeightBias(); if (ret != 0) { MS_LOG(ERROR) << "Convolution depthwise fp16 repack weight failure"; @@ -192,7 +192,7 @@ void ConvolutionDepthwiseSWFp16CPUKernel::FreePackedInputOutput() { } int ConvolutionDepthwiseSWFp16CPUKernel::Eval() { - if (is_trainable()) { + if (IsTrainable()) { is_repack_ = true; } return InnerKernel::Eval(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc index b55e9bc0939..48c3f0c78af 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc @@ -46,7 +46,7 @@ int ConvolutionFP16CPUKernel::InitWeightBias() { } } memset(packed_weight_, 0, pack_weight_size * sizeof(float16_t)); - void *weight_origin_tmp = is_trainable() ? filter_tensor->data_c() : origin_weight_; + void *weight_origin_tmp = IsTrainable() ? filter_tensor->data_c() : origin_weight_; RowMajor2Col8MajorFp16(weight_origin_tmp, packed_weight_, out_channel, in_channel * kernel_plane, false); // init bias @@ -60,7 +60,7 @@ int ConvolutionFP16CPUKernel::InitWeightBias() { memset(bias_data_, 0, oc8 * sizeof(float16_t)); if (in_tensors_.size() == kInputSize2) { auto bias_tensor = in_tensors_.at(kBiasIndex); - void *bias_origin_tmp = is_trainable() ? bias_tensor->data_c() : origin_bias_; + void *bias_origin_tmp = IsTrainable() ? bias_tensor->data_c() : origin_bias_; memcpy(bias_data_, bias_origin_tmp, out_channel * sizeof(float16_t)); } return RET_OK; @@ -152,7 +152,7 @@ int ConvolutionFP16CPUKernel::Run() { return RET_ERROR; } - if (is_trainable() && (IsTrain() || is_repack())) { + if (IsTrainable() && (IsTrain() || IsRepack())) { ret = InitWeightBias(); if (ret != 0) { MS_LOG(ERROR) << "Convolution 1x1 fp16 repack weight failure"; @@ -170,7 +170,7 @@ int ConvolutionFP16CPUKernel::Run() { } int ConvolutionFP16CPUKernel::Eval() { - if (is_trainable()) { + if (IsTrainable()) { is_repack_ = true; } return InnerKernel::Eval(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc index d4f48a777e4..9372088bcd6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_winograd_fp16.cc @@ -66,7 +66,7 @@ int ConvolutionWinogradFP16CPUKernel::InitWeightBias() { MS_LOG(ERROR) << "get matrix g from CookToomFilter failed."; return ret; } - void *weight_origin_tmp = is_trainable() ? weight_tensor->data_c() : origin_weight_; + void *weight_origin_tmp = IsTrainable() ? weight_tensor->data_c() : origin_weight_; ret = WinogradFilterTransformFp16(reinterpret_cast(weight_origin_tmp), matrix_g, matrix_gt, col_tile_); if (ret != RET_OK) { MS_LOG(ERROR) << "winograd filter transform failed."; @@ -84,7 +84,7 @@ int ConvolutionWinogradFP16CPUKernel::InitWeightBias() { memset(bias_data_, 0, oc_block_num * col_tile_ * sizeof(float16_t)); if (in_tensors_.size() == kInputSize2) { auto bias_tensor = in_tensors_.at(kBiasIndex); - void *bias_origin_tmp = is_trainable() ? bias_tensor->data_c() : origin_bias_; + void *bias_origin_tmp = IsTrainable() ? bias_tensor->data_c() : origin_bias_; memcpy(bias_data_, bias_origin_tmp, out_channel * sizeof(float16_t)); } return RET_OK; @@ -229,7 +229,7 @@ int ConvolutionWinogradFP16CPUKernel::Run() { FreeTmpBuffer(); return RET_ERROR; } - if (is_trainable() && (IsTrain() || is_repack())) { + if (IsTrainable() && (IsTrain() || IsRepack())) { ret = InitWeightBias(); if (ret != 0) { MS_LOG(ERROR) << "ConvolutionWinogradFP16 repack weight failure"; @@ -246,7 +246,7 @@ int ConvolutionWinogradFP16CPUKernel::Run() { } int ConvolutionWinogradFP16CPUKernel::Eval() { - if (is_trainable()) { + if (IsTrainable()) { is_repack_ = true; } return InnerKernel::Eval(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc index 259513e5d3f..c745ad1ad10 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/fused_batchnorm_fp16.cc @@ -88,7 +88,7 @@ int FusedBatchnormFp16CPUKernel::DoExecute(int task_id) { Float32ToFloat16(reinterpret_cast(variance->data_c()), reinterpret_cast(variance_fp16), variance->ElementsNum()); - if (IsTrain() && is_trainable() && in_tensors_.size() >= 5) { + if (IsTrain() && IsTrainable() && in_tensors_.size() >= 5) { CalcMeanVar(reinterpret_cast(input_fp16), reinterpret_cast(scale_fp16), reinterpret_cast(offset_fp16), reinterpret_cast(mean_fp16), reinterpret_cast(variance_fp16)); @@ -108,7 +108,7 @@ int FusedBatchnormFp16CPUKernel::DoExecute(int task_id) { return RET_OK; } - if (IsTrain() && is_trainable() && in_tensors_.size() >= 5) { + if (IsTrain() && IsTrainable() && in_tensors_.size() >= 5) { CalcMeanVar( static_cast(in_tensors_.at(0)->data_c()), static_cast(in_tensors_.at(1)->data_c()), static_cast(in_tensors_.at(2)->data_c()), static_cast(in_tensors_.at(3)->data_c()), diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc index 8cf61adbfd6..50f3a63c3ae 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc @@ -270,13 +270,13 @@ int MatmulBaseFP16CPUKernel::RunImpl(int task_id) { int MatmulBaseFP16CPUKernel::Run() { auto c_ptr = reinterpret_cast(out_tensors_.at(0)->data_c()); - if ((params_->a_const_ == false) || is_repack()) { + if ((params_->a_const_ == false) || IsRepack()) { if (RET_OK != InitBufferA()) { return RET_ERROR; } InitMatrixA(in_tensors_.at(0)->data_c()); } - if ((params_->b_const_ == false) || is_repack()) { + if ((params_->b_const_ == false) || IsRepack()) { if (RET_OK != InitBufferB()) { FreeResizeBufA(); return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.h index 89735a7558e..ea2f4e5dec8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.h @@ -42,7 +42,7 @@ class MatmulBaseFP16CPUKernel : public InnerKernel { protected: void InitParameter(); - bool is_repack() { return is_repack_; } + bool IsRepack() { return is_repack_; } bool is_repack_ = false; private: diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc index e046211b6f0..08da0f756d5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_fp16.cc @@ -86,7 +86,7 @@ int MatmulFP16CPUKernel::ReSize() { } int MatmulFP16CPUKernel::Run() { - if (is_trainable() && (IsTrain())) { + if (IsTrainable() && (IsTrain())) { is_repack_ = true; } auto ret = MatmulBaseFP16CPUKernel::Run(); @@ -99,7 +99,7 @@ int MatmulFP16CPUKernel::Run() { int MatmulFP16CPUKernel::Eval() { InnerKernel::Eval(); - if (is_trainable()) { + if (IsTrainable()) { is_repack_ = true; } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc index 65ead5f2b38..4890d042d25 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_fp32.cc @@ -76,6 +76,9 @@ int ArithmeticCPUKernel::CheckDataType() { << in0_dataType << " input 1 dataType: " << in1_dataType; return RET_ERROR; } + if (op_parameter_->is_train_session_) { + data_type_len_ = lite::DataTypeSize(in_tensors_.at(0)->data_type()); + } return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1_fp32.cc index ec62d0aef66..9c61b339861 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1_fp32.cc @@ -242,7 +242,7 @@ int Convolution1x1CPUKernel::Run() { MS_LOG(ERROR) << "Conv1x1 Malloc pack_input_ error!"; return RET_MEMORY_FAILED; } - if (IsTrain() && is_trainable()) { + if (IsTrain() && IsTrainable()) { PackWeight(); } @@ -294,7 +294,7 @@ int Convolution1x1CPUKernel::Eval() { MS_LOG(ERROR) << "eval failed!"; return ret; } - if (is_trainable()) { + if (IsTrainable()) { PackWeight(); } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h index 0b2dd945811..9a3e4cc90c6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h @@ -88,9 +88,9 @@ class ConvolutionDelegateCPUKernel : public InnerKernel { InnerKernel::Train(); return conv_kernel_->Train(); } - void set_trainable(bool trainable) override { - InnerKernel::set_trainable(trainable); - return conv_kernel_->set_trainable(trainable); + void SetTrainable(bool trainable) override { + InnerKernel::SetTrainable(trainable); + return conv_kernel_->SetTrainable(trainable); } protected: diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3_fp32.cc index 6fd0d644204..7174ebde8ee 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3_fp32.cc @@ -119,7 +119,7 @@ int ConvolutionDepthwise3x3CPUKernel::Run() { return RET_MEMORY_FAILED; } - if (IsTrain() && is_trainable()) { + if (IsTrain() && IsTrainable()) { if (InitWeightBias() != RET_OK) { ctx_->allocator->Free(buffer_); MS_LOG(ERROR) << "Convolution depthwise 3x3 run InitWeightBias failed."; @@ -148,7 +148,7 @@ int ConvolutionDepthwise3x3CPUKernel::Eval() { MS_LOG(ERROR) << "eval failed!"; return ret; } - if (is_trainable()) { + if (IsTrainable()) { if (InitWeightBias() != RET_OK) { MS_LOG(ERROR) << "Convolution depthwise 3x3 fp32 Eval:InitWeightBias failed."; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32.cc index cb5549fa8b8..cf81570fecd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32.cc @@ -105,7 +105,7 @@ int ConvDwRun(void *cdata, int task_id, float lhs_scale, float rhs_scale) { } int ConvolutionDepthwiseCPUKernel::Run() { - if (IsTrain() && is_trainable()) { + if (IsTrain() && IsTrainable()) { PackWeight(); } @@ -139,7 +139,7 @@ int ConvolutionDepthwiseCPUKernel::Eval() { MS_LOG(ERROR) << "eval failed!"; return ret; } - if (is_trainable()) { + if (IsTrainable()) { PackWeight(); } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_indirect_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_indirect_fp32.cc index 91c0b56da37..69d8c333fbb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_indirect_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_indirect_fp32.cc @@ -194,7 +194,7 @@ int ConvolutionDepthwiseIndirectCPUKernel::Run() { packed_input_ = input_ptr; } - if (IsTrain() && is_trainable()) { + if (IsTrain() && IsTrainable()) { PackWeight(); } @@ -233,7 +233,7 @@ int ConvolutionDepthwiseIndirectCPUKernel::Eval() { MS_LOG(ERROR) << "eval failed!"; return ret; } - if (is_trainable()) { + if (IsTrainable()) { PackWeight(); } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_fp32.cc index 148b304762e..52dc1edb204 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_fp32.cc @@ -150,7 +150,7 @@ int ConvolutionDepthwiseSWCPUKernel::Run() { return RET_ERROR; } - if (IsTrain() && is_trainable()) { + if (IsTrain() && IsTrainable()) { PackWeight(); } @@ -207,7 +207,7 @@ int ConvolutionDepthwiseSWCPUKernel::Eval() { MS_LOG(ERROR) << "eval failed!"; return ret; } - if (is_trainable()) { + if (IsTrainable()) { PackWeight(); } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_x86_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_x86_fp32.cc index 0ec9f7284a5..d004479ff1c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_x86_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow_x86_fp32.cc @@ -138,7 +138,7 @@ int ConvolutionDepthwiseSWCPUKernelX86::Run() { return RET_ERROR; } - if (IsTrain() && is_trainable()) { + if (IsTrain() && IsTrainable()) { PackWeight(); } @@ -198,7 +198,7 @@ int ConvolutionDepthwiseSWCPUKernelX86::Eval() { MS_LOG(ERROR) << "eval failed!"; return ret; } - if (is_trainable()) { + if (IsTrainable()) { PackWeight(); } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_fp32.cc index 8ee3571370e..c066056141f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_fp32.cc @@ -147,7 +147,7 @@ int ConvolutionCPUKernel::Run() { FreeTmpBuffer(); return RET_ERROR; } - if (IsTrain() && is_trainable()) { + if (IsTrain() && IsTrainable()) { PackWeight(); } @@ -180,7 +180,7 @@ void ConvolutionCPUKernel::PackWeight() { int ConvolutionCPUKernel::Eval() { InnerKernel::Eval(); - if (is_trainable()) { + if (IsTrainable()) { PackWeight(); } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd_fp32.cc index 0edcb1de17f..3c3fb76dc01 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd_fp32.cc @@ -216,7 +216,7 @@ int ConvolutionWinogradCPUKernel::Run() { FreeTmpBuffer(); return RET_ERROR; } - if (IsTrain() && is_trainable()) { + if (IsTrain() && IsTrainable()) { ret = InitWeightBias(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init weight bias failed."; @@ -239,7 +239,7 @@ int ConvolutionWinogradCPUKernel::Eval() { MS_LOG(ERROR) << "eval failed!"; return ret; } - if (is_trainable()) { + if (IsTrainable()) { ret = InitWeightBias(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init weight bias failed."; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc index 85bd3887740..aaf7d9a8346 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm_fp32.cc @@ -66,7 +66,7 @@ int FusedBatchnormCPUKernel::InitConstTensor() { int FusedBatchnormCPUKernel::Run() { auto param = reinterpret_cast(op_parameter_); - if (IsTrain() && is_trainable() && in_tensors_.size() >= 5) { + if (IsTrain() && IsTrainable() && in_tensors_.size() >= 5) { float *in = static_cast(in_tensors_[0]->MutableData()); float *scale = static_cast(in_tensors_[1]->MutableData()); float *offset = static_cast(in_tensors_[2]->MutableData()); diff --git a/mindspore/lite/src/scheduler.cc b/mindspore/lite/src/scheduler.cc index 744a803630d..b8b2fbeff3a 100644 --- a/mindspore/lite/src/scheduler.cc +++ b/mindspore/lite/src/scheduler.cc @@ -445,6 +445,7 @@ int Scheduler::FindCpuKernel(const std::vector &in_tensors, const std: if (ret == RET_OK) { MS_LOG(DEBUG) << "Get TypeId(" << kernel_data_type << ") op success: " << PrimitiveCurVersionTypeName(op_type); if (is_train_session_) { + (*kernel)->Init(); RestoreTensorData(&restored_origin_tensors); } else { FreeRestoreTensors(&restored_origin_tensors); @@ -721,7 +722,7 @@ int Scheduler::ScheduleSubGraphToKernels(size_t subgraph_index, std::vectorInit(); } } diff --git a/mindspore/lite/src/train/train_session.cc b/mindspore/lite/src/train/train_session.cc index b4c947f2367..662428d43f4 100644 --- a/mindspore/lite/src/train/train_session.cc +++ b/mindspore/lite/src/train/train_session.cc @@ -61,6 +61,10 @@ TrainSession::TrainSession() { int TrainSession::Init(const Context *context, const TrainCfg *train_cfg) { if (train_cfg != nullptr) { + if (train_cfg->mix_precision_cfg_.loss_scale_ <= 0) { + MS_LOG(ERROR) << "illegal loss scale configuration"; + return RET_NULL_PTR; + } cfg_ = *train_cfg; } return lite::LiteSession::Init(context); @@ -115,6 +119,9 @@ void TrainSession::FreeWorkSpace() { int TrainSession::InitCallBack() { sched_mix_precision_callback_ = [&](const Model::Node *node) { + if (!context_->IsCpuFloat16Enabled()) { + return false; + } auto node_type = GetPrimitiveType(node->primitive_); if (node_type == schema::PrimitiveType_Cast) { return false; @@ -548,7 +555,7 @@ void TrainSession::CompileOptimizedKernels() { if (!IsOptimizer(kernel)) { for (auto it : kernel->in_tensors()) { if (std::find(out_tensor.begin(), out_tensor.end(), it) != out_tensor.end()) { - kernel->set_trainable(true); + kernel->SetTrainable(true); break; } } @@ -610,7 +617,7 @@ int TrainSession::AdminSetupVirtualBatch(int virtual_batch_multiplier, float lr, } } - if (IsBN(kernel) && kernel->is_trainable()) { + if (IsBN(kernel) && kernel->IsTrainable()) { auto batchnorm = static_cast(kernel->kernel()); auto ret = RET_OK; if (mod == kernel::OptimizerKernel::WeightUpdateMode::VIRTUAL_BATCH) { @@ -711,13 +718,6 @@ int TrainSession::Export(const std::string &file_name, ModelType model_type, Qua session::LiteSession *session::LiteSession::CreateTrainSession(const std::string &fn, const lite::Context *context, bool train_mode, const lite::TrainCfg *cfg) { - if (cfg != nullptr) { - // test legal configuration - if (cfg->mix_precision_cfg_.loss_scale_ <= 0) { - MS_LOG(ERROR) << "illegal loss scale configuration"; - return nullptr; - } - } auto session = std::make_unique(); if (session == nullptr) { MS_LOG(ERROR) << "create session failed"; diff --git a/mindspore/lite/test/config/models_ms_train.cfg b/mindspore/lite/test/config/models_ms_train.cfg index e6303c9bdcb..956ea63ef68 100644 --- a/mindspore/lite/test/config/models_ms_train.cfg +++ b/mindspore/lite/test/config/models_ms_train.cfg @@ -23,15 +23,15 @@ effnet_tune weight_quant 7 googlenet weight_quant 10 densenet weight_quant 11 shufflenetv2 weight_quant 3 -#mini_alexnet fp16 6 -#nin fp16 8.0 +mini_alexnet fp16 6 +nin fp16 8.0 #lenet fp16 2 mobilenetv1 fp16 2 mobilenetv2 fp16 2 -#mobilenetv3 fp16 7 +mobilenetv3 fp16 7 effnet fp16 2 -#effnet_tune fp16 5.0 +effnet_tune fp16 5.0 resnet fp16 2 -#googlenet fp16 10 +googlenet fp16 10 #xception fp16 20.0 # LAST diff --git a/mindspore/lite/test/st/scripts/run_benchmark_arm.sh b/mindspore/lite/test/st/scripts/run_benchmark_arm.sh index d5428607875..2ee721dd03e 100644 --- a/mindspore/lite/test/st/scripts/run_benchmark_arm.sh +++ b/mindspore/lite/test/st/scripts/run_benchmark_arm.sh @@ -1060,12 +1060,17 @@ function Run_arm64() { model_prefix=${line_array[0]} model_name=${line_array[0]}'_train' accuracy_limit=0.5 + enable_fp16="false" if [[ $model_name == \#* ]]; then continue fi if [[ "${line_array[1]}" == "weight_quant" ]]; then model_name=${line_array[0]}'_train_quant' accuracy_limit=${line_array[2]} + elif [[ "${line_array[1]}" == "fp16" ]]; then + enable_fp16="true" + suffix_print="_fp16" + accuracy_limit=${line_array[2]} fi export_file="${tmp_dir}/${model_name}_tod" inference_file="${tmp_dir}/${model_name}_infer" @@ -1086,6 +1091,7 @@ function Run_arm64() { --expectedDataFile=${tmp_dir}/${model_prefix}_output \ --numThreads=${threads} \ --accuracyThreshold=${accuracy_limit} \ + --enableFp16=${enable_fp16} \ --inferenceFile=${inference_file} \ --exportFile=${export_file} ENDM @@ -1095,9 +1101,9 @@ ENDM adb -s ${device_id} shell < adb_run_cmd.txt >> ${run_arm64_fp32_log_file} # TODO: change to arm_type if [ $? = 0 ]; then - run_result='arm64_train: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_train_result_file} + run_result='arm64_train: '${model_name}''${suffix_print}' pass'; echo ${run_result} >> ${run_benchmark_train_result_file} else - run_result='arm64_train: '${model_name}' failed'; echo ${run_result} >> ${run_benchmark_train_result_file}; + run_result='arm64_train: '${model_name}''${suffix_print}' failed'; echo ${run_result} >> ${run_benchmark_train_result_file}; fail=1 fi done < ${models_ms_train_config} @@ -1183,6 +1189,8 @@ function Run_arm32() { if [[ "${line_array[1]}" == "weight_quant" ]]; then model_name=${line_array[0]}'_train_quant' accuracy_limit=${line_array[2]} + elif [[ "${line_array[1]}" != "" ]]; then + continue fi export_file="${tmp_dir}/${model_name}_tod" inference_file="${tmp_dir}/${model_name}_infer" diff --git a/mindspore/lite/test/st/scripts/run_benchmark_x86.sh b/mindspore/lite/test/st/scripts/run_benchmark_x86.sh index 9af9ee9b571..8c49b1669c1 100644 --- a/mindspore/lite/test/st/scripts/run_benchmark_x86.sh +++ b/mindspore/lite/test/st/scripts/run_benchmark_x86.sh @@ -737,6 +737,8 @@ function Run_x86() { if [[ "${line_array[1]}" == "weight_quant" ]]; then model_name=${line_array[0]}'_train_quant' accuracy_limit=${line_array[2]} + elif [[ "${line_array[1]}" != "" ]]; then + continue fi export_file="${ms_train_models_path}/${model_name}_tod" inference_file="${ms_train_models_path}/${model_name}_infer" diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/bn_grad_fp32_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/bn_grad_fp32_test.cc index 52cac588702..53a17c052fb 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/bn_grad_fp32_test.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/bn_grad_fp32_test.cc @@ -194,7 +194,7 @@ TEST_F(TestBNGradFp32, BNTtrainFp32) { EXPECT_EQ(0, ret); kernel_obj->Train(); - kernel_obj->set_trainable(true); + kernel_obj->SetTrainable(true); kernel_obj->Run(); std::cout << "================save_mean==============================\n";