mindspore.hal.is_initialized

View Source On Gitee
mindspore.hal.is_initialized(device_target)[source]

Returns whether specified backend is initialized.

Note

MindSpore’s backends “CPU”, “GPU” and “Ascend” will be initialized in the following scenarios:

  • For distributed job, backend will be initialized after mindspore.communication.init method is called.

  • For standalone job, backend will be initialized after running the first operator or calling creating stream/event interfaces.

Parameters

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

Returns

Bool, whether the specified backend is initialized.

Examples

>>> import mindspore as ms
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> ms.context.set_context(device_target="CPU")
>>> assert not ms.hal.is_initialized("CPU")
>>> a = Tensor(np.ones([1, 2]), ms.float32)
>>> b = Tensor(np.ones([1, 2]), ms.float32)
>>> c = ops.add(a, b).asnumpy()
>>> print(ms.hal.is_initialized("CPU"))
True