|
|
|
@@ -32,6 +32,14 @@ int PadFp16CPUKernel::RunImpl(int task_id) { |
|
|
|
return RET_OK; |
|
|
|
} |
|
|
|
|
|
|
|
int PadFp16CPUKernel::RunMirrorPadImpl(int task_id) { |
|
|
|
int unit = UP_DIV(out_tensors_.at(0)->ElementsNum(), context_->thread_num_); |
|
|
|
int begin = unit * task_id; |
|
|
|
int end = MSMIN(begin + unit, out_tensors_.at(0)->ElementsNum()); |
|
|
|
MirrorPadFp16(input_, output_, in_, pad_param_, begin, end); |
|
|
|
return RET_OK; |
|
|
|
} |
|
|
|
|
|
|
|
int PadFp16CPUKernel::Run() { |
|
|
|
auto input_tensor = in_tensors_.at(0); |
|
|
|
auto output_tensor = out_tensors_.at(0); |
|
|
|
@@ -45,18 +53,26 @@ int PadFp16CPUKernel::Run() { |
|
|
|
MS_LOG(ERROR) << "input or output is nullptr"; |
|
|
|
return RET_ERROR; |
|
|
|
} |
|
|
|
|
|
|
|
if (pad_param_->constant_value_ - 0.0f < 1e-5) { |
|
|
|
memset(output_, 0, output_tensor->ElementsNum() * sizeof(float16_t)); |
|
|
|
int ret = 0; |
|
|
|
if (pad_param_->pad_mode_ == static_cast<int>(schema::PaddingMode_CONSTANT)) { |
|
|
|
if (pad_param_->constant_value_ - 0.0f < 1e-5) { |
|
|
|
memset(output_, 0, output_tensor->ElementsNum() * sizeof(float16_t)); |
|
|
|
} else { |
|
|
|
for (int i = 0; i < output_tensor->ElementsNum(); ++i) { |
|
|
|
output_[i] = pad_param_->constant_value_; |
|
|
|
} |
|
|
|
} |
|
|
|
ret = ParallelLaunch(this->context_->thread_pool_, PadImpl, this, op_parameter_->thread_num_); |
|
|
|
if (ret != RET_OK) { |
|
|
|
MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; |
|
|
|
} |
|
|
|
} else { |
|
|
|
for (int i = 0; i < output_tensor->ElementsNum(); ++i) { |
|
|
|
output_[i] = pad_param_->constant_value_; |
|
|
|
HandleMirrorPad(); |
|
|
|
ret = ParallelLaunch(this->context_->thread_pool_, MirrorPadImpl, this, context_->thread_num_); |
|
|
|
if (ret != RET_OK) { |
|
|
|
MS_LOG(ERROR) << "Pad Reflect or Symmetric mode run error, error_code[" << ret << "]"; |
|
|
|
} |
|
|
|
} |
|
|
|
auto ret = ParallelLaunch(this->context_->thread_pool_, PadImpl, this, op_parameter_->thread_num_); |
|
|
|
if (ret != RET_OK) { |
|
|
|
MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; |
|
|
|
} |
|
|
|
if (is_output_fp32_) { |
|
|
|
Float16ToFloat32(output_, reinterpret_cast<float *>(output_tensor->MutableData()), output_tensor->ElementsNum()); |
|
|
|
} |
|
|
|
|