Floating-Point design coding style and skills

Although usually Fixed-Point is faster and more efficient than the FloaTIng-Point (floating point) algorithm, it is sometimes required to implement FloaTIng-Point. This is because Fixed-Point's limited data dynamic range requires in-depth analysis to determine the pattern of data bit width variation throughout the design. In order to achieve optimized QoR, many different types of Fixed-Point intermediate variables are introduced. While FloaTIng-Point has a larger data dynamic range, only one data type advantage is needed in many algorithms.

The Xilinx Vivado HLS tool supports the C/C++ IEEE-54 standard single-precision and double-precision floating-point data types, making it easy to quickly convert the C/C++ FloaTIng-Point algorithm into RTL code. At the same time, in order to achieve the user's desired FPGA resources and performance, you need to pay attention to the C/C++ coding style and skills when using Vivado HLS directives.

Coding style

1.1 Single and Double Precision Floating Point Math Functions

#include
Float example(float var)
{
Return log(var); // double precision natural logarithm
}

In the C design, in this example, the RTL implementation generated by Vviado HLS converts the input to double-precision floating point, computes the natural logarithm based on double-precision floating-point, and then converts the double-precision floating-point output to single-precision floating-point.

#include
Float example(float var)
{
Return logf(var); // single precision natural logarithm
}
In the C design, logf is a single-precision natural logarithm. In this example, the RTL implementation generated by Vviado HLS will calculate the natural logarithm based on single-precision floating-point, and there is no single-double precision interconversion between input and output.

1.2 Floating point optimization

Let's look at an example. Three are similar in algebra, but they are combined in Vivado HLS with three completely different results.

Void example(float *m0, float *m1, float *m2, float var)
{
*m0 = 0.2 * var; // double precision floating point multiplication, single and double precision type conversion
*m1 = 0.2f * var; // single precision floating point multiplication
*m2 = var / 20.0f; // single precision floating point division
}

Vivado HLS combines day m0, m1, m2 into different RTL implementations.
Since 0.2 is a double-precision number that cannot be accurately characterized, the m0 operation is combined into a double-precision floating-point multiply by Vivado HLS, and var is converted to double precision, and then the double-precision multiply output m0 is converted to single precision.
In particular, if you want Vivado HLS to combine single precision Changshu, you need to add f after the constant, such as 0.2f. Thus m1 is combined into a single precision multiply output. Similarly, m2 will be synthesized by Vivado HLS into a single precision division output.

Let's look at another example.

Void example(float *m0, float *m1, float var)
{
*m0 = 0.2f * 5.0f * var; // *m0 = var; constant multiplication is optimized
*m1 = 0.2f * var * 5.0f; // two double precision floating point multiplications
}

Let's look at another example.

Void example(float *m0, float *m1, float var)
{
*m0 = 0.5 * var; //
*m1 = var/2; //
}
The m0 operation is combined into a double-precision floating-point multiply by Vivado HLS, and var is converted to double precision, and then the double-precision multiply output m0 is converted to single precision.

The m1 operation is combined into a simple right shift operation by Vivado HLS. So if the user wants to divide var by 2, it is written as an expression of m1 instead of an expression of m0.

Parallelism and resource reuse Because of the integer type of floating-point operations, fixed-point operations consume more resources. Vivado HLS will try to implement floating-point operations with more efficient resources. In the case of data correlation and constraint permission, some floating-point arithmetic units will be reused in Vivado HLS. To illustrate this, let's look at a simple example of four floating-point additions. Vivado HLS multiplexes a floating-point adder to implement four floating-point additions serially.
Void example(float *r, float a, float b,
Float c, float d)
{
*r = a + b + c + d;
}

Special Cable

Special Cable,Cable Special,Special Electrical Cables,Special Cables Industries

Shenzhen Bendakang Cables Holding Co., Ltd , https://www.bdkcables.com