boostorg / compute

A C++ GPU Computing Library for OpenCL
http://boostorg.github.io/compute/
Boost Software License 1.0
1.52k stars 333 forks source link

Too much precision expected of OpenCL `length()` function #844

Open etomzak opened 4 years ago

etomzak commented 4 years ago

The test_closure::triangle_area and test_extrema::max_vector_length (and possibly others) expect too much precision of the OpenCL built-in length() function when calculating the lengths of vectors.

The precision of length() is defined in ULP as <= 3 + 0.5 * ((0.5 * n) + 0.5 * (n - 1)) where n is the number of vector elements. [source] For the float4s used in triangle_area, this works out to 4.75 ULP. Given the expected result is 1.0f, the actual answer should be approximately 1.0 +/- 5.7e-07 [1]. The precision expected by the test is 1.0e-6 percent, or 1.0e-8.

That is, the triangle_area test can fail even on a conformant OpenCL implementation. The max_vector_length test has a similar problem.

[1] This doesn't take into account the division by 2 in the test, which introduces further error.