Skip to content

Commit ca3e583

Browse files
authored
Merge branch 'main' into fix/dep
2 parents 22dfc0b + aabddf6 commit ca3e583

10 files changed

Lines changed: 239 additions & 208 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ FROM $BASE_IMAGE
2222
ENV LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/driver:/usr/local/Ascend/driver/lib64/common
2323
COPY --from=build /build/ascend-device-plugin /usr/local/bin/ascend-device-plugin
2424
COPY --from=build /build/lib/hami-vnpu-core/* /usr/local/hami-vnpu-core-assets/
25+
RUN chmod +x /usr/local/hami-vnpu-core-assets/limiter
2526

2627
ENTRYPOINT ["ascend-device-plugin"]

README.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,23 @@
44

55
## Introduction
66

7-
This Ascend device plugin is implemented for [HAMi](https://github.com/Project-HAMi/HAMi) and [volcano](https://github.com/volcano-sh/volcano) scheduling.
7+
This Ascend device plugin is implemented for NPU-Slicing for [HAMi](https://github.com/Project-HAMi/HAMi) and [volcano](https://github.com/volcano-sh/volcano). It supports two modes:
88

99
#### 1. Template-based Hard Slicing (vNPU)
1010

11-
Memory slicing is supported based on virtualization template, lease available template is automatically used. For detailed information, check [template](./ascend-device-configmap.yaml)
11+
Memory slicing is supported based on virtualization template, least available template is automatically used. For detailed information, check [template](https://github.com/Project-HAMi/ascend-device-plugin/blob/main/ascend-device-configmap.yaml)
1212

1313
#### 2. Soft Slicing with Runtime Interception (hami-vnpu-core)
1414

1515
This project implements a soft slicing mechanism based on `libvnpu.so` interception and `limiter` token scheduling, enabling fine-grained resource sharing. For detailed information, check [hami-vnpu-core](https://github.com/Project-HAMi/hami-vnpu-core)
1616

17-
**Note:** `hami-vnpu-core` currently only supports ARM platforms.
17+
**Note 1:** `hami-vnpu-core` currently only supports ARM platforms.
18+
**Note 2:** `hami-vnpu-core` currently only supports HAMi scheduler.
1819

1920
## Prerequisites
2021

2122
[ascend-docker-runtime](https://gitcode.com/Ascend/mind-cluster/tree/master/component/ascend-docker-runtime)
2223

23-
update submodule:
24-
25-
```bash
26-
git submodule update --init --recursive
27-
```
28-
2924
hami-vnpu-core Soft Slicing Requirements:
3025

3126
- **Ascend Driver Version**: ≥ 25.5
@@ -45,14 +40,14 @@ Below is the English translation of the instructions for enabling `device-share`
4540

4641
## Compile
4742

43+
update submodule:
44+
4845
```bash
49-
make all
46+
git submodule update --init --recursive
5047
```
5148

52-
### Build
53-
5449
```bash
55-
docker buildx build -t $IMAGE_NAME .
50+
make all
5651
```
5752

5853
## Deployment
@@ -63,35 +58,39 @@ docker buildx build -t $IMAGE_NAME .
6358
kubectl label node {ascend-node} ascend=on
6459
```
6560

66-
### Deploy ConfigMap
61+
### Deply RuntimeClass
6762

6863
```bash
69-
kubectl apply -f ascend-device-configmap.yaml
64+
kubectl apply -f https://raw.githubusercontent.com/Project-HAMi/ascend-device-plugin/main/ascend-runtimeclass.yaml
7065
```
7166

72-
#### **Node Custom Configuration Description**
73-
The `hami-device-node-config` is used to enable hami-vnpu-core for specific nodes within the cluster.
74-
* By setting `hami-vnpu-core: true`, the specified node will enable soft-partitioning based on `hami-vnpu-core`.
75-
* Specify the number of virtual devices reported to Kubernetes for each physical chip via the `vDeviceCount` field.
76-
* Nodes without specific configurations will default to template-based hard-partitioning.
67+
### Deploy ConfigMap
68+
69+
This configMap is used for global configurations, like resourceName, mode, templates.
70+
* Under `vnpus`, set `hamiVnpuCore: true` so **all nodes** advertise soft-partitioning based on `hami-vnpu-core` to the scheduler (unless overridden per node in `hami-device-node-config`).
7771

7872
```bash
79-
kubectl apply -f ascend-device-node-configmap.yaml
73+
kubectl apply -f https://raw.githubusercontent.com/Project-HAMi/ascend-device-plugin/main/ascend-device-configmap.yaml
8074
```
8175

82-
### Deply RuntimeClass
76+
**Note:** You can choose to ignore this step if this configMap already exists.
77+
78+
79+
#### (Optional) **Node Custom Configuration Description**
80+
81+
The `hami-device-node-config` is used to enable or override hami-vnpu-core for specific nodes within the cluster. Node-level settings take higher priority than the global `vnpus.hamiVnpuCore` switch.
8382

8483
```bash
85-
kubectl apply -f ascend-runtimeclass.yaml
84+
kubectl apply -f https://raw.githubusercontent.com/Project-HAMi/ascend-device-plugin/main/ascend-device-node-configmap.yaml
8685
```
8786

8887
### Deploy `ascend-device-plugin`
8988

9089
```bash
91-
kubectl apply -f ascend-device-plugin.yaml
90+
kubectl apply -f https://raw.githubusercontent.com/Project-HAMi/ascend-device-plugin/main/ascend-device-plugin.yaml
9291
```
9392

94-
If scheduling Ascend devices in HAMi, simply set `devices.ascend.enabled` to true when deploying HAMi, and the ConfigMap and `ascend-device-plugin` will be automatically deployed. refer https://github.com/Project-HAMi/HAMi/blob/master/charts/hami/README.md#huawei-ascend
93+
## Usage
9594

9695
If you require HAMi to automatically add the `runtimeClassName` configuration to Pods requesting Ascend resources (this is disabled by default), you should set `devices.ascend.runtimeClassName` value to **a non-empty string** in HAMi’s `values.yaml` file, ensuring it matches the name of the `RuntimeClass` resource. For example:
9796

@@ -101,14 +100,18 @@ devices:
101100
runtimeClassName: ascend
102101
```
103102
104-
## Usage
105-
106103
To exclusively use an entire card or request multiple cards, you only need to set the corresponding resourceName. If multiple tasks need to share the same NPU, you need to set the corresponding resource request to 1 and configure the appropriate ResourceMemoryName.
107104
108105
### Usage in HAMi
109106
107+
**How HAMi chooses soft vs legacy vNPU:** The device plugin applies **soft slicing** (`libvnpu` / `hami-vnpu-core` mounts and environment) **only** when the Pod sets `huawei.com/vnpu-mode: hami-core`. Pods **without** this annotation still follow the **original vNPU** path (virtualization templates and `ASCEND_VNPU_SPECS`). These two paths are different. If your cluster effectively has **only** soft-slicing–oriented Ascend capacity (for example every node is configured for `hami-vnpu-core` and workloads are expected to use soft slicing), Pods that **omit** `vnpu-mode=hami-core` may remain **Pending** because they still request the legacy vNPU allocation model, which may not match what those nodes expose or how the scheduler pairs Pods to nodes.
108+
110109
```yaml
111110
...
111+
metadata:
112+
name: ascend-soft-slice-pod
113+
annotations:
114+
huawei.com/vnpu-mode: 'hami-core' # Enables hami-vnpu-core soft-segmentation for this pod
112115
containers:
113116
- name: npu_pod
114117
...
@@ -119,10 +122,12 @@ To exclusively use an entire card or request multiple cards, you only need to se
119122
huawei.com/Ascend910B-memory: "4096"
120123
```
121124

122-
For more examples, see [examples](./examples/)
125+
For more examples, see [examples](https://github.com/Project-HAMi/ascend-device-plugin/tree/main/examples)
123126

124127
### Soft Slicing Configuration (HAMi)
125128

129+
Use the annotation below whenever you intend **soft** slicing; omitting it keeps **template-based vNPU** behavior (see the note under [Usage in HAMi](#usage-in-hami)).
130+
126131
```yaml
127132
apiVersion: v1
128133
kind: Pod

README_cn.md

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,47 @@
22

33
## 说明
44

5-
Ascend device plugin 是用来支持在 [HAMi](https://github.com/Project-HAMi/HAMi)[volcano](https://github.com/volcano-sh/volcano) 中调度昇腾NPU设备.
5+
Ascend device plugin 是用来支持在 [HAMi](https://github.com/Project-HAMi/HAMi)[volcano](https://github.com/volcano-sh/volcano) 中调度昇腾 NPU 设备,支持以下两种模式:
66

7-
**基于模板的硬切分 (vNPU)**
7+
#### 1. 基于模板的硬切分 (vNPU)
88

9-
支持基于虚拟化模板的显存切分,系统会自动使用最小可用模板。详细信息请参阅 [template](https://www.google.com/search?q=链接)
9+
支持基于虚拟化模板的显存切分,系统会自动使用最小可用模板。详细信息请参阅 [template](https://github.com/Project-HAMi/ascend-device-plugin/blob/main/ascend-device-configmap.yaml)
1010

11-
**基于运行时拦截的软切分 (hami-vnpu-core)**
11+
#### 2. 基于运行时拦截的软切分 (hami-vnpu-core)
1212

13-
实现了基于 `libvnpu.so` 拦截和limiter令牌调度的软切分机制,能够实现精细化的资源共享。详细信息请参阅 [hami-vnpu-core](https://www.google.com/search?q=链接)
13+
实现了基于 `libvnpu.so` 拦截和 limiter 令牌调度的软切分机制,能够实现精细化的资源共享。详细信息请参阅 [hami-vnpu-core](https://github.com/Project-HAMi/hami-vnpu-core)
1414

15-
**注意:** `hami-vnpu-core`目前只支持ARM平台。
15+
**注意 1:** `hami-vnpu-core` 目前只支持 ARM 平台。
16+
**注意 2:** `hami-vnpu-core` 目前只支持 HAMi 调度器。
1617

1718
## 环境要求
1819

1920
部署 [ascend-docker-runtime](https://gitcode.com/Ascend/mind-cluster/tree/master/component/ascend-docker-runtime)
2021

21-
更新子模块
22-
23-
```bash
24-
git submodule update --init --recursive
25-
```
26-
2722
**hami-vnpu-core 软切分要求:**
2823

2924
- Ascend 驱动版本:≥ 25.5
3025
- 芯片模式:在昇腾芯片上开启 `device-share` 模式以支持虚拟化。
3126

32-
**开启 `device-share`模式**
27+
**开启 `device-share` 模式**
3328

3429
**npu-smi set -t device-share -i** *id* **-d** *value* 用于设置指定设备的所有芯片的容器共享模式。
3530

3631
**参数说明**
3732

3833
| 类型 | 描述 |
3934
| ------- | ----------------------------------------------------------- |
40-
| *id* | 设备ID。通过**npu-smi info -l**命令查出的NPU ID即为设备ID|
41-
| *value* | 容器使能状态:分为禁用、使能。默认禁用。0:禁用1:使能 |
35+
| *id* | 设备 ID。通过 **npu-smi info -l** 命令查出的 NPU ID 即为设备 ID|
36+
| *value* | 容器使能状态:分为禁用、使能。默认禁用。<br>0:禁用<br>1:使能 |
4237

4338
## 编译
4439

40+
更新子模块:
41+
42+
```bash
43+
git submodule update --init --recursive
44+
```
45+
4546
```bash
4647
make all
4748
```
@@ -60,34 +61,40 @@ docker buildx build -t $IMAGE_NAME .
6061
kubectl label node {ascend-node} ascend=on
6162
```
6263

63-
### 部署 ConfigMap
64+
### 部署 RuntimeClass
6465

6566
```bash
66-
kubectl apply -f ascend-device-configmap.yaml
67+
kubectl apply -f https://raw.githubusercontent.com/Project-HAMi/ascend-device-plugin/main/ascend-runtimeclass.yaml
6768
```
6869

69-
#### 节点自定义配置说明
70-
hami-device-node-config 用于对集群中特定节点的显卡虚拟化策略进行精细化控制。
71-
通过设置 hami-vnpu-core: true,指定节点将启用基于 hami-vnpu-core 的软切分,通过 vDeviceCount 字段,手动定义每个物理芯片上报给 Kubernetes 的虚拟设备数量;否则走基于模板的硬切分。
70+
### 部署 ConfigMap
71+
72+
该 ConfigMap 用于全局配置,包括 resourceName、模式、模板等。
73+
*`vnpus` 下设置 `hamiVnpuCore: true`**所有节点**会向调度器声明基于 `hami-vnpu-core` 的软切分能力(可被 `hami-device-node-config` 按节点覆盖)。
74+
7275
```bash
73-
kubectl apply -f ascend-device-node-configmap.yaml
76+
kubectl apply -f https://raw.githubusercontent.com/Project-HAMi/ascend-device-plugin/main/ascend-device-configmap.yaml
7477
```
7578

76-
### 部署 RuntimeClass
79+
**注意:** 如果该 ConfigMap 已存在,可跳过此步骤。
80+
81+
#### (可选)节点自定义配置说明
82+
83+
`hami-device-node-config` 用于对集群中特定节点的 hami-vnpu-core 进行启用或覆盖。节点级配置的优先级高于全局 `vnpus.hamiVnpuCore` 开关。
7784

7885
```bash
79-
kubectl apply -f ascend-runtimeclass.yaml
86+
kubectl apply -f https://raw.githubusercontent.com/Project-HAMi/ascend-device-plugin/main/ascend-device-node-configmap.yaml
8087
```
8188

8289
### 部署 `ascend-device-plugin`
8390

8491
```bash
85-
kubectl apply -f ascend-device-plugin.yaml
92+
kubectl apply -f https://raw.githubusercontent.com/Project-HAMi/ascend-device-plugin/main/ascend-device-plugin.yaml
8693
```
8794

88-
如果要在HAMi中使用升腾NPU, 在部署HAMi时设置 `devices.ascend.enabled` 为 true 会自动部署 ConfigMap 和 `ascend-device-plugin` 参考 <https://github.com/Project-HAMi/HAMi/blob/master/charts/hami/README.md#huawei-ascend>
95+
如果要在 HAMi 中使用昇腾 NPU,在部署 HAMi 时设置 `devices.ascend.enabled` 为 true 会自动部署 ConfigMap 和 `ascend-device-plugin`。参考 <https://github.com/Project-HAMi/HAMi/blob/master/charts/hami/README.md#huawei-ascend>
8996

90-
如果需要 HAMi 为申请 ascend 资源的 Pod 自动添加 runtimeClassName 配置(默认关闭),则应该在 HAMi 的 values.yaml 文件中配置 `deivces.ascend.runtimeClassName`**一个非空字符串**,并且与 RuntimeClass 资源名称保持一致。 例如:
97+
如果需要 HAMi 为申请 ascend 资源的 Pod 自动添加 runtimeClassName 配置(默认关闭),则应该在 HAMi 的 values.yaml 文件中配置 `devices.ascend.runtimeClassName`**一个非空字符串**,并且与 RuntimeClass 资源名称保持一致。例如:
9198

9299
```yaml
93100
devices:
@@ -97,10 +104,12 @@ devices:
97104
98105
## 使用
99106
100-
如果要独占整卡或者申请多张卡只需要设置对应的 resourceName 即可。如果多个任务要共享同一张卡,需要将 resourceName 设置为1,并且设置对应的 ResourceMemoryName。
107+
如果要独占整卡或者申请多张卡只需要设置对应的 resourceName 即可。如果多个任务要共享同一张卡,需要将 resourceName 设置为 1,并且设置对应的 ResourceMemoryName。
101108
102109
### 在 HAMi 中使用
103110
111+
**HAMi 与 vNPU 模式说明:** 只有为 Pod 配置了注解 `huawei.com/vnpu-mode: hami-core` 时,设备插件才会按 **软切分**(`libvnpu` / `hami-vnpu-core` 的挂载与环境变量)处理。**未添加**该注解的任务仍走 **原有 vNPU** 方案(虚拟化模板与 `ASCEND_VNPU_SPECS` 等)。两种路径不同。当集群里 Ascend 节点 **只有** 面向软切分的部署或调度预期(例如节点均按 `hami-vnpu-core` 配置、工作负载预期都使用软切分)时,**未**设置 `vnpu-mode=hami-core` 的任务可能一直处于 **Pending**,因为其仍按旧版 vNPU 申请与分配逻辑,可能与当前节点暴露的资源或调度匹配方式不一致。
112+
104113
```yaml
105114
...
106115
containers:
@@ -109,35 +118,35 @@ devices:
109118
resources:
110119
limits:
111120
huawei.com/Ascend910B: "1"
112-
# 如果不指定显存大小, 就会使用整张卡
121+
# 如果不指定显存大小就会使用整张卡
113122
huawei.com/Ascend910B-memory: "4096"
114123
```
115124

116-
For more examples, see [examples](./examples/)
125+
更多示例请参阅 [examples](https://github.com/Project-HAMi/ascend-device-plugin/tree/main/examples)
117126

118-
#### 软切分配置 (HAMi)
127+
### 软切分配置 (HAMi)
119128

120-
YAML
129+
需要 **软切分** 时请显式加上下文中的注解;不加则仍为 **模板硬切分 vNPU**(与上一节「在 HAMi 中使用」中的说明一致)。
121130

122131
```yaml
123132
apiVersion: v1
124133
kind: Pod
125134
metadata:
126135
name: ascend-soft-slice-pod
127136
annotations:
128-
huawei.com/vnpu-mode: 'hami-core' # 添加该注解的走hami-vnpu-core软切分
137+
huawei.com/vnpu-mode: 'hami-core' # 添加该注解的走 hami-vnpu-core 软切分
129138
spec:
130139
containers:
131140
- name: npu_pod
132141
...
133142
resources:
134143
limits:
135-
huawei.com/Ascend910B3: "1" # 请求 1 块物理 NPU
144+
huawei.com/Ascend910B3: "1" # 请求 1 块物理 NPU
136145
huawei.com/Ascend910B3-memory: "28672" # 请求 28Gi 显存
137146
huawei.com/Ascend910B3-core: "40" # 请求 40% 的算力
138147
```
139148

140-
软切分机制支持在单个 Pod 中申请多个虚拟设备,比如在进行多卡并行推理(如使用 vLLM)时,--gpu-memory-utilization 的值不能大于容器总显存上限”占“所选卡物理显存总和的比例。
149+
软切分机制支持在单个 Pod 中申请多个虚拟设备。在进行多卡并行推理(如使用 vLLM)时,`--gpu-memory-utilization` 的值不能大于"容器总显存上限"占"所选卡物理显存总和"的比例。
141150

142151
**示例:使用 vLLM 开启 2 卡张量并行 (TP=2)**
143152

@@ -155,26 +164,26 @@ spec:
155164
- name: vllm-container
156165
image: vllm-ascend:latest
157166
command: ["/bin/sh", "-c"]
158-
args:
167+
args:
159168
- |
160169
vllm serve /model/Qwen3-0.6B \
161170
--host 0.0.0.0 \
162171
--port 8002 \
163172
--enforce-eager \
164173
--tensor-parallel-size 2 \
165-
--gpu-memory-utilization 0.5 # 关键参数:总申请显存 64G / 总物理显存 128G = 0.5
174+
--gpu-memory-utilization 0.5 # 关键参数:总申请显存 64Gi / 总物理显存 128Gi = 0.5
166175
resources:
167176
limits:
168177
huawei.com/Ascend910B3: "2" # 申请 2 块虚拟设备进行并行计算
169-
huawei.com/Ascend910B3-memory: "65536" # 容器可用的总显存上限(2卡合计 64GiB)
170-
huawei.com/Ascend910B3-core: "50"
178+
huawei.com/Ascend910B3-memory: "65536" # 容器可用的总显存上限(2 卡合计 64GiB)
179+
huawei.com/Ascend910B3-core: "50"
171180
```
172181

173182
### 在 volcano 中使用
174183

175-
在 volcano 中使用时需要提前部署好 volcano, 更多信息请[参考这里](https://github.com/volcano-sh/volcano/tree/master/docs/user-guide/how_to_use_vnpu.md)
184+
在 volcano 中使用时需要提前部署好 volcano更多信息请[参考这里](https://github.com/volcano-sh/volcano/tree/master/docs/user-guide/how_to_use_vnpu.md)
176185

177-
```yaml
186+
```yaml
178187
apiVersion: v1
179188
kind: Pod
180189
metadata:
@@ -189,5 +198,5 @@ spec:
189198
resources:
190199
limits:
191200
huawei.com/Ascend310P: "1"
192-
huawei.com/Ascend310P-memory: "4096"
193-
```
201+
huawei.com/Ascend310P-memory: "4096"
202+
```

0 commit comments

Comments
 (0)