mindspore.set_device

View Source On Gitee
mindspore.set_device(device_target, device_id=None)[source]

Set device target and device id for running environment.

Note

  • The device_target must be set in the ["CPU", "GPU", "Ascend"], there is no default value.

Parameters
  • device_target (str) – The target device to run, only support "Ascend", "GPU", and "CPU".

  • device_id (int) – ID of the target device, the value must be in [0, device_num_per_host-1]. The frame will set different default behaviours according to the scenario: if it is a single-card scenario, the frame will be set to 0. In a distributed scenario where msrun is started, the framework will automatically negotiate the available device_id values. In a distributed scenario with other startup methods, the frame is set to 0. "device_num_per_host" refers to the total number of devices on the host.

Examples

>>> import mindspore as ms
>>> ms.set_device("Ascend", 1)