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
10 changes: 4 additions & 6 deletions pkg/monitor/nvidia/v0/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ func (s Spec) DeviceSmUtil(idx int) uint64 {
}

func (s Spec) SetDeviceSmLimit(l uint64) {
idx := uint64(0)
for idx < s.sr.num {
n := min(s.sr.num, maxDevices)
for idx := range n {
s.sr.smLimit[idx] = l
idx += 1
}
}

Expand All @@ -158,10 +157,9 @@ func (s Spec) DeviceMemoryLimit(idx int) uint64 {
}

func (s Spec) SetDeviceMemoryLimit(l uint64) {
idx := uint64(0)
for idx < s.sr.num {
n := min(s.sr.num, maxDevices)
for idx := range n {
s.sr.limit[idx] = l
idx += 1
}
}

Expand Down
24 changes: 20 additions & 4 deletions pkg/monitor/nvidia/v0/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,15 @@ func TestSpec_SetDeviceSmLimit(t *testing.T) {
}
})
}

t.Run("num larger than maxDevices does not panic", func(t *testing.T) {
s := &Spec{sr: &sharedRegionT{num: 9999}}
s.SetDeviceSmLimit(500)
want := [16]uint64{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500}
if s.sr.smLimit != want {
t.Errorf("SetDeviceSmLimit with oversized num: got %v, want %v", s.sr.smLimit, want)
}
})
}

func TestSpec_IsValidUUID(t *testing.T) {
Expand Down Expand Up @@ -649,10 +658,8 @@ func TestSpec_SetDeviceMemoryLimit(t *testing.T) {
},
},
},
input: 500,
expected: []uint64{
500, 500, 500,
},
input: 500,
expected: []uint64{500, 500, 500},
},
}

Expand All @@ -665,6 +672,15 @@ func TestSpec_SetDeviceMemoryLimit(t *testing.T) {
}
})
}

t.Run("num larger than maxDevices does not panic", func(t *testing.T) {
s := &Spec{sr: &sharedRegionT{num: 9999}}
s.SetDeviceMemoryLimit(750)
want := [16]uint64{750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750}
if s.sr.limit != want {
t.Errorf("SetDeviceMemoryLimit with oversized num: got %v, want %v", s.sr.limit, want)
}
})
}

func TestSpec_LastKernelTime(t *testing.T) {
Expand Down
10 changes: 4 additions & 6 deletions pkg/monitor/nvidia/v1/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ func (s Spec) DeviceSmUtil(idx int) uint64 {
}

func (s Spec) SetDeviceSmLimit(l uint64) {
idx := uint64(0)
for idx < s.sr.num {
n := min(s.sr.num, maxDevices)
for idx := range n {
s.sr.smLimit[idx] = l
idx += 1
}
}

Expand All @@ -172,10 +171,9 @@ func (s Spec) DeviceMemoryLimit(idx int) uint64 {
}

func (s Spec) SetDeviceMemoryLimit(l uint64) {
idx := uint64(0)
for idx < s.sr.num {
n := min(s.sr.num, maxDevices)
for idx := range n {
s.sr.limit[idx] = l
idx += 1
}
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/monitor/nvidia/v1/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,13 @@ func Test_SetDeviceSmLimit(t *testing.T) {
assert.DeepEqual(t, result, test.want)
})
}

t.Run("num larger than maxDevices does not panic", func(t *testing.T) {
s := &Spec{sr: &sharedRegionT{num: 9999, smLimit: [16]uint64{}}}
s.SetDeviceSmLimit(500)
want := [16]uint64{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500}
assert.DeepEqual(t, s.sr.smLimit, want)
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

func Test_IsValidUUID(t *testing.T) {
Expand Down Expand Up @@ -970,6 +977,13 @@ func Test_SetDeviceMemoryLimit(t *testing.T) {
assert.DeepEqual(t, result, test.want)
})
}

t.Run("num larger than maxDevices does not panic", func(t *testing.T) {
s := &Spec{sr: &sharedRegionT{num: 9999}}
s.SetDeviceMemoryLimit(750)
want := [16]uint64{750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750}
assert.DeepEqual(t, s.sr.limit, want)
})
}

func Test_LastKernelTime(t *testing.T) {
Expand Down
Loading