mindspore.ops.NPUClearFloatStatus

class mindspore.ops.NPUClearFloatStatus[source]

Clears the flag which stores the overflow status.

Note

The flag is in the register on the Ascend device. It will be reset and can not be reused again after the NPUClearFloatStatus is called. In addition, there are strict sequencing requirements for use, i.e., before using the NPUGetFloatStatus operator, need to ensure that the NPUClearFlotStatus and your compute has been executed. We use mindspore.ops.Depend on ensure the execution order.

Please refer to the Examples of mindspore.ops.NPUGetFloatStatus.

Inputs:
  • x (Tensor) - The output tensor of NPUAllocFloatStatus. The data type must be float16 or float32.

Outputs:

Tensor, has the same shape as x. All the elements in the tensor will be zero.

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> import mindspore.nn as nn
>>> import mindspore.ops.functional as F
>>> from mindspore.common import dtype as mstype
>>> from mindspore.common.tensor import Tensor
>>> from mindspore.ops import operations as P
>>> class Net(nn.Cell):
...     def __init__(self):
...         super().__init__()
...         self.alloc_status = P.NPUAllocFloatStatus()
...         self.get_status = P.NPUGetFloatStatus()
...         self.clear_status = P.NPUClearFloatStatus()
...         self.sub = P.Sub()
...         self.neg = P.Neg()
...
...     def construct(self, x):
...         init = self.alloc_status()
...         clear_status = self.clear_status(init)
...         x = F.depend(x, clear_status)
...         res = self.sub(x, self.neg(x))
...         init = F.depend(init, res)
...         get_status = self.get_status(init)
...         res = F.depend(res, get_status)
...         return res
>>>
>>> value = 5
>>> data = np.full((2, 3), value, dtype=np.float16)
>>> x = Tensor(data, dtype=mstype.float16)
>>> net = Net()
>>> res = net(x)
>>> print(res)
[[10. 10. 10.]
 [10. 10. 10.]]