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

Allow path to libnvidia-ml.so.1 to be specified #81

Merged
merged 2 commits into from
Oct 20, 2023

Conversation

elezar
Copy link
Member

@elezar elezar commented Oct 12, 2023

These changes add a basic API for allowing the path to libnvidia-ml.so.1 to be set.

This can be used in environments where the path to the library can be determined programatically but not reliably added to the LD_LIBRARY_PATH before program startup, for example.

This builds on the changes from #86

gen/nvml/lib.go Outdated Show resolved Hide resolved
gen/nvml/lib.go Outdated Show resolved Hide resolved
gen/nvml/lib.go Outdated Show resolved Hide resolved
pkg/dl/dl.go Outdated Show resolved Hide resolved
gen/nvml/lib.go Outdated Show resolved Hide resolved
gen/nvml/lib.go Outdated Show resolved Hide resolved
gen/nvml/lib.go Outdated Show resolved Hide resolved
@elezar elezar mentioned this pull request Oct 19, 2023
@elezar elezar self-assigned this Oct 19, 2023
@elezar elezar force-pushed the allow-path-to-be-set branch 6 times, most recently from dfa4760 to aa0b8a7 Compare October 20, 2023 13:07
@elezar elezar requested a review from klueska October 20, 2023 13:13
if libnvml.path == "" {
libnvml.path = defaultNvmlLibraryName
}
if libnvml.flags == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you unset all flags?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a use case that is expected? If so we should use a *int to detect whether it is set or not.

Note it's not currently possible to set the flags through the options, so we could address this in a follow-up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note sure. I doubt anyone will ever override this (beyond adding to it) so its probably fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reevaluate if it ever becomes relevant.

var newDynamicLibrary = func(name string, flags int) dynamicLibrary {
return dl.New(name, flags)
var newDynamicLibrary = func(path string, flags int) dynamicLibrary {
return dl.New(path, flags)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the dl library is already capable of handling a full path, we just never used this until now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. When dl.Open is called, the path is forwarded to C.dlopen which has well defined semantics for handling the path and where to search.


// SetLibraryOptions applies the specified options to the NVML library.
// If this is called when a library is already loaded, and error is raised.
func SetLibraryOptions(opts ...LibraryOption) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was in the last MR, but can you explain the purpose of the Default() method? I'm just thinking about it from a callsite perspective --- nvml.Default() doesn't really imply to me that I'm getting a reference to the default implementation of the nvml Interface. When / how do you actually expect this to be used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns a reference (as an interface) to the default global instance or libnvml. In go-nvlib we're using this as:

	// TODO: For now we rely on the default NVML library and perform the lookups against this.
	return nvml.Default().Library().Lookup(name)

Note that once we implement a New() call that returns an Interface instead this should not be required anymore and we would instantiate the library explicitly.

Can you think of a way to make this clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see -- its specifically so we can get at that Library method -- can we just make a top level Library() function then?

Copy link
Member Author

@elezar elezar Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would GetLibrary() be ok? We would either need to rename this or the Library interface.

I think a top-level function is fine as I would see something similar happening for the NVML functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, right -- I'd rather the top level call be the same as what we would eventually call on an instance of Interface. Maybe that becomes GetLibrary() as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I renamed the function GetLibrary and also included an implementation at the package level.

@elezar elezar force-pushed the allow-path-to-be-set branch from aa0b8a7 to 0e2a408 Compare October 20, 2023 14:46
This change adds a SetLibOptions function that allows the
default library name of libnvidia-ml.so.1 to be overridden.
This is useful on systems where the location of this library is
known but this location cannot be relied upon to be in the
LD_LIBRARY_PATH or ldcache.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
Signed-off-by: Evan Lezar <elezar@nvidia.com>
klueska
klueska previously approved these changes Oct 20, 2023
@elezar elezar force-pushed the allow-path-to-be-set branch from 0e2a408 to e756be6 Compare October 20, 2023 14:48
@elezar elezar requested a review from klueska October 20, 2023 14:48
@elezar elezar merged commit e06766c into NVIDIA:main Oct 20, 2023
1 check passed
@elezar elezar deleted the allow-path-to-be-set branch October 20, 2023 14:54
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

Successfully merging this pull request may close these issues.

2 participants