-
Notifications
You must be signed in to change notification settings - Fork 284
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
Conversation
if gpu_stat is None: | ||
gpu_stat = GPUStatCollection() | ||
else: | ||
gpu_stat.update() | ||
except Exception as e: | ||
sys.stderr.write('Error on querying NVIDIA devices.' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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(): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.' |
There was a problem hiding this comment.
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.
Superceded by #166 |
Fix for #54