Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ To exclusively use an entire card or request multiple cards, you only need to se

### Usage in HAMi

**How HAMi chooses soft vs legacy vNPU:** The device plugin applies **soft slicing** (`libvnpu` / `hami-vnpu-core` mounts and environment) **only** when the Pod sets `huawei.com/vnpu-mode: hami-core`. Pods **without** this annotation still follow the **original vNPU** path (virtualization templates and `ASCEND_VNPU_SPECS`). These two paths are different. If your cluster effectively has **only** soft-slicing–oriented Ascend capacity (for example every node is configured for `hami-vnpu-core` and workloads are expected to use soft slicing), Pods that **omit** `vnpu-mode=hami-core` may remain **Pending** because they still request the legacy vNPU allocation model, which may not match what those nodes expose or how the scheduler pairs Pods to nodes.
**How HAMi chooses soft vs legacy vNPU:**
- A Pod that sets `huawei.com/vnpu-mode: hami-core` always uses **soft slicing** and is scheduled only onto hami-core-capable nodes.
- A Pod that **omits** the annotation is **mode-agnostic**: it may be scheduled onto either a template node or a hami-core node, and its effective mode **follows the node**. On a hami-core node the device plugin applies soft slicing (`libvnpu` / `hami-vnpu-core` mounts and environment); on a template node it uses the original vNPU path (`ASCEND_VNPU_SPECS`). The plugin resolves this from the node's `hami-vnpu-core` setting (`IsHamiVnpuCore()`), so annotation-less Pods no longer remain Pending on hami-core-only clusters.

```yaml
...
Expand Down
5 changes: 3 additions & 2 deletions internal/server/allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func (ps *PluginServer) buildContainerAllocateResponse(pod *v1.Pod, ctrName stri
resp.Envs["ASCEND_VISIBLE_DEVICES"] = ascendVisibleDevices

vnpuMode := pod.Annotations[VNPUModeAnnotation]
klog.V(4).Infof("Pod %s vnpu mode: %s", pod.Name, vnpuMode)
if vnpuMode == VNPUModeHamiCore {
effectiveHamiCore := vnpuMode == VNPUModeHamiCore || (vnpuMode == "" && ps.mgr.IsHamiVnpuCore())
klog.V(4).Infof("Pod %s vnpu mode: %q, effectiveHamiCore: %v", pod.Name, vnpuMode, effectiveHamiCore)
if effectiveHamiCore {
// 1. Handle volume mount injection
var mounts []*v1beta1.Mount
// A.Huawei driver and SMI toolchain (Read-Only)
Expand Down
73 changes: 73 additions & 0 deletions internal/server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,79 @@ func TestBuildContainerAllocateResponse(t *testing.T) {
},
},
},
{
name: "NoAnnotation_NodeHamiCore_FollowsNode",
setup: func() (*PluginServer, CleanupFunc) {
return &PluginServer{
mgr: &FakeManager{
GetDeviceByUUIDFunc: func(uuid string) *manager.Device {
return &manager.Device{UUID: "uuid1", PhyID: 3}
},
IsHamiVnpuCoreFunc: func() bool { return true },
},
allocAnno: allocAnno,
}, func() {}
},
args: buildContainerAllocateResponseArgs{
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}},
containerDevs: device.ContainerDevices{cd("uuid1", "Ascend910", 1024, 4)},
rtInfoLookup: func() map[string]RuntimeInfo {
mem := int64(8738)
core := int32(4)
return map[string]RuntimeInfo{
"uuid1": {UUID: "uuid1", Temp: "vir08", Memory: &mem, Core: &core},
}
}(),
},
want: buildContainerAllocateResponseWant{
envs: map[string]string{
"ASCEND_VISIBLE_DEVICES": "3",
"NPU_MEM_QUOTA": "8738",
"NPU_PRIORITY": "4",
"NPU_GLOBAL_SHM_PATH": "/hami-shared-region/3_global_registry",
},
mounts: []*v1beta1.Mount{
{HostPath: "/usr/local/bin/npu-smi", ContainerPath: "/usr/local/bin/npu-smi", ReadOnly: true},
{HostPath: "/etc/ascend_install.info", ContainerPath: "/etc/ascend_install.info", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/lib64/driver", ContainerPath: "/usr/local/Ascend/driver/lib64/driver", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/version.info", ContainerPath: "/usr/local/Ascend/driver/version.info", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core", ContainerPath: "/hami-vnpu-core", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core/ld.so.preload", ContainerPath: "/etc/ld.so.preload", ReadOnly: true},
{HostPath: "/usr/local/hami-shared-region", ContainerPath: "/hami-shared-region", ReadOnly: false},
},
},
Comment on lines +449 to +465

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Missing mount entry — test will fail.

want.mounts lists only 7 entries, but the hami-core branch always appends an 8th mount for the per-container shmem dir (hostHookPath + "/containers/_", per the existing HamiCoreMode_Mounts case). The len(resp.Mounts) != len(tc.want.mounts) check will fail this subtest.

🐛 Proposed fix
 				mounts: []*v1beta1.Mount{
 					{HostPath: "/usr/local/bin/npu-smi", ContainerPath: "/usr/local/bin/npu-smi", ReadOnly: true},
 					{HostPath: "/etc/ascend_install.info", ContainerPath: "/etc/ascend_install.info", ReadOnly: true},
 					{HostPath: "/usr/local/Ascend/driver/lib64/driver", ContainerPath: "/usr/local/Ascend/driver/lib64/driver", ReadOnly: true},
 					{HostPath: "/usr/local/Ascend/driver/version.info", ContainerPath: "/usr/local/Ascend/driver/version.info", ReadOnly: true},
 					{HostPath: "/usr/local/hami-vnpu-core", ContainerPath: "/hami-vnpu-core", ReadOnly: true},
 					{HostPath: "/usr/local/hami-vnpu-core/ld.so.preload", ContainerPath: "/etc/ld.so.preload", ReadOnly: true},
 					{HostPath: "/usr/local/hami-shared-region", ContainerPath: "/hami-shared-region", ReadOnly: false},
+					{HostPath: hostHookPath + "/containers/_", ContainerPath: "/hami-vnpu-shmem", ReadOnly: false},
 				},
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
want: buildContainerAllocateResponseWant{
envs: map[string]string{
"ASCEND_VISIBLE_DEVICES": "3",
"NPU_MEM_QUOTA": "8738",
"NPU_PRIORITY": "4",
"NPU_GLOBAL_SHM_PATH": "/hami-shared-region/3_global_registry",
},
mounts: []*v1beta1.Mount{
{HostPath: "/usr/local/bin/npu-smi", ContainerPath: "/usr/local/bin/npu-smi", ReadOnly: true},
{HostPath: "/etc/ascend_install.info", ContainerPath: "/etc/ascend_install.info", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/lib64/driver", ContainerPath: "/usr/local/Ascend/driver/lib64/driver", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/version.info", ContainerPath: "/usr/local/Ascend/driver/version.info", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core", ContainerPath: "/hami-vnpu-core", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core/ld.so.preload", ContainerPath: "/etc/ld.so.preload", ReadOnly: true},
{HostPath: "/usr/local/hami-shared-region", ContainerPath: "/hami-shared-region", ReadOnly: false},
},
},
want: buildContainerAllocateResponseWant{
envs: map[string]string{
"ASCEND_VISIBLE_DEVICES": "3",
"NPU_MEM_QUOTA": "8738",
"NPU_PRIORITY": "4",
"NPU_GLOBAL_SHM_PATH": "/hami-shared-region/3_global_registry",
},
mounts: []*v1beta1.Mount{
{HostPath: "/usr/local/bin/npu-smi", ContainerPath: "/usr/local/bin/npu-smi", ReadOnly: true},
{HostPath: "/etc/ascend_install.info", ContainerPath: "/etc/ascend_install.info", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/lib64/driver", ContainerPath: "/usr/local/Ascend/driver/lib64/driver", ReadOnly: true},
{HostPath: "/usr/local/Ascend/driver/version.info", ContainerPath: "/usr/local/Ascend/driver/version.info", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core", ContainerPath: "/hami-vnpu-core", ReadOnly: true},
{HostPath: "/usr/local/hami-vnpu-core/ld.so.preload", ContainerPath: "/etc/ld.so.preload", ReadOnly: true},
{HostPath: "/usr/local/hami-shared-region", ContainerPath: "/hami-shared-region", ReadOnly: false},
{HostPath: hostHookPath + "/containers/_", ContainerPath: "/hami-vnpu-shmem", ReadOnly: false},
},
},
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/server/util_test.go` around lines 449 - 465, The hami-core
allocation test expectation is missing the per-container shared-memory mount, so
the mount count assertion will fail. Update the
`buildContainerAllocateResponseWant` setup in `internal/server/util_test.go` for
this case to include the extra mount appended by the `HamiCoreMode_Mounts` path
(the per-container `hostHookPath + "/containers/_"` shmem dir) so `resp.Mounts`
matches `tc.want.mounts`. Keep the existing `mounts` slice in sync with the
behavior exercised by `buildContainerAllocateResponse` and
`HamiCoreMode_Mounts`.

},
{
name: "NoAnnotation_NodeTemplate_FollowsNode",
setup: func() (*PluginServer, CleanupFunc) {
return &PluginServer{
mgr: &FakeManager{
GetDeviceByUUIDFunc: func(uuid string) *manager.Device {
return &manager.Device{UUID: "uuid1", PhyID: 3}
},
IsHamiVnpuCoreFunc: func() bool { return false },
},
allocAnno: allocAnno,
}, func() {}
},
args: buildContainerAllocateResponseArgs{
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}},
containerDevs: device.ContainerDevices{cd("uuid1", "Ascend910", 1024, 4)},
rtInfoLookup: func() map[string]RuntimeInfo {
mem := int64(8738)
core := int32(0)
return map[string]RuntimeInfo{
"uuid1": {UUID: "uuid1", Temp: "vir08", Memory: &mem, Core: &core},
}
}(),
},
want: buildContainerAllocateResponseWant{
envs: map[string]string{
"ASCEND_VISIBLE_DEVICES": "3",
"ASCEND_VNPU_SPECS": "vir08",
},
},
},
{
name: "NonHamiCore_EmptyTemp",
setup: func() (*PluginServer, CleanupFunc) {
Expand Down
Loading