Skip to content

Commit

Permalink
Return concrete types from mock dgxa100 server instead of interfaces
Browse files Browse the repository at this point in the history
This way the callers can extend these types to futher override their functions
if desired, while still being able to assign them to the appropriate nvml
interfaces.

Signed-off-by: Kevin Klues <kklues@nvidia.com>
  • Loading branch information
klueska committed Apr 23, 2024
1 parent 93fa13d commit 5e1cdb1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/nvml/mock/dgxa100/dgxa100.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ nvml.Device = (*Device)(nil)
var _ nvml.GpuInstance = (*GpuInstance)(nil)
var _ nvml.ComputeInstance = (*ComputeInstance)(nil)

func New() nvml.Interface {
func New() *Server {
server := &Server{
Devices: [8]nvml.Device{
NewDevice(0),
Expand All @@ -90,7 +90,7 @@ func New() nvml.Interface {
return server
}

func NewDevice(index int) nvml.Device {
func NewDevice(index int) *Device {
device := &Device{
UUID: "GPU-" + uuid.New().String(),
Name: "Mock NVIDIA A100-SXM4-40GB",
Expand All @@ -111,7 +111,7 @@ func NewDevice(index int) nvml.Device {
return device
}

func NewGpuInstance(info nvml.GpuInstanceInfo) nvml.GpuInstance {
func NewGpuInstance(info nvml.GpuInstanceInfo) *GpuInstance {
gi := &GpuInstance{
Info: info,
ComputeInstances: make(map[*ComputeInstance]struct{}),
Expand All @@ -121,7 +121,7 @@ func NewGpuInstance(info nvml.GpuInstanceInfo) nvml.GpuInstance {
return gi
}

func NewComputeInstance(info nvml.ComputeInstanceInfo) nvml.ComputeInstance {
func NewComputeInstance(info nvml.ComputeInstanceInfo) *ComputeInstance {
ci := &ComputeInstance{
Info: info,
}
Expand Down Expand Up @@ -261,7 +261,7 @@ func (d *Device) setMockFuncs() {
}
d.GpuInstanceCounter++
gi := NewGpuInstance(giInfo)
d.GpuInstances[gi.(*GpuInstance)] = struct{}{}
d.GpuInstances[gi] = struct{}{}
return gi, nvml.SUCCESS
}

Expand All @@ -274,7 +274,7 @@ func (d *Device) setMockFuncs() {
}
d.GpuInstanceCounter++
gi := NewGpuInstance(giInfo)
d.GpuInstances[gi.(*GpuInstance)] = struct{}{}
d.GpuInstances[gi] = struct{}{}
return gi, nvml.SUCCESS
}

Expand Down Expand Up @@ -329,7 +329,7 @@ func (gi *GpuInstance) setMockFuncs() {
}
gi.ComputeInstanceCounter++
ci := NewComputeInstance(ciInfo)
gi.ComputeInstances[ci.(*ComputeInstance)] = struct{}{}
gi.ComputeInstances[ci] = struct{}{}
return ci, nvml.SUCCESS
}

Expand Down

0 comments on commit 5e1cdb1

Please sign in to comment.