3.5.1.32 Software Macros
(Ask a Question)__SYNTHESIS__
Macro
__SYNTHESIS__
macro is defined in SmartHLS during synthesis. This provides a convenient way to exclude non-synthesizable code without removing/commenting the code itself. In the following example, the assertion header and statement are ignored during synthesis:#ifndef __SYNTHESIS__ #include <assert.h> #endif void func(int A[10], int N) { #pragma HLS function top #ifndef __SYNTHESIS__ assert(N < 10); #endif return A[N]; }
__SYNTHESIS__
macro is useful to exclude debugging and system calls, it can change the results between the software and the synthesized Verilog if the excluded code changes the functionality. This can introduce errors or unexpected behaviour in simulation / co-simulation. Use the __SYNTHESIS__
macro carefully and make sure it does not change the functionality.HAS_ACCELERATOR
Macro
For SoC projects where different code needs to be called depending on if hardware accelerators are used, the HAS_ACCELERATOR
macro can be used. For example, SoC accelerators using DMA transfer need their argument buffers to be initialized using hls_alloc
(see Memory Allocation Library), where as when the function is not accelerated (the software version is run), a simple malloc
will suffice.
#ifdef HAS_ACCELERATOR // Set up a hardware-specific buffer int * InputBuffer = hls_alloc(...); ... #else // Set up a software-specific buffer int * InputBuffer = malloc(...); ... #endif accelearted_function(InputBuffer);
COSIM_EARLY_EXIT
Macro
For projects that invoke accelerated functions many times, Co-Simulation can take a long time due to simulating each accelerated function call. The COSIM_EARLY_EXIT
macro can be used to trigger an early exit for Co-Simulation only. For example, in the following code, Co-Simulation will only run the accelerator 10 times, while running in softwareor SoC-specific features will run the accelerator 100 times.
for (int i = 0; i < 100; i++) { #ifdef COSIM_EARLY_EXIT if (i == 10) break; #endif // Call the accelerated function accelerated_function(...); ... }