Developer Guide

Contents

Declare the
hls_float
Data Type

The
hls_float.hpp
header file provides support for arbitrary-precision floating-point numbers. The floating-point representation for
hls_float
data types adopts the same data layout as the IEEE 754 floating-point representation.
An
hls_float
variable carries an explicit sign bit and an arbitrary number of bits for the exponent and mantissa. Due to the differences in the internal math implementations and rounding errors, the results from
hls_float
operations might not always be bit-accurate compared to those produced by C++ native floating-point types with the same exponent and mantissa bit widths.
Perform the following steps to declare the
hls_float
data type:
  1. Include the
    hls_float.hpp
    header file as follows:
    #include <CL/sycl/INTEL/ac_types/hls_float.hpp>
  2. Declare your
    hls_float
    variables as follows:
    ihc::hls_float<exponent_width, mantissa_width[,rounding_mode]>
    Where, the template attributes are defined as follows:
    • exponent_width
      ,
      mantissa_width
      : The bit-width of the exponent and mantissa of the floating-point variable.
      The
      hls_float.hpp
      header file also provides aliases to declare
      bfloat16
      and
      bfloat19
      data types directly. The
      hls_float
      data type supports the following
      exponent_width
      ,
      mantissa_width
      combinations:
      Exponent- and Mantissa-Width Combinations Supported by the
      hls_float
      Data Type
      5, 10
      8, 7
      8, 10
      8, 17
      8, 23
      8, 26
      10, 35
      11, 44
      11, 52
      15, 63
      Some of these width combinations map to some commonly used floating-point formats, as listed in the following table:
      Exponent- and Mantissa-Width Setting for Various Floating-point Formats
      Floating-point Format
      exponent_width
      ,
      mantissa_width
      Setting
      IEEE 754 half-precision (
      binary16
      )
      5, 10
      bfloat16
      8, 7
      bfloat19
      8,10
      IEEE 754 single-precision (
      binary32
      )
      8. 23
      IEEE 754 double-precision (
      binary64
      )
      11, 52
      80-bit extended precision
      15, 63
    • rounding_mode
      : Optional parameter to specify the IEEE 754 rounding mode used when converting between data types. Set the rounding mode with one of the following values:
      Rounding Mode Values
      Rounding Mode
      Description
      ihc::fp_config::FP_Round::RNE
      Round to the nearest, tie break to even.
      This rounding mode is more accurate (0.5 ULP) but requires more FPGA area.
      ihc::fp_config::FP_Round::RZERO
      Round towards zero.
      This rounding mode is less accurate (1 ULP) and requires less FPGA area.
      If you do not set the
      rounding_mode
      parameter, the
      ihc::FP_Round::RNE
      rounding mode is used by default.

Math Functions Supported by
hls_float
Data Type

The
hls_float
data type supports all overloaded math operators and a limited set of the math functions provided by the
Intel® oneAPI
DPC++/C++
Compiler
. For some math operators, you can control the output's precision by using templated versions of the functions.
Due to the differences in the internal math implementations and rounding errors, the results from
hls_float
operations might not always be bit-accurate when compared to those produced by C++ native floating-point types with the same exponent and mantissa-bit widths. However, these results are validated against the infinitely accurate results.
The following additional math functions are supported through the
hls_float_math.hpp
header file:
Math Functions Provided by the
hls_float_math.hpp
header file
Function Type
Math Function
Comment
Exponential and logarithmic functions
  • ln
  • log
    2
    ,
    log
    10
  • e
    x
    ,
    2
    x
    ,
    10
    x
Supported only for
hls_float
data types with exponent width less than or equal to 15 bits and mantissa width less than or equal to 63 bits.
  • ln(1+x)
  • e
    x
    −1
Supported only for
hls_float
data types with exponent width less than or equal to 11 bits and mantissa width less than or equal to 52 bits.
Advanced functions
  • reciprocal
  • reciprocal_sqrt
  • sqrt
  • cube root
  • hypot
    (hypotenuse)
Power functions
  • pow
  • powr
  • pown
Trigonometric functions
  • sin
    ,
    cos
    ,
    sincos
  • sinpi
    ,
    cospi
  • asin
    ,
    asinpi
  • acos
    ,
    acospit
  • atan
    ,
    atanpi
    ,
    atan2

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.