Skip to content
Merged
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
47 changes: 37 additions & 10 deletions pkg/device/ascend/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ import (
)

const (
NodeLockAscend = "hami.io/mutex.lock"
Ascend910Prefix = "Ascend910"
Ascend910CType = "Ascend910C"
Ascend910NetworkWeight = 10
VNPUModeAnnotation = "huawei.com/vnpu-mode"
VNPUModeHamiCore = "hami-core"
NodeLockAscend = "hami.io/mutex.lock"
Ascend910Prefix = "Ascend910"
Ascend910CType = "Ascend910C"
Ascend910NetworkWeight = 10
VNPUModeAnnotation = "huawei.com/vnpu-mode"
VNPUModeHamiCore = "hami-core"
VNPUNodeSelectorAnnotation = "hami-vnpu-core"
)

type Devices struct {
Expand Down Expand Up @@ -430,16 +431,42 @@ func (npu *Devices) Fit(devices []*device.DeviceUsage, request device.ContainerD
originReq := k.Nums
prevnuma := -1
klog.InfoS("Allocating device for container request", "pod", klog.KObj(pod), "card request", k)
var tmpDevs map[string]device.ContainerDevices
tmpDevs = make(map[string]device.ContainerDevices)
reason := make(map[string]int)

vnpuMode := ""
if pod != nil && pod.Annotations != nil {
vnpuMode = pod.Annotations[VNPUModeAnnotation]
}

isHAMiCore := (vnpuMode == VNPUModeHamiCore)

// Verify whether the Node supports hami vnpu core
Comment thread
archlitchi marked this conversation as resolved.
nodeSupportHamiCore := false

if nodeInfo != nil && nodeInfo.Node != nil && nodeInfo.Node.Annotations != nil {
nodeSupportHamiCore = nodeInfo.Node.Annotations[VNPUNodeSelectorAnnotation] == "true"
}

var totalMemPerCard int32 = 0
if len(devices) > 0 {
totalMemPerCard = devices[0].Totalmem
}

if request.Memreq > 0 && request.Memreq < totalMemPerCard && request.Nums > 0 {
if !nodeSupportHamiCore && isHAMiCore {
reason[common.ModeNotFit]++
klog.V(4).InfoS("Node filtered: Node does not support hami-core mode", "node", nodeInfo.Node.Name, "pod", pod.Name)
return false, nil, common.GenReason(reason, len(devices))
} else if nodeSupportHamiCore && !isHAMiCore {
reason[common.ModeNotFit]++
klog.V(4).InfoS("Node filtered: Reserved for hami-core but pod is legacy vNPU", "node", nodeInfo.Node.Name, "pod", pod.Name)
return false, nil, common.GenReason(reason, len(devices))
}
}
klog.V(4).InfoS("Fit: vnpu-mode annotation", "pod", pod.Name, "vnpuMode", vnpuMode)

var tmpDevs map[string]device.ContainerDevices
tmpDevs = make(map[string]device.ContainerDevices)
reason := make(map[string]int)
needTopology := false
if strings.HasPrefix(npu.CommonWord(), Ascend910Prefix) && hasNetworkID(devices) {
klog.V(4).Infof("all devices have NetworkID. device CommonWord %s", npu.CommonWord())
Expand Down Expand Up @@ -495,7 +522,7 @@ func (npu *Devices) Fit(devices []*device.DeviceUsage, request device.ContainerD
}
// Set dev.Totalcore to 100 if vnpuMode is hami-core
effectiveTotalCore := dev.Totalcore
if vnpuMode == VNPUModeHamiCore {
if isHAMiCore {
effectiveTotalCore = 100
}

Expand Down
58 changes: 50 additions & 8 deletions pkg/device/ascend/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1385,14 +1385,15 @@ func TestDevices_Fit(t *testing.T) {
devs := InitDevices(config)

tests := []struct {
name string
devices []*device.DeviceUsage
request device.ContainerDeviceRequest
annos map[string]string
wantFit bool
wantLen int
wantDevIDs []string
wantReason string
name string
devices []*device.DeviceUsage
request device.ContainerDeviceRequest
annos map[string]string
nodeAnnotation map[string]string
wantFit bool
wantLen int
wantDevIDs []string
wantReason string
}{
{
name: "fit success",
Expand Down Expand Up @@ -1776,6 +1777,42 @@ func TestDevices_Fit(t *testing.T) {
wantDevIDs: []string{"dev-2", "dev-1"},
wantReason: "",
},
{
name: "fit fail: hami-core pod on legacy node (ModeNotFit)",
devices: []*device.DeviceUsage{{
ID: "dev-0", Index: 0, Used: 0, Count: 100,
Usedmem: 0, Totalmem: 32768, Totalcore: 100, Usedcores: 0,
Numa: 0, Health: true,
}},
request: device.ContainerDeviceRequest{
Nums: 1, Memreq: 15360, MemPercentagereq: 0, Coresreq: 20,
},
annos: map[string]string{
VNPUModeAnnotation: VNPUModeHamiCore,
},
wantFit: false,
wantLen: 0,
wantDevIDs: []string{},
wantReason: "1/1 ModeNotFit",
nodeAnnotation: map[string]string{},
},
{
name: "fit fail: legacy pod on hami-core reserved node (ModeNotFit)",
devices: []*device.DeviceUsage{{
ID: "dev-0", Index: 0, Used: 0, Count: 100,
Usedmem: 0, Totalmem: 32768, Totalcore: 100, Usedcores: 0,
Numa: 0, Health: true,
}},
request: device.ContainerDeviceRequest{
Nums: 1, Memreq: 8738, MemPercentagereq: 0, Coresreq: 0,
},
annos: map[string]string{},
wantFit: false,
wantLen: 0,
wantDevIDs: []string{},
wantReason: "1/1 ModeNotFit",
nodeAnnotation: map[string]string{VNPUNodeSelectorAnnotation: "true"},
},
}

for _, dev := range devs {
Expand All @@ -1802,6 +1839,11 @@ func TestDevices_Fit(t *testing.T) {
}
nodeInfo := &device.NodeInfo{
ID: "node1",
Node: &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Annotations: test.nodeAnnotation,
},
},
Devices: map[string][]device.DeviceInfo{
dev.config.CommonWord: {
{
Expand Down
1 change: 1 addition & 0 deletions pkg/device/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
NodeUnfitPod = "NodeUnfitPod"
NodeFitPod = "NodeFitPod"
ResourceQuotaNotFit = "ResourceQuotaNotFit"
ModeNotFit = "ModeNotFit"
)

func GenReason(reasons map[string]int, cards int) string {
Expand Down
Loading