Skip to content

Commit 9de24f5

Browse files
committed
skip old architecture version GPU settings time slice
Signed-off-by: wawa0210 <[email protected]>
1 parent b6c7aae commit 9de24f5

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

cmd/nvidia-dra-plugin/sharing.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"os"
2424
"os/exec"
25+
"strconv"
2526
"strings"
2627
"text/template"
2728
"time"
@@ -101,6 +102,19 @@ func (t *TimeSlicingManager) SetTimeSlice(devices *PreparedDevices, config *nasc
101102
return fmt.Errorf("setting a TimeSlice duration on MIG devices is unsupported")
102103
}
103104

105+
var supportTimeSliceIDs []string
106+
for _, gpu := range devices.Gpu.Devices {
107+
err, isSupportTimeSlice := detectSupportTimeSliceByCudaComputeCapability(gpu.cudaComputeCapability)
108+
if err != nil {
109+
return fmt.Errorf("failed to detectSupportTimeSliceByCudaComputeCapability : %w", err)
110+
}
111+
if isSupportTimeSlice {
112+
supportTimeSliceIDs = append(supportTimeSliceIDs, gpu.uuid)
113+
continue
114+
}
115+
klog.InfoS("the current card does not support setting time slices and will be ignored.", "arch", gpu.architecture, "uuid", gpu.uuid, "cudaComputeCapability", gpu.cudaComputeCapability)
116+
}
117+
104118
timeSlice := nascrd.DefaultTimeSlice
105119
if config != nil && config.TimeSlice != nil {
106120
timeSlice = *config.TimeSlice
@@ -111,7 +125,7 @@ func (t *TimeSlicingManager) SetTimeSlice(devices *PreparedDevices, config *nasc
111125
return fmt.Errorf("error setting compute mode: %w", err)
112126
}
113127

114-
err = t.nvdevlib.setTimeSlice(devices.UUIDs(), timeSlice.Int())
128+
err = t.nvdevlib.setTimeSlice(supportTimeSliceIDs, timeSlice.Int())
115129
if err != nil {
116130
return fmt.Errorf("error setting time slice: %w", err)
117131
}
@@ -389,3 +403,21 @@ func (m *MpsControlDaemon) Stop(ctx context.Context) error {
389403

390404
return nil
391405
}
406+
407+
// detactSupportTimeSliceByArch Determine whether the architecture series
408+
// supports setting time slices based on the gpu cudaComputeCapability.
409+
func detectSupportTimeSliceByCudaComputeCapability(cudaComputeCapability string) (error, bool) {
410+
// ref https://github.com/NVIDIA/k8s-dra-driver/pull/58#discussion_r1469338562
411+
// we believe time-slicing is available on Volta+ architectures, so the check would simply be cudaComputeCapability >= 7.0
412+
// by https://github.com/NVIDIA/go-nvlib/blob/main/pkg/nvlib/device/device.go#L149, We know that cuda major and minor versions are concatenated through `.` .
413+
414+
cudaVersion := strings.Split(cudaComputeCapability, ".")
415+
major, err := strconv.Atoi(cudaVersion[0])
416+
if err != nil {
417+
return fmt.Errorf("error to get cudaComputeCapability major version %v", cudaComputeCapability), false
418+
}
419+
if major >= 7 {
420+
return nil, true
421+
}
422+
return nil, false
423+
}

0 commit comments

Comments
 (0)