Skip to content

Commit

Permalink
Convert GpmSample 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 12, 2024
1 parent 630d5a6 commit 80b4064
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 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: "^GpmSample$", to: "nvmlGpmSample"}
- {action: replace, from: "^ComputeInstance$", to: "nvmlComputeInstance"}
- {action: replace, from: "^GpuInstance$", to: "nvmlGpuInstance"}
- {action: replace, from: "^VgpuInstance$", to: "nvmlVgpuInstance"}
Expand Down
6 changes: 6 additions & 0 deletions pkg/nvml/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ type EventSet interface {
Free() Return
}

type GpmSample interface {
Free() Return
Get(Device Device) Return
MigGet(Device Device, GpuInstanceId int) Return
}

type Unit interface {
GetUnitInfo() (UnitInfo, Return)
GetLedState() (LedState, Return)
Expand Down
12 changes: 6 additions & 6 deletions pkg/nvml/gpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ func (l *library) GpmMetricsGet(MetricsGet *GpmMetricsGetType) Return {

// nvml.GpmSampleFree()
func (l *library) GpmSampleFree(GpmSample GpmSample) Return {
return nvmlGpmSampleFree(GpmSample)
return GpmSample.Free()
}

func (GpmSample GpmSample) Free() Return {
return GpmSampleFree(GpmSample)
func (GpmSample nvmlGpmSample) Free() Return {
return nvmlGpmSampleFree(GpmSample)
}

// nvml.GpmSampleAlloc()
func (l *library) GpmSampleAlloc() (GpmSample, Return) {
var GpmSample GpmSample
var GpmSample nvmlGpmSample
ret := nvmlGpmSampleAlloc(&GpmSample)
return GpmSample, ret
}
Expand All @@ -57,7 +57,7 @@ func (Device nvmlDevice) GpmSampleGet(GpmSample GpmSample) Return {
return GpmSample.Get(Device)
}

func (GpmSample GpmSample) Get(Device Device) Return {
func (GpmSample nvmlGpmSample) Get(Device Device) Return {
return nvmlGpmSampleGet(Device.(nvmlDevice), GpmSample)
}

Expand Down Expand Up @@ -101,6 +101,6 @@ func (Device nvmlDevice) GpmMigSampleGet(GpuInstanceId int, GpmSample GpmSample)
return GpmSample.MigGet(Device, GpuInstanceId)
}

func (GpmSample GpmSample) MigGet(Device Device, GpuInstanceId int) Return {
func (GpmSample nvmlGpmSample) MigGet(Device Device, GpuInstanceId int) Return {
return nvmlGpmMigSampleGet(Device.(nvmlDevice), uint32(GpuInstanceId), GpmSample)
}
24 changes: 12 additions & 12 deletions pkg/nvml/nvml.go

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

6 changes: 3 additions & 3 deletions 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 80b4064

Please sign in to comment.