5.9. sail.Tensor

5.9.1. __init__

Constructor allocates memory of the tensor.

Interface:
def __init__(self,
            handle: sail.Handle,
            data: numpy.array,
            own_sys_data: bool=True)

Parameters

  • handle : sail.Handle

Handle instance

  • array_data : numpy.array

Tensor ndarray data, dtype can be np.float32, np.int8 or np.uint8

  • own_sys_data : bool, default: True

Indicator of whether own system memory, If false, the memory will be copied to device directly

Interface:
def __init__(self,
            handle: sail.Handle,
            shape: tuple,
            dtype: sail.Dtype,
            own_sys_data: bool,
            own_dev_data: bool)

Parameters

  • handle : sail.Handle

Handle instance

  • shape : tuple

Tensor shape

  • dytpe : sail.Dtype

Data type

  • own_sys_data : bool

Indicator of whether own system memory

  • own_dev_data : bool

Indicator of whether own device memory

5.9.2. shape

Get shape of the tensor.

Interface:
def shape(self)-> list

Returns

  • tensor_shape : list

Shape of the tensor

5.9.3. asnumpy

Get system data of the tensor.

Interface:
def asnumpy(self)-> numpy.array

Returns

  • data : numpy.array

System data of the tensor, dtype can be np.float32, np.int8 or np.uint8 with respective to the dtype of the tensor.

Interface:
def asnumpy(self, shape: tuple)-> numpy.array

Parameters

  • shape : tuple

Tensor shape want to get

Returns

  • data : numpy.array

System data of the tensor, dtype can be np.float32, np.int8 or np.uint8 with respective to the dtype of the tensor.

5.9.4. update_data

Update system data of the tensor. The data size should not exceed the tensor size, and the tensor shape will not be changed.

Interface:
def update_data(self, data: numpy.array)

Parameters

data : numpy.array

Data.

5.9.5. scale_from

Scale data to tensor in system memory.

Interface:
def scale_from(self, data: numpy.array, scale: float32)

Parameters

  • data : numpy.array with dtype of float32

Data.

  • scale : float32

Scale value.

5.9.6. scale_to

Scale tensor to data in system memory.

Interface:
def scale_to(self, scale: float32)-> numpy.array

Parameters

  • scale : float32

Scale value.

Returns

  • data : numpy.array with dtype of float32

Data.

Interface:
def scale_to(self, scale: float32, shape: tuple)-> numpy.array

Parameters

  • scale : float32

Scale value.

  • shape : tuple

Tensor shape wanted to get

Returns

  • data : numpy.array with dtype of float32

Data.

5.9.7. reshape

Reset shape of the tensor.

Interface:
def reshape(self, shape: list)

Parameters

  • shape : list

New shape of the tensor

5.9.8. own_sys_dat

Judge if the tensor owns data pointer in system memory.

Interface:
def own_sys_data(self)-> bool

Returns

  • judge_ret : bool

True for owns data pointer in system memory.

5.9.9. own_dev_data

Judge if the tensor owns data in device memory.

Interface:
def own_dev_data(self)-> bool

Returns

  • judge_ret : bool

True for owns data in device memory.

5.9.10. sync_s2d

Copy data from system memory to device memory without or with specified size.

Interface:
def sync_s2d(self)
Interface:
def sync_s2d(self, size: int)

Parameters

  • size : int

Byte size to be copied

5.9.11. sync_d2s

Copy data from device memory to system memory without or with specified size.

Interface:
def sync_d2s(self)
Interface:
def sync_d2s(self, size: int)

Parameters

  • size : int

Byte size to be copied