Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hould we consider employing sync.Once to ensure that Init and Shutdown are executed only once? #74

Closed
LambdaHJ opened this issue Aug 18, 2023 · 3 comments

Comments

@LambdaHJ
Copy link
Contributor

Like this

var initError Return = SUCCESS
var intOnce sync.Once

// nvml.Init()
func Init() Return {
	intOnce.Do(func() {
		lib := dl.New(nvmlLibraryName, nvmlLibraryLoadFlags)
		err := lib.Open()
		if err != nil {
			initError = ERROR_LIBRARY_NOT_FOUND
		}
		nvml = lib
		updateVersionedSymbols()
		nvmlInit()
	})

	return initError
}
@elezar
Copy link
Member

elezar commented Aug 18, 2023

@LambdaHJ this changes the behaviour between calling nvmlInit from C directly or using the go bindings. I think with #69 ensuring that multiple calls to dl.New() and Open() return the same underlying handle, we don't need to wrap the entire call in sync.Once.

The call to Init() should always forward to nvmlInit(), but we could consider wrapping the other logic in sync.Once. Feel free to propose a PR for review.

@klueska
Copy link
Contributor

klueska commented Aug 18, 2023

I don't think we want to prevent someone from shutting down and reinitializing NVML without restarting their program. This would be required, for example, if someone were to reload the nvidia kernel module.

@elezar
Copy link
Member

elezar commented May 13, 2024

@LambdaHJ I believe that with the latest iterations of the bindings and specifically #105, this should no longer be required.

Note that there was a bug in how we were handling the underlying dynamic library and you may have been seeing issues due to this.

I'm closing this issue as resolved, but please reopen it if you're still having problems.

@elezar elezar closed this as completed May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants