‘checkCudaErrors’ was not declared in this scope

Viewed 1998

I wrote a new CUDA program, but when I compile, I get an error 'checkCudaErrors' was not declared in this scope. So I added #include "helper_cuda.h",but I still had the same problem.

I opened the file, helper_cuda.h, with Visual Studio Code and found that most of this file is gray. The problem was I did not have the defination __DRIVER_TYPES_H__, so I added #include "driver_types.h". But it was useless. In the file, driver_types.h, it showed that I already had the definition __DRIVER_TYPES_H__. How can I fix it?

So the real problem is that, the file, driver_tyeps.h, shows I already had the definition of __DRIVER_TYPES_H__, but helper_cuda.h shows I don't have the definition.

2 Answers

I have solved my problem by changing the order of include statement. At first, my program was like this:

    #include "helper_cuda.h"
    #include "driver_types.h"

But now, it is:

    #include "driver_types.h"
    #include "helper_cuda.h"

I don't konw why, but it just works.

You have to define it yourself like this:

#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)
Related