0

I just copied a function from normal CHECK(call) function in CUDA and run with nvcc_plugin in Google Colab

#define CHECK(call)
{
    const cudaError_t error = call;
    if (error != cudaSuccess)
    {
        printf("Error: %s:%d, ", __FILE__, __LINE__);
        printf("code:%d, reason: %s\n", error, cudaGetErrorString(error));
        exit(1);
    }
}

But it raises an error

/tmp/tmpvc2kvnuh/9c0f913f-6a2c-420d-9e3a-94c6e3123f7f.cu(9): error: expected a declaration 

How do I do this?

talonmies
  • 70,661
  • 34
  • 192
  • 269
Minh-Thanh Hoang
  • 542
  • 7
  • 21

1 Answers1

2
#define CHECK(call) \
{\
    const cudaError_t error = call;\
    if (error != cudaSuccess)\
    {\
        printf("Error: %s:%d, ", __FILE__, __LINE__);\
        printf("code:%d, reason: %s\n", error, cudaGetErrorString(error));\
        exit(1);\
    }\
}

You have to add backslashes, if you want to have a multi-line macro.

JCWasmx86
  • 3,473
  • 2
  • 11
  • 29