Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Floating-point support in Altera OpenCL compiler

Dear users,

I wanted to make a comment regarding the floating-point support Altera's OpenCL provides. The compiler provides a complete coverage of floating-point operations, both in single and double precision. The single-precision floating point operations are conformant to the OpenCL 1.0 standard, while the double-precision functions are not at the moment. The compiler supports all vector sizes for these operations.

One item worthy of note is that the compiler may infer a double-precision operation where you may have wanted to use a single-precision operation. This happens in accordance to the C99 standard and how arguments are promoted. For example,

__kernel void test1(__global float *x, __global float *y)

{

int i = get_global_id(0);

y = pow(x, 5.0);

}

may have been intended to use a single-precision pow function, since the variable input is of type float. However, the specification of the constant is actually understood to be double-precision, and thus the compiler sees the function call with arguments

pow(float, double)

and the only legal argument promotion is to pow(double, double). To obtain the desired, and conformant, functionality the kernel should be written as follows:

__kernel void test1(__global float *x, __global float *y)

{

int i = get_global_id(0);

y = pow(x, 5.0f);

}

Now, the second argument is also a single-precision argument and the compiler will correctly invoke the single-precision pow function and produce a conformant result.
No RepliesBe the first to reply