Chapter 6
Vectorized Code Generation
©
National Instruments Corporation
6-7
/* ---------------------------- Gain Block */
/* {gain..2} */
Y->gain_2_1[0] = 1.2*U->gain_1[0];
Y->gain_2_1[1] = 2.3*U->gain_1[2];
Y->gain_2_1[2] = 3.4*U->gain_1[3];
Y->gain_2_1[3] = 4.5*U->gain_1[5];
Y->gain_2_1[4] = 5.6*U->gain_1[6];
This example shows that the penalty for poor connectivity can be great.
In this case, the vectorized code is not an improvement over scalar code.
Vectorization Modes
AutoCode supports two vectorization modes in addition to the default
scalar code generation. All three modes are controlled by one
command-line option,
-Ov
n
, where
n
is the mode. The vectorization
modes allow the same model to be code generated in several ways to suite
your particular goals. The following sections briefly describe each mode.
Maximal Vectorization
Maximal vectorization (mode
-Ov 2
) is one of two vectorization modes
supported by AutoCode. Maximal vectorization is defined by placing all of
the outputs of a block into one or more arrays. For most blocks, only one
array is needed because the block can only have one output data type. For
blocks with more than one output data type, more than one array is used.
External inputs also are formed into arrays and like the basic block, if
mixed data types are used, multiple arrays are generated.
The names of the arrays are taken from the label/name of the first signal
bundled into the array. As a result, maximal vectorization might not
produce generated code that is very traceable back to the diagram. This
vectorization mode is to provide a quick way to get vectorized code without
having to examine your model’s design and tune it for efficient code.
Mixed Vectorization
This vectorization mode (mode
-Ov 1
) allows for both scalar and vector
code generation within the same system. This mode also is called
vector-by-label because the labels/names of the signals determine if a
vector is generated.