Utils Functions

okk_start_npu_index

int okk_start_npu_index(local_addr_t addr)

Calculate the index of the NPU where the tensor starts.

Parameters

addr – Address of the tensor in local memory.

Returns

Index of NPU.

okk_channle_num_per_npu

int okk_channle_num_per_npu(int start_idx, int num_channels)

Calculate the number of channels in each NPU.

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.

okk_128_byte_aligned_stride_for_32bit

void okk_128_byte_aligned_stride_for_32bit(dim4 *stride, int start_idx, const dim4 *shape)

Calculate strides of the tensor in the 128-Byte Aligned Layout for 32-bit data type.

Parameters
  • stride[out] – 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.

okk_128_byte_aligned_stride_for_16bit

void okk_128_byte_aligned_stride_for_16bit(dim4 *stride, int start_idx, const dim4 *shape)

Calculate strides of the tensor in the 128-Byte Aligned Layout for 16-bit data type.

Parameters
  • stride[out] – 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.

okk_128_byte_aligned_stride_for_8bit

void okk_128_byte_aligned_stride_for_8bit(dim4 *stride, int start_idx, const dim4 *shape)

Calculate strides of the tensor in the 128-Byte Aligned Layout for 8-bit data type.

Parameters
  • stride[out] – 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.

okk_compact_stride

void okk_compact_stride(dim4 *stride, int start_idx, const dim4 *shape)

Calculate strides of the tensor in the Compact Layout.

Parameters
  • stride[out] – 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.

okk_continuous_stride

void okk_continuous_stride(dim4 *stride, const dim4 *shape)

Calculate strides of the tensor in the Continuous Layout.

Parameters
  • stride[out] – Pointer to the stride of the tensor.

  • shape – Pointer to the shape of the tensor.