cuda - 如何隐藏 NVCC 的 "function was declared but never referenced"警告?

标签 cuda googletest nvcc

编译使用 Google Test 的 CUDA 程序时,nvcc将发出误报警告:

function <name> was declared but never referenced



一个 MCVE:
// test.cu
#include <gtest/gtest.h>

namespace {

__global__ void a_kernel() {
    printf("Works");
}

TEST(ExampleTest, ExampleTestCase) {
    a_kernel<<<1, 1>>>();
}

}

编译它给出:
$ nvcc test.cu -lgtest -lgtest_main
test.cu(9): warning: function "<unnamed>::ExampleTest_ExampleTestCase_Test::ExampleTest_ExampleTestCase_Test()" was declared but never referenced

这在 google test 和 CUDA 9.1 的 master 分支中得到了确认(我相信它是从 CUDA 9.0 开始发生的,并且该错误在 CUDA 8.0 中不存在)。如果测试在全局命名空间中,则不会发生此问题。

有没有办法禁用这些警告?我知道我可以使用 -w禁用 全部 警告,但我想保留其他类型的警告。

最佳答案

你可以试试蛮力的方式:

   #pragma push
   #pragma diag_suppress 177 // suppress "function was declared but never referenced warning"

   .. your function ..

   #pragma pop

关于cuda - 如何隐藏 NVCC 的 "function was declared but never referenced"警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49836419/

相关文章:

c++ - .cu 源文件中默认包含哪些 header ?

cuda - CUDA共享内存是否也被缓存

python - 如何将二维数组传递到 pycuda 中的内核?

c++ - 从构建中排除文件(自定义和临时)

c++ - 在谷歌模拟中返回对 unique_ptr 的引用

CUDA 和 nvcc : using the preprocessor to choose between float or double

c - 未定义对 `setup(int, char**)' 的引用

cuda - 在 CUDA 中,我们如何调用另一个翻译单元中的设备函数?

linux - CUDA 链接器错误 : undefined reference to main

c++ - 使用 std::shared_ptr 检测循环引用