Nvcc compiler problem Nvcc hangs during compilation of given piece of code

To manage this one can create sample *.cu file with following code and try to compile it by means of nvcc compiler using the command string in comment.

It is worth to note that /O2 key is important to see the effect.

Could you check that the same effect takes place on your machines?

[codebox]/************************************************************


sample.cu

This is an example of the buggy CUDA program.

Nvcc compiler hangs during compilation. CUDA version 2.1 release.

File should be compiled with

“C:\CUDA\bin\nvcc.exe” -arch sm_10 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin” -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -maxrregcount=32 --compile -o Release\sample.cu.obj sample.cu

Remarks: Setting a flag /O0 or commenting lines in main() leads to normal compilation.

The same code is successfully compiled inside a *.cpp file by Microsoft and Intel compilers.

Authors: Denis Sabitov, Anatoly Vershinin

All rights reserved.


*********/

#include <stdio.h>

void main(void)

{

for(int i = 0; i < 10; i++)

	if (i > 1) 

	{

		for (int j = 0; j < 10; j++)

			printf("%d",i);

		while(1);

	}

}[/codebox]

Compiles without a problem with 2.1 under Server 08.

P.S. Please take out the copyright notices for simple code that does nothing.

I tired to compile it on several Microsoft systems and observed the hang problem. Can you fully describe your operating system and version of Microsoft compiler to help me reproduce your successful result?

Windows Server 2008 x64 Enterprise

CUDA toolkit 2.1 x64

CUDA SDK 2.1 x64

Visual Studio 2005 v8.0.50727.867

I think your problem might be related to using the /O2 flag in a Debug configuration. Enabling certain optimizations concurrently with debug information may annoy the compiler. /RTC* and /O* are particular nemeses. I don’t know why nvcc would hang, but select a Release configuration, and see if that leads anywhere.

I tried to compile it in both Debug and Release versions with CUDA 2.1 x64 on MS Server 2003 SP2 and 2008 HPC SP1, VS 2005 8.0.50727.762 and 2008 9.0.21022.8.
Compiler hangs permanently.
Some other people reported me on unsuccessful compiling on x64 platforms. In fact you are the first one whom I know who is able to compile this sample with nvcc.

I was able to repro your problem with the following aruments:
“$(CUDA_BIN_PATH)\nvcc.exe” -arch sm_10 -ccbin “$(VCInstallDir)bin” -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -maxrregcount=32 --compile -o $(ConfigurationName)\sample.cu.obj sample.cu

The answer is pretty simple. Take out the /O2 flag (no idea why it causes the hang). If you need the performance optimizations to work, then compile your CPU code in a .cpp file.

It’s better to have as little as possible in .cu files; just keep your essential GPU functions there (kernels and kernel callers, and maybe some device memory management). This way, if you change compilers to, let’s say Intel C++, you’ll compile more code with the new compiler. That being said, ‘main’ has no business in a .cu file.

Yes, I also mentioned that /O2 is the key for this example :).
The idea to remove as much as possible code from .cu files is generally helpful. Thanks for the advice!

I started doing that when my .cu files were becoming cluttered, and Intellisense didn’t work there. Make sure to include “cuda_runtime.h” in your cuda .cpp (or .c) files. I got a headache figuting out what files to include.