support to codegen new nnacl kernelBase

This commit is contained in:
lz 2022-06-13 14:52:54 +08:00
parent 51c0c3e97a
commit 03bc64d006
4 changed files with 55 additions and 0 deletions

View File

@ -10,6 +10,12 @@ function(__install_micro_wrapper)
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${NNACL_DIR}/fp32 DESTINATION ${CODEGEN_ROOT_DIR}/include/nnacl
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${NNACL_DIR}/kernel DESTINATION ${CODEGEN_ROOT_DIR}/include/nnacl
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${NNACL_DIR}/infer DESTINATION ${CODEGEN_ROOT_DIR}/include/nnacl
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${NNACL_DIR}/experimental DESTINATION ${CODEGEN_ROOT_DIR}/include/nnacl
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${NNACL_DIR}/intrinsics DESTINATION ${CODEGEN_ROOT_DIR}/include/nnacl
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${MICRO_DIR}/coder/wrapper DESTINATION ${CODEGEN_ROOT_DIR}/include

View File

@ -21,6 +21,7 @@
#include "nnacl/pooling_parameter.h"
namespace mindspore::lite::micro::nnacl {
int NNaclFp32Serializer::count = 0;
void NNaclFp32Serializer::CodeStruct(const std::string &name, const PoolingParameter &pooling_parameter) {
CodeBaseStruct("PoolingParameter", name,
// Primitive parameter
@ -166,4 +167,28 @@ void NNaclFp32Serializer::CodeStruct(const std::string &name, const GroupNormPar
CodeBaseStruct("GroupNormParameter", name, gn_param.op_parameter_, gn_param.epsilon_, gn_param.num_groups_,
gn_param.channel_, gn_param.unit_, gn_param.batch_, gn_param.affine_);
}
void NNaclFp32Serializer::CodeStruct(const std::string &name, const OpParameter &op_param) {
CodeBaseStruct<false>("OpParameter", name, op_param.name_, op_param.type_, op_param.thread_num_, op_param.quant_type_,
op_param.is_train_session_, op_param.is_zero_shape_);
}
void NNaclFp32Serializer::CodeArrayStruct(const std::string &name, TensorC *tensorC, std::vector<Tensor *> tensor) {
std::vector<std::string> tensor_names;
int size = tensor.size();
for (int i = 0; i < size; ++i) {
std::string tensor_name = "tensor" + std::to_string(count++);
CodeBaseStruct<false>("TensorC", name, tensor_name, tensorC[i].is_ready_, tensorC[i].data_type_, tensorC[i].format_,
tensor[i], tensorC[i].shape_size_, ToString(tensorC[i].shape_));
tensor_names.emplace_back(tensor_name);
}
code << " TensorC"
<< " " << name << "[" << std::to_string(size) << "]"
<< " = {";
for (int i = 0; i < size - 1; ++i) {
code << tensor_names[i] << ", ";
}
code << tensor_names[size - 1];
code << "};\n";
}
} // namespace mindspore::lite::micro::nnacl

View File

@ -18,6 +18,7 @@
#define MINDSPORE_LITE_TOOLS_CONVERTER_MICRO_CODER_OPCODERS_SERIALIZERS_NNACL_SERIALIZER_NNACL_FP32_SERIALIZER_H_
#include <string>
#include <sstream>
#include <vector>
#include "coder/opcoders/serializers/serializer.h"
#include "nnacl/batchnorm_parameter.h"
#include "nnacl/fp32/arithmetic_fp32.h"
@ -35,6 +36,7 @@
#include "wrapper/fp32/dequant_int8_to_fp32_wrapper.h"
#include "nnacl/fp32/exp_fp32.h"
#include "nnacl/fp32/strided_slice_fp32.h"
#include "nnacl/tensor_c.h"
#include "wrapper/fp32/arithmetic_fp32_wrapper.h"
#include "wrapper/base/affine_wrapper.h"
#include "wrapper/fp32/conv_winograd_fp32_wrapper.h"
@ -63,6 +65,11 @@ class NNaclFp32Serializer : public Serializer {
void CodeStruct(const std::string &name, const SpliceWrapperParam &splice_param);
void CodeStruct(const std::string &name, const TransFuncStr trans_func_str);
void CodeStruct(const std::string &name, const GroupNormParameter &gn_param);
void CodeStruct(const std::string &name, const OpParameter &op_param);
void CodeArrayStruct(const std::string &name, TensorC *tensorC, std::vector<Tensor *> tensor);
private:
static int count;
};
} // namespace mindspore::lite::micro::nnacl
#endif // MINDSPORE_LITE_MICRO_CODER_OPCODERS_SERIALIZERS_NNACL_FP32_ERIALIZER_H_

View File

@ -93,6 +93,23 @@ class Serializer {
code << "}\n";
}
/*
* Code function call to generated code with return variable
* First parameter is the function name, the rest are the parameters of the function
* example:
* CodeFunctionWithCheck("int op", "function", "foo", "bar", "foobar", 42);
* the code above would produce:
* """
* int op = function("foo", "bar", "foobar", 42)
* """
*/
template <typename... PARAMETERS>
void CodeFunctionWithRet(const std::string &ret, const std::string &func_name, PARAMETERS... parameters) {
code << " " << ret << " = " << func_name << "(";
GenCode(parameters...);
code << ");\n";
}
/*
* helper function for coding
* example: