How to optimize the exp function in cuda? What are the differences between the following in CUDA??
exp()
expf()
__expf()
The expf() function – a variation of exp() – computes e raised to the power of x for floating-point exponents in C. Mathematical Representation.
Available to any CUDA C or CUDA C++ application simply by adding “#include math. h” in your source code, the CUDA Math library ensures that your application benefits from high performance math routines optimized for every NVIDIA GPU architecture.
The differences are explained in the CUDA C Programming Guide, appendix D.
exp()
should be used for double precision, although should be overloaded for singleexpf()
should be used for single precision (float
)__expf()
is the fast-math version, the performance is faster with some loss of precision (dependent on the input value, see the guide for more details).Generally exp()
is for doubles, expf()
for floats and both are slightly slower than __exp()
which is available as a hardware operation. The performance gain usually comes at the cost of accuracy but unless you are really concerned about accuracy it shouldn't be a problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With