I do not understand the reason for OpenCL
native_ prefixed functions. The documentation says:
Functions with the native_ prefix may map to one or more native device
instructions and will typically have better performance compared to
the corresponding functions (without the native__ prefix). The
accuracy (and in some cases the input range(s)) of these functions is
Ok, so I get that
native_ functions might be slightly faster and slightly less accurate. Are there any other pros and cons? In what use case might I want to use something like
Apologies if this is a dumb question. I want to make sure I grasp the underlying reason that
native_ functions exist.
If you want to release software that is used on all possible devices you should use the normal functions because you can never know what to expect from native_ functions. Or you can make a simple test that checks if you want to use native_ or not, as an example calculate bunch of values within range of interest and see if they are close enough.
The most important part of native_ functions is that their precision is completely implementation defined. This is important because some parts of OpenCL numerical precision spec are rather stupid to be honest. As an example the spec requires sin to have relative 4 ULP of precision, which is quite funny for an oscillating function and makes implementation really hard when input ULP values grow high.
In practice the native_ implementations are usually pretty much what you would expect from the device. On GPU's the native_ functions are generally what is defined in DirectX spec. Some have even better implementations. As an example on AMD HW the native_sin function is blazingly fast compared to normal sin and from my experiences it has absolute error in order of 1 ULP of input value. On Intel integrated GPU the native_sin is quite imprecise but still within DirectX spec.
The reason native_ functions are in the spec is to allow users who do not care about the extreme precision required by OpenCL spec to use something that performs better.
tl;dr: If you can use native_ functions do it because they are in general much faster than the normal functions.