mindspore.ops.NPUGetFloatStatus

class mindspore.ops.NPUGetFloatStatus[源代码]

Updates the flag which is the output tensor of NPUAllocFloatStatus with the latest overflow status.

The flag is a tensor whose shape is (8,) and data type is mindspore.dtype.float32. If the sum of the flag equals to 0, there is no overflow happened. If the sum of the flag is bigger than 0, there is overflow happened. 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 Depend on ensure the execution order.

Inputs:
  • x (Tensor) - The output tensor of NPUAllocFloatStatus. The data type must be float16 or float32. \((N,*)\) where \(*\) means, any number of additional dimensions, its rank should be less than 8.

Outputs:

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

Raises
  • TypeError – If x is not a Tensor.

  • TypeError – If dtype of x is neither float16 nor float32.

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.]]