Skip to content
Closed
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
26 changes: 15 additions & 11 deletions server/internal/provider/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,21 @@ func DecodePodDevices(pod *corev1.Pod, log *log.Helper) (PodDevices, error) {
}
pd[devType] = make(PodSingleDevice, 0)
switch devType {
case AscendGPUDevice, Ascend310PGPUDevice:
for _, s := range strings.Split(str, OnePodMultiContainerSplitSymbol) {
cd, err := DecodeNpuContainerDevices(s)
if err != nil {
return PodDevices{}, nil
}
if len(cd) == 0 {
continue
}
pd[devType] = append(pd[devType], cd)
}
case AscendGPUDevice, Ascend310PGPUDevice:
for i, s := range strings.Split(str, OnePodMultiContainerSplitSymbol) {
if i >= podContainerCount(pod) {
break
}
if s == "" {
pd[devType] = append(pd[devType], ContainerDevices{})
continue
}
cd, err := DecodeNpuContainerDevices(s)
if err != nil {
return PodDevices{}, nil
}
pd[devType] = append(pd[devType], cd)
}
case CambriconGPUDevice:
instance := annos[DsmluProfileAndInstance]
cd, err := DecodeMLUContainerDevices(fmt.Sprintf("%s_%s", str, instance), nodeName)
Expand Down
35 changes: 35 additions & 0 deletions server/internal/provider/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,38 @@ func TestDecodePodDevicesWithInitContainers(t *testing.T) {
t.Fatalf("unexpected priority: %s", nvidiaDevices[1][0].Priority)
}
}

func TestDecodePodDevicesAscendMultiContainer(t *testing.T) {
SupportDevices["Ascend"] = "hami.io/ascend-devices-allocated"
logger := log.NewHelper(log.DefaultLogger)
pod := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{Name: "container-0"},
{Name: "container-1"},
},
},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"hami.io/ascend-devices-allocated": ";Ascend910B-0,Ascend910B,32768,100:;",
},
},
}
got, err := DecodePodDevices(pod, logger)
if err != nil {
t.Fatalf("DecodePodDevices() error = %v", err)
}
ascendDevices, ok := got["Ascend"]
if !ok {
t.Fatal("expected Ascend devices")
}
if len(ascendDevices) != 2 {
t.Fatalf("expected 2 container slots, got %d", len(ascendDevices))
}
if len(ascendDevices[0]) != 0 {
t.Fatalf("expected empty container-0 devices, got %+v", ascendDevices[0])
}
if len(ascendDevices[1]) != 1 {
t.Fatalf("expected 1 device on container-1, got %+v", ascendDevices[1])
}
}
Loading