1 /** 2 * Copyright 2021 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 #ifndef AICPU_OPS_AICPU_COMMON_KERNEL_BASE_H_ 17 #define AICPU_OPS_AICPU_COMMON_KERNEL_BASE_H_ 18 19 #include <cstdint> 20 #include <vector> 21 #include <string> 22 23 #include "common/kernel_util.h" 24 #include "aicpu/common/aicpu_task_struct.h" 25 #include "securec/include/securec.h" 26 #include "common/tensor.h" 27 #include "cce/fwk_adpt_struct.h" 28 #include "common/kernel_log.h" 29 #include "proto/aicpu_tensor.pb.h" 30 31 namespace aicpu { 32 class KernelBase { 33 public: 34 explicit KernelBase(const std::string &kernel_name); 35 36 virtual ~KernelBase() = default; 37 38 uint32_t Compute(void *param); 39 size_t GetDataTypeSize(::aicpuops::DataType data_type) const; 40 size_t GetTensorMemSizeByShape(const ::aicpuops::Tensor &tensor); 41 42 protected: 43 virtual uint32_t ParseKernelParam() = 0; 44 virtual uint32_t DoCompute() = 0; 45 46 template <typename T> 47 uint32_t ParseExtendParam(T *param_var, const std::string ¶m_name); 48 49 uint32_t ParseNodeDef(); 50 51 uint32_t ParseExtInfo(); 52 53 uint32_t ParseExtShapeType(FWKAdapter::ExtInfo *ext_info); 54 55 uint32_t ParseExtInputShape(FWKAdapter::ExtInfo *ext_info); 56 57 uint32_t ParseExtOutputShape(FWKAdapter::ExtInfo *ext_info); 58 59 void UpdateInputShape(); 60 61 void UpdateOutputShape(); 62 63 private: 64 KernelBase(const KernelBase &) = delete; 65 KernelBase &operator=(const KernelBase &) = delete; 66 KernelBase(KernelBase &&) = delete; 67 KernelBase &operator=(KernelBase &&) = delete; 68 69 uint32_t ParseParam(void *param); 70 71 protected: 72 std::string kernel_name_; 73 std::vector<uintptr_t> io_addrs_; 74 uint32_t extend_param_len_; 75 uint8_t *extend_param_base_; 76 AicpuParamHead *param_head_; 77 bool unknow_shape_; 78 aicpuops::NodeDef node_def_; 79 std::vector<FWKAdapter::ShapeAndType *> input_shape_and_type_; 80 std::vector<FWKAdapter::ShapeAndType *> output_shape_and_type_; 81 }; 82 } // namespace aicpu 83 #endif // AICPU_OPS_AICPU_COMMON_KERNEL_BASE_H_ 84