Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/design/phi/design_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ Tensor scale(const Tensor& x,

C++ API 的自动生成是通过解析 YAML 配置文件来进行生成的,YAML 配置文件分为:

- 前向 API 配置文件(`paddle/phi/api/yaml/api.yaml`,解析后生成代码文件为`paddle/phi/api/include/api.h`和`paddle/phi/api/lib/api.cc`)
- 前向 API 配置文件(`paddle/phi/api/yaml/ops.yaml`,解析后生成代码文件为`paddle/phi/api/include/api.h`和`paddle/phi/api/lib/api.cc`)
- 反向 API 配置文件(`paddle/phi/api/yaml/backward.yaml`,解析后生成的代码文件为`paddle/phi/api/backward/backward_api.h`和`paddle/phi/api/lib/backward_api.cc`)。

C++ API 生成的关键在于 YAML 文件的配置,以 matmul 为例,其前向和反向的配置文件如下:
Expand Down Expand Up @@ -1642,7 +1642,7 @@ PHI 期望的 Op 开发方式:**“完形填空”式算子描述实现 + “
需要写的内容如下:

```
## 配置文件 api.yaml
## 配置文件 ops.yaml
- api : add
args : (const Tensor& x, const Tensor& y)
output : Tensor
Expand Down
2 changes: 1 addition & 1 deletion docs/design/phi/design_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ Described as follows:

The automatic generation of the C++ API is generated by parsing the YAML configuration file. The YAML configuration file is divided into:

- Forward API configuration file(`paddle/phi/api/yaml/api.yaml`. After parsing, the generated code file is `paddle/phi/api/include/api.h` and `paddle/phi/api/lib/api.cc`)
- Forward API configuration file(`paddle/phi/api/yaml/ops.yaml`. After parsing, the generated code file is `paddle/phi/api/include/api.h` and `paddle/phi/api/lib/api.cc`)
- Backward API configuration file(`paddle/phi/api/yaml/backward.yaml`. After parsing, the generated code file is `paddle/phi/api/backward/backward_api.h` and `paddle/phi/api/lib/backward_api.cc`)

The key to C++ API generation lies in the configuration of the YAML file. Taking `matmul` as an example, the forward and backward configuration are as follows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def trace(x, offset=0, axis1=0, axis2=1, name=None):

- `_C_ops` 是 [python/paddle/_C_ops.py](https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/_C_ops.py),其实现了从 Paddle 编译得到的二进制文件中 import C++ 算子对应的 Python C 函数。
- `trace` 是算子的 Python C 函数名。Python C 函数的命名直接采用算子名。
- 参数 `( x, offset, axis1, axis2 )`需按照 [YAML 配置文件](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/phi/api/yaml/api.yaml#L185) 中定义的输入参数顺序传入,C++ 算子的输入、输出和属性等描述是通过 YAML 配置文件定义的,具体可参见 [开发 C++ 算子](new_cpp_op_cn.html) 章节介绍。
- 参数 `( x, offset, axis1, axis2 )`需按照 [YAML 配置文件](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/phi/api/yaml/ops.yaml#L185) 中定义的输入参数顺序传入,C++ 算子的输入、输出和属性等描述是通过 YAML 配置文件定义的,具体可参见 [开发 C++ 算子](new_cpp_op_cn.html) 章节介绍。

> 注意:由于目前飞桨动态图正处在重构升级阶段,所以现有算子的代码会分别有新旧动态图两个代码分支,其中 `in_dygraph_mode()` 表示新动态图分支(默认),`_in_legacy_dygraph()`为旧动态图分支,**在新增算子时无需添加旧动态图分支代码**。

Expand Down