Look at this code, please:
File test.cu:
[codebox]
struct S{};
template global void template_test() {
float4 f = make_float4( 0, 0, 0, 0 );
//int a;
}
void test() {
dim3 g( 1, 1, 1 );
dim3 b(1, 1, 1 );
template_test<S><<<g,b>>>();
}
[/codebox]
It compiles without errors.
Now uncomment //int a and comment float4 :
[codebox]
struct S{};
template global void template_test() {
//float4 f = make_float4( 0, 0, 0, 0 );
int a;
}
void test() {
dim3 g( 1, 1, 1 );
dim3 b(1, 1, 1 );
template_test<S><<<g,b>>>();
}
[/codebox]
Nvcc output:
[codebox]
1>Executing tool NVCC_CUDA on file d:\SciArtSVN\Sciart\PluginSystem\GpuBoard\test.cu, result Tmp\Debug\test.obj
1>test.cu
1>d:/SciArtSVN/Sciart/PluginSystem/GpuBoard/test.cu(5): warning: variable “a” was declared but never referenced
1> detected during instantiation of “void template_test() [with T=S]”
1>(11): here
1>tmpxft_00000d30_00000000-3_test.cudafe1.gpu
1>tmpxft_00000d30_00000000-8_test.cudafe2.gpu
1>d:/SciArtSVN/Sciart/PluginSystem/GpuBoard/test.cu(5): warning: variable “a” was declared but never referenced
1>tmpxft_00000d30_00000000-3_test.cudafe1.cpp
1>tmpxft_00000d30_00000000-13_test.ii
1>d:/SciArtSVN/Sciart/PluginSystem/GpuBoard/test.cu(11) : error C2065: ‘template_test__entry’ : undeclared identifier
1>d:/SciArtSVN/Sciart/PluginSystem/GpuBoard/test.cu(11) : error C2275: ‘S’ : illegal use of this type as an expression
1> d:/SciArtSVN/Sciart/PluginSystem/GpuBoard/test.cu(1) : see declaration of ‘S’
1>d:/SciArtSVN/Sciart/PluginSystem/GpuBoard/test.cu(11) : error C2059: syntax error : ‘)’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(10) : error C2275: ‘S’ : illegal use of this type as an expression
1> d:/SciArtSVN/Sciart/PluginSystem/GpuBoard/test.cu(1) : see declaration of ‘S’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(10) : error C2059: syntax error : ‘)’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(10) : error C2275: ‘S’ : illegal use of this type as an expression
1> d:/SciArtSVN/Sciart/PluginSystem/GpuBoard/test.cu(1) : see declaration of ‘S’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(10) : error C2059: syntax error : ‘)’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(23) : error C2143: syntax error : missing ‘;’ before ‘<’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(23) : error C2182: ‘__wrapper__device_stub_template_test’ : illegal use of type ‘void’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(23) : error C2988: unrecognizable template declaration/definition
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(23) : error C2059: syntax error : ‘<’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(25) : error C2143: syntax error : missing ‘;’ before ‘{’
1>C:\DOCUME~1\Sieciech\LOCALS~1\Temp/tmpxft_00000d30_00000000-3_test.cudafe1.stub.c(25) : error C2447: ‘{’ : missing function header (old-style formal list?)
[/codebox]
What the hell is going on??
I coudn’t use Struct as template arguments in my kernels,
any help will be appreciated