1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "src/runtime/kernel/arm/base/softmax_base.h" 18 #include <vector> 19 #include "src/runtime/kernel/arm/fp32/softmax_fp32.h" 20 #include "nnacl/fp32/softmax_fp32.h" 21 #include "schema/model_generated.h" 22 #include "src/kernel_registry.h" 23 #include "include/errorcode.h" 24 25 using mindspore::lite::KernelRegistrar; 26 using mindspore::lite::RET_ERROR; 27 using mindspore::lite::RET_NULL_PTR; 28 using mindspore::lite::RET_OK; 29 30 namespace mindspore::kernel { Init()31int SoftmaxBaseCPUKernel::Init() { 32 CHECK_LESS_RETURN(in_tensors_.size(), 1); 33 CHECK_LESS_RETURN(out_tensors_.size(), 1); 34 if (softmax_param_ == nullptr) { 35 MS_LOG(ERROR) << "SoftmaxParameter nullptr"; 36 return RET_NULL_PTR; 37 } 38 return RET_OK; 39 } 40 ReSize()41int SoftmaxBaseCPUKernel::ReSize() { 42 auto input_tensor = in_tensors_.front(); 43 CHECK_NULL_RETURN(input_tensor); 44 auto in_shape = input_tensor->shape(); 45 auto in_dims = in_shape.size(); 46 int ele_size = 1; 47 softmax_param_->n_dim_ = in_dims; 48 if (softmax_param_->axis_ == -1) { 49 softmax_param_->axis_ += in_dims; 50 } 51 for (size_t i = 0; i < in_dims; i++) { 52 softmax_param_->input_shape_[i] = in_shape.at(i); 53 ele_size *= in_shape.at(i); 54 } 55 softmax_param_->element_size_ = ele_size; 56 return RET_OK; 57 } 58 } // namespace mindspore::kernel 59