7.3. HAMi
HAMi (Heterogeneous AI Computing Virtualization Middleware),原又称 k8s-vGPU-scheduler,是一个 “all-in-one” Chart,用于管理 k8s 集群中的异构 AI 计算设备。 它提供了共享异构 AI 设备的能力,并在任务之间提供资源隔离。
HAMi 致力于提高 Kubernetes 集群中异构计算设备的使用率,并为不同类型的异构设备提供统一的复用接口。 更多相关信息,参见 HAMi官方文档 。
7.3.1. 部署HAMi
备注
部署HAMi之前,请确保已安装可用的Kubernetes集群,且Kubernetes版本≥1.23。
部署的HAMi版本需≥2.6.0。
在线部署操作步骤参见通过 Helm 在线安装(推荐)。 如果集群无法直接访问外部网络,可以使用离线部署,操作步骤参见离线安装 。
7.3.2. 使用sGPU
使用sGPU可以共享GPU设备资源:可以为任务分配一部分GPU,而不是完整的GPU。 sGPU支持以下参数以共享GPU,参数含义参见下表。
选项 |
类型 |
描述 |
|---|---|---|
|
integer/string |
sGPU数量。值不可大于节点GPU数量,该参数不可缺省 |
|
integer/string |
每张sGPU使用完整GPU的算力百分比。取值范围为1~100,缺省时表示使用GPU完整的算力 |
|
integer/string |
每张sGPU使用完整GPU的显存大小。默认单位为Gi,可指定单位为Mi或Gi,缺省时表示使用GPU完整的显存 |
调度策略
用户可以为任务配置调度策略以影响调度决策,HAMi支持的调度策略参见下表。
选项 |
类型 |
描述 |
|---|---|---|
|
string |
节点调度策略,可选 |
|
string |
GPU调度策略,可选 |
Qos Policy
用户可以为任务配置Qos Policy参数以指定sGPU使用的调度策略。Qos Policy参数说明参见下表。
选项 |
类型 |
描述 |
|---|---|---|
|
string |
Qos Policy,对应sGPU使用的调度策略。可选 |
具体的sGPU调度策略说明参见下表。
选项 |
描述 |
|---|---|
|
sGPU不限制算力 |
|
sGPU有固定的算力配额,且无法超过固定配额使用 |
|
sGPU有固定的算力配额,若GPU卡还有空闲算力,就可以被sGPU使用 |
分配特定GPU
若期望任务运行(或禁止运行)在特定的GPU上,用户可以为任务配置以下参数控制分配的GPU,参数说明参见下表。
选项 |
类型 |
描述 |
|---|---|---|
|
string |
期望分配的GPU UUID列表。支持多个GPU UUID,以逗号分隔。调度器将尝试分配在该列表中的GPU |
|
string |
禁止分配的GPU UUID列表。支持多个GPU UUID,以逗号分隔。调度器将不会分配在该列表中的GPU |
拓扑感知调度
当用户为任务申请完整GPU算力时,系统将分配整张GPU设备,以利用GPU间的物理拓扑加速通信。
调度器支持拓扑感知调度:针对申请完整算力的任务,根据GPU物理拓扑为其分配性能最优的GPU组合。
用户可以为任务配置是否启用拓扑感知调度,参数说明参见下表。部署HAMi时也可通过指定 --set metaxsGPUTopologyAware=true 参数启用全局拓扑感知调度。
选项 |
类型 |
描述 |
|---|---|---|
|
string |
是否启用拓扑感知调度。可选 |
7.3.2.1. sGPU任务示例
用户可参考以下示例编写sGPU任务文件。 更多示例参见 sGPU示例 。
为任务分配算力与显存
apiVersion: v1 kind: Pod metadata: name: sample-pod spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 GPU metax-tech.com/vcore: 60 # requesting 60% compute of full GPU metax-tech.com/vmemory: 4 # requesting 4 GiB device memory of full GPU
为任务分配独占GPU
apiVersion: v1 kind: Pod metadata: name: sample-pod spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 exclusive GPU
为任务配置调度策略
apiVersion: v1 kind: Pod metadata: name: sample-pod annotations: hami.io/node-scheduler-policy: "binpack" # node policy is configured as "binpack" hami.io/gpu-scheduler-policy: "spread" # gpu policy is configured as "spread" spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 GPU metax-tech.com/vcore: 60 # requesting 60% compute of full GPU metax-tech.com/vmemory: 4 # requesting 4 GiB device memory of full GPU
为任务配置Qos Policy
apiVersion: v1 kind: Pod metadata: name: sample-pod annotations: metax-tech.com/sgpu-qos-policy: "best-effort" # allocate "best-effort" qos sgpu spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 GPU metax-tech.com/vcore: 60 # requesting 60% compute of full GPU metax-tech.com/vmemory: 4 # requesting 4 GiB device memory of full GPU
为任务分配特定GPU
apiVersion: v1 kind: Pod metadata: name: sample-pod annotations: metax-tech.com/use-gpuuuid: "GPU-36beae85-c835-6b14-6ab2-02671837a59c" # allocate specific gpu spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 GPU metax-tech.com/vcore: 60 # requesting 60% compute of full GPU metax-tech.com/vmemory: 4 # requesting 4 GiB device memory of full GPU
为任务配置拓扑感知调度
apiVersion: v1 kind: Pod metadata: name: sample-pod annotations: metax-tech.com/sgpu-topology-aware: "true" # enable topology aware scheduling spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 4 # requesting 4 exclusive GPU
7.3.2.2. 提交sGPU任务
在Kubernetes管理节点执行以下命令提交任务。
kubectl create -f sample.yaml