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 #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_MATMUL_FP32_BASE_H_ 18 #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_MATMUL_FP32_BASE_H_ 19 20 #include <vector> 21 #include "src/inner_kernel.h" 22 #include "nnacl/matmul_parameter.h" 23 #include "include/errorcode.h" 24 25 using mindspore::lite::RET_ERROR; 26 using mindspore::lite::RET_MEMORY_FAILED; 27 using mindspore::lite::RET_OK; 28 29 namespace mindspore::kernel { 30 using MatrixPackFun = void (*)(const float *src_ptr, float *dst_ptr, int row, int col); 31 class MatmulFp32BaseCPUKernel : public InnerKernel { 32 public: MatmulFp32BaseCPUKernel(OpParameter * parameter,const std::vector<lite::Tensor * > & inputs,const std::vector<lite::Tensor * > & outputs,const mindspore::lite::InnerContext * ctx)33 MatmulFp32BaseCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs, 34 const std::vector<lite::Tensor *> &outputs, const mindspore::lite::InnerContext *ctx) 35 : InnerKernel(parameter, inputs, outputs, ctx) { 36 params_ = reinterpret_cast<MatMulParameter *>(op_parameter_); 37 vec_matmul_ = false; 38 } 39 ~MatmulFp32BaseCPUKernel() override; 40 int Init() override; 41 int ReSize() override; 42 int Run() override; 43 44 public: 45 int FloatRun(int task_id) const; 46 47 protected: 48 int InitBufferA(); 49 int InitBufferB(); 50 int InitMatrixA(const float *src_ptr); 51 int InitMatrixB(const float *src_ptr); 52 void FreeBiasBuf(); 53 int InitBiasData(); 54 void InitParameter(); 55 void init_global_variable(); 56 57 private: 58 void ResizeParameter(); 59 void FreeResizeBufA(); 60 void FreeResizeBufB(); 61 void FreeBuffSrcB(); 62 int CalBroadCastBiasDataElements(); 63 int InitTmpOutBuffer(); 64 65 protected: 66 MatMulParameter *params_ = nullptr; 67 float *a_pack_ptr_ = nullptr; 68 float *b_pack_ptr_ = nullptr; 69 70 private: 71 int col_tile_ = 0; 72 int row_tile_ = 0; 73 int oc_res_ = 0; 74 int thread_stride_ = 0; 75 int thread_count_ = 0; 76 bool vec_matmul_ = false; 77 float *bias_ptr_ = nullptr; 78 float *batch_a_ptr_ = nullptr; 79 float *batch_b_ptr_ = nullptr; 80 float *batch_c_ptr_ = nullptr; 81 float *output_data_ = nullptr; 82 int matrix_a_pack_size_ = -1; 83 int matrix_b_pack_size_ = -1; 84 float *src_b_ = nullptr; 85 MatrixPackFun matrix_a_pack_fun_ = nullptr; 86 MatrixPackFun matrix_b_pack_fun_ = nullptr; 87 }; 88 } // namespace mindspore::kernel 89 #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_MATMUL_FP32_BASE_H_ 90