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
22 changes: 1 addition & 21 deletions pkg/device/amd/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package amd
import (
"flag"
"fmt"
"slices"
"strings"

"github.com/Project-HAMi/HAMi/pkg/device"
Expand Down Expand Up @@ -135,25 +134,6 @@ func (dev *AMDDevices) checkType(n device.ContainerDeviceRequest) (bool, bool, b
return false, false, false
}

func (dev *AMDDevices) checkUUID(annos map[string]string, d device.DeviceUsage) bool {
userUUID, ok := annos[AMDUseUUID]
if ok {
klog.V(5).Infof("check uuid for AMD GPU user uuid [%s], device id is %s", userUUID, d.ID)
// use , symbol to connect multiple uuid
userUUIDs := strings.Split(userUUID, ",")
return slices.Contains(userUUIDs, d.ID)
}

noUserUUID, ok := annos[AMDNoUseUUID]
if ok {
klog.V(5).Infof("check uuid for AMD GPU no-use uuid [%s], device id is %s", noUserUUID, d.ID)
// use , symbol to connect multiple uuid
noUserUUIDs := strings.Split(noUserUUID, ",")
return !slices.Contains(noUserUUIDs, d.ID)
}
return true
}

func (dev *AMDDevices) CheckHealth(devType string, n *corev1.Node) (bool, bool) {
return true, true
}
Expand Down Expand Up @@ -224,7 +204,7 @@ func (amddevice *AMDDevices) Fit(devices []*device.DeviceUsage, request device.C
klog.V(5).InfoS(common.CardTypeMismatch, "pod", klog.KObj(pod), "device", dev.ID, dev.Type, k.Type)
continue
}
if !amddevice.checkUUID(pod.GetAnnotations(), *dev) {
if !device.CheckUUID(pod.GetAnnotations(), dev.ID, AMDUseUUID, AMDNoUseUUID, amddevice.CommonWord()) {
reason[common.CardUUIDMismatch]++
klog.V(5).InfoS(common.CardUUIDMismatch, "pod", klog.KObj(pod), "device", dev.ID, "current device info is:", *dev)
continue
Expand Down
90 changes: 0 additions & 90 deletions pkg/device/amd/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,96 +265,6 @@ func Test_checkType(t *testing.T) {
}
}

func Test_checkUUID(t *testing.T) {
tests := []struct {
name string
args struct {
annos map[string]string
d device.DeviceUsage
}
want bool
}{
{
name: "no annos",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{},
d: device.DeviceUsage{},
},
want: true,
},
{
name: "use id the same as device id",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{
AMDUseUUID: "test1",
},
d: device.DeviceUsage{
ID: "test1",
},
},
want: true,
},
{
name: "use id the different from device id",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{
AMDUseUUID: "test1",
},
d: device.DeviceUsage{
ID: "test2",
},
},
want: false,
},
{
name: "no use id the same as device id",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{
AMDNoUseUUID: "test1",
},
d: device.DeviceUsage{
ID: "test1",
},
},
want: false,
},
{
name: "no use id the different from device id",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{
AMDNoUseUUID: "test1",
},
d: device.DeviceUsage{
ID: "test2",
},
},
want: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
dev := AMDDevices{}
result := dev.checkUUID(test.args.annos, test.args.d)
assert.Equal(t, result, test.want)
})
}
}

func Test_GenerateResourceRequests(t *testing.T) {
tests := []struct {
name string
Expand Down
22 changes: 1 addition & 21 deletions pkg/device/ascend/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"flag"
"fmt"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -221,25 +220,6 @@ func (dev *Devices) checkType(annos map[string]string, d device.DeviceUsage, n d
return false, false, false
}

func (dev *Devices) checkUUID(annos map[string]string, d device.DeviceUsage) bool {
userUUID, ok := annos[dev.useUUIDAnno]
if ok {
klog.V(5).Infof("check uuid for ascend user uuid [%s], device id is %s", userUUID, d.ID)
// use , symbol to connect multiple uuid
userUUIDs := strings.Split(userUUID, ",")
return slices.Contains(userUUIDs, d.ID)
}

noUserUUID, ok := annos[dev.noUseUUIDAnno]
if ok {
klog.V(5).Infof("check uuid for ascend not user uuid [%s], device id is %s", noUserUUID, d.ID)
// use , symbol to connect multiple uuid
noUserUUIDs := strings.Split(noUserUUID, ",")
return !slices.Contains(noUserUUIDs, d.ID)
}
return true
}

func (dev *Devices) CheckHealth(devType string, n *corev1.Node) (bool, bool) {
return device.CheckHealth(devType, n)
}
Expand Down Expand Up @@ -376,7 +356,7 @@ func (npu *Devices) Fit(devices []*device.DeviceUsage, request device.ContainerD
prevnuma = dev.Numa
tmpDevs = make(map[string]device.ContainerDevices)
}
if !npu.checkUUID(pod.GetAnnotations(), *dev) {
if !device.CheckUUID(pod.GetAnnotations(), dev.ID, npu.useUUIDAnno, npu.noUseUUIDAnno, npu.CommonWord()) {
reason[common.CardUUIDMismatch]++
klog.V(5).InfoS(common.CardUUIDMismatch, "pod", klog.KObj(pod), "device", dev.ID, "current device info is:", *dev)
continue
Expand Down
93 changes: 0 additions & 93 deletions pkg/device/ascend/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,99 +399,6 @@ func Test_checkType(t *testing.T) {
}
}

func Test_checkUUID(t *testing.T) {
dev := Devices{
useUUIDAnno: "hami.io/use-Ascend910A-uuid",
noUseUUIDAnno: "hami.io/no-use-Ascend910A-uuid",
}
tests := []struct {
name string
args struct {
annos map[string]string
d device.DeviceUsage
}
want bool
}{
{
name: "don't set GPUUseUUID,GPUNoUseUUID and annotation",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{},
d: device.DeviceUsage{},
},
want: true,
},
{
name: "set GPUUseUUID,don't set GPUNoUseUUID,annotation and device match",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{
dev.useUUIDAnno: "test123,111",
},
d: device.DeviceUsage{
ID: "test123",
},
},
want: true,
},
{
name: "don't set GPUUseUUID, set GPUNoUseUUID,annotation and device match",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{
dev.noUseUUIDAnno: "test123,222",
},
d: device.DeviceUsage{
ID: "test123",
},
},
want: false,
},
{
name: "set GPUUseUUID, don't set GPUNoUseUUID,annotation and device not match",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{
dev.useUUIDAnno: "test123,222",
},
d: device.DeviceUsage{
ID: "test456",
},
},
want: false,
},
{
name: "don't set GPUUseUUID, set GPUNoUseUUID,annotation and device not match",
args: struct {
annos map[string]string
d device.DeviceUsage
}{
annos: map[string]string{
dev.noUseUUIDAnno: "test123,222",
},
d: device.DeviceUsage{
ID: "test456",
},
},
want: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := dev.checkUUID(test.args.annos, test.args.d)
assert.Equal(t, result, test.want)
})
}
}

func Test_CheckHealth(t *testing.T) {
dev := Devices{}
tests := []struct {
Expand Down
22 changes: 1 addition & 21 deletions pkg/device/awsneuron/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package awsneuron
import (
"flag"
"fmt"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -192,25 +191,6 @@ func (dev *AWSNeuronDevices) checkType(n device.ContainerDeviceRequest) (bool, b
return false, false, false
}

func (dev *AWSNeuronDevices) checkUUID(annos map[string]string, d device.DeviceUsage) bool {
userUUID, ok := annos[AWSNeuronUseUUID]
if ok {
klog.V(5).Infof("check uuid for AWSNeuron user uuid [%s], device id is %s", userUUID, d.ID)
// use , symbol to connect multiple uuid
userUUIDs := strings.Split(userUUID, ",")
return slices.Contains(userUUIDs, d.ID)
}

noUserUUID, ok := annos[AWSNeuronNoUseUUID]
if ok {
klog.V(5).Infof("check uuid for AWSNeuron no-use uuid [%s], device id is %s", noUserUUID, d.ID)
// use , symbol to connect multiple uuid
noUserUUIDs := strings.Split(noUserUUID, ",")
return !slices.Contains(noUserUUIDs, d.ID)
}
return true
}

func (dev *AWSNeuronDevices) CheckHealth(devType string, n *corev1.Node) (bool, bool) {
return true, true
}
Expand Down Expand Up @@ -433,7 +413,7 @@ func (neuron *AWSNeuronDevices) Fit(devices []*device.DeviceUsage, request devic
klog.V(5).InfoS(common.CardTypeMismatch, "pod", klog.KObj(pod), "device", dev.ID, dev.Type, k.Type)
continue
}
if !neuron.checkUUID(pod.GetAnnotations(), *dev) {
if !device.CheckUUID(pod.GetAnnotations(), dev.ID, AWSNeuronUseUUID, AWSNeuronNoUseUUID, neuron.CommonWord()) {
reason[common.CardUUIDMismatch]++
klog.V(5).InfoS(common.CardUUIDMismatch, "pod", klog.KObj(pod), "device", dev.ID, "current device info is:", *dev)
continue
Expand Down
Loading