@@ -6,19 +6,20 @@ package gpusharing
66import (
77 "fmt"
88
9+ "strconv"
10+
911 v1 "k8s.io/api/core/v1"
1012 "sigs.k8s.io/controller-runtime/pkg/client"
1113
1214 "github.com/kai-scheduler/KAI-scheduler/pkg/binder/common/gpusharingconfigmap"
15+ "github.com/kai-scheduler/KAI-scheduler/pkg/common/constants"
1316 "github.com/kai-scheduler/KAI-scheduler/pkg/common/resources"
1417
1518 "github.com/kai-scheduler/KAI-scheduler/pkg/binder/common"
16- gpurequesthandler "github.com/kai-scheduler/KAI-scheduler/pkg/binder/plugins/gpusharing/gpu-request"
1719)
1820
1921const (
20- fractionContainerIndex = 0
21- CdiDeviceNameBase = "k8s.device-plugin.nvidia.com/gpu=%s"
22+ CdiDeviceNameBase = "k8s.device-plugin.nvidia.com/gpu=%s"
2223)
2324
2425type GPUSharing struct {
@@ -44,7 +45,7 @@ func (p *GPUSharing) Validate(pod *v1.Pod) error {
4445 pod .Namespace , pod .Name ,
4546 )
4647 }
47- return gpurequesthandler . ValidateGpuRequests (pod )
48+ return resources . ValidateGPUFractionRequest (pod )
4849}
4950
5051func (p * GPUSharing ) Mutate (pod * v1.Pod ) error {
@@ -61,6 +62,11 @@ func (p *GPUSharing) Mutate(pod *v1.Pod) error {
6162 return fmt .Errorf ("failed to get fraction container ref: %w" , err )
6263 }
6364
65+ err = adjustFractionalMemoryAnnotations (pod , containerRef )
66+ if err != nil {
67+ return err
68+ }
69+
6470 capabilitiesConfigMapName := gpusharingconfigmap .SetGpuCapabilitiesConfigMapName (pod , containerRef )
6571 directEnvVarsMapName , err := gpusharingconfigmap .ExtractDirectEnvVarsConfigMapName (pod , containerRef )
6672 if err != nil {
@@ -73,3 +79,17 @@ func (p *GPUSharing) Mutate(pod *v1.Pod) error {
7379
7480 return nil
7581}
82+
83+ // adjustFractionalMemoryAnnotations adjusts the old fractional memory annotations to NvFractions format
84+ func adjustFractionalMemoryAnnotations (pod * v1.Pod , containerRef * gpusharingconfigmap.PodContainerRef ) error {
85+ gpuMemoryRequestMiB , foundGPUMemory := pod .Annotations [constants .GpuMemory ]
86+ if foundGPUMemory {
87+ gpuMemoryRequestMiB , err := strconv .ParseUint (gpuMemoryRequestMiB , 10 , 64 )
88+ if err != nil {
89+ return fmt .Errorf ("failed to parse gpu memory annotation value: %w" , err )
90+ }
91+ memoryQuantity := resources .GpuMemoryAnnotationToNvFractionsMemoryRequest (gpuMemoryRequestMiB )
92+ pod .Annotations [resources .CalcGpuFractionAnnotationForContainer (containerRef .Container .Name )] = memoryQuantity .String ()
93+ }
94+ return nil
95+ }
0 commit comments