Visual Studio looking for stub.c file to debug cuda kernel

Using visual studio 2022 and cuda-12, when I want to step-in to the kernel for debugging, I see an “open dialog” window is open looking for a file called foo.stub.c. There is no such file in the project folder and I am wondering how that file is created.

The complete code is shown below

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>
#define checkCudaErrors(call)                                 \
  do {                                                        \
    cudaError_t err = call;                                   \
    if (err != cudaSuccess) {                                 \
      printf("CUDA error at %s %d: %s\n", __FILE__, __LINE__, \
             cudaGetErrorString(err));                        \
      exit(EXIT_FAILURE);                                     \
    }                                                         \
  } while (0)
void print(int* a, int N)
    for (int i = 0; i < N; i++)
        std::cout << a[i] << " ";
    std::cout << "\n";

__global__ void increment(int* a, int N)
    int i = threadIdx.x;
    if (i < N)
        a[i] = a[i] + 1;

int main(int argc, char* argv[])
    int M = 1;
    int N = 64;
    int *h_a = new int[N];
    for (int i = 0; i < N; i++)
        h_a[i] = i;
    print( h_a, N );

    int* d_a;
    cudaMalloc((void**)&d_a, N * sizeof(int));
    cudaMemcpy(d_a, h_a, N * sizeof(int), cudaMemcpyHostToDevice);

    dim3 grid_size(M); dim3 block_size(N);
    increment <<< grid_size, block_size >>> (d_a, N);
    cudaMemcpy(h_a, d_a, N * sizeof(int), cudaMemcpyDeviceToHost);
    print( h_a, N );

    return 0;

I didn’t find information about stub.c file on the web. Any thoughts on that?

I tried your code in a simple project and did not see this behavior, I am wondering if it could be something in your project settings. Can you attach the .vcxproj file for the project that reproduces this?

I have found the same problem when using visual studio 2022 and cuda11.6,and I don’t know how to solve this problem