Skip to content

Commit

Permalink
Only check for nvmlEventSetWait_v2 symbol once at initizilation
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Klues <[email protected]>
  • Loading branch information
klueska committed Dec 22, 2020
1 parent d08ea3c commit a16a86c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions bindings/go/nvml/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
XidCriticalError = C.nvmlEventTypeXidCriticalError
)

var nvmlEventSetWait = nvmlEventSetWait_v1

type handle struct{ dev C.nvmlDevice_t }
type EventSet struct{ set C.nvmlEventSet_t }
type Event struct {
Expand All @@ -58,6 +60,14 @@ type Event struct {
Edata uint64
}

func nvmlEventSetWait_v1(Set C.nvmlEventSet_t, Data *C.nvmlEventData_t, Timeoutms C.uint) C.nvmlReturn_t {
return C.nvmlEventSetWait(Set, Data, Timeoutms)
}

func nvmlEventSetWait_v2(Set C.nvmlEventSet_t, Data *C.nvmlEventData_t, Timeoutms C.uint) C.nvmlReturn_t {
return C.nvmlEventSetWait_v2(Set, Data, Timeoutms)
}

func uintPtr(c C.uint) *uint {
i := uint(c)
return &i
Expand Down Expand Up @@ -86,6 +96,12 @@ func init_() error {
if r == C.NVML_ERROR_LIBRARY_NOT_FOUND {
return errors.New("could not load NVML library")
}

found := dl.lookupSymbol("nvmlEventSetWait_v2")
if found == C.NVML_SUCCESS {
nvmlEventSetWait = nvmlEventSetWait_v2
}

return errorString(r)
}

Expand Down Expand Up @@ -157,15 +173,10 @@ func DeleteEventSet(es EventSet) {

func WaitForEvent(es EventSet, timeout uint) (Event, error) {
var data C.nvmlEventData_t
data.gpuInstanceId = 0xFFFFFFFF
data.computeInstanceId = 0xFFFFFFFF

r := dl.lookupSymbol("nvmlEventSetWait_v2")
if r == C.NVML_SUCCESS {
r = C.nvmlEventSetWait_v2(es.set, &data, C.uint(timeout))
} else {
r = C.nvmlEventSetWait(es.set, &data, C.uint(timeout))
data.gpuInstanceId = 0xFFFFFFFF
data.computeInstanceId = 0xFFFFFFFF
}
r := nvmlEventSetWait(es.set, &data, C.uint(timeout))
if r != C.NVML_SUCCESS {
return Event{}, errorString(r)
}
Expand Down

0 comments on commit a16a86c

Please sign in to comment.