pragma HLS array_partition - 2023.2 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2023-12-18
Version
2023.2 English

Description

Important: Array_Partition and Array_Reshape pragmas and directives are not supported for M_AXI Interfaces on the top-level function. Instead you can use the hls::vector data types as described in Vector Data Types.

Partitions an array into smaller arrays or individual elements and provides the following:

  • Results in RTL with multiple small memories or multiple registers instead of one large memory.
  • Effectively increases the amount of read and write ports for the storage.
  • Potentially improves the throughput of the design.
  • Requires more memory instances or registers.

Syntax

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

#pragma HLS array_partition variable=<name> \
type=<type>  factor=<int>  dim=<int> off=true

Where:

variable=<name>
A required argument that specifies the array variable to be partitioned.
type=<type>
Optionally specifies the partition type. The default type is complete. The following types are supported:
cyclic
Cyclic partitioning creates smaller arrays by interleaving elements from the original array. The array is partitioned cyclically by putting one element into each new array before coming back to the first array to repeat the cycle until the array is fully partitioned. For example, if factor=3 is used:
  • Element 0 is assigned to the first new array
  • Element 1 is assigned to the second new array.
  • Element 2 is assigned to the third new array.
  • Element 3 is assigned to the first new array again.
block
Block partitioning creates smaller arrays from consecutive blocks of the original array. This effectively splits the array into N equal blocks, where N is the integer defined by the factor= argument.
complete
Complete partitioning decomposes the array into individual elements. For a one-dimensional array, this corresponds to resolving a memory into individual registers. This is the default <type>.
factor=<int>
Specifies the number of smaller arrays that are to be created.
Important: For complete type partitioning, the factor is not specified. For block and cyclic partitioning, the factor= is required.
dim=<int>
Specifies which dimension of a multi-dimensional array to partition. Specified as an integer from 0 to <N>, for an array with <N> dimensions:
  • If a value of 0 is used, all dimensions of a multi-dimensional array are partitioned with the specified type and factor options.
  • Any non-zero value partitions only the specified dimension. For example, if a value 1 is used, only the first dimension is partitioned.
off=true
Disables the ARRAY_PARTITION feature for the specified variable. Does not work with dim, factor, or type.

Example 1

This example partitions the 13 element array, AB[13], into four arrays using block partitioning:

#pragma HLS array_partition variable=AB type=block factor=4
Tip: Because four is not an integer factor of 13:
  • Three of the new arrays have three elements each
  • One array has four elements (AB[9:12])

Example 2

This example partitions dimension two of the two-dimensional array, AB[6][4] into two new arrays of dimension [6][2]:

#pragma HLS array_partition variable=AB type=block factor=2 dim=2

Example 3

This example partitions the second dimension of the two-dimensional in_local array into individual elements.

int in_local[MAX_SIZE][MAX_DIM];
#pragma HLS ARRAY_PARTITION variable=in_local type=complete dim=2

Example 4

Partitioned arrays can be addressed in your code by the new structure of the array, as shown in the following code example;

struct SS
{
  int x[N];
  int y[N];
};
  
int top(SS *a, int b[4][6], SS &c) {
#pragma HLS array_partition type=complete dim=1 variable=b
#pragma HLS interface mode=ap_memory port = b[0]
#pragma HLS interface mode=ap_memory port = b[1]
#pragma HLS interface mode=ap_memory port = b[2]
#pragma HLS interface mode=ap_memory port = b[3]