mindspore.hal.is_initialized

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

Return whether specified device is initialized, this api will be deprecated and removed in future versions.

Note

MindSpore's devices "CPU", "GPU" and "Ascend" will be initialized in the following scenarios:

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

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

Parameters

device_target (str) – The target device specified, should be one of "CPU" , "GPU" and "Ascend" .

Returns

bool

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