0

I am using CUDA/C++ with windows 7 and VS2013. My GPU has cc 5.2 and I compile my code with this cc. In my code I use sin(), cos() and sqrt functions inside my device kernels and everything is working fine. Now I want to use atan2 function listed in CUDA documentation. However, I cannot build my code because of the error:

error : calling a __host__ function("atan2<int, int> ") from a __global__        function("CalcPsi") is not allowed

As far as I understood, this function is recognized on host only. I tried to search CUDA documentation and SO, but didn't find any information what's wrong. I wonder if I am missing some headers of didn't link my project against some static libraries. I include the following headers to my project:

#include <cufft.h>
#include <cuda_runtime.h>
#include <iostream>
#include <cuda.h> 

Here is the full output.

1>------ Build started: Project: EBeqationSolverdoubleNematic, Configuration:     Debug x64 ------
1>  Compiling CUDA source file GPU.cu...
1>  
1>  C:\programs\misha\cuda\Projects\Edwards-    Berris\EBeqationSolverdoubleNematic\EBeqationSolverdoubleNematic>"C:\Program     Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe" -    gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env --cl-version     2013 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio     12.0\VC\bin\x86_amd64"  -I"C:\Program Files\MATLAB\R2012a\extern\include" -    I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" -I"C:\Program     Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include"  -G   --keep-dir x64\Debug     -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DWIN32 -DWIN64 -    D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o     x64\Debug\GPU.cu.obj "C:\programs\misha\cuda\Projects\Edwards-    Berris\EBeqationSolverdoubleNematic\EBeqationSolverdoubleNematic\GPU.cu" 
1>C:/programs/misha/cuda/Projects/Edwards-    Berris/EBeqationSolverdoubleNematic/EBeqationSolverdoubleNematic/GPU.cu(254):     error : calling a __host__ function("atan2<int, int> ") from a __global__     function("CalcPsi") is not allowed
1>  GPU.cu
1>C:\Program Files     (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA     6.5.targets(593,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU     Computing Toolkit\CUDA\v6.5\bin\nvcc.exe" -    gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env --cl-version     2013 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio     12.0\VC\bin\x86_amd64"  -I"C:\Program Files\MATLAB\R2012a\extern\include" -    I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" -I"C:\Program     Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include"  -G   --keep-dir x64\Debug     -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DWIN32 -DWIN64 -    D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o     x64\Debug\GPU.cu.obj "C:\programs\misha\cuda\Projects\Edwards-    Berris\EBeqationSolverdoubleNematic\EBeqationSolverdoubleNematic\GPU.cu"" exited     with code 2.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Thanks,

Mikhail

Community
  • 1
  • 1
Mikhail Genkin
  • 3,247
  • 4
  • 27
  • 47
  • 2
    The [device function](http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#mathematical-functions-appendix) expects `float` or `double` types. So cast your arguments to `float` or `double` and you should have better luck. The compiler doesn't find a device prototype for the `int`,`int` arguments, so it tries to use the host library version for `int`, `int`, and that won't work in device code. And you should include `` also. – Robert Crovella Apr 18 '16 at 21:14
  • 1
    That should be cast to `double` and use `atan2` or to `float` and use `atan2f`, although I think `float` would work with `atan2` also. I'm pretty sure this is a duplicate of various other questions – Robert Crovella Apr 18 '16 at 21:21
  • Oh, yes, now it is working. Thanks – Mikhail Genkin Apr 18 '16 at 21:22
  • 2
    The CUDA math library functions are overloaded for `float` and `double`, so you can call `atan2(float, float)` or `atan2(double, double)`. `int` overloads of math functions are available on the host because either the latest C++ standard added them or this is a gcc extensions; my memory is hazy which it is. You may want to file a feature request with NVIDIA for `int` overloads of the device-side math functions. – njuffa Apr 18 '16 at 22:23

0 Answers0