Error 0xC0000005 with cudafe++ with a very simple code

I wrote a very simple code:

#include <cuda_runtime.h>
#include <stdio.h>
__global__ void kernel() { 
     printf("Ciao dal kernel CUDA!\n"); 
} 
int main() { 
     kernel<<<1,1>>>(); 
     cudaDeviceSynchronize(); 
     return 0; 
}

but it doesn’t work, the error is: nvcc error : ‘cudafe++’ died with status 0xC0000005 (ACCESS_VIOLATION)

OS: Windows 11
Version of CUDA: 12.04
GPU: RTX 4060
how I compile: nvcc kernel.cu -o kernel.exe
Version of driver: 576.57Preformatted text

Please format your code, otherwise the underscores e.g. of __global__ will not be shown.

The code is actually well formatted, but in the forum it looks like __global__ is shown in bold due to the double underscores being interpreted that way.
So yes, __global__ is there, just visually emphasized.
Thanks anyway!

Here’s one method to properly format code for display in this forum:

  1. click the pencil icon beneath the post, to edit the post
  2. select the code in the post
  3. click the </> button at the top of the edit pane
  4. save your changes

I did it, but I guess the problem isn’t the code.

This does not seem right:

kernel<>>();

Try kernel<<<1, 1>>>(); instead.

There should not be an access violation, even with wrong code.
But many people are successfully running very similar code.
So it can be both. Wrong code and another bug in the Cuda compiler.
It is either your code or your Cuda Toolkit installation (combined with the compiler bug).

In the code that i wrote there’s kernel<<<1, 1>>>();not kernel<>>();

I agree it is probably not the code. This error often indicates that either your CUDA Toolkit install is somehow broken, or else the paths used to select the host compiler are not correct. When you set up a machine to compile from the command line in windows, its very important that PATH variables in windows be set correctly (and that the compile command itself is issued correctly.)

What I usually advise is that people who are unfamiliar with this start by validating/verifying that the CUDA toolkit install is “correct” by compiling a sample project using the Visual Studio GUI. If that is working correctly, then study the VS console to learn the exact format of a proper compilation command (this will explicitly specify paths to compilers and etc.) Then work on getting your command-line compilation settings based on that.

If any of this is not working, you have an installation/setup issue. Questions about that belong in a different forum: CUDA Setup and Installation - NVIDIA Developer Forums

People run into this particular error from time to time, so you can find other forum reports with specific descriptions.

Thanks man you are an angel for me, now it’s working. Respect

Can you tell, what specifically helped?

The problem was that to compile .cu you didn’t just use nvcc kernel.cu -o kernel but a big build script that Visual Studio did when you pressed “RUN”.

Normally under Windows there is a special Visual Studio Console setting all the right environment variables for calling the MS Visual Compiler.

But if that is enough for an exception in cudafe, then I would call it a bug.