Skip to content

Commit

Permalink
Add ability to create an NVML Device from a UUID
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Klues <[email protected]>
  • Loading branch information
klueska committed Sep 21, 2020
1 parent 9732363 commit 145fcea
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bindings/go/nvml/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ func deviceGetHandleByIndex(idx uint) (handle, error) {
return handle{dev}, errorString(r)
}

func deviceGetHandleByUUID(uuid string) (handle, error) {
var dev C.nvmlDevice_t

r := C.nvmlDeviceGetHandleByUUID(C.CString(uuid), &dev)
return handle{dev}, errorString(r)
}

func deviceGetTopologyCommonAncestor(h1, h2 handle) (*uint, error) {
r := dl.lookupSymbol("nvmlDeviceGetTopologyCommonAncestor")
if r == C.NVML_ERROR_FUNCTION_NOT_FOUND {
Expand Down
48 changes: 48 additions & 0 deletions bindings/go/nvml/nvml.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,30 @@ func NewDevice(idx uint) (device *Device, err error) {

h, err := deviceGetHandleByIndex(idx)
assert(err)

device, err = newDevice(h)
assert(err)

return device, err
}

func NewDeviceByUUID(uuid string) (device *Device, err error) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
}
}()

h, err := deviceGetHandleByUUID(uuid)
assert(err)

device, err = newDevice(h)
assert(err)

return device, err
}

func newDevice(h handle) (device *Device, err error) {
model, err := h.deviceGetName()
assert(err)
uuid, err := h.deviceGetUUID()
Expand Down Expand Up @@ -413,6 +437,30 @@ func NewDeviceLite(idx uint) (device *Device, err error) {

h, err := deviceGetHandleByIndex(idx)
assert(err)

device, err = newDeviceLite(h)
assert(err)

return device, err
}

func NewDeviceLiteByUUID(uuid string) (device *Device, err error) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
}
}()

h, err := deviceGetHandleByUUID(uuid)
assert(err)

device, err = newDeviceLite(h)
assert(err)

return device, err
}

func newDeviceLite(h handle) (device *Device, err error) {
uuid, err := h.deviceGetUUID()
assert(err)
minor, err := h.deviceGetMinorNumber()
Expand Down

0 comments on commit 145fcea

Please sign in to comment.