Skip to content

Commit 3c29535

Browse files
Merge pull request #91 from FouoF/fix-vnpu-core
fix: correct register cores for HamiVnpuCore mode
2 parents ce9ab91 + ea64f5f commit 3c29535

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

internal/server/register.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,16 @@ func (ps *PluginServer) registerHAMi() error {
7070
apiDevices := make([]*device.DeviceInfo, 0, len(devs))
7171
// hami currently believes that the index starts from 0 and is continuous.
7272
for i, dev := range devs {
73+
devcore := dev.AICore
74+
if ps.mgr.IsHamiVnpuCore() {
75+
devcore = HamiVnpuCoreMaxPercent
76+
}
7377
device := &device.DeviceInfo{
7478
Index: uint(i),
7579
ID: dev.UUID,
7680
Count: int32(ps.mgr.VDeviceCount()),
7781
Devmem: int32(dev.Memory),
78-
Devcore: dev.AICore,
82+
Devcore: devcore,
7983
Type: ps.mgr.CommonWord(),
8084
Numa: 0,
8185
Health: dev.Health,

internal/server/register_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,42 @@ func TestRegisterHAMi(t *testing.T) {
387387
},
388388
},
389389
},
390+
{
391+
name: "IsHamiVnpuCore_Devcore100",
392+
args: registerHAMiArgs{
393+
nodeName: "test-node",
394+
registerAnno: "hami.io/node-register-Ascend310P",
395+
handshakeAnno: "hami.io/node-handshake-Ascend310P",
396+
mgr: &FakeManager{
397+
GetDevicesFunc: func() []*manager.Device {
398+
return []*manager.Device{
399+
{UUID: "uuid1", Memory: 21527, AICore: 8, Health: true},
400+
}
401+
},
402+
VDeviceCountFunc: func() int { return 1 },
403+
CommonWordFunc: func() string { return "Ascend310P" },
404+
IsHamiVnpuCoreFunc: func() bool { return true },
405+
},
406+
nodes: []*v1.Node{
407+
{ObjectMeta: metav1.ObjectMeta{Name: "test-node", Annotations: map[string]string{}}},
408+
},
409+
},
410+
want: registerHAMiWant{
411+
deviceCount: 1,
412+
deviceCheck: func(t *testing.T, devs []*device.DeviceInfo) {
413+
t.Helper()
414+
if devs[0].Devcore != HamiVnpuCoreMaxPercent {
415+
t.Fatalf("device Devcore = %d, want %d in hami-vnpu-core mode", devs[0].Devcore, HamiVnpuCoreMaxPercent)
416+
}
417+
},
418+
annotationCheck: func(t *testing.T, annos map[string]string) {
419+
t.Helper()
420+
if annos[VNPUNodeSelectorAnnotation] != "true" {
421+
t.Fatalf("VNPUNodeSelectorAnnotation = %q, want 'true'", annos[VNPUNodeSelectorAnnotation])
422+
}
423+
},
424+
},
425+
},
390426
{
391427
name: "IsHamiVnpuCore_False",
392428
args: registerHAMiArgs{

internal/server/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const (
4646
VNPUModeAnnotation = "huawei.com/vnpu-mode"
4747
VNPUModeHamiCore = "hami-core"
4848
VNPUNodeSelectorAnnotation = "hami-vnpu-core"
49+
// HamiVnpuCoreMaxPercent is the total allocatable core units per device in
50+
// soft-slice (hami-vnpu-core) mode, where core requests are percentages.
51+
HamiVnpuCoreMaxPercent = 100
4952
)
5053

5154
var (

0 commit comments

Comments
 (0)