-
Notifications
You must be signed in to change notification settings - Fork 165
Device properties example #474
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
Conversation
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 do you think about renaming to show_device_properties.py?
For quicker aha when people see the filename.
from cuda.core.experimental import Device, system | ||
|
||
|
||
def _bool_str(value: bool) -> str: |
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.
_yes_or_no
(or just _yes_no
works, too)
makes this self-explanatory (in the call sites).
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.
Yep, will change both filename and function to _yes_no
return "YES" if value else "NO" | ||
|
||
|
||
def _bytes_to_mbytes(value): |
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.
def _bytes_to_mbytes(value):
return f"{value / (1024 ** 2):.2f}MB"
def _bytes_to_gbytes(value):
return f"{value / (1024 ** 3):.2f}GB"
These were generated by ChatGPT: https://chatgpt.com/share/67bfde2c-7b20-8008-a099-302d0ed4dc60
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.
No, I am an old schooler. I used Windows calculator to calculate magic numbers
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 agree, it's more readable but my guts protest to use expensive power and division ops
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.
(Today I started experimenting with claude.ai)
https://claude.ai/share/5830e427-4b3b-44f5-8bef-c47d10ebe01f
I'm slightly modifying what it suggests:
BYTES_TO_GBYTES = 1 / (1024 ** 3)
def _bytes_to_gbytes(value):
return f"{value * BYTES_TO_GBYTES:.2f}GB"
Making our examples readable seems valuable.
print(f"- Constant memory available: {properties.total_constant_memory}B") | ||
print(f"- Support for unified address space with host: {_bool_str(properties.unified_addressing)}") | ||
print(f"- Support for virtual memory management: {_bool_str(properties.virtual_memory_management_supported)}") | ||
|
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.
Optional, but I'd lean towards adding a print()
here, so that the output doesn't run directly into the command line prompt.
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 point
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 double checked log.txt
. The last few lines in the output will be:
...
- Support for unified address space with host: YES
- Support for virtual memory management: YES
*****************************************************
Two blank lines are printed before command line appears. See line 169
print(f"DEVICE {device.name} (id={device_id})") | ||
|
||
device.set_current() | ||
ctx = device.context |
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.
This seems to be unused. (Hm, not sure why ruff doesn't catch this.)
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.
Hm, not sure why ruff doesn't catch this.
Oh! Because it's currently a module-level variable (which could in theory be used from elsewhere). Another reason to move this code into a function. I think ruff will then flag this.
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 have initiated a separate discussion on set_current()
. I wanted to add some meaningful example for it but it appears that context management is not yet fully implemented. Or am I wrong? I am happy to extend example with context stuff
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 upvoted your suggestion (yesterday).
it appears that context management is not yet fully implemented.
I had to look this up myself: #189
What do you think about adding a comment (very rough, just to give the idea):
# Extend example to show device context information after #189 is resolved.
@rwgk Your suggestions have been addressed |
/ok to test |
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.
Looks great to me!
We trigger CI testing via /ok to test comments. I think it works for anyone, but I just did that right now to get it going.
It works for all GitHub IDs linked with a valid NVIDIA email address, so Sergey you should be able to trigger it yourself! |
This comment has been minimized.
This comment has been minimized.
(I tried to look at the log of the one failing test but it doesn't load. I'll try again later.) |
It was a transient network issue, I reran the failed job and all is good now. Merging, thanks Sergey & Ralf! |
|
This example aims to get familiar with cuda.core device and device properties concepts. The script iterates across all devices in the system and prints their device properties.
log.txt