开发者需要进行算子适配插件的开发,实现将第三方框架(TensorFlow/ONNX)网络中的算子进行解析并映射成昇腾AI处理器中的算子。
MindStudio在“framework/tf_plugin/tensorflow_reshape_cust_plugin.cc”文件已自动生成了ReshapeCust算子的插件代码。
1 2 | //包含该头文件,可使用算子注册类相关,调用算子注册相关的接口,为Ascend-cann-toolkit开发套件包中compiler/include/register/register.h文件 #include "register/register.h" |
1 2 3 4 5 6 7 8 9 | using namespace ge; // 需手动添加 namespace domi { // register op info to GE REGISTER_CUSTOM_OP("ReshapeCust") .FrameworkType(TENSORFLOW) // type: CAFFE, TENSORFLOW .OriginOpType("ReshapeCust") // name in tf module .ParseParamsByOperatorFn(AutoMappingByOpFn); .ImplyType(ImplyType::AI_CPU); // 需手动添加 } // namespace domi |
MindStudio在“framework/onnx_plugin/xxx_plugin.cc”文件已自动生成了算子的插件代码。
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)