Skip to content

Commit 6a9d556

Browse files
committed
[GCU] Add GCU backend
1 parent 9b00c61 commit 6a9d556

File tree

15 files changed

+186
-6
lines changed

15 files changed

+186
-6
lines changed

docs/other_devices_support/multi_devices_use_guide.en.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Kunlun XPU: [Kunlun XPU PaddlePaddle Installation Guide](./paddlepaddle_install_
1818

1919
Hygon DCU: [Hygon DCU PaddlePaddle Installation Guide](./paddlepaddle_install_DCU.en.md)
2020

21+
Enflame GCU: [Enflame GCU PaddlePaddle Installation Guide](./paddlepaddle_install_GCU.en.md)
22+
2123
### 1.2 PaddleX Installation
2224
Welcome to use PaddlePaddle's low-code development tool, PaddleX. Before we officially start the local installation, please clarify your development needs and choose the appropriate installation mode based on your requirements.
2325

@@ -164,4 +166,4 @@ All packages are installed.
164166

165167
## 2. Usage
166168

167-
The usage of PaddleX model pipeline development tool on hardware platforms such as Ascend NPU, Cambricon MLU, Kunlun XPU, and Hygon DCU is identical to that on GPU. You only need to modify the device configuration parameters according to your hardware platform. For detailed usage tutorials, please refer to [PaddleX Pipeline Development Tool Local Usage Guide](../pipeline_usage/pipeline_develop_guide.en.md).
169+
The usage of PaddleX model pipeline development tool on hardware platforms such as Ascend NPU, Cambricon MLU, Kunlun XPU, Hygon DCU and Enflame GCU is identical to that on GPU. You only need to modify the device configuration parameters according to your hardware platform. For detailed usage tutorials, please refer to [PaddleX Pipeline Development Tool Local Usage Guide](../pipeline_usage/pipeline_develop_guide.en.md).

docs/other_devices_support/multi_devices_use_guide.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ comments: true
1818

1919
海光 DCU:[海光 DCU 飞桨安装教程](./paddlepaddle_install_DCU.md)
2020

21+
燧原 GCU:[燧原 GCU 飞桨安装教程](./paddlepaddle_install_GCU.md)
22+
2123
### 1.2 PaddleX安装
2224
欢迎您使用飞桨低代码开发工具PaddleX,在我们正式开始本地安装之前,请先明确您的开发需求,并根据您的需求选择合适的安装模式。
2325

@@ -161,4 +163,4 @@ paddlex --install --platform gitee.com
161163
All packages are installed.
162164
```
163165
## 2、使用
164-
基于昇腾 NPU、寒武纪 MLU、昆仑 XPU、海光DCU 硬件平台的 PaddleX 模型产线开发工具使用方法与 GPU 相同,只需根据所属硬件平台,修改配置设备的参数,详细的使用教程可以查阅[PaddleX产线开发工具本地使用教程](../pipeline_usage/pipeline_develop_guide.md)
166+
基于昇腾 NPU、寒武纪 MLU、昆仑 XPU、海光DCU、燧原 GCU 硬件平台的 PaddleX 模型产线开发工具使用方法与 GPU 相同,只需根据所属硬件平台,修改配置设备的参数,详细的使用教程可以查阅[PaddleX产线开发工具本地使用教程](../pipeline_usage/pipeline_develop_guide.md)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
comments: true
3+
---
4+
5+
# Enflame GCU PaddlePaddle Installation Tutorial
6+
7+
Currently, PaddleX supports the Enflame S60 chip. Considering environmental differences, we recommend using the <b>Enflame development image provided by PaddlePaddle</b> to complete the environment preparation.
8+
9+
## 1. Docker Environment Preparation
10+
* Pull the image. This image is only for the development environment and does not contain a pre-compiled PaddlePaddle installation package. The image has TopsRider, the Enflame basic runtime environment library, installed by default.
11+
```bash
12+
# For X86 architecture
13+
docker pull ccr-2vdh3abv-pub.cnc.bj.baidubce.com/device/paddle-gcu:topsrider3.2.109-ubuntu20-x86_64-gcc84
14+
```
15+
* Start the container with the following command.
16+
```bash
17+
docker run --name paddle-gcu-dev -v /home:/home \
18+
--network=host --ipc=host -it --privileged \
19+
ccr-2vdh3abv-pub.cnc.bj.baidubce.com/device/paddle-gcu:topsrider3.2.109-ubuntu20-x86_64-gcc84 /bin/bash
20+
```
21+
* Install the driver **outside of docker**. Please refer to the environment preparation section of [PaddlePaddle Custom Device Implementation for Enflame GCU](https://github.com/PaddlePaddle/PaddleCustomDevice/blob/develop/backends/gcu/README.md).
22+
```bash
23+
bash TopsRider_i3x_*_deb_amd64.run --driver --no-auto-load
24+
```
25+
## 2. Install Paddle Package
26+
Download and install the wheel package released by PaddlePaddle within the docker container. Currently, Python 3.10 wheel installation packages are provided. If you require other Python versions, refer to the [PaddlePaddle official documentation](https://www.paddlepaddle.org.cn/en/install/quick) for compilation and installation.
27+
28+
* Download and install the wheel package.
29+
```bash
30+
# Note: You need to install the CPU version of PaddlePaddle first
31+
python -m pip install paddlepaddle==3.0.0.dev20241127 -i https://www.paddlepaddle.org.cn/packages/nightly/cpu/
32+
python -m pip install paddle_custom_gcu==3.0.0.dev20241127 -i https://www.paddlepaddle.org.cn/packages/nightly/gcu/
33+
```
34+
* Verify the installation package. After installation, run the following command:
35+
```bash
36+
python -c "import paddle; paddle.utils.run_check()"
37+
```
38+
* Expect to get output like this:
39+
```bash
40+
Running verify PaddlePaddle program ...
41+
PaddlePaddle works well on 1 gcu.
42+
PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.
43+
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
comments: true
3+
---
4+
5+
# 燧原 GCU 飞桨安装教程
6+
7+
当前 PaddleX 支持燧原 S60 芯片。考虑到环境差异性,我们推荐使用<b>飞桨官方提供的燧原 GCU 开发镜像</b>完成环境准备。
8+
9+
## 1、docker环境准备
10+
* 拉取镜像,此镜像仅为开发环境,镜像中不包含预编译的飞桨安装包,镜像中已经默认安装了燧原软件栈 TopsRider。
11+
```bash
12+
# 适用于 X86 架构
13+
docker pull ccr-2vdh3abv-pub.cnc.bj.baidubce.com/device/paddle-gcu:topsrider3.2.109-ubuntu20-x86_64-gcc84
14+
```
15+
* 参考如下命令启动容器
16+
```bash
17+
docker run --name paddle-gcu-dev -v /home:/home \
18+
--network=host --ipc=host -it --privileged \
19+
ccr-2vdh3abv-pub.cnc.bj.baidubce.com/device/paddle-gcu:topsrider3.2.109-ubuntu20-x86_64-gcc84 /bin/bash
20+
```
21+
* **容器外**安装驱动程序。可以参考[飞桨自定义接入硬件后端(GCU)](https://github.com/PaddlePaddle/PaddleCustomDevice/blob/develop/backends/gcu/README_cn.md)环境准备章节。
22+
```bash
23+
bash TopsRider_i3x_*_deb_amd64.run --driver --no-auto-load
24+
```
25+
## 2、安装paddle包
26+
在启动的 docker 容器中,下载并安装飞桨官网发布的 wheel 包。当前提供 Python3.10 的 wheel 安装包。如有其他 Python 版本需求,可以参考[飞桨官方文档](https://www.paddlepaddle.org.cn/install/quick)自行编译安装。
27+
28+
* 下载并安装 wheel 包。
29+
```bash
30+
# 注意需要先安装飞桨 cpu 版本
31+
python -m pip install paddlepaddle==3.0.0.dev20241127 -i https://www.paddlepaddle.org.cn/packages/nightly/cpu/
32+
python -m pip install paddle_custom_gcu==3.0.0.dev20241127 -i https://www.paddlepaddle.org.cn/packages/nightly/gcu/
33+
```
34+
* 验证安装包:安装完成之后,运行如下命令:
35+
```bash
36+
python -c "import paddle; paddle.utils.run_check()"
37+
```
38+
预期得到类似如下输出结果:
39+
40+
```bash
41+
Running verify PaddlePaddle program ...
42+
PaddlePaddle works well on 1 gcu.
43+
PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.
44+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
comments: true
3+
---
4+
5+
# PaddleX Model List (Enflame GCU)
6+
7+
PaddleX incorporates multiple pipelines, each containing several modules, and each module encompasses various models. You can select the appropriate models based on the benchmark data below. If you prioritize model accuracy, choose models with higher accuracy. If you prioritize model size, select models with smaller storage requirements.
8+
9+
## Image Classification Module
10+
<table>
11+
<thead>
12+
<tr>
13+
<th>Model Name</th>
14+
<th>Top-1 Accuracy (%)</th>
15+
<th>Model Size (M)</th>
16+
<th>Model Download Link</th></tr>
17+
</thead>
18+
<tbody>
19+
<tr>
20+
<td>ResNet50</td>
21+
<td>76.96</td>
22+
<td>90.8 M</td>
23+
<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/ResNet50_infer.tar">Inference Model</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/ResNet50_pretrained.pdparams">Trained Model</a></td></tr>
24+
</tbody>
25+
</table>
26+
<b>Note: The above accuracy metrics refer to Top-1 Accuracy on the [ImageNet-1k](https://www.image-net.org/index.php) validation set.</b>

docs/support_list/model_list_gcu.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
comments: true
3+
---
4+
5+
# PaddleX模型列表(燧原 GCU)
6+
7+
PaddleX 内置了多条产线,每条产线都包含了若干模块,每个模块包含若干模型,具体使用哪些模型,您可以根据下边的 benchmark 数据来选择。如您更考虑模型精度,请选择精度较高的模型,如您更考虑模型存储大小,请选择存储大小较小的模型。
8+
9+
## 图像分类模块
10+
<table>
11+
<thead>
12+
<tr>
13+
<th>模型名称</th>
14+
<th>Top1 Acc(%)</th>
15+
<th>模型存储大小(M)</th>
16+
<th>模型下载链接</th></tr>
17+
</thead>
18+
<tbody>
19+
<tr>
20+
<td>ResNet50</td>
21+
<td>76.96</td>
22+
<td>90.8 M</td>
23+
<td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/ResNet50_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/ResNet50_pretrained.pdparams">训练模型</a></td></tr>
24+
</tbody>
25+
</table>
26+
<b>注:以上精度指标为</b>[ImageNet-1k](https://www.image-net.org/index.php)<b>验证集 Top1 Acc。</b>

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ plugins:
170170
寒武纪 MLU 飞桨安装教程: Cambricon MLU PaddlePaddle Installation Guide
171171
昇腾 NPU 飞桨安装教程: Ascend NPU PaddlePaddle Installation Guide
172172
昆仑 XPU 飞桨安装教程: Kunlun XPU PaddlePaddle Installation Guide
173+
燧原 GCU 飞桨安装教程: Enflame GCU PaddlePaddle Installation Guide
173174
数据标注教程: Data Annotation Tutorials
174175
计算机视觉: Computer Vision
175176
图像分类任务模块: Image Classification Task
@@ -197,6 +198,7 @@ plugins:
197198
PaddleX模型列表(MLU): PaddleX Model List (MLU)
198199
PaddleX模型列表(NPU): PaddleX Model List (NPU)
199200
PaddleX模型列表(XPU): PaddleX Model List (XPU)
201+
PaddleX模型列表(GCU): PaddleX Model List (GCU)
200202
产业实践教程&范例: Practical Tutorials & Examples
201203
论文文献信息抽取教程: Document Scene Information Extraction Tutorial
202204
垃圾分类教程: Garbage Classification Tutorial
@@ -371,6 +373,7 @@ nav:
371373
- 寒武纪 MLU 飞桨安装教程: other_devices_support/paddlepaddle_install_MLU.md
372374
- 昇腾 NPU 飞桨安装教程: other_devices_support/paddlepaddle_install_NPU.md
373375
- 昆仑 XPU 飞桨安装教程: other_devices_support/paddlepaddle_install_XPU.md
376+
- 燧原 GCU 飞桨安装教程: other_devices_support/paddlepaddle_install_GCU.md
374377
- 数据标注教程:
375378
- 计算机视觉:
376379
- 图像分类任务模块: data_annotations/cv_modules/image_classification.md
@@ -398,6 +401,7 @@ nav:
398401
- PaddleX模型列表(MLU): support_list/model_list_mlu.md
399402
- PaddleX模型列表(NPU): support_list/model_list_npu.md
400403
- PaddleX模型列表(XPU): support_list/model_list_xpu.md
404+
- PaddleX模型列表(XPU): support_list/model_list_gcu.md
401405
- 产业实践教程&范例:
402406
- 论文文献信息抽取教程: practical_tutorials/document_scene_information_extraction(layout_detection)_tutorial.md
403407
- 垃圾分类教程: practical_tutorials/image_classification_garbage_tutorial.md

paddlex/inference/components/paddle_predictor/predictor.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ def _create(self):
154154
pass
155155
elif self.option.device == "mlu":
156156
config.enable_custom_device("mlu")
157+
elif self.option.device == "gcu":
158+
assert paddle.device.is_compiled_with_custom_device("gcu"), (
159+
"Args device cannot be set as gcu while your paddle "
160+
"is not compiled with gcu!"
161+
)
162+
config.enable_custom_device("gcu")
163+
from paddle_custom_device.gcu import passes as gcu_passes
164+
165+
gcu_passes.setUp()
166+
name = "PaddleX_" + self.option.model_name
167+
if hasattr(config, "enable_new_ir") and self.option.enable_new_ir:
168+
config.enable_new_ir(True)
169+
config.enable_new_executor(True)
170+
kPirGcuPasses = gcu_passes.inference_passes(use_pir=True, name=name)
171+
config.enable_custom_passes(kPirGcuPasses, True)
172+
else:
173+
config.enable_new_ir(False)
174+
config.enable_new_executor(False)
175+
pass_builder = config.pass_builder()
176+
gcu_passes.append_passes_for_legacy_ir(pass_builder, name)
157177
else:
158178
assert self.option.device == "cpu"
159179
config.disable_gpu()

paddlex/inference/utils/pp_option.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PaddlePredictorOption(object):
3131
"mkldnn",
3232
"mkldnn_bf16",
3333
)
34-
SUPPORT_DEVICE = ("gpu", "cpu", "npu", "xpu", "mlu", "dcu")
34+
SUPPORT_DEVICE = ("gpu", "cpu", "npu", "xpu", "mlu", "dcu", "gcu")
3535

3636
def __init__(self, model_name=None, **kwargs):
3737
super().__init__()

paddlex/modules/base/build_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def build_model(model_name: str, config_path: str = None) -> tuple:
2222
2323
Args:
2424
model_name (str): model name
25-
device (str): device, such as gpu, cpu, npu, xpu, mlu
25+
device (str): device, such as gpu, cpu, npu, xpu, mlu, gcu
2626
config_path (str, optional): path to the PaddleX config yaml file.
2727
Defaults to None, i.e. using the default config file.
2828

paddlex/repo_apis/PaddleDetection_api/instance_seg/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ def update_device(self, device_type: str):
270270
elif device_type.lower() == "mlu":
271271
self["use_mlu"] = True
272272
self["use_gpu"] = False
273+
elif device_type.lower() == "gcu":
274+
self["use_gcu"] = True
275+
self["use_gpu"] = False
273276
else:
274277
assert device_type.lower() == "cpu"
275278
self["use_gpu"] = False

paddlex/repo_apis/PaddleDetection_api/object_det/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ def update_device(self, device_type: str):
271271
elif device_type.lower() == "mlu":
272272
self["use_mlu"] = True
273273
self["use_gpu"] = False
274+
elif device_type.lower() == "gcu":
275+
self["use_gcu"] = True
276+
self["use_gpu"] = False
274277
else:
275278
assert device_type.lower() == "cpu"
276279
self["use_gpu"] = False

paddlex/repo_apis/PaddleOCR_api/text_rec/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def update_device(self, device: str):
228228
"Global.use_xpu": False,
229229
"Global.use_npu": False,
230230
"Global.use_mlu": False,
231+
"Global.use_gcu": False,
231232
}
232233

233234
device_cfg = {
@@ -236,6 +237,7 @@ def update_device(self, device: str):
236237
"xpu": {"Global.use_xpu": True},
237238
"mlu": {"Global.use_mlu": True},
238239
"npu": {"Global.use_npu": True},
240+
"gcu": {"Global.use_gcu": True},
239241
}
240242
default_cfg.update(device_cfg[device])
241243
self.update(default_cfg)

paddlex/repo_apis/base/runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ def distributed(self, device, ips=None, log_dir=None):
205205
new_env["ASCEND_RT_VISIBLE_DEVICES"] = dev_ids
206206
elif device == "mlu":
207207
new_env["MLU_VISIBLE_DEVICES"] = dev_ids
208+
elif device == "gcu":
209+
new_env["TOPS_VISIBLE_DEVICES"] = dev_ids
208210
else:
209211
new_env["CUDA_VISIBLE_DEVICES"] = dev_ids
210212
return args, new_env

paddlex/utils/device.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from . import logging
2020
from .errors import raise_unsupported_device_error
2121

22-
SUPPORTED_DEVICE_TYPE = ["cpu", "gpu", "xpu", "npu", "mlu"]
22+
SUPPORTED_DEVICE_TYPE = ["cpu", "gpu", "xpu", "npu", "mlu", "gcu"]
2323

2424

2525
def _constr_device(device_type, device_ids):
@@ -77,7 +77,7 @@ def _set(envs):
7777
logging.debug(f"{key} has been set to {val}.")
7878

7979
device_type, device_ids = parse_device(device)
80-
if device_type.lower() in ["gpu", "xpu", "npu", "mlu"]:
80+
if device_type.lower() in ["gpu", "xpu", "npu", "mlu", "gcu"]:
8181
if device_type.lower() == "gpu" and paddle.is_compiled_with_rocm():
8282
envs = {"FLAGS_conv_workspace_size_limit": "2000"}
8383
_set(envs)
@@ -101,3 +101,6 @@ def _set(envs):
101101
if device_type.lower() == "mlu":
102102
envs = {"FLAGS_use_stride_kernel": "0"}
103103
_set(envs)
104+
if device_type.lower() == "gcu":
105+
envs = {"FLAGS_use_stride_kernel": "0"}
106+
_set(envs)

0 commit comments

Comments
 (0)