Intel® High Level Synthesis Compiler Pro Edition: Reference Manual

ID 683349
Date 12/04/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

3.2. C and C++ Libraries

The Intel® High Level Synthesis (HLS) Compiler provides a number of header files to provide FPGA implementations of certain C and C++ functions.
Intel® HLS Compiler Pro Edition Header Files Summary
HLS Header File Description
HLS/hls.h Required for component identification and component parameter interfaces.
HLS/math.h Includes FPGA-specific definitions for the math functions from the math.h for your operating system.
HLS/extendedmath.h Includes additional FPGA-specific definitions of math functions not in math.h.
HLS/ac_int.h Provides FPGA-optimized arbitrary width integer support.
HLS/ac_fixed.h

Provides FPGA-optimized arbitrary precision fixed point support.

HLS/ac_fixed_math.h

Provides FPGA-optimized arbitrary precision fixed point math functions.

HLS/ac_complex.h Provides FPGA-optimized complex number support.
HLS/hls_float.h Provides FPGA-optimized arbitrary-precision IEEE-754 compliant floating-point number support.
HLS/hls_float_math.h Provides FPGA-optimized floating-point math functions.
HLS/math_dsp_control.h Provides the ihc::math_dsp_control function to control the hardware implementation for supported data types and math functions at a local-scope.
HLS/stdio.h Provides printf support for components so that printf statements work in x86 emulations, but are disabled in component when compiling to an FPGA architecture.
<iostream> To use cout and cerr in your component, guard the statements with the HLS_SYNTHESIS macro.

math.h

To access functions in math.h from your component function, include the "HLS/math.h" file in your source code. The header ensures that the components call the hardware versions of the math functions.

For more information about supported math.h functions, see Supported Math Functions.

stdio.h

Synthesized component functions generally do not support C and C++ standard library functions such as FILE objects.

A component can call printf by including the header file HLS/stdio.h. This header changes the behavior of printf depending on the compilation target:

  • For compilation that targets the x86-64 architecture (that is, -march=x86-64 ), the printf call behaves as normal.
  • For compilation that targets the FPGA architecture (that is, ‑march="<FPGA_family_or_part_number>"), the compiler removes the printf call.

If you use printf in a component function without first including the #include "HLS/stdio.h" line in your code, you get an error message similar to the following error when you compile hardware to the FPGA architecture:

$ i++ -march="<FPGA_family_or_part_number>" test.cpp
Error: HLS gen_qsys FAILED.
See ./a.prj/dut.log for details.

You can use C and C++ standard library functions such as fopen and printf as normal in all testbench functions.

iostream

The C++ standard output streams (cout or cerr) output streams are not supported in RTL, but you can use them to debug your component in emulation. However, you must guard any cout or cerr statements with the HLS_SYNTHESIS macro.

This macro ensures that statements in a component work in x86 emulations (that is, -march=x86-64), but are disabled in the component when compiling it to an FPGA architecture (that is, -march="<FPGA_family_or_part_number>" ). For example:
#include "HLS/hls.h"
#include <iostream>

component int debug_component (int a){
#ifndef HLS_SYNTHESIS
    std::cout << "input value: " << a << std::endl;
#endif
    return a;
}

If you attempt to use cout or cerr in a component function without guarding the line in your code with the HLS_SYNTHESIS macro , you get an error message similar to the following error when you compile hardware to the FPGA architecture:

$ i++ -march="<FPGA_family_or_part_number>" test.cpp 
test.cpp:5: Compiler Error: Cannot synthesize std::cout used inside of a component.
HLS Main Optimizer FAILED.