Bambu: optimizations

NOTE: This page is a work in progress and refers to Bambu release 2026.11.

Loop Unrolling and Array Partitioning

Loop unrolling exposes parallelism by replicating the operations performed in different loop iterations. However, the resulting hardware may be limited by the number of memory accesses that can be performed simultaneously.

Array partitioning addresses this limitation by splitting an array into independent storage elements or banks, enabling concurrent accesses.

Consider the following example:

void vector_add(
    int a[16], int b[16], int c[16])
{
#pragma HLS array_partition variable=a type=complete
#pragma HLS array_partition variable=b type=complete
#pragma HLS array_partition variable=c type=complete

    for (int i = 0; i < 16; i++) {
#pragma HLS unroll
        c[i] = a[i] + b[i];
    }
}

The unroll directive requests full loop unrolling, while array_partition distributes array elements across independent storage resources.

Together, these transformations allow the synthesis tool to implement multiple additions concurrently, without introducing memory-port bottlenecks.

Generation of Parallel Multi-Threaded Accelerators with OpenMP

Bambu supports the synthesis of parallel multi-threaded hardware accelerators from C/C++ applications annotated with OpenMP directives, using the SPARTA methodology.

SPARTA generates parallel processing cores that execute OpenMP threads. Each core can optionally support multiple hardware execution contexts, allowing it to switch between threads to tolerate long-latency operations, such as external memory accesses.

The following example parallelizes a vector addition with OpenMP:

#ifndef THREAD_NUMBER
#define THREAD_NUMBER 4
#endif

void vector_add(
    const int *a, const int *b,
    int *c, int n)
{
#pragma omp parallel for num_threads(THREAD_NUMBER)
    for (int i = 0; i < n; i++) {
        c[i] = a[i] + b[i];
    }
}

The generation of a SPARTA architecture is triggered by the -fopenmp command-line option.

The number of parallel cores is derived from the requested number of OpenMP threads (THREAD_NUMBER) and execution contexts (--context-switch) as follows:

Number of OpenMP threads = Number of cores × Contexts per core

Increasing the number of cores exposes more spatial parallelism, while increasing the number of execution contexts allows each core to interleave multiple threads, potentially improving utilization when threads stall on memory operations.

Bambu supports the following OpenMP constructs: parallel, for, parallel for, sections, section, critical, and barrier. Supported clauses include num_threads, private, firstprivate, reduction, nowait, and schedule(static[, chunk]). Nested parallel regions are also supported.

Caches

Bambu can introduce hardware caches (derived from IOb-cache) between an accelerator and its external memory interface. Caches can reduce the latency and bandwidth requirements of repeated memory accesses by retaining recently accessed data in local storage.

A cache is configured through the cache directive, coupled with an interface bundle. The --generate-interface=INFER option must also be selected.

void sum_array(
    const int *a, int *result, int n)
{
#pragma HLS interface port=a mode=m_axi \
    bundle=gmem
#pragma HLS cache bundle=gmem \
    line_count=64 line_size=16

    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
    }
    *result = sum;
}

Cache configuration options

Option Description
bundle Name of the memory interface bundle to which the cache is attached (required).
line_count Number of cache lines (required).
line_size Cache line size (required)
bus_size Bus width, from 32 to 1024 bits
ways Cache associativity
rep_policy Replacement policy: lru or tree
write_policy Write-back (wb) or write-through (wt)
num_write_outstanding Maximum configured outstanding writes

Task-Level Parallelism with Dataflow

The dataflow directive allows multiple functions to be organized into a concurrent hardware architecture.

Rather than executing every function sequentially, Bambu can preserve separate hardware modules and enable overlapping execution.

Consider a computation divided into three stages:

void load(...);
void compute(...);
void store(...);

#pragma HLS dataflow
void accelerator(...)
{
    load(...);
    compute(...);
    store(...);
}

The dataflow directive identifies accelerator as a composition of hardware submodules.

Each stage can potentially execute concurrently with the others, provided that data dependencies and communication mechanisms permit overlapping execution.

This approach is particularly useful for streaming architectures, where processing can begin before all input data has been loaded.

A framework for Hardware-Software Co-Design of Embedded Systems