{"id":1207,"date":"2026-12-03T16:35:14","date_gmt":"2026-12-03T16:35:14","guid":{"rendered":"https:\/\/panda.deib.polimi.it\/?page_id=1207"},"modified":"2026-12-03T16:35:14","modified_gmt":"2026-12-03T16:35:14","slug":"bambu-optimizations","status":"publish","type":"page","link":"https:\/\/panda.deib.polimi.it\/?page_id=1207","title":{"rendered":"Bambu: optimizations"},"content":{"rendered":"<p><span style=\"color: #ff0000;\">NOTE: This page is a work in progress and refers to Bambu release <strong>2026.11.<\/strong><\/span><\/p>\n<h2 data-pm-slice=\"1 1 []\">Loop Unrolling and Array Partitioning<\/h2>\n<p><em>Loop unrolling<\/em> 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.<\/p>\n<p><em>Array partitioning<\/em> addresses this limitation by splitting an array into independent storage elements or banks, enabling concurrent accesses.<\/p>\n<p>Consider the following example:<\/p>\n<pre data-pm-slice=\"1 1 []\"><code class=\"language-cpp\">void vector_add(\r\n    int a[16], int b[16], int c[16])\r\n{\r\n#pragma HLS array_partition variable=a type=complete\r\n#pragma HLS array_partition variable=b type=complete\r\n#pragma HLS array_partition variable=c type=complete\r\n\r\n    for (int i = 0; i &lt; 16; i++) {\r\n#pragma HLS unroll\r\n        c[i] = a[i] + b[i];\r\n    }\r\n}<\/code><\/pre>\n<p>The <code dir=\"ltr\">unroll<\/code> directive requests full loop unrolling, while <code dir=\"ltr\">array_partition<\/code> distributes array elements across independent storage resources.<\/p>\n<p>Together, these transformations allow the synthesis tool to implement multiple additions concurrently, without introducing memory-port bottlenecks.<\/p>\n<h2>Generation of Parallel Multi-Threaded Accelerators with OpenMP<\/h2>\n<p data-pm-slice=\"1 1 []\">Bambu supports the synthesis of <em>parallel multi-threaded hardware accelerators<\/em> from C\/C++ applications annotated with OpenMP directives, using the <a href=\"https:\/\/doi.org\/10.1145\/3677035\">SPARTA<\/a> methodology.<\/p>\n<p data-pm-slice=\"1 1 []\">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.<\/p>\n<p data-pm-slice=\"1 1 []\">The following example parallelizes a vector addition with OpenMP:<\/p>\n<pre data-pm-slice=\"1 1 []\"><code class=\"language-cpp\">#ifndef THREAD_NUMBER\r\n#define THREAD_NUMBER 4\r\n#endif\r\n\r\nvoid vector_add(\r\n    const int *a, const int *b,\r\n    int *c, int n)\r\n{\r\n#pragma omp parallel for num_threads(THREAD_NUMBER)\r\n    for (int i = 0; i &lt; n; i++) {\r\n        c[i] = a[i] + b[i];\r\n    }\r\n}<\/code><\/pre>\n<p>The generation of a SPARTA architecture is triggered by the <code>-fopenmp<\/code> command-line option.<\/p>\n<p data-pm-slice=\"1 1 []\">The number of parallel cores is derived from the requested number of OpenMP threads (<code>THREAD_NUMBER<\/code>) and execution contexts (<code>--context-switch<\/code>) as follows:<\/p>\n<p><strong>Number of OpenMP threads = Number of cores \u00d7 Contexts per core<\/strong><\/p>\n<p data-pm-slice=\"1 1 []\">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.<\/p>\n<p>Bambu supports the following OpenMP constructs: <code>parallel<\/code>, <code>for<\/code>, <code>parallel for<\/code>, <code>sections<\/code>, <code>section<\/code>, <code>critical<\/code>, and <code>barrier<\/code>. Supported clauses include <code>num_threads<\/code>, <code>private<\/code>, <code>firstprivate<\/code>, <code>reduction<\/code>, <code>nowait<\/code>, and <code>schedule(static[, chunk])<\/code>. Nested parallel regions are also supported.<\/p>\n<h2>Caches<\/h2>\n<p data-pm-slice=\"1 1 []\">Bambu can introduce hardware caches (derived from <a href=\"https:\/\/github.com\/IObundle\/iob-cache\">IOb-cache<\/a>) 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.<\/p>\n<p>A cache is configured through the <code dir=\"ltr\">cache<\/code> directive, coupled with an interface bundle. The <code>--generate-interface=INFER<\/code> option must also be selected.<\/p>\n<pre><code class=\"language-cpp\">void sum_array(\r\n    const int *a, int *result, int n)\r\n{\r\n#pragma HLS interface port=a mode=m_axi \\\r\n    bundle=gmem\r\n#pragma HLS cache bundle=gmem \\\r\n    line_count=64 line_size=16\r\n\r\n    int sum = 0;\r\n    for (int i = 0; i &lt; n; i++) {\r\n        sum += a[i];\r\n    }\r\n    *result = sum;\r\n}<\/code><\/pre>\n<p><strong>Cache configuration options<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<th>Option<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td><code>bundle<\/code><\/td>\n<td>Name of the memory interface bundle to which the cache is attached (required).<\/td>\n<\/tr>\n<tr>\n<td><code>line_count<\/code><\/td>\n<td>Number of cache lines (required).<\/td>\n<\/tr>\n<tr>\n<td><code dir=\"ltr\">line_size<\/code><\/td>\n<td>Cache line size (required)<\/td>\n<\/tr>\n<tr>\n<td><code dir=\"ltr\">bus_size<\/code><\/td>\n<td>Bus width, from 32 to 1024 bits<\/td>\n<\/tr>\n<tr>\n<td><code dir=\"ltr\">ways<\/code><\/td>\n<td>Cache associativity<\/td>\n<\/tr>\n<tr>\n<td><code dir=\"ltr\">rep_policy<\/code><\/td>\n<td>Replacement policy: <code dir=\"ltr\">lru<\/code> or <code dir=\"ltr\">tree<\/code><\/td>\n<\/tr>\n<tr>\n<td><code dir=\"ltr\">write_policy<\/code><\/td>\n<td>Write-back (<code dir=\"ltr\">wb<\/code>) or write-through (<code dir=\"ltr\">wt<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><code dir=\"ltr\">num_write_outstanding<\/code><\/td>\n<td>Maximum configured outstanding writes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Task-Level Parallelism with Dataflow<\/h2>\n<p>The <code dir=\"ltr\">dataflow<\/code> directive allows multiple functions to be organized into a concurrent hardware architecture.<\/p>\n<p>Rather than executing every function sequentially, Bambu can preserve separate hardware modules and enable overlapping execution.<\/p>\n<p>Consider a computation divided into three stages:<\/p>\n<pre><code class=\"language-cpp\">void load(...);\r\nvoid compute(...);\r\nvoid store(...);\r\n\r\n#pragma HLS dataflow\r\nvoid accelerator(...)\r\n{\r\n    load(...);\r\n    compute(...);\r\n    store(...);\r\n}<\/code><\/pre>\n<p>The <code dir=\"ltr\">dataflow<\/code> directive identifies <code dir=\"ltr\">accelerator<\/code> as a composition of hardware submodules.<\/p>\n<p>Each stage can potentially execute concurrently with the others, provided that data dependencies and communication mechanisms permit overlapping execution.<\/p>\n<p>This approach is particularly useful for streaming architectures, where processing can begin before all input data has been loaded.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/panda.deib.polimi.it\/?page_id=1207\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Bambu: optimizations<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":101162,"featured_media":0,"parent":31,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"footnotes":""},"class_list":["post-1207","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v29.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bambu: optimizations - panda.deib.polimi.it<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/panda.deib.polimi.it\/?page_id=1207\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bambu: optimizations - panda.deib.polimi.it\" \/>\n<meta property=\"og:description\" content=\"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 &hellip; Continue reading Bambu: optimizations &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/panda.deib.polimi.it\/?page_id=1207\" \/>\n<meta property=\"og:site_name\" content=\"panda.deib.polimi.it\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@PandA4Design\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/panda.deib.polimi.it\\\/?page_id=1207\",\"url\":\"https:\\\/\\\/panda.deib.polimi.it\\\/?page_id=1207\",\"name\":\"Bambu: optimizations - panda.deib.polimi.it\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/panda.deib.polimi.it\\\/#website\"},\"datePublished\":\"2026-12-03T16:35:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/panda.deib.polimi.it\\\/?page_id=1207#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/panda.deib.polimi.it\\\/?page_id=1207\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/panda.deib.polimi.it\\\/?page_id=1207#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/panda.deib.polimi.it\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bambu\",\"item\":\"https:\\\/\\\/panda.deib.polimi.it\\\/?page_id=31\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Bambu: optimizations\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/panda.deib.polimi.it\\\/#website\",\"url\":\"https:\\\/\\\/panda.deib.polimi.it\\\/\",\"name\":\"panda.deib.polimi.it\",\"description\":\"A framework for Hardware-Software Co-Design of Embedded Systems\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/panda.deib.polimi.it\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bambu: optimizations - panda.deib.polimi.it","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/panda.deib.polimi.it\/?page_id=1207","og_locale":"en_US","og_type":"article","og_title":"Bambu: optimizations - panda.deib.polimi.it","og_description":"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 &hellip; Continue reading Bambu: optimizations &rarr;","og_url":"https:\/\/panda.deib.polimi.it\/?page_id=1207","og_site_name":"panda.deib.polimi.it","twitter_card":"summary_large_image","twitter_site":"@PandA4Design","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/panda.deib.polimi.it\/?page_id=1207","url":"https:\/\/panda.deib.polimi.it\/?page_id=1207","name":"Bambu: optimizations - panda.deib.polimi.it","isPartOf":{"@id":"https:\/\/panda.deib.polimi.it\/#website"},"datePublished":"2026-12-03T16:35:14+00:00","breadcrumb":{"@id":"https:\/\/panda.deib.polimi.it\/?page_id=1207#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/panda.deib.polimi.it\/?page_id=1207"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/panda.deib.polimi.it\/?page_id=1207#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/panda.deib.polimi.it\/"},{"@type":"ListItem","position":2,"name":"Bambu","item":"https:\/\/panda.deib.polimi.it\/?page_id=31"},{"@type":"ListItem","position":3,"name":"Bambu: optimizations"}]},{"@type":"WebSite","@id":"https:\/\/panda.deib.polimi.it\/#website","url":"https:\/\/panda.deib.polimi.it\/","name":"panda.deib.polimi.it","description":"A framework for Hardware-Software Co-Design of Embedded Systems","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/panda.deib.polimi.it\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=\/wp\/v2\/pages\/1207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=\/wp\/v2\/users\/101162"}],"replies":[{"embeddable":true,"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1207"}],"version-history":[{"count":2,"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=\/wp\/v2\/pages\/1207\/revisions"}],"predecessor-version":[{"id":1209,"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=\/wp\/v2\/pages\/1207\/revisions\/1209"}],"up":[{"embeddable":true,"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=\/wp\/v2\/pages\/31"}],"wp:attachment":[{"href":"https:\/\/panda.deib.polimi.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}