摩尔线程云原生套件 v2.0.0 安装指南
容器运行时套件
支持的平台
支持的 Linux 发行版
| 操作系统名称及版本 | amd64 / x86_64 | arm64 / aarch64 |
|---|---|---|
| Ubuntu 20.04 | Y | N/A |
| Kylin V10 SP1 | N/A | Y |
| UnionTech OS Desktop 20 Pro | N/A | Y |
| Debian 12 | Y | N/A |
支持的容器运行时
| 容器运行时名称及版本 | amd64 / x86_64 | arm64 / aarch64 |
|---|---|---|
| Docker 20.10 | Y | Y |
| containerd 1.5 | Y | Y |
安装指南
先决条件
在开始之前,请确保已为您的 Linux 发行版安装了最新的摩尔线程显卡驱动。您可以通过以下命令来进行验证:
❯ mthreads-gmi
Fri May 16 10:41:32 2025
---------------------------------------------------------------
mthreads-gmi:2.0.0 Driver Version:3.0.0
---------------------------------------------------------------
ID Name |PCIe |%GPU Mem
Device Type |Pcie Lane Width |Temp MPC Capable
| ECC Mode
+-------------------------------------------------------------+
0 MTT S80 |00000000:01:00.0 |0% 516MiB(16384MiB)
Physical |16x(16x) |60C YES
| N/A
---------------------------------------------------------------
---------------------------------------------------------------
Processes:
ID PID Process name GPU Memory
Usage
+-------------------------------------------------------------+
No running processes found
---------------------------------------------------------------
安装 Docker CE
sudo apt install docker.io
更多安装信息请参考官方文档。
安装摩尔线程容器运行时套件
使用 dpkg 包管理工具进行安装:
sudo dpkg -i mtml_2.0.0.deb mt-container-toolkit_2.0.0.deb
绑定摩尔线程容器运行时到 Docker,设置默认的容器运行时为 mthreads 并重启 Docker daemon:
$ (cd /usr/bin/musa && sudo ./docker setup $PWD)
您可以通过如下命令验证上述步骤是否成功:
❯ docker run --rm --env MTHREADS_VISIBLE_DEVICES=all ubuntu:22.04 mthreads-gmi
Fri May 16 02:42:24 2025
---------------------------------------------------------------
mthreads-gmi:2.0.0 Driver Version:3.0.0
---------------------------------------------------------------
ID Name |PCIe |%GPU Mem
Device Type |Pcie Lane Width |Temp MPC Capable
| ECC Mode
+-------------------------------------------------------------+
0 MTT S80 |00000000:01:00.0 |0% 516MiB(16384MiB)
Physical |16x(16x) |60C YES
| N/A
---------------------------------------------------------------
---------------------------------------------------------------
Processes:
ID PID Process name GPU Memory
Usage
+-------------------------------------------------------------+
No running processes found
---------------------------------------------------------------
可以看到在容器内部已经能够获取到摩尔线程 GPU 设备。
卸载摩尔线程容器运行时套件
恢复 Docker 默认的容器运行时并重启 Docker daemon:
$ (cd /usr/bin/musa && sudo ./docker cleanup $PWD)
通过 dpkg 包管理工具卸载摩尔线程容器运行时套件:
$ sudo dpkg -r mt-container-toolkit mtml sgpu-dkms
# 完全卸载并清除配置文件
$ sudo dpkg -P mt-container-toolkit mtml sgpu-dkms
使用指南
摩尔线程容器运行时可以使用以下环境变量对容器中的 GPU 设备进行设置:
MTHREADS_VISIBLE_DEVICES设置挂载到容器中的摩尔线程 GPU 设备。MTHREADS_DRIVER_CAPABILITIES设置容器中用户态驱动程序的能力。
GPU 枚举
通过设置 MTHREADS_VISIBLE_DEVICES 环境变量可以指定特定的 GPU 设备到容器中。
MTHREADS_VISIBLE_DEVICES 可以设置的值如下:
| 可设置的值 | 描述 |
|---|---|
0,1,2, 或者 438e3949-f6f2-f7b4-c904-8ffb9d6fa9d3 | 通过 GPU 的设备编号或者 GPU UUID 指定。 |
all | 所有的 GPU 设备均可见。 |
void, empty 或者 unset | mthreads-container-runtime 的行为将和 runc[1] 保持一致。 |
示例:
使用全部 GPU:
❯ docker run --rm -e MTHREADS_VISIBLE_DEVICES=all ubuntu:20.04 mthreads-gmi
Mon Jul 17 07:49:07 2023
---------------------------------------------------------------
mthreads-gmi:2.0.0 Driver Version:3.0.0
---------------------------------------------------------------
ID Name |PCIe |%GPU Mem
Device Type |Pcie Lane Width |Temp MPC Capable
+-------------------------------------------------------------+
0 MTT S2000 |00000000:03:00.0 |0% 4MiB(16384MiB)
Physical |8x(8x) |51C NO
+-------------------------------------------------------------+
1 MTT S2000 |00000000:04:00.0 |0% 4MiB(16384MiB)
Physical |8x(8x) |50C NO
---------------------------------------------------------------
---------------------------------------------------------------
Processes:
ID PID Process name GPU Memory
Usage
+-------------------------------------------------------------+
No running processes found
---------------------------------------------------------------
使用设备号指定 GPU:
❯ docker run --rm -e MTHREADS_VISIBLE_DEVICES=1 ubuntu:20.04 mthreads-gmi
Mon Jul 17 07:49:36 2023
---------------------------------------------------------------
mthreads-gmi:2.0.0 Driver Version:3.0.0
---------------------------------------------------------------
ID Name |PCIe |%GPU Mem
Device Type |Pcie Lane Width |Temp MPC Capable
+-------------------------------------------------------------+
0 MTT S2000 |00000000:04:00.0 |0% 4MiB(16384MiB)
Physical |8x(8x) |50C NO
---------------------------------------------------------------
---------------------------------------------------------------
Processes:
ID PID Process name GPU Memory
Usage
+-------------------------------------------------------------+
No running processes found
---------------------------------------------------------------
使用 GPU UUID 指定 GPU:
❯ mthreads-gmi --query | grep UUID
GPU UUID : 7e8581f5-6722-035b-9b7f-07b8ed270fd0
GPU UUID : 2716ae75-44e4-231b-df26-f7c2c4abb678
❯ docker run --rm -e MTHREADS_VISIBLE_DEVICES=2716ae75-44e4-231b-df26-f7c2c4abb678 ubuntu:20.04 mthreads-gmi
Mon Jul 17 07:50:33 2023
---------------------------------------------------------------
mthreads-gmi:2.0.0 Driver Version:3.0.0
---------------------------------------------------------------
ID Name |PCIe |%GPU Mem
Device Type |Pcie Lane Width |Temp MPC Capable
+-------------------------------------------------------------+
0 MTT S2000 |00000000:04:00.0 |0% 4MiB(16384MiB)
Physical |8x(8x) |50C NO
---------------------------------------------------------------
---------------------------------------------------------------
Processes:
ID PID Process name GPU Memory
Usage
+-------------------------------------------------------------+
No running processes found
---------------------------------------------------------------
驱动能力
MTHREADS_DRIVER_CAPABILITIES 用于控制容器中用户态驱动程序的能力。
MTHREADS_DRIVER_CAPABILITIES 可以设置的值如下:
| 可设置的值 | 描述 |
|---|---|
compute,video 或者 graphics,utility | 可以传入多个驱动能力,以 “,” 为分割符。 |
all | GPU 所有的能力。 |
| empty 或者 unset | 设置默认值: compute, utility。 |
void | 不挂载任何驱动能力。 |
支持设置的驱动能力列表。
| 驱动能力 | 描述 |
|---|---|
compute | 使用 MUSA 和 OpenCL 的应用。 |
graphics | 使用 OpenGL 和 Vulkan 的应用。 |
utility | 使用 mthreads-gmi 和 MTML。 |
video | 使用编解码能力的应用。 |
示例:
❯ docker run --rm \
-e MTHREADS_VISIBLE_DEVICES=all \
-e MTHREADS_DRIVER_CAPABILITIES=compute,utility \
ubuntu:20.04 mthreads-gmi
Mon Jul 17 07:55:29 2023
---------------------------------------------------------------
mthreads-gmi:2.0.0 Driver Version:3.0.0
---------------------------------------------------------------
ID Name |PCIe |%GPU Mem
Device Type |Pcie Lane Width |Temp MPC Capable
+-------------------------------------------------------------+
0 MTT S2000 |00000000:03:00.0 |0% 4MiB(16384MiB)
Physical |8x(8x) |51C NO
+-------------------------------------------------------------+
1 MTT S2000 |00000000:04:00.0 |0% 4MiB(16384MiB)
Physical |8x(8x) |50C NO
---------------------------------------------------------------
---------------------------------------------------------------
Processes:
ID PID Process name GPU Memory
Usage
+-------------------------------------------------------------+
No running processes found
---------------------------------------------------------------
Dockerfiles
构建容器镜像时在 Dockerfile 添加环境变量,运行容器时就无需再指定它们。
ENV MTHREADS_VISIBLE_DEVICES all
ENV MTHREADS_DRIVER_CAPABILITIES compute,utility
MT GPU Operator
先决条件
在安装 MT GPU Operator 前, 您应该确保 Kubernetes 集群满足一些先决条件:
-
节点必须配置容器引擎,例如 Docker CE/EE、containerd 或 cri-o。安装 Docker 请参见安装 Docker Engine。
-
节点功能发现 (NFD) 是每个节点上 GPU Operator 的依赖项。默认情况下,NFD master 和 worker 由 GPU Operator 自动部署。如果在部署 GPU Operator 之前,NFD 已在集群中运行,则可以将 GPU Operator 配置为不安装 NFD。
-
要在 Kubernetes 1.13 和 1.14 中进行监控,请启用 kubelet
KubeletPodResources[a] 功能门。从 Kubernetes 1.15 开始,默认启用KubeletPodResources。 -
要在 Kubernetes 中收集 GPU 使用数据,必须在集群中部署 Prometheus。
$ export VERSION=$(curl -s https://api.github.com/repos/prometheus-operator/prometheus-operator/releases | grep tag_name | grep -v -- '-rc' | grep -v -- '-alpha' | sort -r | head -1 | awk -F': ' '{print $2}' | sed 's/,//' | xargs)$ echo $VERSION$ kubectl create -f https://github.com/prometheus-operator/prometheus-operator/releases/download/${VERSION}/bundle.yaml -
要自动安装 MT 驱动程序,必须在集群内的每个节点上手动安装以下软件包:
-
LightDM 是一个跨桌面显示管理器,可以使用以下命令进行安装:
$ sudo apt install -y lightdm -
libdrm2是内核直接渲染管理器 (DRM) 服务的用户空间接口,可以使用以下命令进行安装。$ sudo apt install -y libdrm2注意:所需的最低版本是
2.4.99。
-
-
GPU 调度器是基于 Scheduling Framework 构建的。如果要启用此功能,请确保 Kubernetes 的版本大于
1.19. -
为了确保 sGPU DEB 包的成功安装,需要首先在集群内的每个节点上安装所需的依赖包
dkms。-
dkms可以使用以下命令安装:$ sudo apt install -y dkms注意:所需的最低版本是
1.95。
-
要启用 Kubelet Pod Resources 功能门,请运行以下命令:
echo -e "KUBELET_EXTRA_ARGS=--feature-gates=KubeletPodResources=true" | sudo tee /etc/default/kubelet
安装指南
先将部署包下载,然后解压:
$ unzip mt-gpu-operator-2.0.0.zip
$ rm mt-gpu-operator-2.0.0.zip
$ cd operator_2.0.0
$ tree
.
├── change_image_repo.sh
├── end-user-cn.md
├── mt-gpu-operator-2.0.0.tgz
├── mt-gpu-operator-custom-resources-2.0.0.tgz
├── mt-gpu-operator.yaml
├── mthreads_v1alpha4_clusterconfig.yaml
├── mthreads_v1beta2_clusterpolicy.yaml
└── sync_image.sh
0 directories, 8 files
$ tar -xvzf mt-gpu-operator-2.0.0.tgz
$ tar -xvzf mt-gpu-operator-custom-resources-2.0.0.tgz
$ tree
.
├── change_image_repo.sh
├── end-user-cn.md
├── mt-gpu-operator
│ ├── Chart.yaml
│ ├── crds
│ │ ├── biosconfigs.mthreads.com-crd.yaml
│ │ ├── clusterconfigs.mthreads.com-crd.yaml
│ │ ├── clusterpolicies.mthreads.com-crd.yaml
│ │ └── nodeconfigs.mthreads.com-crd.yaml
│ ├── templates
│ │ ├── _helpers.tpl
│ │ ├── mt-controller-manager-cm.yaml
│ │ ├── mt-controller-manager-deployment.yaml
│ │ ├── mt-controller-manager-metrics-service-svc.yaml
│ │ ├── mt-controller-manager-sa.yaml
│ │ ├── mt-gpu-operator-cleanup-crd-job.yaml
│ │ ├── mt-gpu-operator-namespace.yaml
│ │ ├── mt-gpu-operator-upgrade-crd-job.yaml
│ │ ├── mt-leader-election-rolebinding-rb.yaml
│ │ ├── mt-leader-election-role-role.yaml
│ │ ├── mt-manager-rolebinding-crb.yaml
│ │ ├── mt-manager-role-cr.yaml
│ │ ├── mt-metrics-reader-cr.yaml
│ │ ├── mt-mutating-webhook-configuration-mutatingwebhookconfiguration.yaml
│ │ ├── mt-proxy-rolebinding-crb.yaml
│ │ ├── mt-proxy-role-cr.yaml
│ │ ├── mt-published-device-cm.yaml
│ │ ├── mt-validating-webhook-configuration-validatingwebhookconfiguration.yaml
│ │ └── mt-webhook-service-svc.yaml
│ └── values.yaml
├── mt-gpu-operator-2.0.0.tgz
├── mt-gpu-operator-custom-resources
│ ├── Chart.yaml
│ ├── templates
│ │ ├── _helpers.tpl
│ │ ├── mt-gpu-cluster-config-clusterconfig.yaml
│ │ └── mt-gpu-cluster-policy-clusterpolicy.yaml
│ └── values.yaml
├── mt-gpu-operator-custom-resources-2.0.0.tgz
├── mt-gpu-operator.yaml
├── mthreads_v1alpha4_clusterconfig.yaml