3.5.1.14 Memory Partitioning

Memory Partitioning is an optimization where aggregate types such as arrays and structs are partitioned into smaller pieces allowing for a greater number of reads and writes (accesses) per cycle. SmartHLS instantiates a RAM for each aggregate type where each RAM has up to two ports (allowing up to two reads/writes per cycle). Partitioning aggregate types into smaller memories or into its individual elements allows for more accesses per cycle and improves memory bandwidth.

Important: There are two flavors of memory partitioning, access-based partitioning and user-specified partitioning.
  • Accessing memory outside of an array dimension is not supported by memory partitioning and will sometimes cause incorrect circuit behavior. An example of this is casting a 2-d array to a pointer and iterating through the size of the 2-d array.
  • Pointers that alias to different memories (e.g. a function called with different memories) or different sections of the same memory (for example, a pointer that is assigned to multiple memories based on a condition) can be partitioned if the aliased memories/sections have the same partitions. Otherwise, access-based partitioning will not partition the aliased memories, or a warning will be displayed for user-specified partitioning. The following example shows an unsupported aliasing case:
    int sum_array(int *z) {
    #pragma HLS function noinline
      int sum = 0;
      for (int i = 0; i < 100; i++)
        sum += z[i];
      return sum;
    }
    
    int main() {
    #pragma HLS function top
    #pragma HLS memory partition variable(x) type(block) dim(1) factor(2)
      int x[100];   // x should be partitioned into 2 partitions
    #pragma HLS memory partition variable(x) type(cyclic) dim(1) factor(4)
      int y[100];   // x should be partitioned into 4 partitions
      // ...
      int sum_x = sum_array(x);
      int sum_y = sum_array(y);
      // ...
    }
                      
                   

    SmartHLS will output a warning:

    Warning: The user specified memory "x" on line 80 of test.cpp could not be partitioned because the memory aliases with another memory at line 71 of test.cpp that has a different partitioning.
    Warning: The user specified memory "y" on line 82 of test.cpp could not be partitioned because the memory aliases with another memory at line 71 of test.cpp that has a different partitioning.
  • Partitions with no accesses are discarded.