Chapter 6
Vectorized Code Generation
©
National Instruments Corporation
6-21
You should notice two things in the code shown in Example 6-8. First,
the gain block added to merge the data is generated as copies from the
respective inputs into the single array. Second, the integrator block is
tightly rolled. If the merge was not present, the Integrator would have been
unrolled, causing a 6-fold increase in the amount of code for that block.
The only reason to introduce a merge block (unit gain block) is when the
cost of unrolling the algorithm of your block—in this case the integrator
block—is more expensive then the merge block. It can be seen from the
code that the cost of a merge block is a copy in a local array. Because the
integrator algorithm is complicated, it is necessary to have the merge so that
the integrator is rolled.
AutoCode will not automatically introduce the merge (copy) just to
improve vectorization. The reason is that traceability from the code to
model is reduced anytime extra code other than the block algorithm is
generated. Also, AutoCode is not able to evaluate the design decision to
make one block rolled at the expense of another. Therefore, for optimal
vectorization, you might need to change your model.
External Outputs
Another variation of the split-merge problem appears with external outputs.
External outputs are represented by the
Y
-structure. It contains only those
signals marked as external outputs. For scalar code generation, AutoCode
directly uses the symbol in the
Y
-structure instead of using local storage.
However, when the output of a block is a vector and only a subset of the
outputs are connected to external outputs, a conflict of requirements
appears between storing the block output into an array and optimizing
access to external output.
Copy-Back
When a split-merge occurs with external outputs, AutoCode must act to
preserve the semantics of the model. AutoCode has been designed to
preserve the array, and therefore the block vectorization and
copy-back
those external outputs from the array into the
Y
-structure. In the example
shown in Figure 6-6, a simple gain block has only two of its five outputs
connected to the external output. AutoCode preserves the array for the gain
block, but copies the pieces of the array that are external output into the
Y
-structure.