Skip to content

Commit

Permalink
Move op note into dev_guides (#4738) (#4740)
Browse files Browse the repository at this point in the history
* move op note into dev_guides

* change doc title

* change title and add tree
  • Loading branch information
chenwhql authored May 12, 2022
1 parent ac05a55 commit 325f97c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 17 additions & 17 deletions docs/dev_guides/api_contributing_guides/new_cpp_op_cn.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# C++ OP 开发(新增原生算子)
# C++ OP 开发

> 注:飞桨原生算子的开发范式正在进行重构与升级,升级后算子开发方式会大幅简化,我们会及时更新本文档内容,升级后的算子开发范式预计会在2.3版本正式上线。
Expand Down Expand Up @@ -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的,相应花括号内留空,不能省略花括号
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 原生算子开发注意事项
# C++ OP 开发注意事项

## Paddle中Op的构建逻辑
### 1.Paddle中Op的构建逻辑
Expand Down
File renamed without changes.
11 changes: 4 additions & 7 deletions docs/guides/07_new_op/index_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`_

Expand Down
9 changes: 6 additions & 3 deletions docs/guides/07_new_op/index_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <new_op_en.html>`_ :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 <op_notes_en.html>`_ :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.

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/07_new_op/new_custom_op_cn.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 自定义外部算子
# 自定义C++算子

## 概述

Expand Down

0 comments on commit 325f97c

Please sign in to comment.