CUDA Infernal Error assertion failed: gen_initializer_consta

Hi everyone

I’m getting a very unusual error when compiling with CUDA. The code seems to compile but then cudafe++ crashes with the following error:

\projects\cuda_test\vecMath.h(21): internal error: assertion failed: gen_initializer_constant: ran out of fields

The error points to a specific line in the code, so I am including that section of the code. I was not able to find this error code anywhere (Google included), so I’m hoping someone might be able to shed some light.

I’m using Visual studio 2005.

Oh, this is the command line I’m using to call nvcc:

(CUDA_BIN_PATH_32)\nvcc.exe" -ccbin "(VCInstallDir)bin” -c -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/O2,/Zi,/MT -I"(CUDA_INC_PATH)" -I./ -I../../common/inc -o (ConfigurationName)\CUDA_Main.obj CUDA_Main.cu

(I actually took one of the projects in the SDK and replaced the code with my code)

Thanks in advance for any help! :)

template <class T>

__device__ __host__ inline Vector3<T> vecGet3D(const Vector3<T> head, const Vector3<T> tail)

{

	Vector3<T> result = {(head.x - tail.x), (head.y - tail.y), (head.z - tail.z)};//Error points to this line

	return result;

}

where Vector3 is given by:

template <class T>

struct Vector3

{

	T x, y, z;

};

Visual Studio output:

1>------ Build started: Project: CUDA_Test, Configuration: Release Win32 ------

1>Performing Custom Build Step

1>CUDA_Main.cu

1>tmpxft_00000e54_00000000-3_CUDA_Main.cudafe1.gpu

1>tmpxft_00000e54_00000000-8_CUDA_Main.cudafe2.gpu

[b]

1>z:\projects\cuda_test\vecMath.h(21): internal error: assertion failed: gen_initializer_constant: ran out of fields

[/b](D:/Bld/rel/gpgpu/toolkit/r2.0/compiler/edg/EDG_3.9/src/cp_gen_be.c, line 3295)

1>1 catastrophic error detected in the compilation of “D:\LOCALS~1\Temp/tmpxft_00000e54_00000000-6_CUDA_Main.cpp1.ii”.

1>Compilation aborted.

1>This application has requested the Runtime to terminate it in an unusual way.

1>Please contact the application’s support team for more information.

1>Build log was saved at “file://z:\projects\CUDA_Test\Release\BuildLog.htm”

1>CUDA_Test - 1 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

EDIT: Now there is one Google result for:

internal error: assertion failed: gen_initializer_constant:

It points to this page. :magic:

Doing an explicit specialization of Vector3 fixed the problem. It seems that cudafe does not like generic templates, but by specializing the utilised types, i no longer complains. With this simple fix, there is no need to rewrite any code.

#ifdef __CUDACC__

template<>

struct Vector3<float>

{

	float x, y, z;

};

#endif

Templates mostly work but aren’t officially supported just yet…

(also infernal error would be awesome, noted for my own special debugging routines)

“internal” to NVCC is “infernal” to user… :)

It was infernal when I was writing my first CUDA program, and did not know what to do. For a few days, I though all hope was lost, untill I started messing with the templates.

OK, we have a newer version of CUDA, which solves some problems, but I still use a workaround I found, and I think I mentioned in other threads as well I’ll put it here for any Googler that hits on this thread.

Since nvcc still complains about returning a template, it is possible to shut it up by explicitly specializing it. So in the example, if I use the ‘float’ template, I can get rid of the error by explicitly specializing the template for the type float. I need to do that for every type I will use. It isn’t the prettyest solution but I do not have to rewrite the template functions for every type.

[codebox]

template

struct Vector3

{

T x, y, z;

};

template <>

struct Vector3

{

float x, y, z;

};

[/codebox]