From b7e0167eb32438ba3442bab2cca7113a1c2efe1a Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Thu, 12 May 2022 10:46:55 +0800 Subject: [PATCH] Move op note into dev_guides (#4738) * move op note into dev_guides * change doc title * change title and add tree --- .../api_contributing_guides_cn.rst | 1 + .../api_contributing_guides/new_cpp_op_cn.md | 34 +++++++++--------- .../api_contributing_guides/new_cpp_op_en.md} | 0 .../new_cpp_op_notes_cn.md} | 2 +- .../new_cpp_op_notes_en.md} | 0 .../op_inheritance_relation_diagram.png | Bin docs/guides/07_new_op/index_cn.rst | 11 +++--- docs/guides/07_new_op/index_en.rst | 9 +++-- docs/guides/07_new_op/new_custom_op_cn.md | 2 +- 9 files changed, 30 insertions(+), 29 deletions(-) rename docs/{guides/07_new_op/new_op_en.md => dev_guides/api_contributing_guides/new_cpp_op_en.md} (100%) rename docs/{guides/07_new_op/op_notes_cn.md => dev_guides/api_contributing_guides/new_cpp_op_notes_cn.md} (99%) rename docs/{guides/07_new_op/op_notes_en.md => dev_guides/api_contributing_guides/new_cpp_op_notes_en.md} (100%) rename docs/{guides/07_new_op => dev_guides/api_contributing_guides}/op_inheritance_relation_diagram.png (100%) diff --git a/docs/dev_guides/api_contributing_guides/api_contributing_guides_cn.rst b/docs/dev_guides/api_contributing_guides/api_contributing_guides_cn.rst index 49ba4b54b70..0e5730b6d39 100644 --- a/docs/dev_guides/api_contributing_guides/api_contributing_guides_cn.rst +++ b/docs/dev_guides/api_contributing_guides/api_contributing_guides_cn.rst @@ -107,5 +107,6 @@ API设计文档的目的是为了社区开发者更容易的参与开源项目 api_design_guidelines_standard_cn.md new_python_api_cn.md new_cpp_op_cn.md + new_cpp_op_notes_cn.md api_docs_guidelines_cn.md api_accpetance_criteria_cn.md diff --git a/docs/dev_guides/api_contributing_guides/new_cpp_op_cn.md b/docs/dev_guides/api_contributing_guides/new_cpp_op_cn.md index 00c2e100785..5215f6ed5ee 100644 --- a/docs/dev_guides/api_contributing_guides/new_cpp_op_cn.md +++ b/docs/dev_guides/api_contributing_guides/new_cpp_op_cn.md @@ -1,4 +1,4 @@ -# C++ OP 开发(新增原生算子) +# C++ OP 开发 > 注:飞桨原生算子的开发范式正在进行重构与升级,升级后算子开发方式会大幅简化,我们会及时更新本文档内容,升级后的算子开发范式预计会在2.3版本正式上线。 @@ -590,28 +590,28 @@ void TraceKernel(const Context& dev_ctx, 仍然以trace op为例,首先在`paddle/phi/ops/compat`目录下新建`trace_sig.cc`文件,用于放置这里的映射函数。 - 由于函数式kernel的一个最重要的特别就是参数顺序和类型(顺序和类型是关键,变量名称不影响),我们需要定义一个函数来做一个从OpMaker中如何获取信息,并且按照顺序传递给新的kernel函数; 这个模块就是OpArgumentMapping, trace反向op的OpArgumentMapping定义如下, KernelSignature共包含4个内容 - 1. kernel名称,这个是我们给kernel注册的时候的名称 - 2. input list: 这个要和OpMaker(或者GradOpMaker)中定义的Key要完全一致 - 3. attribute list: 这个要和OpMaker(或者GradOpMaker)中定义的Key要完全一致 - 4. output list: 这个要和OpMaker(或者GradOpMaker)中定义的Key要完全一致 + 1. kernel名称,这个是我们给kernel注册的时候的名称 + 2. input list: 这个要和OpMaker(或者GradOpMaker)中定义的Key要完全一致 + 3. attribute list: 这个要和OpMaker(或者GradOpMaker)中定义的Key要完全一致 + 4. output list: 这个要和OpMaker(或者GradOpMaker)中定义的Key要完全一致 - ```cpp - #include "paddle/phi/core/compat/op_utils.h" + ```cpp + #include "paddle/phi/core/compat/op_utils.h" - namespace phi { + namespace phi { - KernelSignature TraceGradOpArgumentMapping(const ArgumentMappingContext& ctx) { - return KernelSignature("trace_grad", - {GradVarName("Out"), "Input"}, - {"offset", "axis1", "axis2"}, - {GradVarName("Input")}); - } + KernelSignature TraceGradOpArgumentMapping(const ArgumentMappingContext& ctx) { + return KernelSignature("trace_grad", + {GradVarName("Out"), "Input"}, + {"offset", "axis1", "axis2"}, + {GradVarName("Input")}); + } - } // namespace phi + } // namespace phi - PD_REGISTER_ARG_MAPPING_FN(trace_grad, phi::TraceGradOpArgumentMapping); - ``` + PD_REGISTER_ARG_MAPPING_FN(trace_grad, phi::TraceGradOpArgumentMapping); + ``` >注:没有input list或attribute list的,相应花括号内留空,不能省略花括号 diff --git a/docs/guides/07_new_op/new_op_en.md b/docs/dev_guides/api_contributing_guides/new_cpp_op_en.md similarity index 100% rename from docs/guides/07_new_op/new_op_en.md rename to docs/dev_guides/api_contributing_guides/new_cpp_op_en.md diff --git a/docs/guides/07_new_op/op_notes_cn.md b/docs/dev_guides/api_contributing_guides/new_cpp_op_notes_cn.md similarity index 99% rename from docs/guides/07_new_op/op_notes_cn.md rename to docs/dev_guides/api_contributing_guides/new_cpp_op_notes_cn.md index 6674cb2b833..98295ba7ec9 100644 --- a/docs/guides/07_new_op/op_notes_cn.md +++ b/docs/dev_guides/api_contributing_guides/new_cpp_op_notes_cn.md @@ -1,4 +1,4 @@ -# 原生算子开发注意事项 +# C++ OP 开发注意事项 ## Paddle中Op的构建逻辑 ### 1.Paddle中Op的构建逻辑 diff --git a/docs/guides/07_new_op/op_notes_en.md b/docs/dev_guides/api_contributing_guides/new_cpp_op_notes_en.md similarity index 100% rename from docs/guides/07_new_op/op_notes_en.md rename to docs/dev_guides/api_contributing_guides/new_cpp_op_notes_en.md diff --git a/docs/guides/07_new_op/op_inheritance_relation_diagram.png b/docs/dev_guides/api_contributing_guides/op_inheritance_relation_diagram.png similarity index 100% rename from docs/guides/07_new_op/op_inheritance_relation_diagram.png rename to docs/dev_guides/api_contributing_guides/op_inheritance_relation_diagram.png diff --git a/docs/guides/07_new_op/index_cn.rst b/docs/guides/07_new_op/index_cn.rst index a61655db210..43701ad20f1 100644 --- a/docs/guides/07_new_op/index_cn.rst +++ b/docs/guides/07_new_op/index_cn.rst @@ -2,15 +2,12 @@ 自定义算子 ############# -本部分将指导您如何在飞桨中新增算子(Operator,简称Op),也包括一些必要的注意事项。此处的算子是一个广义的概念,包括以下几类: +本部分将指导您如何使用飞桨的自定义算子(Operator,简称Op)机制,包括以下两类: -1. 原生算子:遵循飞桨框架内部算子开发规范,源码合入到飞桨框架中,与框架一起编译后使用的算子 -2. 外部算子:编写方法较为简洁,不涉及框架内部概念,无需重新编译飞桨框架,以外接模块的方式使用的算子 -3. Python算子:使用Python编写实现前向(forward)和反向(backward)方法,在模型组网中使用的自定义API +1. C++算子:编写方法较为简洁,不涉及框架内部概念,无需重新编译飞桨框架,以外接模块的方式使用的算子 +2. Python算子:使用Python编写实现前向(forward)和反向(backward)方法,在模型组网中使用的自定义API -- `原生算子开发注意事项 <./op_notes_cn.html>`_ - -- `自定义外部算子 <./new_custom_op_cn.html>`_ +- `自定义C++算子 <./new_custom_op_cn.html>`_ - `自定义Python算子 <./new_python_op_cn.html>`_ diff --git a/docs/guides/07_new_op/index_en.rst b/docs/guides/07_new_op/index_en.rst index 560efcd560f..5fe0b2c77c8 100644 --- a/docs/guides/07_new_op/index_en.rst +++ b/docs/guides/07_new_op/index_en.rst @@ -2,11 +2,14 @@ Write New Operators ################### -This section will guide you how to add an operator, and it also includes some necessary notes. +This section will guide you on how to use the custom operator mechanism of Paddle, including the following two categories: -- `How to write new operator `_ :guides to write new operators +1. C++ operator: The writing method is relatively simple, does not involve the internal concept of the framework, does not need to recompile the paddle framework, and is used as an external module. +2. Python operator: use Python to implement forward and backward methods, then used in network. -- `op notes `_ :notes on developing new operators +- `Custom C++ Operator <./new_custom_op_cn.html>`_ + +- `Custom Python Operator <./new_python_op_cn.html>`_ - `Kernel Primitives API <./kernel_primitive_api/index_en.html>`_ : Introduce the block-level CUDA functions provided by PaddlePaddle to speed up operator development. diff --git a/docs/guides/07_new_op/new_custom_op_cn.md b/docs/guides/07_new_op/new_custom_op_cn.md index 61e3310f97a..b64ca9f0375 100644 --- a/docs/guides/07_new_op/new_custom_op_cn.md +++ b/docs/guides/07_new_op/new_custom_op_cn.md @@ -1,4 +1,4 @@ -# 自定义外部算子 +# 自定义C++算子 ## 概述