Visible to Intel only — GUID: zkw1521223853620
Ixiasoft
Visible to Intel only — GUID: zkw1521223853620
Ixiasoft
5.6. Implementing Arbitrary Precision Integers
Use the Intel® FPGA SDK for OpenCL™ arbitrary precision integer extension to define integers with a custom bit-width. You can define integer custom bit-widths up to and including 64 bits.
#include "ihc_apint.h"
aoc <other command options> -I $INTELFPGAOCLSDKROOT/include/kernel_headers <my_kernel_file>
#define ap_int<d> intd_t
#define ap_uint<d> uintd_t
int10_t x_signed;
uint10_t x_unsigned;
You can declare arbitrary precision integers with widths up to 64 bits.
#pragma OPENCL EXTENSION cl_intel_arbitrary_precision_integers : enable
ap_int<d> intd_t my_signed_integer
ap_uint<d> uintd_t my_unsigned_integer
If you do operations where the bit width of the result is larger than the bit widths of the arguments, you must explicitly cast one of the arguments to the resulting bit width.
int10_t a;
int10_t b;
int20_t res;
res = a * b;
In the example, the compiler attempts to instantiate a multiplier that multiplies two 10-bit integers and put the results into another 10-bit integer. The result is then sign extended or zero extended up to 20-bits.
res = ((int20_t)a) * b
When you compile a program for x86-64 platforms, the bit widths for arbitrary precisions integers are rounded up to either 32 bits or 64 bits. When you compile a kernel for an FPGA platform, the bit widths are not rounded up and the arbitrary precision integers remain at their declared bit width.
As a result, an operation that appears to work correctly in an x86-64 program can overflow and lose precision when you compile that same operation in an FPGA kernel. The additional precision provided by bit-width rounding on x86-64 platforms masks possible overflow and precision-loss problems you might encounter when your compile your FPGA kernel.