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

Added the possibility to filter by GPU IDs #22

Merged
merged 5 commits into from
Jan 16, 2024
Merged

Conversation

PCudrano
Copy link
Contributor

The standard nvidia-smi summary provides an option to display only some of the available GPUs. This feature is very useful in systems with many GPUs.

The standard nvidia-smi command is:
nvidia-smi -i <comma-serparated-gpu-ids>
For example, to display only GPU 1, 2 and 4:
nvidia-smi -i 1,2,4

I added the same exact -i argument, exploiting the nvidia-smi command directly.

Usage:

nvidia-htop.py -i <comma-separated-gpu-ids>

For example, to display only GPU 1, 2 and 4:
nvidia-htop.py -i 1,2,4

If a wrong ID list is passed, the command fails with the original nvidia-smi error message.
For example, asking for an non-existing GPU ID:
nvidia-htop.py -i 42 or nvidia-htop.py -i random,string
Return:
nvidia-smi exited with error code 6: No devices were found

@PCudrano PCudrano closed this Jan 10, 2024
@PCudrano PCudrano reopened this Jan 10, 2024
@peci1
Copy link
Owner

peci1 commented Jan 10, 2024

Thanks for the PR.

Could you please also update the readme? And, there is also a description of the CLI options at the beginning of the Python script. Could you update that, too?

Would it be possible to add a test for this CLI flag? I think you can just copy one of the already present test and just add the -i flag. This is to test that the CLI flag is correctly parsed and recognized.

@peci1
Copy link
Owner

peci1 commented Jan 10, 2024

And do you know since when the -i flag is supported by nvidia-smi? Has it been there forever?

@PCudrano
Copy link
Contributor Author

My pleasure, I've been using the script for some time and figured I'd contribute with my little edit.

I added the usage string in the readme and in the Python script, thanks for pointing it out.

It's worth stressing out that this implementation sends the -i argument directly to the nvidia-smi call by subprocess.run. This means that the -i option would not work if this command is piped to nvidia-smi. It only works when nvidia-htop.py is called directly. Otherwise, this option is not considered.
We might look into filtering out the GPU IDs manually from the full nvidia-smi output, but that'd be kinda inefficient, I don't see much purpose to it if not for backward compatibility. Let me know what you think though.

I looked into testing the changes, but for the reason above I could not add new test cases, as they'd require nvidia-htop.py to be piped to a fake output txt.

I think I've used the native -i option on nvidia-smi for years, but I'm not sure when it was first introduced tbh.

@peci1 peci1 self-requested a review January 16, 2024 11:04
@peci1
Copy link
Owner

peci1 commented Jan 16, 2024

Thanks for pointing out it doesn't work in pipe mode. I've added a warning. I also added the test, but it only tests that the option is accepted, nothing more.

@peci1 peci1 merged commit a73833f into peci1:master Jan 16, 2024
2 checks passed
@peci1
Copy link
Owner

peci1 commented Jan 16, 2024

Released in version 1.1.0. Thanks for your contribution!

@PCudrano
Copy link
Contributor Author

Great! Thank you!

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