Developer Guide

FPGA Optimization Guide for Intel® oneAPI Toolkits

ID 767853
Date 7/13/2023
Public

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

Document Table of Contents

Floating-Point Pragmas

Use fp contract and fp reassociate pragmas to influence the intermediate rounding and conversions of floating-point operations and the ordering of arithmetic operations in your kernel at finer granularity than the Intel® oneAPI DPC++/C++ Compiler flags.

NOTICE:

Starting with the oneAPI 2021.2 release, fast math is enabled by default, allowing the Intel® oneAPI DPC++/C++ Compiler to make various out-of-box floating point math (float or double) optimizations. With these optimizations enabled, you might observe different bitwise results when compared to results from the oneAPI 2021.1 release or from GCC. The tradeoff is done to improve performance and area of your design. Automatic dot product inference and floating-point contraction for double precision math are two key noticeable FPGA optimizations that save a large amount of FPGA area and improve performance/latency. To return to the same precision as the oneAPI 2021.1 release or GCC, use the following compiler options:

  • For Linux: -no-fma -fp-model=precise
  • For Windows: /Qfma- /fp:precise

For more information about these options, refer to -fp-model, fp and fma, Qfma topics in the Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference.

NOTE:
  • You can place fp contract and fp reassociate pragma statements inside any compound statement (brace-enclosed sequences of statements), outside of all functions (file scope), or at the start of a function within the curly braces. For example:
    {
      #pragma clang fp reassociate(on)
      float temp1 = 0.0f, temp2 = 0.0f;
      temp1 = accessorA[0] + accessorB[0];
      temp2 = accessorC[0] + accessorD[0];
      accessorRES[0] += temp1 * temp2;
    }
  • The -fp-model=<value> command option and the floating-point pragmas do not affect performance and area of designs implemented with ap_float data types.

fp contract Pragma

The fp contract pragma controls whether the compiler can skip intermediate rounding and conversions mainly between double precision arithmetic operations. If multiple occurrences of this pragma affect the same scope of your code, the pragma with the narrowest scope takes precedence.

Syntax

#pragma clang fp contract(fast|off|on)

where:

State Description
fast Allows the fusing of multiply and add instructions into an FMA, but it might violate the language standard.

With fast math enabled by default, the fp contract pragma is set to fast by default. This allows the compiler to skip intermediate rounding and conversions mainly between double-precision arithmetic operations.

off Prohibits the compiler from fusing multiple floating-point operations.
on Fuses floating-point operations (multiply and add) within the same statement to form FMAs.

fp reassociate Pragma

The fp reassociate pragma controls the relaxing of the order of floating-point arithmetic operations within the code block that this pragma is applied to. With reordering, the compiler can optimize the hardware structure, which improves the performance of your kernel. If multiple occurrences of this pragma affect the same scope of your code, the pragma with the narrowest scope takes precedence.

Syntax

#pragma clang fp reassociate(on|off)

Where:

State Description
on

Enables the compiler to reorder floating-point operations to improve performance and on-chip area.

With fast math enabled by default, the fp reassociate pragma is set to on by default.

off

Prohibits the compiler from reordering floating-point operations to improve performance and on-chip area.