更新时间:2024-02-23 GMT+08:00
分享

NPU调度

CCE支持在容器中使用NPU资源。

前提条件

使用NPU

创建工作负载申请NPU资源,可按如下方法配置,指定显卡的数量。

kind: Deployment
apiVersion: apps/v1
metadata:
  name: npu-test
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: npu-test
  template:
    metadata:
      labels:
        app: npu-test
    spec:
      containers:
        - name: container-0
          image: nginx:perl
          resources:
            limits:
              cpu: 250m
              huawei.com/ascend-310: '1'
              memory: 512Mi
            requests:
              cpu: 250m
              huawei.com/ascend-310: '1'
              memory: 512Mi
      imagePullSecrets:
      - name: default-secret

通过huawei.com/ascend-310指定申请NPU的数量。

使用huawei.com/ascend-310参数指定NPU数量时,requests和limits值需要保持一致。

指定huawei.com/ascend-310后,在调度时不会将负载调度到没有NPU的节点。如果缺乏NPU资源,会报类似“0/2 nodes are available: 2 Insufficient huawei.com/ascend-310.”的Kubernetes事件。

在CCE控制台使用NPU资源,只需在创建工作负载时,勾选NPU配额,并指定使用NPU芯片的数量。

图1 使用NPU

NPU节点标签

创建NPU节点后,CCE会给节点打上对应标签,如下所示。

$ kubectl get node -L accelerator/huawei-npu
NAME           STATUS   ROLES    AGE     VERSION                                    HUAWEI-NPU
10.100.2.59    Ready    <none>   2m18s   v1.19.10-r0-CCE21.11.1.B006-21.11.1.B006   ascend-310
在使用NPU时,可以根据标签让Pod与节点亲和,从而让Pod选择正确的节点,如下所示。
kind: Deployment
apiVersion: apps/v1
metadata:
  name: npu-test
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: npu-test
  template:
    metadata:
      labels:
        app: npu-test
    spec:
      nodeSelector:
        accelerator/huawei-npu: ascend-310
      containers:
        - name: container-0
          image: nginx:perl
          resources:
            limits:
              cpu: 250m
              huawei.com/ascend-310: '1'
              memory: 512Mi
            requests:
              cpu: 250m
              huawei.com/ascend-310: '1'
              memory: 512Mi
      imagePullSecrets:
      - name: default-secret
分享:

    相关文档

    相关产品