Skip to content

Commit

Permalink
Convert ComputeInstance into an interface instead of a concrete type
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Klues <kklues@nvidia.com>
  • Loading branch information
klueska committed Apr 10, 2024
1 parent 8f58f39 commit bd7ef9a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 33 deletions.
1 change: 1 addition & 0 deletions gen/nvml/nvml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ TRANSLATOR:
- {action: replace, from: "^Device$", to: "nvmlDevice"}
- {action: replace, from: "^Unit$", to: "nvmlUnit"}
- {action: replace, from: "^EventSet$", to: "nvmlEventSet"}
- {action: replace, from: "^ComputeInstance$", to: "nvmlComputeInstance"}
- {action: replace, from: "^GpuInstance$", to: "nvmlGpuInstance"}
- {action: replace, from: "^VgpuInstance$", to: "nvmlVgpuInstance"}
- {action: replace, from: "^VgpuTypeId$", to: "nvmlVgpuTypeId"}
Expand Down
5 changes: 5 additions & 0 deletions pkg/nvml/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ type GpuInstance interface {
CreateComputeInstanceWithPlacement(Info *ComputeInstanceProfileInfo, Placement *ComputeInstancePlacement) (ComputeInstance, Return)
}

type ComputeInstance interface {
Destroy() Return
GetInfo() (ComputeInstanceInfo, Return)
}

type EventSet interface {
Wait(Timeoutms uint32) (EventData, Return)
Free() Return
Expand Down
26 changes: 13 additions & 13 deletions pkg/nvml/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -2176,20 +2176,20 @@ func (l *library) GpuInstanceCreateComputeInstance(GpuInstance GpuInstance, Info

func (GpuInstance nvmlGpuInstance) CreateComputeInstance(Info *ComputeInstanceProfileInfo) (ComputeInstance, Return) {
if Info == nil {
return ComputeInstance{}, ERROR_INVALID_ARGUMENT
return nil, ERROR_INVALID_ARGUMENT
}
var ComputeInstance ComputeInstance
var ComputeInstance nvmlComputeInstance
ret := nvmlGpuInstanceCreateComputeInstance(GpuInstance, Info.Id, &ComputeInstance)
return ComputeInstance, ret
}

// nvml.ComputeInstanceDestroy()
func (l *library) ComputeInstanceDestroy(ComputeInstance ComputeInstance) Return {
return nvmlComputeInstanceDestroy(ComputeInstance)
return ComputeInstance.Destroy()
}

func (ComputeInstance ComputeInstance) Destroy() Return {
return ComputeInstanceDestroy(ComputeInstance)
func (ComputeInstance nvmlComputeInstance) Destroy() Return {
return nvmlComputeInstanceDestroy(ComputeInstance)
}

// nvml.GpuInstanceGetComputeInstances()
Expand All @@ -2202,9 +2202,9 @@ func (GpuInstance nvmlGpuInstance) GetComputeInstances(Info *ComputeInstanceProf
return nil, ERROR_INVALID_ARGUMENT
}
var Count uint32 = Info.InstanceCount
ComputeInstances := make([]ComputeInstance, Count)
ComputeInstances := make([]nvmlComputeInstance, Count)
ret := nvmlGpuInstanceGetComputeInstances(GpuInstance, Info.Id, &ComputeInstances[0], &Count)
return ComputeInstances[:Count], ret
return convertSlice[nvmlComputeInstance, ComputeInstance](ComputeInstances[:Count]), ret
}

// nvml.GpuInstanceGetComputeInstanceById()
Expand All @@ -2213,22 +2213,22 @@ func (l *library) GpuInstanceGetComputeInstanceById(GpuInstance GpuInstance, Id
}

func (GpuInstance nvmlGpuInstance) GetComputeInstanceById(Id int) (ComputeInstance, Return) {
var ComputeInstance ComputeInstance
var ComputeInstance nvmlComputeInstance
ret := nvmlGpuInstanceGetComputeInstanceById(GpuInstance, uint32(Id), &ComputeInstance)
return ComputeInstance, ret
}

// nvml.ComputeInstanceGetInfo()
func (l *library) ComputeInstanceGetInfo(ComputeInstance ComputeInstance) (ComputeInstanceInfo, Return) {
return ComputeInstance.GetInfo()
}

func (ComputeInstance nvmlComputeInstance) GetInfo() (ComputeInstanceInfo, Return) {
var Info ComputeInstanceInfo
ret := nvmlComputeInstanceGetInfo(ComputeInstance, &Info)
return Info, ret
}

func (ComputeInstance ComputeInstance) GetInfo() (ComputeInstanceInfo, Return) {
return ComputeInstanceGetInfo(ComputeInstance)
}

// nvml.DeviceIsMigDeviceHandle()
func (l *library) DeviceIsMigDeviceHandle(Device Device) (bool, Return) {
return Device.IsMigDeviceHandle()
Expand Down Expand Up @@ -2620,7 +2620,7 @@ func (l *library) GpuInstanceCreateComputeInstanceWithPlacement(GpuInstance GpuI
}

func (GpuInstance nvmlGpuInstance) CreateComputeInstanceWithPlacement(Info *ComputeInstanceProfileInfo, Placement *ComputeInstancePlacement) (ComputeInstance, Return) {
var ComputeInstance ComputeInstance
var ComputeInstance nvmlComputeInstance
ret := nvmlGpuInstanceCreateComputeInstanceWithPlacement(GpuInstance, Info.Id, Placement, &ComputeInstance)
return ComputeInstance, ret
}
Expand Down
38 changes: 19 additions & 19 deletions pkg/nvml/nvml.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/nvml/types_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd7ef9a

Please sign in to comment.