Method 1: Mounting vNPUs Using Ascend Docker Runtime
This section describes how to use Ascend Docker Runtime (container engine plugin) to mount vNPUs to a container.
Prerequisites
Obtain the Ascend-docker-runtime_{version}_linux-{arch}.run package and install it by referring to Ascend Docker Runtime.
Usage on Ascend Docker Runtime
Use either of the following methods:
- Static virtualization: After creating a vNPU using the npu-smi tool, run the following command to mount the vNPU to a container when starting the container. The following command means to mount the vNPU whose ID is 100 when the container is started:
docker run -it -e ASCEND_VISIBLE_DEVICES=100 -e ASCEND_RUNTIME_OPTIONS=VIRTUAL image-name:tag /bin/bash
- Dynamic virtualization: When starting a container, run the following command to split four AI Cores from the physical device (ID = 0) as vNPUs and mount them to the container. If a container is started in this way, the virtual device is automatically destroyed when the container process is ended.
docker run -it --rm -e ASCEND_VISIBLE_DEVICES=0 -e ASCEND_VNPU_SPECS=vir04 image-name:tag /bin/bash
- To use dynamic virtualization, disable the vNPU restoration function.
- You can query the available processor IDs as follows:
- Physical processor ID:
ls /dev/davinci*
- Virtual processor ID:
ls /dev/vdavinci*
- Physical processor ID:
- image-name:tag: image name and tag, for example, ascend-tensorflow:tensorflow_TAG.
- Do not repeatedly define or fix environment variables such as ASCEND_VISIBLE_DEVICES, ASCEND_RUNTIME_OPTIONS, and ASCEND_VNPU_SPECS in the container image.
Parameter |
Description |
Example |
|---|---|---|
ASCEND_VISIBLE_DEVICES |
ASCEND_VISIBLE_DEVICES must be used to specify the NPU device to be mounted to the container. Otherwise, the NPU device fails to be mounted. If the NPU device ID is used to specify devices, one or more devices can be specified, and devices can be used together. If the NPU name is used to specify devices, multiple NPU names of the same type can be specified at the same time. |
|
ASCEND_RUNTIME_OPTIONS |
Restricts the processor ID specified by ASCEND_VISIBLE_DEVICES.
|
|
ASCEND_VNPU_SPECS |
Splits a certain number of AI Cores from a physical NPU device as virtual devices. The value can be vir01, vir02, vir02_1c, vir04, vir04_3c, vir08, vir16, vir04_4c_dvpp, or vir04_3c_ndvpp.
This parameter must be used together with ASCEND_VISIBLE_DEVICES that specifies the physical NPU device to be virtualized. |
ASCEND_VNPU_SPECS=vir04 indicates that four AI Cores are allocated as vNPUs that will be mounted to a container. |