mindspore.hal.device_count

mindspore.hal.device_count(device_target=None)[source]

Returns device count of specified backend.

Note

If device_target is not specified, get the device count of the current backend set by context. For CPU backend, this method always returns 1.

Parameters

device_target (str, optional) – The device name of backend, should be one of "CPU", "GPU" and "Ascend".

Returns

int.

Examples

>>> import mindspore as ms
>>> device_target = ms.context.get_context("device_target")
>>> print(ms.hal.device_count(device_target))