mindspore.hal.memory_allocated

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

Returns the actual memory size currently occupied by Tensor.

Note

  • If device_target is not specified, get the device capability of the current backend set by context.

  • For the CPU backend, 0 is always returned.

Parameters

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

Returns

int, in Byte.

Examples

>>> import mindspore as ms
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> 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.memory_allocated())
1024