pragma HLS array_map

Description

Combines multiple smaller arrays into a single large array to help reduce block RAM resources.

Designers typically use the pragma HLS array_map command (with the same instance= target) to combine multiple smaller arrays into a single larger array. This larger array can then be targeted to a single larger memory (RAM or FIFO) resource.

Each array is mapped into a block RAM or UltraRAM, when supported by the device. The basic block RAM unit provided in an FPGA is 18K. If many small arrays do not use the full 18K, a better use of the block RAM resources is to map many small arrays into a single larger array.

TIP: If a block RAM is larger than 18K, they are automatically mapped into multiple 18K units.
The ARRAY_MAP pragma supports two ways of mapping small arrays into a larger one:
  • Horizontal mapping: this corresponds to creating a new array by concatenating the original arrays. Physically, this gets implemented as a single array with more elements.
  • Vertical mapping: this corresponds to creating a new array by concatenating the original words in the array. Physically, this gets implemented as a single array with a larger bit-width.

The arrays are concatenated in the order that the pragmas are specified, starting at:

  • Target element zero for horizontal mapping, or
  • Bit zero for vertical mapping.

Syntax

Place the pragma in the C source within the boundaries of the function where the array variable is defined.

#pragma HLS array_map variable=<name> instance=<instance> \
<mode> offset=<int>

Where:

  • variable=<name>: A required argument that specifies the array variable to be mapped into the new target array <instance>.
  • instance=<instance>: Specifies the name of the new array to merge arrays into.
  • <mode>: Optionally specifies the array map as being either horizontal or vertical.
    • Horizontal mapping is the default <mode>, and concatenates the arrays to form a new array with more elements.
    • Vertical mapping concatenates the array to form a new array with longer words.
  • offset=<int>: Applies to horizontal type array mapping only. The offset specifies an integer value offset to apply before mapping the array into the new array <instance>. For example:
    • Element 0 of the array variable maps to element <int> of the new target.
    • Other elements map to <int+1>, <int+2>... of the new target.
    IMPORTANT!: If an offset is not specified, Vivado HLS calculates the required offset automatically to avoid overlapping array elements.

Example 1

Arrays array1 and array2 in function foo are mapped into a single array, specified as array3 in the following example:

void foo (...) {
int8 array1[M];
int12 array2[N];
#pragma HLS ARRAY_MAP variable=array1 instance=array3 horizontal
#pragma HLS ARRAY_MAP variable=array2 instance=array3 horizontal
...
loop_1: for(i=0;i<M;i++) {
array1[i] = ...;
array2[i] = ...;
...
}
...
}

Example 2

This example provides a horizontal mapping of array A[10] and array B[15] in function foo into a single new array AB[25].
  • Element AB[0] will be the same as A[0].
  • Element AB[10] will be the same as B[0] because no offset= option is specified.
  • The bit-width of array AB[25] will be the maximum bit-width of either A[10] or B[15].
#pragma HLS array_map variable=A instance=AB horizontal
#pragma HLS array_map variable=B instance=AB horizontal

Example 3

The following example performs a vertical concatenation of arrays C and D into a new array CD, with the bit-width of C and D combined. The number of elements in CD is the maximum of the original arrays, C or D:

#pragma HLS array_map variable=C instance=CD vertical
#pragma HLS array_map variable=D instance=CD vertical

See Also