This section describes the alignment restriction rules when using BPU.
BPU does not restrict the model input size or parity. Both 416x416 inputs (e.g., YOLO) and 227x227 inputs (e.g., SqueezeNet) can be supported.
For NV12, Both H & W of the input are required to be even to meet the requirement that the UV is half of the Y.
The BPU has alignment requirements for data. Valid data arrangement and aligned data arrangement are represented by validShapeand stride in hbDNNTensorProperties.
validShape is the shape of the valid data.stride represents the stride of each dimension of validShape, describing the number of bytes required to cross each dimension of the tensor.
Note that models with hbDNNDataType as NV12 or Y type inputs are special cases where the obtained stride is always 0, because these types of inputs only require alignment in the width (W) direction by 32.The model input and output tensors can get the correct data layout through validShape and stride.
For example, if the getted model input attribute hbDNNDataType = HB_DNN_TENSOR_TYPE_U16, validShape = [1, 3, 212, 212] and stride = [301056, 100352, 448, 2],
this indicates that the valid input size of the model is 1x3x212x212 .
stride[3] = 2 indicates that each element is 16 bits in size.stride[2] = 448 = 2 * 224 indicates that the dimension at index=3 is aligned according to 224, therefore the stride for the dimension at index=3 is 448.stride[1] = 100352 = 448 * 224 indicates that the dimension at index=2 is also aligned according to 224, therefore the stride for the dimension at index=2 is 100352.stride[0] = 301056 = 100352 * 3 indicates that ithe dimension at index=1 is aligned according to 3 , consistent with the valid size, therefore the stride for the dimension at index=1 is 301056.In subsequent usage scenarios, considering the alignment requirements, it is recommended to apply for memory space according to the alignedByteSize.