jacinle.cli.device#
Uiltity functions to parse CPU/CUDA device strings.
Classes
The target fmt of device names. |
Functions
|
Convert a device name to a canonical format. |
|
Parse a input list of strings or a single comma-separated string into a list of device names. |
|
Parse a input list of strings or a single comma-separated string into a list of device names. |
|
Set the CUDA_VISIBLE_DEVICES environment variable with a single comma-separated string or a list of strings. |
Class DeviceNameFormat
- class DeviceNameFormat[source]#
Bases:
JacEnum
The target fmt of device names. Supported formats are:
DeviceNameFormat.INT
: integer, e.g.,0
,1
,2
, etc.DeviceNameFormat.TENSORFLOW
: TensorFlow-style device name, e.g.,/cpu:0
,/gpu:1
, etc.
- __new__(value)#
- classmethod assert_valid(value)#
Assert if the value is a valid choice.
- classmethod choice_names()#
Returns the list of the name of all possible choices.
- classmethod choice_objs()#
Returns the list of the object of all possible choices.
- classmethod choice_values()#
Returns the list of the value of all possible choices.
- classmethod is_valid(value)#
Check if the value is a valid choice.
- classmethod type_name()#
Return the type name of the enum.
- INT = 'int'#
- TENSORFLOW = 'tensorflow'#
Functions
- canonlize_device_name(d, fmt=DeviceNameFormat.INT)[source]#
Convert a device name to a canonical format.
- Parameters:
d (str) – the device name to be converted. The string can be either:
cpu
,gpu0
, or0
.fmt (str | DeviceNameFormat) – the target format.
- Returns:
the canonical device name. If the target format is
DeviceNameFormat.INT
, the return value is an integer. When d iscpu
, the return value is-1
. If the target format isDeviceNameFormat.TENSORFLOW
, the return value is a string: e.g.,/cpu:0
,/gpu:1
, etc.- Return type:
- parse_and_set_devices(devs, fmt=DeviceNameFormat.INT, set_device=True)[source]#
Parse a input list of strings or a single comma-separated string into a list of device names. When
set_device
is True, the CUDA_VISIBLE_DEVICES environment variable will be set accordingly.