please help me on Hardware mathematic functions

Hi, I am pretty new on CUDA programming. I heard that CUDA offers hardware mathematic functions which run fast. I tried to add the following line in my code

       float x = __cos(y)

where y is an automatic variable of float type.

But when I compiled the code, the error message said identifier “__cos” is undefined. I wonder if I need to include any header file or change some settings in the properties.

BTW, I use Microsoft Visual Studio to compile the code. If I turn “Use fast math” property to “Yes”, are the math functions in the program automatically converted to hardward functions? For example, is cos(y) converted to __cos(y)?

Please help me. Thanks a lot in advance.

You are looking for __cosf(), not __cos(). The trailing “f” in the function name indicates a single-precision function, in keeping with C99 naming conventions. Similarly, __expf(), __logf(), __sinf(), etc. See the CUDA C Programming Guide for a complete list.

Thanks, Njuffa. On page 163 of David Kirk & Wen-mei Hwu’s “Programming Massively Parallel Processors” book, they used __cos() and __sin(), and they called them hardware trigomometry functions. I wonder where I can get more information about those functions and how I can use them (by including some header files". Is __cos() in their book the same as __cosf()?

Thanks.

There are a number of device functions (intrinsics) that map more or less directly to hardware instructions for several single-precision math functions. A complete list can be found in the CUDA C Programming Guide, section B.7. The latest online copy can be found here:

http://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/docs/CUDA_C_Programming_Guide.pdf