Using math.h under CUDA version 4

I need to use some functions from math.h in my device code. From my reading of recent documents etc this is possible with Version 4.0, which I have.
My example code is
#include <math.h>

global void kernel(void)
{
exp(1);
}

int main(void)
{
kernel<<<1,1>>>();
return 0;
}

I run nvcc and it gives me

simple_kernel.cu(4): error: calling a host function("std::exp ") from a device/global function(“kernel”) is not allowed

How can I get the device side version of my math functions in the device side code.

Sorry if this is awfully simple, Im rather a newbie at this.
Thanks for your time.

Thanks for your time

Try using [font=“Courier New”]exp(1.0)[/font] instead.

CUDA only supplies the overloaded versions

float exp(float);
double exp(double);

Best I can tell from the 1998 ISO C++ standard (section 26.5), there are only three flavors of exp() defined: float, double, long double. CUDA does not support the long double type, so except for that version CUDA supports all overloaded versions required by the C++ standard.

It looks like your host compiler supplies exp(int) as an extension to the standard. The CUDA math library includes the host’s math.h header file. The call to exp(int) in device code therefore does not match any of the CUDA supplied prototypes, but it does match the prototype from the host, which then leads to the diagnostic about a host function being invoked from device code.

As tera said, you would want to invoke exp() either with a float argument, e.g. exp(1.0f), or a double argument, e.g. exp(1.0).

Thanks!Thanks!