开发者需要进行算子适配插件的开发,实现将第三方框架(TensorFlow/Caffe/ONNX)网络中的算子进行解析并映射成昇腾AI处理器中的算子。
MindStudio在“framework/tf_plugin/tensorflow_add_plugin.cc”(以TensorFlow为例)文件已自动生成了Add算子的插件代码。
1 2 | //包含该头文件,可使用算子注册类相关,调用算子注册相关的接口,为Ascend-cann-toolkit安装目录/ascend-toolkit/latest/compiler/include/register/register.h文件 #include "register/register.h" |
1 2 3 4 5 6 7 | namespace domi{ REGISTER_CUSTOM_OP("Add") .FrameworkType(TENSORFLOW) .OriginOpType({ge::AscendString("Add")}) .ParseParamsByOperatorFn(AutoMappingFn) .ImplyType(ImplyType::TVM); //需手动添加 } |
MindStudio在“framework/onnx_plugin/Add_plugin.cc”文件已自动生成了Add算子的插件代码。
1 2 | //包含该头文件,可使用算子注册类相关,调用算子注册相关的接口,为Ascend-cann-toolkit安装目录/ascend-toolkit/latest/compiler/include/register/register.h文件 #include "register/register.h" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using namespace ge; // 需手动添加 namespace domi { // Onnx ParseParams Status ParseParamAdd(const Message* op_src, ge::Operator& op_dest) { // To do: Implement the operator plugin by referring to the Onnx Operator Development Guide. return SUCCESS; } // register op info to GE REGISTER_CUSTOM_OP("Add") .FrameworkType(ONNX) // Operator name with the original framework .OriginOpType("") // Set the original frame type of the operator .ParseParamsByOperatorFn(ParseParamAdd)// Registering the callback function for parsing operator parameters .ImplyType(ImplyType::TVM); // 需手动添加 } // namespace domi |
回调函数ParseParamAdd的声明如下所示:
Status ParseParamAdd(const ge::Operator& op_src, ge::Operator& op_dest)