Updated on 2023-03-20 GMT+08:00

NPU Scheduling

You can use NPUs in CCE containers.

Prerequisites

  • An NPU node has been ready for use. For details, see Buying a Node.
  • The huawei-npu has been installed. For details, see huawei-npu.

Using NPUs

Create a workload and request NPUs. You can specify the number of NPUs as follows:

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

Specify the number of NPUs to be requested in huawei.com/ascend-310.

After huawei.com/ascend-310 is specified, workloads will not be scheduled to nodes without NPUs. If NPUs are insufficient, a Kubernetes event similar to "0/2 nodes are available: 2 Insufficient huawei.com/ascend-310." will be reported.

To use NPUs on the CCE console, select the Ascend 310 quota and specify the number of Ascend chips to be used when creating a workload.

Figure 1 Using NPUs

NPU Node Labels

CCE will label NPU-enabled nodes that are ready to use.

Figure 2 NPU node labels
When using NPUs, you can enable the affinity between pods and nodes based on labels so that the pods can be scheduled to the correct nodes.
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