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

[WIP] Fix redundant nvml init by cached handles #56

Closed
wants to merge 1 commit into from

Conversation

Stonesjtu
Copy link
Collaborator

@Stonesjtu Stonesjtu commented Nov 10, 2018

Fix for #54

if gpu_stat is None:
gpu_stat = GPUStatCollection()
else:
gpu_stat.update()
except Exception as e:
sys.stderr.write('Error on querying NVIDIA devices.'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The error catching workflow is complicated for me, can we just throw the raw error messages instead of the current one.

Copy link
Owner

Choose a reason for hiding this comment

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

For example, if an error happens during the loop, we can simply throw it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The error catching requires all the NVML API calls to be wrapped with a long try-catch block.

@Stonesjtu Stonesjtu requested a review from wookayin November 10, 2018 09:28
Copy link
Owner

@wookayin wookayin left a comment

Choose a reason for hiding this comment

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

Good job and thanks. I would like a better style of handling loops (maybe involving a bit of refactoring on main function; please see the comments on code). BTW does it indeed bring improvement on the performance?


@staticmethod
def new_query():
Copy link
Owner

Choose a reason for hiding this comment

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

We should not remove this static method this is already being used (as a public API, sort of) in other applications. Since you are lengthening the lifecycle of GPUStatCollection and making it update-able, we can think of supporting both constructor and factory method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought the wrapper function gpustat.new_query() was the real API for users, instead of the implementation itself.

It's ok to retain the legacy API, but I prefer a factory function like

@classmethod
def new_query(cls):
    return cls()

@@ -11,12 +11,16 @@
from .core import GPUStatCollection


def print_gpustat(json=False, debug=False, **kwargs):
def print_gpustat(json=False, debug=False, gpu_stat=None, **kwargs):
Copy link
Owner

Choose a reason for hiding this comment

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

It makes less sense to take gpu_stat as an argument for this function. I was thinking of a style like (i) we first create a GPUStatCollection instance here and (ii) then print outputs using it. As the same instance should be reused, we can consider running a wait loop inside this function rather than calling it multiple times.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What about making this function a generator, so we can keep the GPUStatCollection object in the closure.

if gpu_stat is None:
gpu_stat = GPUStatCollection()
else:
gpu_stat.update()
except Exception as e:
sys.stderr.write('Error on querying NVIDIA devices.'
Copy link
Owner

Choose a reason for hiding this comment

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

For example, if an error happens during the loop, we can simply throw it out.

@wookayin
Copy link
Owner

Superceded by #166

@wookayin wookayin closed this Nov 24, 2023
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