Python Device API¶
| Function | Signature | Notes |
|---|---|---|
get_device_count |
() -> int |
Valid device IDs are 0 .. count-1 |
set_device |
(device_id: int) -> None |
Sets the current device of the calling thread |
get_device |
() -> int |
|
get_device_attribute |
(attr: HaDeviceAttr, device_id: int) -> int |
Returns one device attribute (chip generation is HaDeviceAttr.VERSION). Raises RuntimeError (HaNotSupported) if the value is unavailable |
reset_device |
(device_id: int) -> None |
Invalidates the allocations, streams, and events of that device |
reset_all_devices |
() -> None |
Also registered as an atexit hook |
Example¶
get_device¶
Reads back the value set by this thread. Raises if it was never set.
Example
1 2 3 4 | |
get_device_attribute¶
Reads one device attribute. See HaDeviceAttr for the attribute kinds.
An attribute the device cannot report raises RuntimeError (HaNotSupported) instead of returning a placeholder such as 0.
A virtual device ID may differ from the number in the device node name (for example, in an environment where only some cards
are assigned, ID 1 can be /dev/ha2). To find the node, do not build the path from the ID; check the PCI_* attributes.
Example
1 2 3 4 5 6 7 | |
get_device_count¶
Checks the number of devices and the valid ID range.
Example
1 2 3 4 5 6 7 8 | |
reset_all_devices¶
Affects the whole process. It also resets devices used by other threads.
Example
1 2 3 4 | |
reset_device¶
A reset invalidates everything on that device, so clean up handles first.
Example
1 2 3 4 5 6 7 | |
set_device¶
The current device is set per thread, so a pool thread has none until it sets one itself.
Example
1 2 3 4 5 6 7 8 9 10 11 12 | |