Skip to content

Commit

Permalink
skip old architecture version GPU settings time slice
Browse files Browse the repository at this point in the history
Signed-off-by: wawa0210 <[email protected]>
  • Loading branch information
wawa0210 committed Jan 29, 2024
1 parent 58ae162 commit b46450f
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion cmd/nvidia-dra-plugin/sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"text/template"
"time"
Expand Down Expand Up @@ -101,6 +102,21 @@ func (t *TimeSlicingManager) SetTimeSlice(devices *PreparedDevices, config *nasc
return fmt.Errorf("setting a TimeSlice duration on MIG devices is unsupported")
}

var noSupportTimeSliceIDs []string
for _, gpu := range devices.Gpu.Devices {
err, isSupportTimeSlice := detectSupportTimeSliceByCudaComputeCapability(gpu.cudaComputeCapability)
if err != nil {
return fmt.Errorf("failed to detectSupportTimeSliceByCudaComputeCapability : %w", err)
}
if !isSupportTimeSlice {
klog.InfoS("the current card does not support setting time slices and will be ignored.", "arch", gpu.architecture, "uuid", gpu.uuid, "cudaComputeCapability", gpu.cudaComputeCapability)
noSupportTimeSliceIDs = append(noSupportTimeSliceIDs, gpu.uuid)
continue
}
}

supportTimeSliceIDs := difference(devices.UUIDs(), noSupportTimeSliceIDs)

timeSlice := nascrd.DefaultTimeSlice
if config != nil && config.TimeSlice != nil {
timeSlice = *config.TimeSlice
Expand All @@ -111,7 +127,7 @@ func (t *TimeSlicingManager) SetTimeSlice(devices *PreparedDevices, config *nasc
return fmt.Errorf("error setting compute mode: %w", err)
}

err = t.nvdevlib.setTimeSlice(devices.UUIDs(), timeSlice.Int())
err = t.nvdevlib.setTimeSlice(supportTimeSliceIDs, timeSlice.Int())
if err != nil {
return fmt.Errorf("error setting time slice: %w", err)
}
Expand Down Expand Up @@ -389,3 +405,36 @@ func (m *MpsControlDaemon) Stop(ctx context.Context) error {

return nil
}

// detactSupportTimeSliceByArch Determine whether the architecture series
// supports setting time slices based on the gpu cudaComputeCapability.
func detectSupportTimeSliceByCudaComputeCapability(cudaComputeCapability string) (error, bool) {
// ref https://github.com/NVIDIA/k8s-dra-driver/pull/58#discussion_r1469338562
// we believe time-slicing is available on Volta+ architectures, so the check would simply be cudaComputeCapability >= 7.0
// 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 `.` .

cudaVersion := strings.Split(cudaComputeCapability, ".")
major, err := strconv.Atoi(cudaVersion[0])
if err != nil {
return fmt.Errorf("error to get cudaComputeCapability major version %v", cudaComputeCapability), false
}
if major >= 7 {
return nil, true
}
return nil, false
}

// difference returns the elements in `a` that aren't in `b`.
func difference(a, b []string) []string {
mb := make(map[string]struct{}, len(b))
for _, x := range b {
mb[x] = struct{}{}
}
var diff []string
for _, x := range a {
if _, found := mb[x]; !found {
diff = append(diff, x)
}
}
return diff
}

0 comments on commit b46450f

Please sign in to comment.