Dynamic Input Introduction
When the model input tensor properties validShape or stride contains -1, it means that the model input is dynamic and you need to fill in the dynamic dimension according to the actual input.
This section describes the rules for filling in stride and gives a complete derivation using a three-input model as an example. After reading this section, you should be able to obtain a set of validShape and stride values that can be used directly for input preparation.
The following rules should be followed when filling in stride:
-
Make sure the filled value satisfies , where
idxrepresents the current dimension. -
For
strideof Y and UV inputs, due to some hardware constraints, fixed alignment requirement needs to be ensured in the W direction, where J6H/P and S6P require 64-byte alignment and J6E/M/B require 32-byte alignment, which means you need to align the input according tostride. For the full set of input/output handling differences across computing platforms, refer to the Input/Output Handling Differences section of Platform Differences.
Here, using the J6E model as an example, the stride is required to be 32-byte aligned, and the model has three inputs:
input_y: validShape = [1,-1,-1,1],stride = [-1,-1,1,1]input_uv: validShape = [1,-1,-1,2],stride = [-1,-1,2,1]input_roi: validShape = [1,4],stride = [16,4]
input_y and input_uv are dynamic inputs, and are Y and UV inputs. Assume that the actually inputs: input_y's validShape = [1,220,220,1], input_uv's validShape = [1,110,110,2]. stride is calculated as follows to ensure that the dynamic dimension is aligned to 32, where ALIGN_32 represents 32-byte alignment:
-
input_y:stride[3] = 1;
stride[2] = 1;
stride[1] = ALIGN_32(stride[2] * validShape.dimensionSize[2]) = ALIGN_32(1 * 220) = 224;
stride[0] = ALIGN_32(stride[1] * validShape.dimensionSize[1]) = ALIGN_32(224 * 220) = 49280;
-
input_uv:stride[3] = 1;
stride[2] = 2;
stride[1] = ALIGN_32(stride[2] * validShape.dimensionSize[2]) = ALIGN_32(2 * 110) = 224;
stride[0] = ALIGN_32(stride[1] * validShape.dimensionSize[1]) = ALIGN_32(224 * 110) = 24640;
You need to set the following properties when preparing the input, and align the input data according to stride:
input_y: validShape = [1,220,220,1],stride = [49280,224,1,1]input_uv: validShape = [1,110,110,2],stride = [24640,224,2,1]input_roi: validShape = [1,4],stride = [16,4]
The example above uses the 32-byte alignment requirement of the J6E platform. If the same model is deployed on the J6H/P or S6P platform, the alignment requirement in the W direction becomes 64-byte alignment. The derivation formula itself does not change, you only need to replace every ALIGN_32 in the derivation with ALIGN_64. Using the same actual inputs, stride is calculated as follows, where ALIGN_64 represents 64-byte alignment:
-
input_y:stride[3] = 1;
stride[2] = 1;
stride[1] = ALIGN_64(stride[2] * validShape.dimensionSize[2]) = ALIGN_64(1 * 220) = 256;
stride[0] = ALIGN_64(stride[1] * validShape.dimensionSize[1]) = ALIGN_64(256 * 220) = 56320;
-
input_uv:stride[3] = 1;
stride[2] = 2;
stride[1] = ALIGN_64(stride[2] * validShape.dimensionSize[2]) = ALIGN_64(2 * 110) = 256;
stride[0] = ALIGN_64(stride[1] * validShape.dimensionSize[1]) = ALIGN_64(256 * 110) = 28160;
The corresponding input properties are set as follows:
input_y: validShape = [1,220,220,1], stride = [56320,256,1,1]input_uv: validShape = [1,110,110,2], stride = [28160,256,2,1]input_roi: validShape = [1,4], stride = [16,4]
input_roi is neither a Y nor a UV input, and it is not a dynamic input either, so it is not affected by the change of the W-direction alignment requirement. Its values are the same on both platforms.
Where to Look Next
-
You need to confirm the alignment requirement for the first address of the input and output memory, and how to use
alignedByteSize: refer to the Alignment Rule section. -
You need to know how to allocate memory in code and lay out input data according to the
strideyou filled in: refer to the Model Inference Application Development Guide section.
