提问者:小点点

检查(调用)函数在Google Colab中获得错误[重复]


我刚刚从CUDA中普通的check(call)函数复制了一个函数,并在Google Colab中使用nvcc_plugin运行

#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);
    }
}

但会引发一个错误

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

我该怎么做?


共1个答案

匿名用户

#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);\
    }\
}

如果你想要一个多行宏,你必须添加反斜杠。