I am taking my first faltering steps with CUDA Toolkit 5.0 RC using VS2010.
Separate compilation has me confused.
I tried to set up a project as a Static Library (.lib), but when I try to build it, it does not create a device-link.obj and I don't understand why.
For instance, there are 2 files:
A caller function that uses a function f
#include "thrust\host_vector.h"
#include "thrust\device_vector.h"
using namespace thrust::placeholders;
extern __device__ double f(double x);
struct f_func
{
__device__ double operator()(const double& x) const
{
return f(x);
}
};
void test(const int len, double * data, double * res)
{
thrust::device_vector<double> d_data(data, data + len);
thrust::transform(d_data.begin(), d_data.end(), d_data.begin(), f_func());
thrust::copy(d_data.begin(),d_data.end(), res);
}
And a library file that defines f
__device__ double f(double x)
{
return x+2.0;
}
If I set the option generate relocatable device code to No, the first file will not compile due to unresolved extern function f.
If I set it to -rdc, it will compile, but does not produce a device-link.obj file and so the linker fails.
If I put the definition of f into the first file and delete the second it builds successfully, but now it isn't separate compilation anymore.
How can I build a static library like this with separate source files?
[Updated here]
I called the first caller file "caller.cu" and the second "libfn.cu".
The compiler lines that VS2010 outputs (which I don't fully understand) are (for caller):
nvcc.exe
-ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include"
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include"
-G
--keep-dir "Debug"
-maxrregcount=0
--machine 32
--compile
-g
-D_MBCS
-Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd "
-o "Debug\caller.cu.obj" "G:\Test_Linking\caller.cu"
-clean
and the same for libfn, then:
nvcc.exe
-gencode=arch=compute_20,code=\"sm_20,compute_20\"
--use-local-env
--cl-version 2010
-ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"
-rdc=true
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include"
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include"
-G
--keep-dir "Debug"
-maxrregcount=0
--machine 32
--compile
-g
-D_MBCS
-Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd "
-o "Debug\caller.cu.obj" "G:\Test_Linking\caller.cu"
and again for libfn.