CUDA has supported pow (double, int)
in device code since proper double-precision support was added around 2008. This was a required function since at least the C++98 standard (ISO/IEC 14882 section 26.5). Here is a complete example program incorporating OP's function, with error checking omitted for brevity:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
__device__ double Len(double a, double b)
{
return pow(a, 2) + pow(b, 2);
}
__global__ void kernel (double a, double b)
{
printf ("len = %23.16e\n", Len(a, b));
}
int main (void)
{
kernel<<<1,1>>>(3,4);
cudaDeviceSynchronize();
return EXIT_SUCCESS;
}
This compiles without errors on
CUDA 9.2 with MSVS 2010 (Microsoft (R) C/C++ Optimizing Compiler Version 16.00.40219.01 for x64
) on Windows 7
CUDA 11.1 with MSVS 2019 (Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29112 for x64
) on Windows 10
I compiled for release and debug builds as follows (arguments in curly braces for debug build):
nvcc -o pow_dbl_int.exe {-g -G} pow_dbl_int.cu
The executable when run produces this output:
len = 2.5000000000000000e+01
If this example program does not compile correctly with the command line as shown, I would suspect that there is something messed up with the MSVS installation or the CUDA installation. In my practice, I find it generally beneficial to first install MSVS and then CUDA, so CUDA can integrate properly into MSVS when installed.
Since OP apparently installed a version of MSVS that shipped only a few days ago on November 10, 2020, there is also a possibility of an incompatibility between a host compiler header file and a CUDA header file, which is the reason why CUDA has historically imposed tight checks for supported host compiler versions (not sure whether it does so now). I note that Microsoft has since released MSVS 2019 16.8.1, with a release date of November 12, 2020.
As noted in multiple comments and also in the CUDA Best Practices Guide, squaring is more easily accomplished with just a multiply, and there is no need to invoke pow()
.