Utils Functions
tpu_data_type_size
Get the size of a data type.
- int tpu_data_type_size(data_type_t dtype)
** DT_INT4/DT_UINT4 is not supported, which will cause an assert
tpu_data_type_bits
Get the bit width of a data type.
- int tpu_data_type_bits(data_type_t dtype)
tpu_npu_index
Get the index of NPU by local address.
- int tpu_npu_index(local_addr_t addr)
tpu_bank_index
Get the index of bank by local address.
- int tpu_bank_index(local_addr_t addr)
tpu_channle_num_per_npu
Calculate the number of channels in each NPU.
- int tpu_channle_num_per_npu(int start_idx, int num_channels)
- Parameters
start_idx – Index of the NPU where the tensor starts.
num_channels – Number of channels of the tensor.
- Returns
Number of channels per NPU.
tpu_aligned_feature_size
Calculate the memory size of a matrix in the 64-byte aligned layout.
- int tpu_aligned_feature_size(int h, int w, data_type_t dtype)
- Parameters
h – Height h of a 2D vector.
w – Width w of a 2D vector.
dtype – Type of data.
tpu_aligned_stride
Calculate strides of the tensor in the 64-byte aligned layout.
- void tpu_aligned_stride(dim4 *stride, int start_idx, const dim4 *shape, data_type_t dtype)
- Parameters
stride – Pointer to the stride of the tensor.
start_idx – Index of the NPU where the tensor starts.
shape – Pointer to the shape of the tensor.
dtype – Type of data.
tpu_compact_stride
Calculate strides of the tensor in the compact layout.
tpu_line_aligned_stride
Calculate strides of the tensor in the Line 64-byte aligned layout.
- void tpu_line_aligned_stride(dim4 *stride, int start_idx, const dim4 *shape, data_type_t dtype)
- Parameters
stride – Pointer to the stride of the tensor.
start_idx – Index of the NPU where the tensor starts.
shape – Pointer to the shape of the tensor.
dtype – Type of data.
tpu_continuous_stride
Calculate strides of the tensor in the continuous layout.