Intel® FPGA SDK for OpenCL™ Pro Edition: Programming Guide

ID 683846
Date 3/28/2022
Public

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

Document Table of Contents

5.2.10. Floating Point Optimizations (fp contract and fp reassociate Pragma)

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® FPGA SDK for OpenCL™ Offline Compiler command options.

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)
  T=(1.0f-a)*(1.0f-b)*Ti0j0+a*(1.0f-b)*Ti1j0+(1.0f-a)*b*Ti0j1+a*b*Ti1j1;
}

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.

This pragma has the following syntax:
#pragma clang fp contract(state)

where, the state parameter can be one of the following values:

Table 2.   state Parameter Values
Value Description
off

Turns off any permissions to fuse instructions into FMAs.

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

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.

This pragma has the following syntax:

#pragma clang fp reassociate(state)

where, the state parameter can be one of the following values:

Table 3.   state Parameter Values
Value Description
on

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

off

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