Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the contribution guide #5104

Merged
merged 20 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ API设计文档的目的是为了社区开发者更容易的参与开源项目
.. toctree::
:hidden:

read_before_contributing_cn.md
api_design_guidelines_standard_cn.md
new_python_api_cn.md
new_cpp_op_cn.md
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 贡献前阅读

本章主要介绍开发飞桨原生算子 API 的方法,可先参见通用的 [代码贡献流程](../code_contributing_path_cn.html) 章节,再结合本文介绍的 API 开发要点,即可掌握飞桨原生算子 API 开发方法和流程。

## 一、飞桨原生算子 API 开发解读

飞桨框架 API 前端采用 Python 语言,以便获得更好的编程体验;后端的计算逻辑实现采用 C++ 语言,调用底层算子内核 (kernel)函数实现计算逻辑,以便获得更好的运行性能,如图1所示。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图1好像没有标注出来

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


开发一个新的飞桨原生算子(Operator,OP),通常需要先开发 C++ OP,即通过 Yaml 配置定义算子描述、C++ 开发算子 kernel,再封装 Python API;如果要新增的算子可以用其他 Python API 组合得到,则可以只开发 Python API 代码。

- 使用 C++ 定义算子,开发门槛较高,需有一定 C++ 或 CUDA 等软件栈开发基础,但是具有性能优势;
- 使用 Python API 组合方式,只需 Python 编码,代码实现相对简单灵活,但会引入 Python 调度开销,影响性能;如果当前飞桨框架提供的基础算子 API 无法满足需求,仍然需要使用 C++ 实现算子。

![img](images/paddle_api.png)


## 二、飞桨 API 设计文档提交说明

设计文档,通常也叫 RFC(Request for Comment)文档,可方便开发者与飞桨核心团队、其他社区开发者充分交流设计思路,以便进一步完善设计方案,并确保与飞桨设计理念一致。请参考如下步骤完成 API 设计文档的提交:

1. 阅读 [飞桨 API 设计和命名规范](api_design_guidelines_standard_cn.html),确保新增 API 符合飞桨相关规范。
2. 根据 [API 设计文档模版](https://github.com/PaddlePaddle/community/blob/master/rfcs/APIs/api_design_template.md),填写必要的设计内容。另外可参考 [API 设计文档样例](https://github.com/PaddlePaddle/community/blob/master/rfcs/APIs/20200301_api_design_for_quantile.md)。
3. 将设计文档提交 Pull Request (PR)到 [community/rfcs/APIs/ ](https://github.com/PaddlePaddle/community/tree/master/rfcs/APIs) 目录下。
4. 等待文档接受评审和讨论,并根据各方意见修改文档。通常飞桨团队会在三个工作日内回复,如果 API 功能较复杂,还将发起评审会议,并提前在 PR 的评论区公布会议时间、会议地址、参与人、议题等内容,请及时关注 PR 中最新动态。

当设计文档通过评审后,将会合入到 [community/rfcs/APIs/ ](https://github.com/PaddlePaddle/community/tree/master/rfcs/APIs) 目录下。

## 三、飞桨 API 代码实现流程

当 API 设计文档合入后,开发者即可进行代码开发。此过程请参考相应的开发规范,包括如下步骤:

- 如果新增 API 不需要开发新的 C++ OP,可以用其他 Python API 组合得到新的 API,请参考 [开发 API Python 端](new_python_api_cn.html) 章节完成,包括开发 Python 代码、单元测试代码和 API 文档等步骤。
- 如果新增 API 需要开发新的 C++ OP,请参考 [开发 C++ OP](new_cpp_op_cn.html) 章节完成,包括开发 OP 实现代码、封装 Python API 代码、单元测试代码和 API 文档等步骤。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[开发 C++ OP] 最新文档里标题更新为了 [C++ 算子开发指南]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

- 在 paddle/phi/kernels 目录下存放了飞桨框架已经实现的不同硬件的算子内核,可供开发 C++ OP 时调用。
- 有时也需要自己开发新的算子内核(OP Kernel),这时可能需要使用硬件支持的软件栈(如 CUDA)来实现,或者使用飞桨框架提供的 Kernel Primitive API 来实现,后者具体介绍请参见 [Kernel Primitive API](../op_optimization/kernel_primitive_api/index_cn.html) 章节。

值得注意的是,代码开发完成后,请确保通过了单元测试和 CI 测试。

![img](images/paddle_api_dev_flow.png)

## 四、飞桨 API 代码开发规范说明

请遵循如下开发规范和测试要求:

- [代码风格规范](../style_guide_and_references/style_guides_cn.html)
- [飞桨 API 设计和命名规范](api_design_guidelines_standard_cn.html)
- [飞桨 API 单元测试及验收规范](api_accpetance_criteria_cn.html)
- [Paddle CI 测试详解](../style_guide_and_references/paddle_ci_manual_cn.html)
329 changes: 329 additions & 0 deletions docs/dev_guides/code_contributing_path_cn.md

Large diffs are not rendered by default.

Binary file added docs/dev_guides/images/compare_pull_request2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions docs/dev_guides/index_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@

同样的,如果你觉得本篇文档有缺失,或者是有描述不清楚的地方,我们也非常欢迎你一同贡献本系列文档。

- `概述 <./Overview_cn.html>`_ : 贡献指南概述。
- `代码规范 <./style_guides_cn.html>`_ : 代码规范说明。
- `Git 操作指南 <./git_guides/index_cn.html>`_ : Git 操作相关说明与Paddle CI 手册。
- `概述 <./Overview_cn.html>`_ : 参与飞桨开源项目的贡献指引。
- `代码贡献流程 <./code_contributing_path_cn.html>`_ : 向飞桨开源项目贡献代码的通用流程。
- `编译安装 <https://www.paddlepaddle.org.cn/documentation/docs/zh/install/compile/fromsource.html>`_ : 如何从源码编译安装Paddle。
- `API开发指南 <./api_contributing_guides/api_contributing_guides_cn.html>`_ : API开发相关说明。
- `算子性能优化贡献指南 <./op_optimization/op_optimization_contributing_guides_cn.html>`_ : 飞桨算子性能优化相关说明。
- `算子数据类型扩展贡献指南 <./op_dtype_extension/op_dtype_extension_contributing_guides_cn.html>`_ : 飞桨算子数据类型扩展相关说明。
- `曙光开发指南 <./sugon/index_cn.html>`_ : 曙光开发相关说明。
- `自定义新硬件接入指南 <./custom_device_docs/index_cn.html>`_: 介绍如何通过自定义硬件功能为飞桨接入新硬件后端。
- `文档贡献指南 <./docs_contributing_guides_cn.html>`_ : 飞桨文档贡献指南。
- `规范和参考信息 <./style_guide_and_references/index_cn.html>`_ : 飞桨代码开发的相关风格规范和通用参考信息。


.. toctree::
:hidden:

Overview_cn.md
style_guides_cn.md
git_guides/index_cn.rst
code_contributing_path_cn.md
api_contributing_guides/api_contributing_guides_cn.rst
op_optimization/op_optimization_contributing_guides_cn.rst
op_dtype_extension/op_dtype_extension_contributing_guides_cn.rst
sugon/index_cn.rst
custom_device_docs/index_cn.rst
docs_contributing_guides_cn.md
style_guide_and_references/index_cn.rst

18 changes: 18 additions & 0 deletions docs/dev_guides/style_guide_and_references/index_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
############
规范和参考信息
############

本章主要介绍飞桨代码开发的规范和一些公共的参考信息。

- `代码风格规范 <./style_guides_cn.html>`_ : Python 和 C++ 代码开发需遵循的风格规范。
- `代码风格检查指南 <../git_guides/codestyle_check_guide_cn.html>`_ : Paddle 进行代码风格检查相关工具和说明。
- `Paddle CI 测试详解 <./paddle_ci_manual_cn.html>`_ : Paddle CI 测试流水线中的测试项的详细介绍,以及 CI 失败的处理方法。



.. toctree::
:hidden:

style_guides_cn.md
../git_guides/codestyle_check_guide_cn.md
paddle_ci_manual_cn.md
243 changes: 243 additions & 0 deletions docs/dev_guides/style_guide_and_references/paddle_ci_manual_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
# Paddle CI 测试详解
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是修改了文档位置吗?那之前位置的文档有做删除吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只是挪了位置。删除copy件,改为链接到原内容。


## 整体介绍

当你提交一个PR`(Pull_Request)`,你的PR需要经过一些CI`(Continuous Integration)`,以触发`develop`分支的为例为你展示CI执行的顺序:

![ci_exec_order.png](../images/ci_exec_order.png)

如上图所示,提交一个`PR`,你需要:

- 签署CLA协议
- PR描述需要符合规范
- 通过不同平台`(Linux/Mac/Windows/XPU/NPU等)`的编译与单测
- 通过静态代码扫描工具的检测

**<font color=red>需要注意的是:如果你的PR只修改文档部分,你可以在commit中添加说明(commit message)以只触发文档相关的CI,写法如下:</font>**

```shell
# PR仅修改文档等内容,只触发PR-CI-Static-Check
git commit -m 'test=document_fix'
```

## 各流水线介绍

下面以触发`develop`分支为例,分平台对每条`CI`进行简单介绍。

### CLA

贡献者许可证协议[Contributor License Agreements](https://cla-assistant.io/PaddlePaddle/Paddle)是指当你要给Paddle贡献代码的时候,需要签署的一个协议。如果不签署那么你贡献给 Paddle 项目的修改,即`PR`会被 Github 标志为不可被接受,签署了之后,这个`PR`就是可以在 review 之后被接受了。

### CheckPRTemplate

检查PR描述信息是否按照模板填写。

- 通常10秒内检查完成,如遇长时间未更新状态,请re-edit一下PR描述重新触发该CI。

```markdown
### PR types
<!-- One of [ New features | Bug fixes | Function optimization | Performance optimization | Breaking changes | Others ] -->
(必填)从上述选项中,选择并填写PR类型
### PR changes
<!-- One of [ OPs | APIs | Docs | Others ] -->
(必填)从上述选项中,选择并填写PR所修改的内容
### Describe
<!-- Describe what this PR does -->
(必填)请填写PR的具体修改内容
```

### Linux平台

#### PR-CI-Clone

该CI主要是将当前PR的代码从GitHub clone到CI机器,方便后续的CI直接使用。

#### PR-CI-APPROVAL

该CI主要的功能是检测PR中的修改是否通过了审批。在其他CI通过之前,你可以无需过多关注该CI, 其他CI通过后会有相关人员进行review你的PR。

- 执行脚本:`paddle/scripts/paddle_build.sh assert_file_approvals`

#### PR-CI-Build

该CI主要是编译出当前PR的编译产物,并且将编译产物上传到BOS(百度智能云对象存储)中,方便后续的CI可以直接复用该编译产物。

- 执行脚本:`paddle/scripts/paddle_build.sh build_pr_dev`

#### PR-CI-Py3

该CI主要的功能是为了检测当前PR在CPU、Python3版本的编译与单测是否通过。

- 执行脚本:`paddle/scripts/paddle_build.sh cicheck_py37`

#### PR-CI-Coverage

该CI主要的功能是检测当前PR在GPU、Python3版本的编译与单测是否通过,同时增量代码需满足行覆盖率大于90%的要求。

- 编译脚本:`paddle/scripts/paddle_build.sh cpu_cicheck_coverage`
- 测试脚本:`paddle/scripts/paddle_build.sh gpu_cicheck_coverage`

#### PR-CE-Framework

该CI主要是为了测试P0级框架API与预测API的功能是否通过。此CI使用`PR-CI-Build`的编译产物,无需单独编译。

- 框架API测试脚本([PaddlePaddle/PaddleTest](https://github.com/PaddlePaddle/PaddleTest)):`PaddleTest/framework/api/run_paddle_ci.sh`
- 预测API测试脚本([PaddlePaddle/PaddleTest](https://github.com/PaddlePaddle/PaddleTest)):`PaddleTest/inference/python_api_test/parallel_run.sh `

#### PR-CI-ScienceTest

该CI主要是为了科学计算相关的单测是否通过。此CI使用`PR-CI-Build`的编译产物,无需单独编译。

- 测试脚本([PaddlePaddle/PaddleScience](https://github.com/PaddlePaddle/PaddleScience)):`PaddleScience/tests/test_examples/run.sh`

#### PR-CI-OP-benchmark

该CI主要的功能是PR中的修改是否会造成OP性能下降或者精度错误。此CI使用`PR-CI-Build`的编译产物,无需单独编译。

- 执行脚本:`tools/ci_op_benchmark.sh run_op_benchmark`

关于CI失败解决方案等详细信息可查阅[PR-CI-OP-benchmark Manual](https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual)

#### PR-CI-Model-benchmark

该CI主要的功能是检测PR中的修改是否会导致模型性能下降或者运行报错。此CI使用`PR-CI-Build`的编译产物,无需单独编译。

- 执行脚本:`tools/ci_model_benchmark.sh run_all`

关于CI失败解决方案等详细信息可查阅[PR-CI-Model-benchmark Manual](https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-Model-benchmark-Manual)

#### PR-CI-Static-Check

该CI主要的功能是检查代码风格是否符合规范,检测`develop`分支与当前`PR`分支的增量的API英文文档是否符合规范,以及当变更API或OP时需要TPM approval。

- 编译脚本:`paddle/scripts/paddle_build.sh build_and_check_cpu`
- 示例文档检测脚本:`paddle/scripts/paddle_build.sh build_and_check_gpu`

#### PR-CI-infrt

该CI主要是为了检测infrt是否编译与单测通过

- 编译脚本:`paddle/scripts/infrt_build.sh build_only`
- 测试脚本:`paddle/scripts/infrt_build.sh test_only`

#### PR-CI-CINN

该CI主要是为了编译含CINN的Paddle,并运行Paddle-CINN对接的单测,保证训练框架进行CINN相关开发的正确性。

- 编译脚本:`paddle/scripts/paddle_build.sh build_only`
- 测试脚本:`paddle/scripts/paddle_build.sh test`

#### PR-CI-Inference

该CI主要的功能是为了检测当前PR对C++预测库与训练库的编译和单测是否通过。

- 编译脚本:`paddle/scripts/paddle_build.sh build_inference`
- 测试脚本:`paddle/scripts/paddle_build.sh gpu_inference`

#### PR-CI-GpuPS

该CI主要是为了保证GPUBOX相关代码合入后编译可以通过。

- 编译脚本:`paddle/scripts/paddle_build.sh build_gpubox`

### MAC

#### PR-CI-Mac-Python3

该CI是为了检测当前PR在MAC系统下python35版本的编译与单测是否通过,以及做develop与当前PR的单测增量检测,如有不同,提示需要approval。

- 执行脚本:`paddle/scripts/paddle_build.sh maccheck_py35`

### Windows

#### PR-CI-Windows

该CI是为了检测当前PR在Windows系统下MKL版本的GPU编译与单测是否通过,以及做develop与当前PR的单测增量检测,如有不同,提示需要approval。

- 执行脚本:`paddle/scripts/paddle_build.bat wincheck_mkl`

#### PR-CI-Windows-OPENBLAS

该CI是为了检测当前PR在Windows系统下OPENBLAS版本的CPU编译与单测是否通过。

- 执行脚本:`paddle/scripts/paddle_build.bat wincheck_openblas`

#### PR-CI-Windows-Inference

该CI是为了检测当前PR在Windows系统下预测模块的编译与单测是否通过。

- 执行脚本:`paddle/scripts/paddle_build.bat wincheck_inference`

### XPU机器

#### PR-CI-Kunlun

该CI主要的功能是检测PR中的修改能否在昆仑芯片上编译与单测通过。

- 执行脚本:`paddle/scripts/paddle_build.sh check_xpu_coverage`

### NPU机器

#### PR-CI-NPU

该CI主要是为了检测当前PR对NPU代码编译跟测试是否通过。

- 编译脚本:`paddle/scripts/paddle_build.sh build_only`
- 测试脚本:`paddle/scripts/paddle_build.sh gpu_cicheck_py35`

### Sugon-DCU机器

#### PR-CI-ROCM-Compile

该CI主要的功能是检测PR中的修改能否在曙光芯片上编译通过。

- 执行脚本:`paddle/scripts/musl_build/build_paddle.sh build_only`

### 静态代码扫描

#### PR-CI-iScan-C

该CI是为了检测当前PR的C++代码是否可以通过静态代码扫描。

#### PR-CI-iScan- Python

该CI是为了检测当前PR的Python代码是否可以通过静态代码扫描。



## CI失败如何处理
### CLA失败

- 如果你的cla一直是pending状态,那么需要等其他CI都通过后,点击 Close pull request ,再点击 Reopen pull request ,并等待几分钟(建立在你已经签署cla协议的前提下);如果上述操作重复2次仍未生效,请重新提一个PR或评论区留言。
- 如果你的cla是失败状态,可能原因是你提交PR的账号并非你签署cla协议的账号,如下图所示:
![cla.png](./images/cla.png)
- 建议你在提交PR前设置:

```
git config –local user.email 你的邮箱
git config –local user.name 你的名字
```

### CheckPRTemplate失败

如果你的`CheckPRTemplate`状态一直未变化,这是由于通信原因状态未返回到GitHub。你只需要重新编辑一下PR描述保存后就可以重新触发该条CI,步骤如下:
![checkPRtemplate1.png](../images/checkPRtemplate1.png)
![checkPRTemplate2.png](../images/checkPRTemplate2.png)

### 其他CI失败

当你的`PR`的CI失败时,`paddle-bot`会在你的`PR`页面发出一条评论,同时此评论GitHub会同步到你的邮箱,让你第一时间感知到`PR`的状态变化(注意:只有第一条CI失败的时候会发邮件,之后失败的CI只会更新`PR`页面的评论。)

![paddle-bot-comment.png](../images/paddle-bot-comment.png)

![ci-details.png](../images/ci-details.png)

你可以通过点击`paddle-bot`评论中的CI名字,也可通过点击CI列表中的`Details`来查看CI的运行日志,如上图。通常运行日志的末尾会告诉你CI失败的原因。

由于网络代理、机器不稳定等原因,有时候CI的失败也并不是你的`PR`自身的原因,这时候你只需要rerun此CI即可(你需要将你的GitHub授权于效率云CI平台)。

![rerun.png](../images/rerun.png)

如果CI失败你无法判断原因,请联系 @[lelelelelez](https://github.com/lelelelelez)。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还是联系春乐吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先删掉这个内容吧。


若遇到其他问题,请联系 @[lelelelelez](https://github.com/lelelelelez)。
6 changes: 6 additions & 0 deletions docs/dev_guides/style_guide_and_references/style_guides_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 代码风格规范

请参考以下规范,进行代码开发:

- C++:[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
- Python:[Google Python Style Guide](https://google.github.io/styleguide/pyguide.html)