Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUDA exp() expf() and __expf()

Tags:

cuda

How to optimize the exp function in cuda? What are the differences between the following in CUDA??

   exp()
   expf()
   __expf()
like image 225
user570593 Avatar asked Aug 31 '11 13:08

user570593


People also ask

What is expf?

The expf() function – a variation of exp() – computes e raised to the power of x for floating-point exponents in C. Mathematical Representation.

How do you do Cuda in math?

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.


Video Answer


2 Answers

The differences are explained in the CUDA C Programming Guide, appendix D.

  • exp() should be used for double precision, although should be overloaded for single
  • expf() 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).
like image 98
Tom Avatar answered Oct 01 '22 10:10

Tom


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.

like image 43
Dan Avatar answered Oct 01 '22 12:10

Dan