The problem is not that nvcc itself doesn’t compile the following code, but whenever I try to use a member of Vectror3 in my code, I get the following output from the compiler:
1>Compiling CPU segment (Microsoft VC++ Environment)
1>Electrostatics.cu
1>Electrostatics.cudafe1.gpu
1>f:\electromagnetism sim\electromag\gpgpu segment\Electrostatics kernel.cuh(140): error: struct “_Z7Vector3IdE” has no field “__T241”
1>
1>f:\electromagnetism sim\electromag\gpgpu segment\Electrostatics kernel.cuh(140): error: struct “_Z7Vector3IdE” has no field “__T241”
1>
1>2 errors detected in the compilation of “Electrostatics.cpp2.i”.
[codebox]
template
struct Vector2
{
T x, y;
};
template
struct Vector3
{
union
{
Vector2 xy;
struct
{
T x, y;
};
};
T z;
};
global void kernel(params)
{
Vector3<float> vector;
vector.x = 0; // This is where the error points to
}
[/codebox]
It seems that nvcc compiles the code fine, but some later stage fails. I believe nvcc has some problems with unions inside templates, although the code compiles perfectly fine with any other C++ compiler. Even if I name the struct or remove it from the union, nvcc will still fail, but removing the union solves the problem. The error points to a line within the kernel. If I just declare Vector3 as a structure of{x, y, z}, everything compiles flawlessly.
Attempted to compile with
-
CUDA toolkit 2.1 x64
-
Visual Studio 2008
-
CUDA SDK 2.1 x64
-
Windows Server Enterprise x64